Type-Erasure in WTF
The goal of WTF is to have the user work with objects like wtf::Float,
wtf::FloatBuffer and not say wtf::Float<double>, but at the same time
ensure that operations are done in a type-safe manner. This is achieved
through a pattern known as “type-erasure”. This page documents how we pull
type-erasure off in WTF.
Terminology
Type-erasure involves three classes.
The “Interface” class. This is the class that the user interacts with. In WTF these are
wtf::Floatandwtf::Buffer.The “Holder” class. This is an abstract base class that defines the interactions between the “Interface” class and the actual data. In WTF this is
wtf::detail::FloatHolderandwtf::detail::BufferHolder.The “Model” class. This is a class templated on the type of data being held. It derives from the “Holder” class and implements a model for data of type
T. In WTF these arewtf::detail::FloatModel<T>andwtf::detail::BufferModel<T>.