No Compiler Required - Hand-Rolling C++20 Coroutines in C++17
summary
Shows how a C++20 coroutine body maps to a C++17 heapallocated state machine by generating concrete coroutine frames, explicit suspension-indexed switch labels, and manual lifetime management for locals and temporaries; implements symmetric transfer, initial/final_suspend semantics and exception-unwinding. Demonstrates a hand-rolled state machine lowered to C++17, a stackful alternative that matches handwritten iterator performance for simple generators, and an automated source-to-source rewriter built on LibTooling that produces working C++17 instantiations (demo compiles and runs under ASan).
AI-written summary · about
chapters (10)
- 0:00Introduction
- 5:22C++20 coroutine overview
- 11:07Simple iota generator rewrite
- 23:56Coroutine handle class
- 31:25Coroutine frame setup
- 41:01Local variables in coroutines
- 57:39Exception handling
- 1:05:49Optimizing coroutines
- 1:16:30Automating coroutine rewrite
- 1:27:55Q&A
related talks
57mC++ Coroutines: Under the covers
56mGenerators, Coroutines and Other Brain Unrolling Sweetness
31mGenerators, Coroutines and Other Brain Unrolling Sweetness
58m“C++ Coroutines - a negative overhead abstraction"
48m“Coroutines: what can't they do?”
01h 01mMoving to C++20 for Fun, Beauty... and Results!
01h 33mC++11 to C++23 in the C++ Memory Model
01h 01mWhat We’ve Been Awaiting For? - How to Build a C++ Coroutine Type
