Hi,

What exactly qualifies the difference between template specialization
and partial template specialization?

From: http://www.gotw.ca/gotw/049.htm

<quote>

The first template is the primary class template:

template<class T1, class T2, int I>
class A { }; // #1
We can specialize this for the case when T2 is a T1*:

template<class T, int I>
class A<T, T*, I> { }; // #2

Or for the case when T1 is any pointer:

template<class T1, class T2, int I>
class A<T1*, T2, I> { }; // #3

Or for the case when T1 is int and T2 is any pointer and I is 5:

template<class T>
class A<int, T*, 5> { }; // #4

Or for the case when T2 is any pointer:

template<class T1, class T2, int I>
class A<T1, T2*, I> { }; // #5
Declarations 2 to 5 declare partial specializations of the primary template.

</quote>

I presume "partial specialization" to occur only when some members of the
template list are specialized, as in say #2 or #5.

Then how does the case in #4 be "partial specialization", since all of them
are specialized?


TIA,
Sucharit

Re: Difference between template specialization and partial specializat by Simon

Simon
Tue May 10 07:42:56 CDT 2005

When you declare a template specialization, you state that for a particular
set of template parameters, you wish to use a particular implementation.

Any specialization where all template parameters aren't explicitly defined,
either by type or value as appropriate, is a partial specialization.

#4 isn't a complete specialization, as you can use it for any type T.

A non-partial specialization of the example would be:

template<>
class A<int, double*, 5> {};


"SD" <SD@discussions.microsoft.com> wrote in message
news:C44B4ADE-3410-43F4-B15B-C574B5780C30@microsoft.com...
> Hi,
>
> What exactly qualifies the difference between template specialization
> and partial template specialization?
>
> From: http://www.gotw.ca/gotw/049.htm
>
> <quote>
>
> The first template is the primary class template:
>
> template<class T1, class T2, int I>
> class A { }; // #1
> We can specialize this for the case when T2 is a T1*:
>
> template<class T, int I>
> class A<T, T*, I> { }; // #2
>
> Or for the case when T1 is any pointer:
>
> template<class T1, class T2, int I>
> class A<T1*, T2, I> { }; // #3
>
> Or for the case when T1 is int and T2 is any pointer and I is 5:
>
> template<class T>
> class A<int, T*, 5> { }; // #4
>
> Or for the case when T2 is any pointer:
>
> template<class T1, class T2, int I>
> class A<T1, T2*, I> { }; // #5
> Declarations 2 to 5 declare partial specializations of the primary
template.
>
> </quote>
>
> I presume "partial specialization" to occur only when some members of the
> template list are specialized, as in say #2 or #5.
>
> Then how does the case in #4 be "partial specialization", since all of
them
> are specialized?
>
>
> TIA,
> Sucharit



Re: Difference between template specialization and partial specializat by Jerry

Jerry
Tue May 10 23:34:29 CDT 2005

In article <C44B4ADE-3410-43F4-B15B-C574B5780C30@microsoft.com>,
SD@discussions.microsoft.com says...

[ ... ]

> template<class T>
> class A<int, T*, 5> { }; // #4

[ ... ]

> I presume "partial specialization" to occur only when some members of the
> template list are specialized, as in say #2 or #5.
>
> Then how does the case in #4 be "partial specialization", since all of them
> are specialized?

T has to be a pointer, but it can still be a pointer to any type.

An explicit specialization starts with 'template <>' (i.e. the list
of template parameters is empty) and then gives the actual type for
each of the parameters from the base template, such as:

template <>
class A<int, void *, 5> {};

--
Later,
Jerry.

The universe is a figment of its own imagination.