__traits(getAttributes) with string mixin
Jacob Carlborg
doob at me.com
Mon Jan 7 11:40:27 PST 2013
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
More information about the Digitalmars-d
mailing list