![]() |
In C++, template specialization enables us to define specialized versions of templates for some specific argument patterns. It is of two types:
In this article, we will discuss the partial template specialization in C++ and how it is different from the full template specialization Partial Template Specialization in C++In C++, partial template specialization allows us to define a specialized version of the template for some of the template arguments in contrast to full template specialization which requires all the arguments to be defined. Partial template specialization can be defined for all template types, i.e., class template, function template, and variable template. Syntax of Partial Template SpecializationThe syntax for partial template specialization depends on our requirement, template type, and number of templates. In General, 1. For Class TemplatesConsider the primary class template: template <class T, class X> If we want a specialization of the class Geek only for argument X as an integer, we use template specialization like this: template < class T> 2. For Function TemplatesLet the primary function template be: template <typename A, typename B> To specialize the above function template for A as a pointer, we can use the following syntax: template <typename A, typename B> Examples of Partial Template SpecializationExample 1: C++ Program to illustrate Partial Specialization of Class TemplateC++
Output
Primary Template Partial Specialization for int Example 2: C++ Program to illustrate Partial Specialization of Function TemplateC++
Output
Primary Template Partial Specialization Template |
Reffered: https://www.geeksforgeeks.org
C++ |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |