C++ Logo


Advanced search

Re: async coroutines vs. lambdas

From: Avi Kivity <avi_at_[hidden]>
Date: Thu, 14 May 2020 14:59:42 +0300
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.

Received on 2020-05-14 07:02:47