A Surprising Partial Specialization

M

Michael Olea

I came across code of the following form:

template<typename T>
class X { ... };

template<typename T, size_t N>
class X<T[N]> { ... };

I was surprised that the partial specialization has more template parameters
than does the primary template. I would not have guessed that was possible.
Now client code of the form:

template<typename T>
class Y { ... X<T>::whatever ... };

.... Y<int[2]> ...

works as expected (i.e. Y invokes the specialized version of X). Hmm...
 
P

Pete Becker

Michael said:
I came across code of the following form:

template<typename T>
class X { ... };

template<typename T, size_t N>
class X<T[N]> { ... };

I was surprised that the partial specialization has more template parameters
than does the primary template. I would not have guessed that was possible.
Now client code of the form:

template<typename T>
class Y { ... X<T>::whatever ... };

... Y<int[2]> ...

works as expected (i.e. Y invokes the specialized version of X). Hmm...

It doesn't have more parameters. The template Y has exactly one
parameter in both cases. It's just that in the second case you need a
larger vocabulary to describe that parameter. <g>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top