Topic: Template function specialization.


Author: "Michael Kochetkov" <Michael.Kochetkov@trustworks.commmm>
Date: 22 May 01 21:01:01 GMT
Raw View
"Igor Krasnopeev" <captaincomatoz@mail.ru> wrote in message
news:9e8jab$epf$1@josh.sovintel.ru...
> 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?
The explicit specialization of a template has the following form:
template <> declaration.

You may not use a template-id as a parameterized function's name. A
template-id may be used as parameterized class name for a class template
partial specialization declaration only. There is no such this as the
function template partial specialization in C++.

With regards,
Michael Kochetkov.




      [ 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: "Samuel Schulman" <s.schulman@berlin.de>
Date: 21 May 2001 15:09:26 -0400
Raw View
"Igor Krasnopeev" wrote in message :
> 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*);
                                               ^ these brackets only for
specializations
> template <class T> bool less<>(T*, T*);
                                                ^ same here
> template <class T> bool less(T*, T*);
>
>
> Why? Is my compiler is not standard in this case, or there is another
> reason?
>

The reason is that this is not legal C++ code, except the third declaration.
The second < > are used only when you declare template specializations, not
when you declare a general template.


Samuel Schulman
---
[ 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: "Paul Mensonides" <pmenso57@home.com>
Date: 21 May 2001 15:10:02 -0400
Raw View
"Igor Krasnopeev" <captaincomatoz@mail.ru> wrote in message
news:9e8jab$epf$1@josh.sovintel.ru...
| 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?

Partial specialization of template functions are illegal (for no good reason).
#1 and #2 are both partial specialization "attempts."

given #3 (which compiles if you pass pointers to the type specified by T):

int a, b;
less<int>(a, b); // error:  parameters are of type int*
less<int>(&a, &b); // okay

Paul Mensonides
---
[ 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                ]