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.

Reply via email to