C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 13 Jun 2023 10:45:59 -0700
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;

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-06-13 17:46:01