C++ Coroutines - Don’t Try This at Home
summary
C++20 coroutines require explicit boilerplate: a heap-allocated coroutine frame, a coroutine_handle owning a promise_type that must implement initial_suspend/final_suspend/unhandled_exception and hold yielded or returned state; examples implement a radio-station generator, a pinball resumable action, and an average that co_returns a final value. Custom awaiters show how the caller can pass feedback into the coroutine (store score in promise and return it from await_resume). C++23’s std::generator replaces boilerplate for generators but other patterns still need explicit promise_type stores state and sometimes a custom awaiter passes data back. Compilers vary in support.
AI-written summary · about
chapters (14)
- 0:00C++ coroutines intro
- 6:38Radio station with coroutines
- 14:27Compiler magic behind coroutines
- 21:13Promise type config
- 26:15Coroutine API implementation
- 35:34Coroutines in practice
- 41:00Challenges and boilerplate
- 43:34C++23 std::generator
- 49:43Pinball machine example
- 55:48Understanding awaitables
- 1:01:14Passing values coroutine-caller
- 1:10:13Nested coroutines lazy eval
- 1:19:21Making coroutines awaitable
- 1:25:00Summary & Q&A
related talks
01h 36mUnderstanding C++ Coroutines by Example, Part 2: Generators
01h 16mC++ Feature Coroutines, Beginner Friendly
01h 06mC++ Coroutines from scratch
01h 31mC++ Coroutines Demystified
47mHow to start using coroutines
58m“Introduction to C++ Coroutines"
01h 01mUnderstanding C++ Coroutines by Example, Part 1
48m“Coroutines: what can't they do?”
