C++ Logo

std-proposals

Advanced search

Re: async coroutines vs. lambdas

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Thu, 14 May 2020 15:56:01 +0200
czw., 14 maj 2020 o 15:43 Avi Kivity <avi_at_[hidden]> napisaƂ(a):
>
>
> On 14/05/2020 16.30, Marcin Jaczewski via Std-Proposals wrote:
> > And code like:
> >
> > ```
> > lazy<int> get_custom_lambda() {
> > struct X
> > {
> > int i = 3;
> > lazy<int> operator()(){ co_return i; }
> > } x();
> > return x();
> > }
> >
> > ```
> >
> > This still crash, and this is same code as `get_real_lambda`.
> > How do you like fix it?
>
>
> If the coroutine is a member function, then
>
> If the member function was called on an rvalue object, the object is
> captured in the coroutine frame by value (and is not a reference in
> coroutine_trait's type parameters)
>
> If the member function was called on an lvalue object, the object is
> captured by reference (as the current standard requires).
>
>
> > and what if lambda is not movable?
>
>
> If the lambda cannot be moved or copied to the coroutine frame, then the
> program is ill formed (same as passing a non-copyable, non-movable
> argument).
>
>
>

But then corutine can see only this:

```
lazy<int> X::operator()() const
{
   co_return this->i;
}
```
There is no info if you have rvalue or lvalue; If we had
`X::operator()() &&` then it could work, but this will need lot more
changes than you propose.

Received on 2020-05-14 08:59:14