Need help with movement from C to D

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 5 10:55:35 PDT 2014


On Monday, 5 May 2014 at 04:05:35 UTC, Mark Isaacson wrote:
> Something like:
>
> unittest {
>   enum offsetof(string type, string field) = mixin(type ~ "." ~ 
> field ~ ".offsetof");
>
>   struct StrToBob {
>     string str;
>     int bob;
>   }
>
>   writeln(offsetof!("StrToBob", "bob"));
> }
>
> ?
>
> If not that then I'm not sure what you're asking for.

That enum template might be better like this:

enum offsetof(T, string field) = mixin(type.stringof ~ "." ~ 
field ~ ".offsetof");

To ensure that a syntactically valid symbol is passed as the type.


More information about the Digitalmars-d-learn mailing list