Why it doesn't compile in D 2.0?
aarti_pl
aarti at interia.pl
Sat Jan 16 07:18:00 PST 2010
W dniu 2010-01-16 15:30, Lutger pisze:
>
> Perhaps this is or should be a bug. You can override dup to work in ctfe:
>
> char[] dup(string str)
> {
> return str.dup;
> }
>
> class Test {
> string t1 = "test"; //Ok!
> char[] t2 = "test".dup; //Compile error
> char[] t3 = "test".dup(); //Ok!
> }
>
> The spec even mentions it under ctfe:
>
> 6. as a special case, the following properties can be executed at
> compile time:
> ..dup
> ..length
> ..keys
> ..values
>
> http://www.digitalmars.com/d/2.0/function.html
>
Thanks! I will use function dup() as a workaround for now, and will put
bug to bugzilla.
I still wonder what has CTFE to do with this case. Do you know?
I am asking because it's not possible in general case to initialize all
variables in classes/structs and in global namespace.
E.g. I had to use:
Serializer!(TextArchive) serializer;
static this() {
serializer = new typeof(serializer);
}
to initialize serializer. I am wondering if with better CTFE we could
get it working?
BR
Marcin Kuszczak
(aarti_pl)
More information about the Digitalmars-d-learn
mailing list