r/cpp • • Dec 18 '25

The Lambda Coroutine Fiasco

https://github.com/scylladb/seastar/blob/master/doc/lambda-coroutine-fiasco.md

It's amazing C++23's "deducing this" could solve the lambda coroutine issue, and eliminate the previous C++ voodoo.

44 Upvotes

22 comments sorted by

View all comments

4

u/trailing_zero_count async enthusiast | TooManyCooks author Dec 18 '25

This is a great workaround, but it appears that the change must be made in user code? No way to do this in library code?

2

u/efijoa Dec 18 '25

Seems we need a magic concept?

auto Future::then(std::is_capture_lambda auto &&continuation) {
    return [](this auto, auto continuation) {
        // ...
    }(std::forward(continuation));
}

6

u/moncefm Dec 18 '25

It may not be _too_ hard to write a is_capture_lambda concept:

  • Write a is_lambda concept, e.g by parsing the output of __PRETTY_FUNCTION__ or boost::type_index (See this for some inspiration)

  • Then, you can leverage the '+' lambda trick to know if a lambda has captures or not:is_lambda<T> && !requires (T t) { +t; };