Compile time features

qsdf via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 29 09:53:48 PDT 2015


On Thursday, 29 October 2015 at 15:14:13 UTC, Shammah Chancellor 
wrote:
> On Thursday, 29 October 2015 at 06:02:05 UTC, qsdf wrote:
>> On Thursday, 29 October 2015 at 02:43:59 UTC, Shammah 
>> Chancellor wrote:
>>> ....
>>
>> I agree with you on an aspect: writing code with __traits() 
>> often leads to a  cascade of "unfriendly", "cryptic", 
>> "undigest", static if and loops.
>>
>> However your examples are discutables:
>>
>> 1/ The symbol is not always a type, so to test it there is 
>> `if(is()){}`:
>>
>> ---
>> import std.stdio;
>>
>> enum hack(A...) = A;
>>
>> int main() {
>> 	foreach(member; __traits(allMembers, std.stdio)) {
>> 		pragma(msg, member);
>>         static if (is(member))
>> 		    alias sym = hack!(__traits(getMember, std.stdio, 
>> member))[0];
>> 	}
>> }
>> ---
>
> The point is that you cannot use is() without first using 
> getMember, but using __traits(getMember) before 
> __traits(compiles) generates an error.  In your example you're 
> trying to use `is` on a string, which does not work.

> ```

Right. I forgot to put the pragma message into the compile-time 
branch and I've been cheated by all the member list printed in 
the console...Gotta sleep before writing more craps.


More information about the Digitalmars-d mailing list