DMD tells me "Error: variable m cannot be read at compile time", but why ?

[code]
struct MyStruct {
        float float_value = 0.0f ;
        ubyte ubyte_value = 2 ;
}

enum members = [ __traits( allMembers , MyStruct ) ] ;

foreach( m ; members )  {
mixin( "writeln( " ~ m ~ " , \" : \" , ( MyStruct." ~ m ~ ".offsetof ) ;" ) ;
}
[\code]

I also tried ref m and foreach( i ; 0..members.length ) with m[i]. A simple writeln( m or m[i] ) always worked. I read the limitation of "String Mixins and Compile Time Function Execution" here: http://dlang.org/function.html#interpretation But it doesn't make sense to me as members are enum values and known at compile time.

What am I doing wrong, and how could it be done ?

Regards, ParticlePeter

Reply via email to