~/talk

C++ Lambda Idioms

Talkat CppNorth 2022 · 2022-07-18..07-20· [c-and-cpp]
links:none on file
slides:none on file

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

  1. 0:00Introduction to lambdas
  2. 2:05Under the hood of lambdas
  3. 6:12The unary plus trick
  4. 8:50Capture traps
  5. 14:43Immediately invoked lambdas
  6. 24:15Generic lambdas (C++14)
  7. 27:33Init capture
  8. 30:35Lambda overload sets
  9. 37:56Lambdas in C++20
  10. 42:22Deducing this (C++23)
  11. 52:49Bonus: Variable template lambdas
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.