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