Hacker News new | ask | show | jobs
by grogers 1352 days ago
Alternatively, 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);
  }();