Need help with movement from C to D

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 6 04:29:45 PDT 2014


On Tuesday, 6 May 2014 at 11:09:37 UTC, Andrey wrote:
> On Monday, 5 May 2014 at 17:55:37 UTC, Meta wrote:
>
>>
>> enum offsetof(T, string field) = mixin(type.stringof ~ "." ~ 
>> field ~ ".offsetof");
>>
>> To ensure that a syntactically valid symbol is passed as the 
>> type.
>
> Interestingly, but this code doesn't compile:
>
> enum offsetof(typenfield) = mixin(type.stringof ~ ".offsetof");
>
> writeln(offsetof!(StrToBob.bob));

That's because `StrToBob.bob.stringof` is "bob". You can use this 
instead:

     import std.traits;
     enum offsetof(alias typenfield) =
         mixin(fullyQualifiedName!(typenfield) ~ ".offsetof");


More information about the Digitalmars-d-learn mailing list