~/talk

std::function: a deep dive behind the curtain

Talkat Meeting C++ 2022 · 2022-11-17..11-19· [rust]
slides:none on file

A concrete walkthrough shows how std::function implements type erasure: partial template specialization extracts return and argument types, a shared_ptr-based type erasure holds a polymorphic callable implementation, and copying semantics can end up sharing rather than cloning the target unless clone logic is added. Library comparisons reveal surprising sizes — MSVC reports roughly a six-pointer footprint while others use a smaller two‑pointer small‑buffer — and C++23’s move_only_function removes RTTI-heavy target access and supports move-only callables and emplace construction.

AI-written summary · about

  1. 0:00Introduction
  2. 2:17Function signatures
  3. 4:19Function pointer
  4. 5:47Summary
  5. 6:20Why use std function
  6. 7:10Function pointers
  7. 8:08Instance method
  8. 9:06Objectoriented approach
  9. 10:33Objectiveended approach
  10. 11:56devils advocate
  11. 13:40task scheduler
  12. 15:33wrap up
  13. 17:09naive implementation
  14. 19:18call operator
  15. 21:28callable
  16. 27:33recap
  17. 28:03question
  18. 28:13comparison
  19. 30:00empty state
  20. 30:56compare pointer
  21. 32:03member function
  22. 33:01return type
  23. 33:48member pointers
  24. 34:27function signature
  25. 35:32member functions
  26. 36:14target type
  27. 37:39summary and comments
  28. 40:27standard mandates
  29. 41:28other implementations
  30. 42:43benchmarks
  31. 44:35size
  32. 44:59pointer size
  33. 48:41extensions
  34. 50:15multiple overloads
  35. 51:12different overloads
  36. 51:45more ideas
  37. 55:10moveonly function
  38. 57:53conclusion
  39. 58:41our company
  40. 59:04user group
~/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.