C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Chimeric Pointer

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 25 Nov 2022 09:45:01 +0000
On Thu, Nov 24, 2022 at 11:41 PM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Thursday, 24 November 2022 14:46:32 PST Frederick Virchanza Gotham via Std-
> Proposals wrote:
> > I've written a 2-page PDF file to describe my new idea of chimeric
> > pointers. I've tried to attach it to this email, and also you can
> > download it from my webspace here:
> >
> > http://www.virjacode.com/download/chimeric_pointer.pdf
> >
> > Here's a excerpt from the PDF:
> >
> > "When you apply the ‘->’ operator to a chimeric pointer and then try
> > to access a member object or a member function, the compiler tries to
> > find the member in all the base classes"
>
> Instead of
>
> void Red( chimeric_pointer<wxControl,wxTextEntry> p )
> {
> p->SetBackgroundColour( *wxRED );
> p->SetValue("pending");
> p->Refresh();
> }
>
> Write:
> void Red(std::Variant<wxControl,wxTextEntry> &p )
> {
> std::visit(([](auto &p) {
> p/SetBackgroundColour( *wxRED );
> p.SetValue("pending");
> p.Refresh();
> }, p);
> }


That forward slash is supposed to be a dot, right? Anyway if I try to
compile the following standalone function:

        void Red( std::variant<wxControl,wxTextEntry> &p )
        {
                std::visit(([](auto &p) {
                  p.SetBackgroundColour( *wxRED );
                  p.SetValue("pending");
                  p.Refresh();
               }, p);
        }

then I get:

    cannot declare field '__gnu_cxx::__aligned_membuf<wxTextEntry>::_Tp2::_M_t'
    to be of abstract type 'wxTextEntry'

So the types inside a variant cannot be abstract. I'll try your code
snippet with two concrete types instead:

        void Red( std::variant<std::string, std::exception> &p )
        {
               std::visit([](auto &p) {
                    p.size(); // from std::string
                    p.what(); // from std::exception
               } , p);
        }

This fails to compile with the following error:

        'class std::__cxx11::basic_string<char>' has no member named 'what'

I'm not sure how your code snippet was supposed to work. Right now I
can't fathom how it could possibly work.

Received on 2022-11-25 09:45:13