Lambdas, how to capture everything and stay sane
summary
Describes exact capture kinds, gives concrete rules and compiler surprises: simple captures preserve constness while init captures drop CV qualifiers, capture-defaults can silently capture the wrong object (globals aren’t capturable) and create lifetime bugs, move-only objects become usable via init captures and move semantics, and parameter packs are handled with init-capture pack expansion and forwarding. Includes clear code examples, explains why the closure type gets const operator() by default, and shows practical fixes (mutable, explicit captures, overloads for lvalue/rvalue).
AI-written summary · about
chapters (11)
- 0:00Start
- 2:03A casual occurrence
- 4:01Lambdas & closures
- 6:28Simple captures & capture defaults
- 8:03Generalized captures a.k.a init captures
- 12:54Capture type deduction rules
- 16:39Adding const with init capture
- 17:46When (not) to capture
- 30:30The magic of this
- 36:41Being explicit with this
- 48:44Capturing parameter...packs
related talks
01h 00mDesign Idioms from an Alternate Universe
01h 02mBack to Basics: Designing Classes (part 2 of 2)
01h 02mBack to Basics: Initialization in C++
01h 01mComposable C++: Principles and Patterns
09mA variant of recursive decent parsing
59mBuilding an Intuition for Composition
36mUnderstanding Recomposition Performance Pitfalls
43mRepresenting State: the Kotlin Edition
