C++ Logo

std-proposals

Advanced search

Re: Do we need a way to take *this by value, for coroutines?

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 8 Nov 2021 16:42:13 +0200
On Mon, 8 Nov 2021 at 15:30, Phil Endecott via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Quoting Marcin's example:
>
> text_generator_t text(this F self) //no `&`!
> {
> for (auto c: *(self.p)) co_yield c;
> }
>
> I do wonder why it needs to introduce the parameter name "self",
> and can't simply keep the concise syntax in the body, i.e.
>
> text_generator_t text(F this)
> {
> for (auto c: *p) co_yield c; // p is this.p
> }

Because a lambda can have both a deduced-this for the lambda and a
captured this from a surrounding
class. The solution to that possible confusion is that a deduced-this
is never named 'this'.

Received on 2021-11-08 08:42:26