Detecting manifest contants

Anonymouse zorael at gmail.com
Sat Mar 12 18:49:32 UTC 2022


I'm introspecting structs, and I ran into an issue where  
`__traits(derivedMembers)` includes manifest constant enums in 
the returned tuple.

What is the correct way to statically detect these? The immediate 
thing that springs to mind is `is(symbol == enum)`, but it's not 
it.

Currently I'm testing if a function that takes the address of the 
member compiles, and I think it works, but like with everything 
`__traits(compiles)` it strikes me as it might not be the right 
way to go about things.

```d
struct Foo
{
     int i;
     enum k = 42;
}

void main()
{
     foreach (memberstring; __traits(derivedMembers, Foo))
     {
         static if (__traits(compiles, { Foo f; auto ptr = 
&__traits(getMember, f, memberstring); }))
         {
             // ...
         }
     }
}
```

What else can I try?


More information about the Digitalmars-d-learn mailing list