O'Reilly logo

Advanced Metaprogramming in Classic C++ by Davide Di Gennaro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required