bug in tupleof ?
Derek Parnell
derek at nomail.afraid.org
Wed Mar 7 22:32:30 PST 2007
On Thu, 08 Mar 2007 00:51:05 -0500, Guillaume Chereau wrote:
> Is that normal that this very simple code :
...
> Is it a bug in the compiler, or I am missing something about properties ?
I'm not sure if its a bug or not, but I have an explanation <G>
Have a look at this modified code ...
import std.stdio;
class Test {int i; float x;}
int main()
{
auto t = new Test();
t.i = 10;
t.x = 4.2;
writefln("(%s, %s)", t.tupleof);
// define the tuple and show it contains .init values.
auto f = t.tupleof;
writefln("(%s, %s)", f);
// update the tuple's fields.
f[0] = 9;
f[1] = 2.4;
writefln("(%s, %s)", f);
// show that the object hasn't changed.
writefln("(%s, %s)", t.tupleof);
// Now assign values back into the object.
t.tupleof[0] = f[0];
writefln("(%s, %s)", t.tupleof);
t.tupleof[1] = f[1];
writefln("(%s, %s)", t.tupleof);
return 0;
}
When you code "writefln(t.tupleof)" the compiler seems to convert that into
"writefln(t.i, t.x)", but when you code "auto f = t.tupleof" the compiler
seems to convert that into a tuple instance based on the datatypes in the
Test class, and does not use the data values that the 't' instance
contains.
The variable 'f' can be thought of a fixed length array but in which each
element has a different datatype.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
8/03/2007 5:23:29 PM
More information about the Digitalmars-d-learn
mailing list