O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

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

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

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