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

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 14 08:03:59 PDT 2015


On Monday, 14 September 2015 at 14:21:12 UTC, John Colvin wrote:
> On Monday, 14 September 2015 at 14:05:01 UTC, Laeeth Isharc 
> wrote:
>> On Sunday, 13 September 2015 at 17:34:11 UTC, BBasile wrote:
>>> On Sunday, 13 September 2015 at 17:24:20 UTC, Laeeth Isharc 
>>> wrote:
>>>> [...]
>>>
>>> can't you use 'hasMember' (either with __traits() or 
>>> std.traits.hasMember)? It's more idiomatic than checking if 
>>> it's compilable.
>>
>> I'll check again in a bit, but I seem to recall hasMember 
>> didn't work.  I would like to get the type of a member of a 
>> type, and I think hasMember!(T.bar.date","hour") didn't work 
>> for that.  Possibly it does work and I messed it up somehow, 
>> or it doesn't work and there is a more elegant way.
>
> You mean hasMember!(typeof(T.bar.date), "hour"), right?

Ahh.  Probably that was why (I will check it shortly).  Why do I 
need to do a typeof?  What kind of thing is T.bar.date before the 
typeof given that T is a type?



More information about the Digitalmars-d-learn mailing list