Re: Explicitly specializing std::min() on VC++ 2005 Express Edition
Matthias Hofmann wrote:
Hello everyone,
I am trying to explicitly specialize std::min() to be able to process
C-style strings, but it does not work. Here's the code I have tried:
namespace std
{
template <> inline const char*& min<>
( const char*& a, const char*& b )
{
return std::strcmp( a, b ) < 0 ? a : b;
}
}
What I get is the following error on Visual C++ 2005 Express Edition:
error C2912: explicit specialization; 'const char *&std::min(const char
*&,const char *&)' is not a specialization of a function template
What am I doing wrong?
You have your answer, but just to make things worse, what you are doing
is illegal anyway - you aren't allowed to specialize std function
templates unless the specialization involves a user-declared name (e.g.
you can specialize them for your own types, but not for built-in or
standard library types).
In practice, whether you care about this is up to you, but it is
possible a library might include its own explicit specializations or
explicit instantiations for such specializations, thus rendering your
own explicit specialization either undefined behaviour or a compiler error.
Tom