~/talk

Taming Lambdas' uniqueness

Talkat Meeting C++ 2023 · 2023-11-12..11-14· [rust]
links:none on file
slides:none on file

C++ lambdas each produce a unique closure type, which breaks passing, storing, or comparing them; concrete fixes are shown: use templates for zero overhead, use std::move_only_function or type erasure when dynamic storage is needed, and prefer indirection or static polymorphism when performance matters. A reusable functors container with an invoke map and cached invokers gets near-template speed and beats std::function; benchmarks report about 3× faster than std::function on GCC and sometimes Clang fully optimizes away indirection.

AI-written summary · about

  1. 0:00Lambda uniqueness problem
  2. 1:28Core problem with identical lambdas
  3. 3:15C++ unique closure types
  4. 5:20Non-capturing lambdas to function pointers
  5. 7:48Capturing lambdas and function pointers
  6. 10:15Scenario with three different lambdas
  7. 11:40Passing lambdas via templates
  8. 13:04std::function and move-only variants
  9. 16:13Benchmarking lambda passing
  10. 17:43Storing lambdas in containers
  11. 19:10Factory for identical lambdas
  12. 20:58Move-only lambdas in containers
  13. 22:00Solutions for different signatures
  14. 23:03Benchmarking lambda storage
  15. 25:11Performance of std::function
  16. 26:17Custom type eraser for lambdas
  17. 28:51Evaluating custom type eraser
  18. 29:34Syntax for lambda container
  19. 30:15Static polymorphism with overload
  20. 32:45Parameter packs and concepts
  21. 33:46Functors container structure
  22. 35:09Constructing functors container
  23. 36:14Deduction guides for container
  24. 37:17Adding elements to container
  25. 39:48Handling references in push_back
  26. 41:10Calling all container lambdas
  27. 43:59Calling lambdas by index
  28. 46:05Benchmarking custom container
  29. 47:07Dynamic dispatch with runtime index
  30. 48:54Implementing invoke map
  31. 51:45Performance of invoke map
  32. 53:14Optimizing invoke map with caching
  33. 55:20Final benchmarks and takeaways
  34. 55:41Conclusion and Q&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.