C++20 coroutines as an API principle
summary
Claim: C++20 coroutines let APIs expose lazy, non-owning sequences instead of owning containers so functions interoperate across ABI boundaries while avoiding eager allocation. Evidence: generator return types, ABI and out-of-line codegen analysis, virtual coroutines, and Qt examples that reveal initial_suspend lifetime traps, heap coroutine frames and reentrancy hazards. Solutions shown include pinning rvalues via custom promise or overloads, allocator-aware promise allocation and the experimental caller-supplied storage idiom. Result: coroutines reduce wasted work but require careful promise design and lifetime discipline.
AI-written summary · about
chapters (12)
- 0:00Start
- 1:36Introduction
- 9:24Owning Containers and Apis Restrict the Implementation
- 14:39How To Fix the Lifetime Issue
- 22:41Yielding Coroutine
- 23:51Limitations of Coroutines
- 28:02Custom Promise Type
- 30:14Re-Entrance
- 30:26Multi-Threading
- 32:18Keep Resources in Right Objects
- 33:06Coroutine Frame Allocation
- 44:39Signal Slot Connections
related talks
01h 02mC++20’s Coroutines for Beginners
58mAn Introduction to C++ Coroutines
01h 05mWhy use coroutines for asynchronous applications
01h 05mCoroutines: C++ vs Rust
01h 03mHow C++20 changes the way we write code
01h 00mUsing Coroutines to Implement C++ Exceptions for Freestanding Environments
01h 03mDeciphering C++ Coroutines - A Diagrammatic Coroutine Cheat Sheet
53mC++ Coroutines and Structured Concurrency in Practice
