Dealing with raw types as attributes

Nicholas Wilson iamthewilsonator at hotmail.com
Fri Nov 2 04:01:00 UTC 2018


On Friday, 2 November 2018 at 03:13:19 UTC, Neia Neutuladh wrote:
> On Fri, 02 Nov 2018 00:36:18 +0000, Nicholas Wilson wrote:
>>> What do you do to handle this?
>> 
>> @Foo() int bar;
>> 
>> instead of
>> 
>> @Foo int bar;
>
> Right. And if you're offering a library with UDAs for other 
> people to use?

I mean I suppose if you really wanted to avoid the parentheses, 
you could do

   static foreach (uda; __traits(getAttributes, bar))
   {
     static if (is(typeof(uda.init) == Foo)
     {
       pragma(msg, "bar is @Foo");
     }
   }

By noting that all (interesting for the purpose of UDA's i.e. not 
void) types have a .init

or you could do

static if (is(typeof(uda) == Foo) || is(uda == Foo))


More information about the Digitalmars-d-learn mailing list