C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Chimeric Pointer

From: Gergely Nagy <gergely.nagy.alt_at_[hidden]>
Date: Fri, 25 Nov 2022 10:48:42 +0100
if constexpr (requires { p.what(); }) p.what();

On Fri, Nov 25, 2022, 10:45 Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-11-25 09:48:56