Triple-DES
10/7/2008 10:56:00 AM
On 7 Okt, 12:45, matthias.neuba...@gmail.com wrote:
> On Oct 3, 7:42 pm, Jiøí Paleèek <jpale...@web.de> wrote:
>
>
>
>
>
> > On Fri, 03 Oct 2008 16:07:46 +0200, <matthias.neuba...@gmail.com> wrote:
> > > template<typename C>
> > > int foo_t(C& c)
> > > {
> > > return 0;
> > > }
>
> > > template<typename C>
> > > int foo_t(const C *c)
> > > {
> > > return 1;
> > > }
>
> > > int main() {
> > > const char * s = "Hi!";
> > > return foo_t(s);
> > > }
> > The reason why there is no ambiguity, is because the two functions are
> > ordered by the partial ordering of functions. That is, the second template
> > is more specialized than the first. That is possible because, when
> > matching (const C*) against C&, the reference is stripped from C& (see
> > 14.8.2.1/2). If you call foo_t(1) [eg. calling the C& version with an
> > rvalue], overload resolution succeeds, but the call fails.
>
> ALright. I am still a little bit confused. As you say, when comparing
> function templates ("14.5.5.2 partial ordering of function
> templates"), we perform argument deduction. But 14.5.5.2p4 also
> dictates
>
> "The transformed template is at least as specialized as the other
> if, and only if, the deduction succeeds
> and the deduced parameter types are an exact match (so the
> deduction does not rely on implicit conversions)."
>
> What exactly does the term "exact match" mean in this context? Is this
> specified somewhere else?
>
> In my example above, as I understand it, the deduced parameter type
> for (C&) is
>
> const C*&
>
> which is NOT an exact match to
>
> const C*.
>
> Instead, we MUST use an implicit conversion to strip away the
> reference.
>
> Or, does the term "exact match" mean here, we still compare the
> deduced parameter type and the expected parameter type "inexactly" by
> ignoring
> some parts as specified in 14.8.2.1?
>
> -Matthias
Yes, there is a special case for reference binding, so that the
conversion from const C* to const C*& has "Exact Match" ranking.