External Polymorphism in C++: Achieving Extensibility Without Virtual Functions
External polymorphism is a decades-old technique that enables type extensibility and composability without relying on virtual functions, thunks, or modifying the original types. The approach has evolved in C++ from early vtable recreation efforts toward more refined patterns like type erasure, which is now commonplace but represents only one form of the technique. The author explores building a composable ValueAdapter template that binds external operations to a type via references, using variadic inheritance and the Curiously Recurring Template Pattern. Simple, single-purpose operation structs such as Read and Write are composed into the adapter, each holding a reference to the target value and exposing minimal, focused functionality. The goal is to incrementally construct a practical external polymorphism framework starting from plain data types, without imposing any requirements on those underlying types.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in