CTFE determination?
bmeck
bmeck at stedwards.edu
Thu Sep 11 21:14:44 PDT 2008
Hi i was messing around in D2 and noticed that the following always is saying that it is only at runtime even when the input is a constant... was wondering if there was a right way to do this.
import std.stdio;
void main(char[][] args)
{
writefln("test");
auto ct = test(cast(char[])"123");
auto rt = test(args[0]);
writefln(ct);
writefln(rt);
}
pure char[] test(char[] src)
{
// foo!(src);
static if(__traits(compiles,foo!(src)/*check for something only available at compile time...*/))
{
return ((cast(char[])"argument available at compiletime of '")~src~cast(char[])"'");
}
else
{
return (cast(char[])"argument available at runtime of '")~src~(cast(char[])"'");
}
}
pure template foo(char[] src)
{
const uint foo = src.length;
}
More information about the Digitalmars-d
mailing list