~/talk

Unveiling Type Erasure in C++: From std::function to std::any

Talkat CppNorth 2025 · 2025-07-21..07-23· [c-and-cpp, compilers-and-language-design]
slides:none on file

Builds a minimal std::function clone that stores heterogeneous callables by wrapping them in a templated function_model, adds a virtual clone() to gain copyable value semantics, and implements small buffer optimization to avoid heap allocation for small callables. Compares that approach to how std::shared_ptr uses type erasure in its control block (storing a deleter) and how std::any can be implemented with a stored typeid plus a manual deleter for manual virtual dispatch. Notes the two real costs: heap allocation and virtual calls.

AI-written summary · about

  1. 0:00Introduction and overview
  2. 1:46The problem of generic design
  3. 6:46Limitations of inheritance
  4. 10:37Implementing type erasure
  5. 17:18Refining the implementation
  6. 22:34Advanced std::function features
  7. 32:02Performance optimizations
  8. 36:24Type safety in standard library
  9. 45:48Exploring std::any
  10. 52:05Conclusion and Q&A
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 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
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
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.