C++ Logo


Advanced search

Re: [std-proposals] Draft Paper - Increase the versatility of operator->

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 21 Sep 2022 15:37:11 -0400
On Wed, Sep 21, 2022 at 2:13 PM Breno GuimarĂ£es via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Hi,
> My first feeling is this is too drastic of a change in terms of language ergonomics. Perhaps, if you word it a bit differently it would fit a bit better with the rest of the language.
> For example, instead of using the "inline" keyword as a placeholder to "whatever is passed after ->", you could make the syntactic sugar to just generate a lambda.
> Such that:
> v->Init();
> would be transformed by the compiler into
> v.operator->( [&] (auto& arg) { arg.Init(); } );
> By doing so, all you need is the ability to pass more arguments to the operator-> (today it's forbidden).
> See how that would work for variant: https://godbolt.org/z/xxKnE44dr
> That might still be a big stretch, but it seems to me it would be more reasonable.

C++ is a language that has a *lot* of internal, hidden code
transformations in it. `operator->` already has a built-in one. Why
does it need a second? And why should this one start implicitly
generating lambda functions, which could cause all sorts of problems
if they get stored long-term?

Received on 2022-09-21 19:38:13