CHAPTER 10

image

Refactoring

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.