C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Pointer to member of member

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Tue, 13 Jun 2023 20:37:04 +0100
On Tue, Jun 13, 2023, 18:46 Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Tuesday, 13 June 2023 07:46:08 PDT Arthur O'Dwyer via Std-Proposals
> wrote:
> > Rewritten to use names that are clearly members or types:
> > struct A { int x_, y_, z_; };
> > struct B { A a_; };
> > struct C { B b_; };
> > B C::*pb = &C::b_; // OK
> > int C::*px = &C::b_::a_::x_; // Proposed
> > int C::*py = &C::b_.a_.y_; // Maybe better syntax?
> > int C::*pz = (&C::b_).a_.z_; // Maybe even better syntax?
>
> I'd still prefer:
>
> int C:: *pmfx = &C::b_ + &B::a_ + &A::x_;
>
> That is,
> auto operator+(Member Base:: *pmo1, Submember Member::*pmo2)
> -> Submember Base::*;
>
> You should also be able to do:
> int *px = &obj_c + pmfx;
> Which is the same as:
> int *px = &(obj_c.*pmfx);
>
> But that's useful if you start allowing negations. By using the unary
> operator- to create a pointer-to-container:
>
> A int::* = -&A::y;
>
> you can reverse a regular pointer-to-y to the container:
>
> A *a = py - &A::y;
>

I have something of a recollection of being told that TBAA would be impeded
by allowing to reverse pointer to members.

>

Received on 2023-06-13 19:42:00