how do I check if a member of a T has a member ?

BBasile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 13 10:34:09 PDT 2015


On Sunday, 13 September 2015 at 17:24:20 UTC, Laeeth Isharc wrote:
> On Sunday, 13 September 2015 at 17:09:57 UTC, wobbles wrote:
>> Use __traits(compiles, date.second)?
>
>
> Thanks.
>
> This works:
>
> static if (__traits(compiles, { T bar; bar.date.hour;}))
> 		pragma(msg,"hour");
> 	else
> 		pragma(msg,"nohour");
> 	

can't you use 'hasMember' (either with __traits() or 
std.traits.hasMember)? It's more idiomatic than checking if it's 
compilable.


More information about the Digitalmars-d-learn mailing list