C++ Lambda Idioms
summary
The talk shows concrete lambda behaviors and practical patterns: the compiler creates closure types, unary plus forces an explicit conversion to a function pointer (works pre-C++14 but not for generic lambdas), static/global variables are not captured, and immediately‑invoked lambdas initialize const or non‑defaultable objects and implement thread‑safe one‑time init (often faster than std::call_once). It demos init‑capture for move‑only types, a lambda overload set via inheriting closure types used with std::visit, and deducing this (C++23) to write recursive lambdas and combine with overload sets; examples compile on a recent MSVC toolchain.
AI-written summary · about
chapters (11)
- 0:00Introduction to lambdas
- 2:05Under the hood of lambdas
- 6:12The unary plus trick
- 8:50Capture traps
- 14:43Immediately invoked lambdas
- 24:15Generic lambdas (C++14)
- 27:33Init capture
- 30:35Lambda overload sets
- 37:56Lambdas in C++20
- 42:22Deducing this (C++23)
- 52:49Bonus: Variable template lambdas
related talks
56mC++ Lambda Idioms
01h 00mA Kaleidoscope of C++ Lambdas
01h 26mLet's Look at Lambdas
01h 00mC++: λ Demystified
52mBack to Basics: Lambdas from Scratch
01h 01mC++ Insights: How stuff works, Lambdas and more!
07mLightning Talk: Into the Lambdaverse — The Beginning
04mFunction Extraction with Lambda Expressions
