Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct Foo
- {
- int a;
- int b;
- };
- template<typename T, typename Struct>
- constexpr size_t offset_of(T Struct::*member) {
- using pointer = Struct*;
- return size_t(&(pointer(nullptr)->*member));
- }
- enum : size_t {
- offset_of_Foo_a = offset_of(&Foo::a),
- offset_of_Foo_b = offset_of(&Foo::b),
- };
- int main() {
- std::cout<< "offset_of_Foo_a: " << offset_of_Foo_a << "\n";
- std::cout<< "offset_of_Foo_b: " << offset_of_Foo_b << "\n";
- return 0;
- }
Add Comment
Please, Sign In to add comment