C++ Logo

std-proposals

Advanced search

Re: [std-proposals] explicit this

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 3 Apr 2023 13:02:21 +0300
On Mon, 3 Apr 2023 at 12:54, Frederick Virchanza Gotham
<cauldwell.thomas_at_[hidden]> wrote:
>
> On Mon, Apr 3, 2023 at 10:44 AM Ville Voutilainen
> <ville.voutilainen_at_[hidden]> wrote:
> >
> > > I still think you only skimmed my first post.
> >
> > Cool, but the language already allows you to do what you want, since
> > C++23. You're welcome. (Although deduced-this
> > wasn't my doing.)
>
>
> Please write a minimal code example of how you can enforce the use of "this->".

It doesn't work quite like that, but it does enforce using
"thisref.member" instead of just "member".

class SomeClass {

    void (*SomeOtherFunc)(void);

    void SomeFunc(this SomeClass& self)
    {
        //SomeOtherFunc(); /* compiler error */
        self.SomeOtherFunc(); // OK
    }
};

> Right now I haven't got a clue what you're talking about.

Gee, perhaps you have just skimmed the responses given to you. Maybe
reading this will help:
wg21.link/p0847
Maybe reading this would help further:
https://en.cppreference.com/w/cpp/language/member_functions#Explicit_object_parameter
And especially the example

struct C
{
    void bar();

    void foo(this C c)
    {
        auto x = this; // error: no this
        bar(); // error: no implicit this->
        c.bar(); // ok
    }
};

Received on 2023-04-03 10:02:33