iterate traits ?
Philippe Sigaud via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 19 11:33:53 PDT 2014
>> A foreach becomes compile-time whenever the aggregate is a purely compile-
>> time construct such as a tuple.
Yeah, I think you transformed it into a runtime array by using [ ...
]. Tuples with compatible types can be 'downgraded' to arrays that
way. But there is no need to: tuples are iterable, indexable and
slice-able in D.
import std.stdio;
struct Vertex {float[3] position; float[3] normal;}
void main() {
foreach(e; __traits(allMembers, Vertex)) {
alias tt = typeof(__traits(getMember, Vertex, e)); // worksforme
writeln(tt.sizeof);
}
}
More information about the Digitalmars-d-learn
mailing list