Re: Which function gets specialized?
On May 13, 1:24 am, Zeppe <z...@remove.all.this.long.comment.email.it>
wrote:
James Kanze wrote:
On May 13, 12:18 am, Zeppe
<z...@remove.all.this.long.comment.email.it> wrote:
desktop wrote:
I have this example:
template<class T> (1)
void f( T );
template<class T> (2)
void f( T* );
template<> (3)
void f<>(int*);
Which of (1) and (2) does (3) specialize, and why?
Is the order just a matter of when the specialization is declared?
It's simpler: (2) is a partial specialization of (1), while (3) is a
specialization of (1). Note that there is no relationship between the
specializations, they are just different implementations. So, it makes
no sense to ask if (3) specializes directly (1) or the partial
specialization (2): it's just a specialization of (1).
There's no such thing as partial specialization of a function
template. (1) and (2) are two, independent function templates.
Whatever. The effect is that for a pointer (2) will be called instead of
(1), and, if there is no method to call (1) with pointer, it's the same
of a partial specialization, isn't it?
No. In this case, it sort of acts like one, but partial
specialization of class templates and overloading of function
templates obey different rules in general, and it is better to
keep the vocabulary clean, and to not mix up the two.
You might want to reread section 13.7 of Vandevoorde and
Josuttis. The section carries the somewhat misleading title of
"Partial Specialization of Function Templates", but it explains
in detail the concrete differences between partial
specialization (of class templates) and overloading (of function
templates). (If you haven't already read the book, then you
definitly should. It is the definitive reference concerning
templates, and it is exceptionally well written.)
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34