CRTP and policy-based design
Policy-based design is a compile-time variant of the well-known Strategy pattern; we have an entire chapter dedicated to it, Chapter 15, aptly named Policy-Based Design. Here, we’re going to stay focused on the use of CRTP to provide additional functionality to the derived classes. Specifically, we are going to generalize the use of CRTP base classes to extend the interface of the derived class.
So far, we have used one base class to add features to the derived class:
template <typename D> struct plus_base {…}; class D : public plus_base<D> {…};
However, if we want to extend the interface of the derived class in multiple ways, a single base class presents an unnecessary restriction. First of all, if we add several member functions, the base class can get quite large. Second, we may want a more modular approach to the interface design. For example, we can have one base class template that adds factory construction...