Looking for a workaround

Adam D Ruppe destructionator at gmail.com
Wed Apr 6 18:21:11 UTC 2022


On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat 
wrote:
> Any idea how to workaround that?

Works fine if you just use the language instead of the buggy 
phobos wrappers:

---
     struct MyUDA
     {
     }

     class A
     {
         @MyUDA int a;
     }

     class B : A
     {
         @MyUDA int b;
     }

     void main()
     {
         foreach(memberName; __traits(allMembers, B))
         foreach(attr; __traits(getAttributes, __traits(getMember, 
B, memberName)))
         static if(is(attr == MyUDA))
                 pragma(msg, memberName); // a, b
     }
---

So make a function that does that and applies whatever it is you 
need to apply and you're in business.

Note that it is `is(typeof(attr) == MyUDA)` if defined 
`@MyUDA(args)`.


More information about the Digitalmars-d-learn mailing list