Using Modern C++ to Eliminate Virtual Functions
summary
Claims that as of C++20 no statically linked program needs virtual functions, and replaces runtime polymorphism with C++20 Concepts and CTAD. Implements alternatives: constrained templates, a tuple of vectors for multi-type storage, and std::variant for runtime choices, plus a same_as-fold to check allowed types. Builds a device-manager example that removes virtual base pointers and works but costs larger TUs, bigger binaries and compile time, some runtime costs for variant, ordering caveats, and shows a reported 2–4× microbenchmark speedup in favorable cases.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 4:04Binding interfaces
- 7:03Usage
- 9:01Polymorphic Types
- 10:45Virtual Implementation
- 11:11NonVirtual Implementation
- 23:01Storing Multiple Types
- 23:27Properties
- 24:25Vectors
- 27:21Implementations
- 29:10Review
- 29:57Downsides
- 32:28Bold Claim
- 33:08Devirtualization
- 38:08Comments
- 43:33Practice Task
related talks
49mA Journey Into Non-Virtual Polymorphism in C++
59mConcepts driven design
23mFunctional Programming in C++ (Run time vs Compile time types)
56mConcepts - Evolution or Revolution
53mCan C++ Data-oriented-design be Improved?
01h 01mC++ Design Patterns - The Most Common Misconceptions (2 of N)
01h 01mthe Concepts of concepts
32mOptimizing Away C++ Virtual Functions May Be Pointless
