template UDA

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 7 15:03:09 PDT 2015


On Monday, 7 September 2015 at 22:00:07 UTC, bitwise wrote:
> Is there any real(and plausible) use case where providing a 
> template with no argument as a UDA would be useful?

Yes, you actually wrote it yourself!

> @MyAttribute!SomeClass class SomeClass { }

That right there is a reason. When you are looking for UDAs, you 
look for declarations. The usage code looks like:

foreach(member; getMembers!module)
   if(member.hasUDA!(MyAttribute)) {
       // do something
   }


The beauty of it is that member is right there! So your 
reflection code could instantiate it right there:

   // do something becomes...
   MyAttribute!(member);

so it instantiates the template with the given member in the 
reflection code itself.



More information about the Digitalmars-d mailing list