Using alias parameters with class members in CTFE (related to UDAs)

Johannes Pfau nospam at example.com
Tue Jul 23 13:26:08 PDT 2013


Does anyone know why this code is not working?
http://dpaste.dzfl.pl/b89e7b3f

It seems calling "enum a = __traits(getAttributes, Class.member);" is OK
without an instance. But if I wrap the __traits call into another
template with alias parameter like this:

-----------
auto getAttribute(alias target)()
{
    return __traits(getAttributes, target)[0];
}
-----------

I can no longer call it at compile time ("enum b =
getAttribute!(Class.member)").


What I want to do ultimately is assigning special values to all class
members which have a specific UDA while avoiding runtime overhead as
much as possible. In pseudo code:

------------
instance i1;

static foreach member in i1
    static if i1.hasUDA(UdaType)
        member = specialValue();
------------

Should compile down to only this:
instance i1;

i1.member1 =  specialValue();
i1.member2 =  specialValue();
i1.member3 =  specialValue();


More information about the Digitalmars-d-learn mailing list