Need help with movement from C to D

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 6 07:24:46 PDT 2014


I'm not sure why you'd want to wrap the .offsetof expression in
a template, but it can easily be done like this:

   enum offsetOf(alias A, string S) = mixin("A."~S~".offsetof");


Keep in mind that D's offsetof is flawed - if the object does not
contain the requested member, but implicitly converts to another one
that does have such field then the expression compiles, but yields
a bogus value. Eg

   struct S { int a, b, c; S2 s2; alias s2 this; }
   struct S2 { int d, e; }
   static assert(S.e.offsetof==4); // Oops.

artur


More information about the Digitalmars-d-learn mailing list