Breaking Dependencies: Type Erasure - The Implementation Details
summary
Shows two concrete ~20 line implementations for owning and non‑owning wrappers that use a templated constructor plus a nested base/model hierarchy, placement new into a fixed buffer, and a virtual clone/move for copying. Demonstrates a Small Buffer Optimization that avoids allocations and yields about a 10% speedup in the presenter’s bench (25k ops over ~2.5k random shapes), and an alternative manual virtual dispatch via function pointers that performs differently on GCC versus Clang. Practical code choices for copy/move semantics and storage policies are given.
AI-written summary · about
chapters (12)
- 0:00Type erasure introduction
- 1:55Type erasure vs inheritance
- 7:18External polymorphism basics
- 14:43Value wrapper encapsulation
- 18:15Copy operations and clone
- 27:10Performance with small buffer
- 31:06No dynamic allocations
- 38:56Buffer size via templates
- 41:45Storage policy challenges
- 43:51Lightweight virtual dispatch
- 51:18Type erasure summary
- 52:03Q&A
related talks
57mFun with Type Erasure: Implementing a Value Wrapper for Polymorphic Types
01h 23mRethink Polymorphism in C++
36mInterfaces Matter
01h 08mRuntime Polymorphism: Back to the Basics
01h 01mGetting Allocators out of Our Way
01h 22mThese 10 tricks that only library implementors know!
01h 35mRuntime Polymorphism: Back to the Basics
01h 13mNothing is better than copy or move
