__traits getMember is context sensetive?

JDemler via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 14 03:16:23 PDT 2015


On Sunday, 14 June 2015 at 10:04:35 UTC, John Colvin wrote:
> On Sunday, 14 June 2015 at 09:46:56 UTC, JDemler wrote:
>> On Sunday, 14 June 2015 at 05:52:00 UTC, ketmar wrote:
>>> oh, seems that i managed to make everything even less 
>>> understandable...
>>
>> Your code works perfectly and makes at least some sense to me. 
>> Thank you.
>>
>> If i understand it correctly: __traits-time = 
>> templateinstatiation-time = pragma-time before ctfe-time?
>
> Not really. These things are just (conceptually) done as/when 
> they are required. If a template instantiation needs to do ctfe 
> to calculate it's result, it does it. If some code running in 
> ctfe needs the result of a template, it instantiates it.
>
> The only distinction you have to think about is compile-time vs 
> run-time, with the caveat that ctfe code is run as if it were 
> run-time, but the result can be used at compile-time. If you 
> imagine ctfe as being "compiling the function, running it, 
> getting the answer and copying it in to your code" then even 
> that distinction goes away and you just have ct vs rt.

If that is the case then i really do not get why my first example 
compiles and my second does not.

The compiler sees the pragma(msg, test(e)) and runs test(e).
If test uses __traits it does not work if it does not it works.

If __traits is just another ctfe function i dont see the 
difference.


More information about the Digitalmars-d-learn mailing list