Item 47. Template Partial Specialization

Let’s get it straight: you can’t partially specialize function templates. It’s just not a part of the C++ language (although it may be some day). What you probably want to do is overload them (see Overloading Function Templates [58, 213]). Accordingly, we are considering only class templates in this item.

The way class template partial specialization works is straightforward. As with complete specialization, you first need a general case—or primary template—to specialize. Let’s use our Heap template from Class Template Explicit Specialization [46, 155]:

template <typename T> class Heap;

Explicit specialization (also known colloquially as “complete” specialization) is used to customize a class template ...

Get C++ Common Knowledge: Essential Intermediate Programming now with O’Reilly online learning.

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