~/talk

C++ Lambda Idioms

Talkat NDC TechTown 2022 · 2022-08-29..09-01· [c-and-cpp]
links:none on file
slides:none on file

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

  1. 0:00Lambda idioms intro
  2. 1:30How lambdas work
  3. 6:06Unary plus trick for conversion
  4. 7:50Lambda captures by value/ref
  5. 11:43Gotchas with static captures
  6. 14:32Immediately invoked lambdas
  7. 22:37Generic lambdas in C++14
  8. 26:52Variable templates with lambdas
  9. 33:30Init capture for move-only
  10. 34:33Init capture optimization
  11. 36:16Lambda overload sets C++17
  12. 40:25C++20 lambda features
  13. 44:21Unique types with lambdas
  14. 47:35Deducing this in C++23
  15. 53:09Overload sets with recursion
  16. 55:59Q&A
~/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.