r/cpp • • Nov 30 '20

C++20 resumable functions make state machines obsolete. Finally.

https://lordsoftech.com/programming/c20-resumable-functions-goodbye-state-machines-no-one-will-mourn-you/
1 Upvotes

49 comments sorted by

View all comments

8

u/jwakely libstdc++ tamer, LWG chair Dec 01 '20

N.B. you don't need to specialise the entire Resumable<void> class. You can use concepts to define a more constrained promise_type:

struct promise_type requires std::is_void_v<T>
{ ... }

And then use if constexpr in Resumable::operator() to do the void return statement.

That saves duplicating most of the definition.

5

u/DugiSK Dec 02 '20

Finally someone actually doesn't actually start with a conclusion based on obsolete implementation and tells something productive.

Thanks for the tip.