On Tuesday, 10 June 2014 at 16:13:31 UTC, Adam D. Ruppe wrote:
Two options: do allMembers and filter it out to only be data
members, or do some slicing of tupleof.stringof:
S s;
foreach(idx, member; s.tupleof) {
writeln("Name: ", s.tupleof[idx].stringof[2..$]);
}
The tupleof[idx] inside the loop is important instead of just
using member because then you get the name, then the slicing is
because you get:
s.foo
for example, and you want to slice off the "s." to leave just
the name.
You may not want to use stringof for this, because stringof is
explicitly defined as being able to change across versions, and
no actual format is defined. Instead use __traits(identifier,
s.tupleof[idx]).
Also note that .tupleof will not return static fields.