I have some code looking like this. I don't understand why I can use a string mixin together with __traits(getAttributes) when it doesn't work if I use the template "getAttributes".

template Tuple (T...)
{
    alias T Tuple;
}

struct Foo
{
    @(3) int a;
}

template getAttributes (alias s)
{
    alias Tuple!(__traits(getAttributes, s)) getAttributes;
}

void main ()
{
    Foo foo;
    writeln(__traits(getAttributes, mixin("foo.a")));

    // Error: variable foo cannot be read at compile time       
    // writeln(getAttributes!(mixin("foo.a")));

    writeln(getAttributes!(foo.a));
    mixin(`writeln(getAttributes!(foo.a));`);
}

--
/Jacob Carlborg

Reply via email to