Topic: Q: Template function specialization.


Author: "Igor Krasnopeev" <captaincomatoz@mail.ru>
Date: 21 May 01 03:29:47 GMT
Raw View
In [3rd] 13.5.2 Stroustrup writes, that following declarations are
equivalent:

template <> bool less<const char*>(const char*, const char*);
template <> bool less<>(const char*, const char*);
template <> bool less(const char*, const char*);

And my compiler think so too.

Now, what about this declarations:
(In first and second cases I get compilation error. The third compiles and
works fine.)

template <class T> bool less<T*>(T*, T*);
template <class T> bool less<>(T*, T*);
template <class T> bool less(T*, T*);


Why? Is my compiler is not standard in this case, or there is another
reason?

--

Igor Krasnopeev





      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]




Author: Kent Dahl <kentda@stud.ntnu.no>
Date: 22 May 2001 11:57:31 -0400
Raw View
Igor Krasnopeev wrote:
> template <> bool less<const char*>(const char*, const char*);
...
> template <class T> bool less<T*>(T*, T*);
...
>
> Why? Is my compiler is not standard in this case, or there is another
> reason?

Although I'm no template expert, I belive that a big difference between
the two declarations above, is that the second is a partial template
specialization, while the first is a complete specialization.

AFAIK, partial template specialization is still one of those things that
don't work properly on all compilers, or atleast so I've read here.
Which compiler are you using?

--
<[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]>
  )____(stud.techn.;ind.   k.data)||(softwareDeveloper.at(Trustix))_(
 /"Opinions expressed are mine and not those of my Employer,      "\
( "the University, my girlfriend, stray cats, banana fruitflies,  " )
 \"nor the frontal lobe of my left cerebral hemisphere.           "/
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
Date: 22 May 2001 12:18:01 -0400
Raw View
"Igor Krasnopeev" <captaincomatoz@mail.ru> writes:

| Now, what about this declarations:
| (In first and second cases I get compilation error. The third compiles and
| works fine.)
|
| template <class T> bool less<T*>(T*, T*);
| template <class T> bool less<>(T*, T*);

This syntax is reserved for template partial specialization and there
is no such thing for function template.  So, it is ill-formed.  You
can just explicitly specialize them, or overloading them.

| template <class T> bool less(T*, T*);

This defines another family of functions.  That family overloads
the family defined by

 template<typename T> bool less(T, T);

--
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]