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

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


On Sunday, 13 September 2015 at 16:46:54 UTC, Laeeth Isharc wrote:
> can I check if a member of a T has a member without using a 
> mixin?
>
> hid_t createDataType(T)()
> if (__traits(isSame, TemplateOf!(T), PriceBar))
> {
> 	auto tid=H5T.create(H5TClass.Compound,T.sizeof);
> 	enum offsetof(alias type, string field) = mixin(type.stringof 
> ~"."~field~".offsetof");
> 	H5T.insert(tid, "date", offsetof!(T,"date"), 
> createDataType!(KalDate));
> 	static if(hasMember!(T,"open"))
> 		H5T.insert(tid,"open",offsetof!(T,"open"),mapDtoHDF5Type("double"));
> }
>
> I would like to check if date has a member called second.
>
> Thanks.

Use __traits(compiles, date.second)?


More information about the Digitalmars-d-learn mailing list