C++ Logo


Advanced search

Re: std::parent_of_member

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sat, 6 Nov 2021 10:44:11 -0400
On Sat, Nov 6, 2021 at 10:21 AM connor horman via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> On Fri, 5 Nov 2021 at 20:27, Lénárd Szolnoki via Std-Proposals <std-proposals_at_[hidden]> wrote:
>> Hi,
>> I don't think a non-UB implementation is possible here. I have the impression that the pointer to the parent type is intentionally unreachable and in theory compilers are allowed to optimize based on that.
> If it's a standard library function, there's always an implementation: __builtin_parent_of_member
> That being said, isn't this undefined behaviour anyways for anything other than the first member of a standard-layout type? Either that or the definition of reachability would have to be extended to include pointers to any subobject.

I don't really see how it matters within the context of a standard
library *proposal*. The function does what it says it does: it returns
a reference to the parent type of a class given a pointer-to-member
object of that class and a reference to a member object instance of
that class.

How it does this is sophistry.

Received on 2021-11-06 09:44:26