C++ Lambda Idioms
summary
Covers concrete techniques and gotchas: how closure types are generated, the unary-plus trick for forcing conversion to function pointer, using immediately-invoked lambda for complex const initialization (works for move-only types via init-capture), init-capture to avoid per-iteration allocations, generic lambdas create operator() templates, inheriting lambdas to make an overload set, a static-local lambda trick to run initialization exactly once (faster than std::call_once in one benchmark), and C++23’s deducing-this enabling natural recursive lambdas.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 1:25Lambda Expressions
- 6:15Unary Trick
- 8:30Captures
- 13:08Local Variables
- 16:35Immediately Invoked Functions
- 22:57Never Again
- 26:24Generic Lambda
- 30:38Variable Template
- 38:14Init Capture
- 41:15Class Template Argument Deduction
- 46:36C20 Lambda Changes
- 53:22C23 Lambda Changes
- 53:33C23 Deducing
- 55:53Recursive Lambda
- 58:38Tree Traversal
related talks
01h 06mLambdas - uses and abuses
53mExplaining Lambda Calculus through Plain JavaScript
37mFun with Lambdas!
01h 03mLambda Calculus For People Who Can't Be Bothered to Learn It - part 2 of 2
59mLambda Calculus For People Who Can't Be Bothered to Learn It - part 1 of 2
48mIt’s birds all the way down: Fun Introduction to Lambda Calculus
45mClosed for Inventory: The History and Mechanics of Closures
04mConstexpr and operator overloading: Why everything is terrible
