Dealing with raw types as attributes

Stanislav Blinov stanislav.blinov at gmail.com
Thu Nov 1 20:50:03 UTC 2018


On Thursday, 1 November 2018 at 20:33:10 UTC, Neia Neutuladh 
wrote:
> On Thu, 01 Nov 2018 20:01:51 +0000, Stanislav Blinov wrote:
>> Check if an UDA is a type?.. As in, not just `is(uda == Foo)`,
>> but simply `is(uda)`:
>
> Which works, but generally makes things more complex in code 
> that's already pretty deeply nested. It's also something I have 
> to worry about every time I do the static foreach to get UDAs, 
> in the cases where that's more than once.

Yes, it does :(

>  I could use a customized version of [getUDAs] that replaces 
> @Type with @Type.init, and that's a reasonable choice...

That can't be generic, as you can have UDAs that don't have an 
.init:

enum XXX;

@XXX int bar;

static foreach (uda; __traits(getAttributes, bar)) {
     static if (is(uda == XXX)) {
         pragma(msg, "bar is XXX");
     }
}

...but so long as you can live without such UDAs, I guess it 
could work.


More information about the Digitalmars-d-learn mailing list