This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Template Specialization Again
- To: <egcs at egcs dot cygnus dot com>
- Subject: Re: Template Specialization Again
- From: "Ross Smith" <ross dot s at ihug dot co dot nz>
- Date: Wed, 17 Feb 1999 16:31:47 +1300
From: Alexandre Oliva <oliva@dcc.unicamp.br>
>
>On Feb 14, 1999, Hirofumi SHINKE <shinke@newhouse.rim.or.jp> wrote:
>
>> template <class T> void f(T x){
>[snip]
>> template <class T> void f<T *>(T x){ // error at this line!
>
>> Dose it mean that egcs dosen't support this type of specialization yet?
>
>There's no such thing as partial specialization of function templates.
>C++ only supports partial specialization of class templates, and
>explicit (full) specialization of function and class templates.
Not true; C++ does support partial specialisation (also called partial
ordering) of function templates, and it's implemented in EGCS. He just
has his syntax slightly wrong. Example:
#include <iostream>
template <typename T> void f(T) { std::cout << "Generic\n"; }
template <typename T> void f(T*) { std::cout << "Partial\n"; }
template <> void f(int*) { std::cout << "Special\n"; }
int main() {
int i(0);
double d(0);
f(i);
f(d);
f(&i);
f(&d);
}
This prints:
Generic
Generic
Special
Partial
as expected.
>Try:
>template <class T> void f(T* x) {
That's the right syntax, so I don't understand why you said there was
no such thing.
--
Ross Smith ................................... mailto:ross.s@ihug.co.nz
.............. The Internet Group, Auckland, New Zealand ..............
"The award for the Most Effective Promotion of Linux
goes to Microsoft." -- Nicholas Petreley