iterate traits ?

ddos via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 19 11:15:33 PDT 2014


Hi,

i'm trying to create a dynamic vertex format for opengl, defined 
at compiletime by a struct

e.g. struct Vertex {float[3] position, float[3] normal}

i can get the name of all members with this:
auto b = [ __traits(allMembers, VertexType) ];

but i can't iterate them at compiletime because there is no 
static foreach?
foreach(e; b) {
   alias tt = typeof(__traits(getMember, VertexType, e)); // not 
working
   writeln(tt.sizeof);
}

since i need to setup vertexpointers for opengl at runtime my 
next question? - is it possible to evaluate the traits also at 
runtime? but i'd also like to know how i can iterate them at 
compiletime

thx in advance :)


More information about the Digitalmars-d-learn mailing list