On 08/05/2011 19:19, Lutger Blijdestijn wrote:
test also doesn't compile normally on my box, dmd errors on Foo.tupleof. Not
sure if this is illegal or not. I think you want the allMembers trait or
something similar. Something like this:

import std.traits;

string test(T)()
{
     string str = "struct " ~ T.stringof ~ "_{";
     alias FieldTypeTuple!T FieldTypes;
     foreach (i, fieldName; __traits(allMembers, T ) )
     {
         str ~= FieldTypes[i].stringof ~ " " ~ fieldName ~ ";";
     }
     return str ~ "}";
}

This works for your example but is a bit crude, I'm sorry for that, you'll
have to modify it. ( allMembers also returns functions, including ctors
while FieldTypeTuple doesn't. I also haven't read anything about the order
in which FieldTypeTuple and allMembers return their elements )

This seems to do what I need, thanks! :D

--
Robert
http://octarineparrot.com/

Reply via email to