C++ Lambda Idioms
summary
Explains what the compiler actually generates for a lambda (closure type, const call operator, implicit conversion to function pointer) and gives concrete tricks: use unary plus to force a function-pointer conversion, watch ODR-use rules so statics and compile-time consts are not captured, use immediately-invoked lambdas to initialize const or non-default-constructible objects and to run one-time setup faster than std::call_once, use init-capture for move-only state, write variable template lambdas to wrap chrono::duration_cast, build a lambda overload set via inheritance and CTAD, and use C++23 deducing-this for clean recursive lambdas.
AI-written summary · about
chapters (16)
- 0:00Lambda idioms intro
- 1:30How lambdas work
- 6:06Unary plus trick for conversion
- 7:50Lambda captures by value/ref
- 11:43Gotchas with static captures
- 14:32Immediately invoked lambdas
- 22:37Generic lambdas in C++14
- 26:52Variable templates with lambdas
- 33:30Init capture for move-only
- 34:33Init capture optimization
- 36:16Lambda overload sets C++17
- 40:25C++20 lambda features
- 44:21Unique types with lambdas
- 47:35Deducing this in C++23
- 53:09Overload sets with recursion
- 55:59Q&A
related talks
01h 04mC++ Lambda Idioms
01h 00mC++: λ Demystified
01h 26mLet's Look at Lambdas
52mBack to Basics: Lambdas from Scratch
01h 00mA Kaleidoscope of C++ Lambdas
01h 01mC++ Insights: How stuff works, Lambdas and more!
04mFunction Extraction with Lambda Expressions
05mLightning Talk: Into the Lambdaverse - Weird C++ Lambda Shenanigans
