Get attributes of type by string name
Jacob Carlborg
doob at me.com
Tue Aug 6 04:51:36 PDT 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
More information about the Digitalmars-d-learn
mailing list