C++ Logo


Advanced search

Re: std::parent_of_member

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Sat, 6 Nov 2021 03:35:18 +0300
On 06/11/2021 03:12, Brian Bi via Std-Proposals wrote:
> `reinterpret_cast<uintptr_t>(std::addressof(reinterpret_cast<ParentType
> *>(0)->*member_ptr))` is UB. You have to use the magic `offsetof` macro.
> P1278 <http://wg21.link/p1278> proposes to add a similar non-macro facility.
> The problem is how to then perform the pointer arithmetic and convert the
> result into a pointer to the parent type. This cannot be done in user code
> in C++17, so even at runtime, it would require compiler magic. If P1839
> <http://wg21.link/P1839> gets accepted, it will be possible to implement it
> in user code.

I think this has already been discussed in this mail list: it won't be possible.

Received on 2021-11-05 19:35:36