Dynamic Polymorphism with Metaclasses and Code Injection
summary
Argues that virtual inheritance can be replaced by type erasure implemented via static reflection plus code injection and metaclasses, showing a prototype built on an experimental metaclasses Clang fork (Rock3) and Composer Explorer examples. Generates per-facade vtables, clone/move helpers, and storage policies (remote, small-buffer, in-place), restoring value semantics and container friendliness while avoiding intrusive base classes; implementation works in the prototype, but compiler and runtime tradeoffs remain (compile-time cost, occasional V-table faster cases) and generated source can be emitted for tooling.
AI-written summary · about
chapters (13)
- 0:00Introduction and welcome
- 0:29What is dynamic polymorphism
- 1:36Problems with inheritance
- 6:31Implementing virtual functions by hand
- 8:16Type erasure and value semantics
- 16:19Challenges of manual implementation
- 17:01Static reflection in C++
- 20:08Code injection overview
- 27:57Generating virtual functions with code injection
- 37:57Solving dynamic allocation with storage policies
- 40:29Metaclasses for dynamic polymorphism
- 49:18Future work and concerns
- 50:00Resources and closing remarks
related talks
01h 07mDynamic Polymorphism With Code Injection and Metaclasses
59mMeta++: Language Support for Advanced Generative Programming
01h 08mRuntime Polymorphism: Back to the Basics
01h 35mRuntime Polymorphism: Back to the Basics
49mPolymorphism != Virtual: Easy, Flexible Runtime Polymorphism Without Inheritance
01h 48m“Meta: Thoughts on generative C++”
21mSeamless Scope-Safe Metaprogramming Through Polymorphic Subtype Inference (Short Paper)
01h 11mThoughts on Metaclasses - Herb Sutter
