CTFE determination?

bmeck bmeck at stedwards.edu
Fri Sep 12 14:05:30 PDT 2008


I just get both at run time with your example. I was hoping to encapsulate it somehow so you could just have:

import std.stdio;

void main(string[] args)
{
        
        writefln("test");

        static if (CompileTimeAvailable!("123"))
                writeln("123 compile");
        else
                writeln("123 run");

        static if (CompileTimeAvailable!(args[0]))
                writeln("args[0] compile");
        else
                writeln("args[0] run");

}
template CompileTimeAvailable(alias expr)
{
    static if(__traits(compiles, CompileTime!(expr)))
        CompileTimeAvailable = false;
    else
        CompileTimeAvailable = false;
}
template CompileTime(alias Expr)
{
   auto CompileTime = Expr;//Need this to force it to check for CTFE
}

unfortunately args[0] is not constant so no go...



More information about the Digitalmars-d mailing list