Is it possible to force CTFE?

Tommi tommitissari at hotmail.com
Sun Jun 10 00:04:18 PDT 2012


Three related questions:

1) Is there a way to force a function to be always executed at 
compile time (when it's possible to do so) no matter what context 
it's called in?

2) Is it possible to specialize a function based on whether or 
not the parameter that was passed in is a compile time constant?

3) Does any D compiler currently optimize out a conditional 
branch which _can_ be evaluated at compile time (but which isn't 
forced into CTFE)? Like:

int getValue(bool b)
{
     return b ? 123 : 456;
}

//...
    auto value = getValue(true);


More information about the Digitalmars-d-learn mailing list