C++ Logo

std-proposals

Advanced search

Re: [std-proposals] explicit this

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 3 Apr 2023 21:02:38 +0100
On Mon, Apr 3, 2023 at 11:02 AM Ville Voutilainen wrote:
>
> void SomeFunc(this SomeClass& self)
> {
> //SomeOtherFunc(); /* compiler error */
> self.SomeOtherFunc(); // OK
> }



None of the compilers up on Godbolt can compile this. When will we
have this new feature?



On Mon, Apr 3, 2023 at 1:05 PM Andrew Tomazos wrote:
>
> To be fair to the OP, even though he doesn't know about explicit object parameters yet,
> they were not designed for his use case. I think he wants to force people to put `this->`
> in front of member names, because he thinks it makes the code more readable (by making
> member names visually distinct from non-member names). The solution of always using
> explicit object parameters sort of achieves this goal, but requires additional syntax of
> declaring the explicit object parameter in every function, and declaring a new and
> potentially-unique name for it in every member function. While, granted, conventionally you
> could always call it `self`, it's still not as good as using the long-standing and familiar syntax of `this->`


You hit the nail on the head, this is exactly what I was on about.

Received on 2023-04-03 20:02:51