digitalmars.D.learn - Get attributes of type by string name
- JS (7/7) Aug 01 2013 how can I get the UDA's of a type that I only know by name and
- Jacob Carlborg (12/19) Aug 06 2013 You need to use a typetuple as well:
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~");");
Aug 01 2013
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
Aug 06 2013