tell if __traits(allMembers, ... ) is an enum (not manifest constant)

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 24 20:50:14 PST 2016


On Thursday, 25 February 2016 at 04:32:24 UTC, Adam D. Ruppe 
wrote:
> On Thursday, 25 February 2016 at 04:25:25 UTC, Nicholas Wilson 
> wrote:
>> foreach(m; __traits(allMembers, ...)
>> {
>>     static if(is(m== enum))
>> }
>
>
> That's close but not quite there... try
>
> static if(is(typeof(__traits(getMember, Item, m)) == enum))
>
> for member variables, or if you are looking at a type itself 
> youcan leave off the typeof() bit.

what is this black magic???

static if(is(typeof(__traits(getMember, vulkan_input, m)) == 
enum))
{
             writeln(typeof(__traits(getMember, vulkan_input, 
m))).stringof; //fails to compile
             writeln(m); //prints nothing
}



More information about the Digitalmars-d-learn mailing list