C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Chimeric Pointer

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 25 Nov 2022 09:25:35 -0800
On Friday, 25 November 2022 08:45:41 PST Arthur O'Dwyer via Std-Proposals
wrote:
> Frederick's suggested solution was to just make it work by magic:
>
> void Red(__chimerical(Control, TextEntry) *p) {
> p->SetBackgroundColor(); // this means Control::SetBackgroundColor
> p->SetValue("pending"); // this means TextEntry::SetValue
> }
[snip]

Please ignore my earlier replies today, before reading what the feature was
actually trying to achieve.

A third alternative, in addition to the two that Arthur suggested, is a simple
pointer wrapper that stores one pointer to each of the requested sub-objects
of the object.

template <typename... Bases>
struct chimeric_pointer : chimeric_pointer_storage<Base>...
{
    template <typename T>
    chimeric_pointer(T *obj) : chimeric_pointer_storage<Base>(obj)... {}
};
or something, plus a set of std::get or get members to extract each of the
sub-objects as desired, to write something like:

void Red(chimeric_pointer<wxControl, wxTextEntry> p)
{
    p.get<wxControl>()->SetBackgroundColor();
    p.get<wxTextEntry>()->SetValue("pending");
};

This idea would have a size of N * sizeof(void*) for N bases. I don't know if
it's possible to shrink it without a getter that is per chimeric pointer and
per complete object type.

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

Received on 2022-11-25 17:25:37