C++ Logo

std-proposals

Advanced search

Re: async coroutines vs. lambdas

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 14 May 2020 15:09:06 +0300
On Thu, 14 May 2020 at 14:59, Avi Kivity <avi_at_[hidden]> wrote:
>
> On 5/14/20 2:46 PM, Ville Voutilainen wrote:
> > On Thu, 14 May 2020 at 14:34, Avi Kivity <avi_at_[hidden]> wrote:
> >>>> With a lambda coroutine, we have a problem. This is because lambdas are
> >>>> captured by reference:
> >>> Says what?
> >>
> >> Says the quote below, from cppreference.
> > Your wording was confusing; I thought you meant a lambda as a
> > coroutine parameter.
> > For cases where we are in a non-static member function, the *this is
> > indeed not copied.
>
>
> Ah, the lambda _is_ a coroutine parameter in a sense, if you follow the
> regular translation of a lambda to a struct with operator().
>
>
> And note this is not specific to lambdas, it happens for any member
> coroutine called on a temporary. A lambda is just the most common way of
> generating such calls.

Right. Calling a member function coroutine of a temporary seems like
madness to me.
It's quite like calling a member function that queues async work that
is later completed in
some other member of the object.

I'm not sure I understand where the temporary really is in the
not-so-lame testcase in the bug report. To me,
it seems like everything is stored and lifetimes don't end
prematurely, but I don't understand how initial_suspend
really works. :)

Received on 2020-05-14 07:12:19