C++ Coroutines Demystified
summary
Starts from blank code and walks to a working coroutine by letting the compiler drive each step: use Compiler Explorer with GCC and Clang, add #include <coroutine>, create a Task return type with nested promise_type, implement ~8 promise methods (get_return_object, initial_suspend, final_suspend, unhandled_exception, return_value, yield_value), pass a coroutine_handle into the Task, log execution to see suspension/resume, and finally swap to C++23 std::generator (Fibonacci demo) using std::suspend_always/std::suspend_never so the examples compile and actually run.
AI-written summary · about
chapters (10)
- 0:00C++ coroutines introduction
- 5:43Minimal coroutine in Compiler Explorer
- 19:34Coroutine execution and suspension
- 34:36Coroutine frames and promise types
- 45:11Coroutine lifetime handles
- 59:53Returning values from coroutines
- 1:01:21Generating sequences with co_yield
- 1:13:22C++23 generators
- 1:20:17Awaiters and awaitables
- 1:29:55Summary








