C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Chimeric Pointer

From: Phil Endecott <std_proposals_list_at_[hidden]>
Date: Sun, 27 Nov 2022 17:03:28 +0000
Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
> template<class... Bases>
> class chimeric_ptr {
> protected:
>
> std::tuple<Bases*...> pointers;
>
> public:
>
> template<class T>
> requires ((std::is_convertible_v<T*, Bases*> && ...))
> /* implicit */ chimeric_ptr(T *const obj)
> {
> // The fold expression on the next line sets
> // each of the pointers in the tuple
> ((std::get<Bases*>(pointers) = obj), ...);
> }
>
> template<class As>
> requires ((std::is_same_v<Bases, As> || ...))
> As *as(void)
> {
> return std::get<As*>(pointers);
> }
> };


I think it would be possible to implement operator->* to make this
possible:

   struct A { void fn_a(); };
   struct B { void fn_b(); };
   struct AB: A, B {};

   chimeric_ptr<A,B> p;
   p ->* &A::fn_a ();

That's fractionally less typing than p.as<A> -> fn_a (). Is it any
clearer? (Does it actually work - I've not tried to implement it!)

I could imagine a core language change to make p -> A::fn_a equivalent
to p ->* &A::fn_a, i.e. allowing the "redundant" *& to be elided. Would
that conflict with other syntax?


Regards, Phil.

Received on 2022-11-27 17:03:30