Re: Conversion error in template specialization
"Daniel Kr?gler" <daniel.kruegler@googlemail.com> schrieb im Newsbeitrag
news:1179082187.075938.51950@w5g2000hsg.googlegroups.com...
[This is a second attempt to get my posting through]
On 12 Mai, 13:54, "Matthias Hofmann" <hofm...@anvil-soft.com> wrote:
The disambiguation overload works! :-) Here's the complete (?) list of
Unfortunatly the list is incomplete. It will e.g. fail for the
use-case
char* a = ...;
const char* b = ...;
minimum(a, b);
That's right, but std::min() suffers from the same problem. You would have
to code as follows:
char* a= ...;
const char* b = ...;
minimum<const char*>( a, b );
The solution is easy: Replace both *specializations* of
the primary minimum template by a single non-template
function:
char const* minimum( char const* a, char const* b )
{
return std::strcmp( a, b ) < 0 ? a : b;
}
I found an interesting article explaining why functions should not be
specialized: http://www.gotw.ca/publications/mill17.htm
No, there does not exist the concept of partial specialization
for function templates, these are called overloads. For class
templates only we have also partial specialization, for functions
only we have overloading.
And what about the following example:
template <class T> class Foo {};
template <std::size_t N> class Foo<char[N]> {};
Am I right in thinking that the specialization of template class Foo is a
*partial* one?
--
Matthias Hofmann
Anvil-Soft, CEO
http://www.anvil-soft.com - The Creators of Toilet Tycoon
http://www.anvil-soft.de - Die Macher des Klomanagers
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]