Templates can be considered a generalization of ordinary classes and functions. Often a preexisting function or class, which is already tested, is promoted to a template, because of new software requirements; this will often save debugging time.

However, be careful before adding template parameters that correspond to implementation details, because they are going to be part of the type. Objects that do not differ significantly may not be interoperable. Consider again the example from Section 1.4.9, which is a container that violates this rule:

template <typename T, size_t INITIAL_CAPACITY = 0>class special_vector;

It makes ...

Get Advanced Metaprogramming in Classic C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.