Here are my highlights from Andre Alexandrescu’s Modern C++ Design: Generic Programming and Design Patterns Applied.
Overview:
Policy-based class design fosters assembling a class with complex behavoir out of many little classes (called policies), each of which takes care of only one behavioral or structural aspect.
By using template template parameters, you can avoid redundant (or easily inferred) parameters and give the host class access to the template. Thus, do this:
// Libarary code
template <template <class Created> class CreationPolicy>
class WidgetManager : public CreationPolicy<Widget> {}
// App code
typedef WidgetManager<OpNewCreator> MyWidgetManager;
(The Widget in the library class’s inheritance allows it to specify the type it works with—it is the Created class.)
Combining policy classes in a single host class:
// Library code
template <class T, template<class> class CheckingPolicy, template<class> class ThreadingModel>
class SmartPtr;
// App code
typedef SmartPtr<Widget, NoChecking, SingleThreaded> WidgetPtr;