~/talk

C++ Type Erasure Demystified

Talkat C++Now 2024 · 2024-04-29..05-03· [compilers-and-language-design]
slides:none on file

Explains type erasure by building three concrete implementations: inheritance with virtuals, static-function pointers, and a compiler-like vtable-as-a-static-variable approach, with code for a smart pointer and a function wrapper. Shows local-buffer optimization to avoid allocations, measures deletion and call latency (custom function matches direct call within noise; typical std::function is about twice as slow), and demonstrates how rearranging the call path can make std::function 50% faster. Uses simple benchmarks, points to the zoo library and GCC behavior for real-world tradeoffs.

AI-written summary · about

  1. 0:00Understanding Type Erasure
  2. 10:23Designing with Type Erasure
  3. 14:41Type Erasure in C
  4. 20:40Inheritance-Based Type Erasure
  5. 42:01Static Type Erasure
  6. 55:02V-Table Based Type Erasure
  7. 1:14:38Performance Benchmarks
  8. 1:33:25Conclusion 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.