__traits getMember is context sensetive?
JDemler via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 14 03:41:23 PDT 2015
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
More information about the Digitalmars-d-learn
mailing list