3 ms·
You have to use something similar to https://github.com/facebook/folly/tree/main/folly/experimental/coro#lambdas https://github.com/facebook/folly/tree/main/fol
by somerando7 4y ago
You have to use something similar to https://github.com/facebook/folly/tree/main/folly/experimental/coro#lambdas https://github.com/facebook/folly/tree/main/folly/experiment... to solve this problem.
It's a nasty bug that everyone encounters when first working with coroutines. (Similarly everyone will encounter references that don't live until you co_await the task).
- boundchecked 4y agoC++20 coroutines demonstrated one side of committee-led modern C++ that left an impression of it is ultimately designed-by and -for library writers; instead of being suggested third-party library or "wait for C++23" for better experience, I'd love to see these related machinery released the same time in the standard library.
- grogers 4y agoAlternatively, you can pass the things you would have captured instead as arguments to the lambda (by value!) and they are valid for the duration of the coroutine. So you can do a lambda returning a coroutine lambda like task<Foo> t = [foo]() { return [](auto f) -> task<Foo> { co_await something(); co_return f; }(foo); }();