Let's Look at Lambdas
summary
Timeline from C++98 tricks to C++20: lambdas are compiler-generated unnamed classes that let you pass small callables into algorithms, support capture-by-value vs capture-by-reference, require auto for their type, and can be generic lambdas with auto or use init-capture and move semantics. Pitfalls: dangling references when returning a lambda that captured by reference, implicit this capture is deprecated, capturing lambdas cannot convert to function pointers, and template-heavy code can cause code bloat. Performance: debug builds show extra calls, but -O1 usually inlines and erases them.
AI-written summary · about
chapters (25)
- 0:00Start
- 13:00Pre Standardization
- 16:10Boost Bind
- 17:42Recap
- 18:41Lambda Expression
- 19:57The Lambda Introducer
- 20:29Lambda Introducer
- 28:10Capture Local Variables That Are in Scope
- 31:59Does the Compiler Name the Local Struct
- 37:16Implicitly Capture Variables
- 38:43Implicit Capture of Fields
- 45:44With Implicit Capture Does the Anonymous Class Contain Only the Set of Variables Used in the Body
- 47:35Generic Lambdas
- 49:42Syntactic Sugar
- 51:29Initialize the Capture Variable
- 52:20Rename Capture Variable
- 56:53Delayed Initialization
- 1:00:18Refactoring
- 1:01:42Template Arguments
- 1:06:39Code Bloat
- 1:09:07Runtime Cost
- 1:19:23Implicit Capture
- 1:20:10Advantage of Using a Lambda inside a Class versus a Function
- 1:20:25When Is the Right Time Uh To Use a Lambda inside a Class Rather than To Use a Free Function a Member Function
- 1:24:05Can a Lambda with Captures Be Passed as a Function Pointer
related talks
01h 00mA Kaleidoscope of C++ Lambdas
52mBack to Basics: Lambdas from Scratch
01h 04mC++ Lambda Idioms
01h 00mC++: λ Demystified
56mC++ Lambda Idioms
05mLightning Talk: Into the Lambdaverse - Weird C++ Lambda Shenanigans
05mImmediately Invoked Coroutine Lambdas in C++23 - Lifetime Pitfalls & Best Practices
01h 01mC++ Insights: How stuff works, Lambdas and more!
