On Sunday, 14 June 2015 at 10:29:09 UTC, anonymous wrote:
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 */
----
So if i want to use parameters in a static context at compile
time i have to pass them as template parameters?
That would explain my problems. Thanks