Phobos Members-Tuple function?

Timon Gehr timon.gehr at gmx.ch
Sat Jan 19 19:26:31 PST 2013


On 01/20/2013 03:41 AM, Ali Çehreli wrote:
> ...
> void main()
> {
>      auto ship = new Ship;
>      alias T = typeof(ship);
>
>      foreach (m; __traits(allMembers, T))
>      {
>          writefln("member %s", m);
>
>          enum atrs = __traits(getAttributes, mixin(T.stringof ~ "." ~ m));

This only works because Ship happens to be defined in the same module. 
Use __traits(getMember, T, m) instead of the mixin.


>          foreach (a; atrs)
>          {
>              writefln("  attribute %s", a);
>              if (is(typeof(a) == Bind))
>                  Engine.bindActors(ship, a.pattern);
>          }
>      }
> }
>
> Ali
>



More information about the Digitalmars-d-learn mailing list