Compiler bug ?

Kenji Hara k.hara.pg at gmail.com
Sun Jun 9 08:49:11 PDT 2013


On Sunday, 9 June 2013 at 13:37:45 UTC, Temtaime wrote:
> Hello guys!
>
> It seems that it is bug. And critical for me.
> http://dpaste.1azy.net/b93f5776
>
> Regards.

The code should be rejected. It's a compiler bug.
But, you can do what you want as follows.

import std.stdio, std.typetuple;

struct A {
     @("1") int a;
     @("2") int b;
     @("3") int c;
}

auto bar(alias expr)() @property {
     writeln(expr);
}

void main() {
     A a;

     foreach(it; __traits(allMembers, A))
     {
         enum tp = [__traits(getAttributes, mixin(`a.` ~ it))];
         // or
         alias tp = TypeTuple!(__traits(getAttributes, mixin(`a.` 
~ it)));

         writeln(`passing: `, tp[0]);
         bar!(tp[0])();
     }
}

Kenji Hara


More information about the Digitalmars-d-learn mailing list