Back to Basics: Lambdas
summary
Shows exactly what lambdas do and how they differ from functions: the compiler generates a closure type with an operator() and captures become members; lambdas can capture by value (so returned function objects keep runtime parameters) or by reference, become mutable state when allowed, and instantiate as templates with C++14 generic lambda auto parameters. Demonstrates concrete uses: sort with case‑insensitive lexicographical_compare, count_if/find_if predicates, C++20 ranges/projections, conversion to function pointers when no captures, and surprising copies when algorithms take callables by value.
AI-written summary · about
chapters (14)
- 0:00Intro
- 1:40Why Lambdas
- 8:10Countif
- 10:38Sorting
- 16:50Generic Lambda
- 19:25No Lambdas
- 30:49Behind the scene
- 34:46The rule
- 36:46Templates
- 39:38Functions vs Lambdas
- 44:38Local copy of elements
- 45:38Prefix
- 51:16Copy if
- 54:50Questions
related talks
01h 10mType Deduction and Why You Care
59mCute C++ Tricks, Part 2.5 of N - Code You Should Learn From & Never Write
01h 03mTemplate-less Metaprogramming in C++
01h 01mBack to Basics: Concepts in C++
01h 02mBack to Basics: Forwarding References - How to Forward Parameters in Modern C++
01h 03mBack to Basics: Declarations in C++
06mLightning Talk: C++20 - A New Way of Meta-Programming?
07mLightning Talk: Higher-Order Template Metaprogramming with C++23
