Compile time function execution...
Walter Bright
newshound at digitalmars.com
Thu Feb 15 13:00:37 PST 2007
Michiel wrote:
> That's a great feature! A couple of questions, if I may:
>
> * Can sqrt still call another function?
Yes, as long as that function can also be compile time executed.
Recursion works, too.
> * Does it still work if classes or structs are involved in any way? What
> about enums? What about arrays?
No, yes, array literals only.
> * Why is the second sqrt(10) run at runtime?
Because the compiler cannot tell if it is a reasonable thing to try and
execute it at compile time. To force it to happen at compile time:
template eval(A...) { alias A eval; }
writefln("%s", eval!(sqrt(10)));
which works because templates can only take constants as value arguments.
> In theory it's still a
> constant, right?
No.
> Is this something that will work in a later version?
I don't see a motivating reason why, at the moment, given the eval template.
More information about the Digitalmars-d
mailing list