August 02, 2013 Get attributes of type by string name | ||||
---|---|---|---|---|
| ||||
how can I get the UDA's of a type that I only know by name and only in a CTFE. I would like to loop over an array of names passed to a me(I don't know their contents beforehand) and get the attributes. I've tried to use a mixin but I can't get the mixin to work on the string name... e.g., mixin("alias a = __traits(getAttributes, "~type~");"); |
August 06, 2013 Re: Get attributes of type by string name | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On 2013-08-02 03:02, JS wrote: > how can I get the UDA's of a type that I only know by name and only in a > CTFE. > > I would like to loop over an array of names passed to a me(I don't know > their contents beforehand) and get the attributes. > > I've tried to use a mixin but I can't get the mixin to work on the > string name... > > e.g., mixin("alias a = __traits(getAttributes, "~type~");"); You need to use a typetuple as well: import std.typetuple; enum attribute; @attribute struct Foo {} void main () { alias a = TypeTuple!(__traits(getAttributes, mixin("Foo"))); pragma(msg, a); } -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation