On Sunday, 25 March 2012 at 15:24:18 UTC, Jacob Carlborg wrote:
On 2012-03-22 02:23, Tove wrote:

mixin(attr(q{struct Foo
{
@NonSerialized int x;
@NonSerialized int y;
int z;
}}));

void main()
{
auto m = [ __traits(allMembers, Foo) ];
writeln("Normal members of Foo:", m);

auto n = [ __traits(allMembers, Foo_Serializable) ];
writeln("Serializable members of Foo:", n);
}


Just really ugly and it creates a new type, completely unnecessary if D supported user defined attributes.

Well... "eye of the beholder"... I think that's exactly the beautiful part, because:
1) The original type is 100% unaltered...
2) Easy for the compiler to optimize the new type away as it's never instantiated, nor used beyond ctfe reflection i.e. 0 runtime overhead. 3) It trivially allows using the built-in traits system everyone already is familiar with.

but I wonder if one can do better with a mixin template, accessing it's "parent"...

Reply via email to