3 ms·
Rather than storing the offset within the struct, you could store a type-erased pointer to data member: struct M { std::byte M::*p; std::si
by scatters 6y ago
Rather than storing the offset within the struct, you could store a type-erased pointer to data member:
struct M {
std::byte M::*p;
std::size_t l;
template<class C, class T>
M(T C::*e) : p{reinterpret_cast<std::byte M::*>(e)}, l{sizeof(T)} {}
};
Also there are ways (not necessarily legal) to convert a pointer to data member to an offset; see the proposal http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0908r0.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p090...