Re: Conversion error in template specialization
On 14 Mai, 15:47, "Matthias Hofmann" <hofm...@anvil-soft.com> wrote:
"Daniel Kr?gler" <daniel.krueg...@googlemail.com> schrieb im > > On 12 Mai, 13:54, "Matthias Hofmann" <hofm...@anvil-soft.com> wrote:
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 );
I did not deny that. But currently you already overload
minimum (by providing functions templates for char[]
and char const []), so the two specializations show
no real advantage compared to overloading. Or is it
important for you to invoke the functions via explicit
template argument provision? If yes, than you have
to get rid of your overloads, which handle character
arrays, anyway because they would not be invoked
by any explicit type specification!
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?
Correct, the second Foo is a partial specialization of
the first (primary) class template. Note also that writing
template <std::size_t N> class Foo {};
instead of the partial specialization would be an invalid
attempt to *overload* the first class template. It also
has a totally different meaning: While the below "overload"
would be instantiated via a std::size_t value, this is not
so for the partial specialization, which is invoked, if the
type is deduced to match a char[N] array.
Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]