Specialization of what?

D

Dave Theese

Hello all,

The code shown below is adapted from Mr. Sutter's Guru of the Week #49.

The 8'th definition of f() is a specialization. What is it a specialization
of (i.e., which is the primary template)???

Is there an answer? If so, is it moot or is the answer meaningful in some
functional way?

Thanks,
Dave

template<class T1, class T2> int f(T1, T2) {return 1;}

template<class T> int f(T) {return 2;}

template<class T> int f(T, T) {return 3;}

template<class T> int f(T*) {return 4;}

template<class T> int f(T*, T) {return 5;}

template<class T> int f(T, T*) {return 6;}

template<class T> int f(int, T*) {return 7;}

template<> int f<int>(int) {return 8;}

int f(int, double) {return 9;}

int f(int) {return 10;}
 
V

Victor Bazarov

Dave Theese said:
The code shown below is adapted from Mr. Sutter's Guru of the Week #49.

The 8'th definition of f() is a specialization. What is it a specialization
of (i.e., which is the primary template)???

Is there an answer? If so, is it moot or is the answer meaningful in some
functional way?

Thanks,
Dave

template<class T1, class T2> int f(T1, T2) {return 1;}

template<class T> int f(T) {return 2;}

template<class T> int f(T, T) {return 3;}

template<class T> int f(T*) {return 4;}

template<class T> int f(T*, T) {return 5;}

template<class T> int f(T, T*) {return 6;}

template<class T> int f(int, T*) {return 7;}

template<> int f<int>(int) {return 8;}

int f(int, double) {return 9;}

int f(int) {return 10;}

I believe (8) is a specialisation of (2). That's the only template
which has one type argument and whose sole function argument is a pure
type as well (not a pointer) and the same as the template type argument.

Wasn't there an answer given to that GotW? Search Google news archives,
I bet it has been discussed in comp.lang.c++.moderated...

Victor
 

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
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top