The offsetof(type, member)
returns the offset value in bytes from the beginning of the layout of type
to its member
.
I am pretty sure the language does not provide a way to do the reciprocal: a memberof(type, offset)
to go from a type and offset to a pointer to member. Is there a way to achieve that? Without abusing the language? In a cross-platform way? In a constexpr way?
struct my_type_t type {
var_type_t m_var;
};
I can do:
size_t offset_in_bytes = offsetof(my_type_t, m_var);
I am looking for:
var_type_t my_type_t::* ptr_to_var_member = memberof(my_type_t, offset_in_bytes);