On Sunday, 14 June 2015 at 10:10:51 UTC, ketmar wrote:
i.e. when it need a value in compile time. the interpreter is
invoked, it evaluates (interprets) the given code (function or
template instantiation), and then it returns result (or raises
an error).
One important thing I didn't see stated clearly by anyone in here:
CTFE may run at compile time but it follows the same rules as run
time evaluation (plus some restrictions).
This means, you can't use dynamic values (e.g. function
parameters) in static contexts (e.g. __traits).
Example:
----
int f(int x)
{
if (__ctfe)
{
enum e = x; /* nope, not even during CTFE */
alias t = some_template!x; /* nope */
pragma(msg, x); /* nope */
}
return x;
}
enum result = f(1); /* CTFE-ing f */
----