~/talk

Back to Basics: Type Erasure

Talkat CppCon 2019 · 2019-09-15..09-20· [compilers-and-language-design]
slides:none on file

Explains how to implement type erasure step-by-step: start with representation and behavior split using void plus function pointers, build a reference form (no ownership), then a value form using heap allocation and lambdas for clone/delete* affordances, and finally show vtable/virtual-base and single-function-with-switch optimizations. Compares std::function, std::any, function_ref, unique_function and inplace_function, shows tradeoffs (heap cost, ABI, speed) and provides working code (Godbolt link) that demonstrates each approach.

AI-written summary · about

  1. 0:00Introduction
  2. 1:00What is type erasure?
  3. 2:06Motivating type erasure in C++
  4. 7:00Representation and behavior
  5. 13:26Building type-erased types
  6. 23:10Affordances and special members
  7. 30:41Standard library examples
  8. 40:20Other applications
  9. 43:20Conclusion 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.