Getting all struct members and values with introspection avoiding string mixins

ParticlePeter via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 1 02:42:37 PDT 2016


I am logging arbitrary POD struct types with member names and 
data:

void printStructInfo( T )( T info ) {
   foreach( i, A; typeof( T.tupleof )) {
     enum attribName = T.tupleof[i].stringof;
     writefln( "%s : %s", attribName, mixin( "info." ~ attribName 
));
   }
}

Is there is some other way to evaluate info.attribName without 
using string mixins?

Cheers, PP



More information about the Digitalmars-d-learn mailing list