From 787894944137171780
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,3b5faa9aaea18095
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-09-29 10:03:24 PST
Path: news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: gp1@paradise.net.nz (Graeme Prentice)
Newsgroups: comp.std.c++
Subject: Re: Problem with function template overload resolution
Date: Mon, 29 Sep 2003 17:03:23 +0000 (UTC)
Lines: 68
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <fur9nvsta83c5et8drf2amoqhhs1lvoqu5@4ax.com>
References: <4e6fccc6.0309162227.1aa4bda7@posting.google.com> <3F6E975F.8050300@grad.hr> <bkos2l$8t1$1@sunnews.cern.ch> <4e6fccc6.0309231302.4c6a4a9f@posting.google.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: mail2news.demon.co.uk 1064855003 967 10.0.0.1 (29 Sep 2003 17:03:23 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Mon, 29 Sep 2003 17:03:23 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1A41Qf-0000FJ-00
	for mail2news@news.news.demon.net; Mon, 29 Sep 2003 17:03:22 +0000
X-Received: by mulga.cs.mu.OZ.AU
	id DAA17570; Tue, 30 Sep 2003 03:03:13 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-Orig-NNTP-Posting-Host: 203-96-146-236.apx1.paradise.net.nz (203.96.146.236)
X-Orig-X-Trace: news.uni-berlin.de 1064629433 7830622 203.96.146.236 (16 [98036])
X-Newsreader: Forte Agent 1.93/32.576 English (American)
X-Spamscanner: mailbox7.ucsd.edu  (v1.2 May 26 2003 01:55:38, 0.2/5.0 2.55)
X-MailScanner: PASSED (v1.2.8 56858 h8R2ujlR067857 mailbox7.ucsd.edu)
X-Spam-Status: No, hits=0.2 required=5.0
	tests=EMAIL_ATTRIBUTION,HTML_00_10,REFERENCES
	version=2.55
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
Xref: news1.google.com comp.std.c++:42

On Wed, 24 Sep 2003 15:23:13 +0000 (UTC), jhrwalter@yahoo.com (Joerg
Walter) wrote:

>
>We're not talking about partial specializations but about the interference
>of explicit specification with argument deduction as far as I understand
>14.1.8 bullet 2:
>
>----------
>Trailing template arguments that can be deduced (14.8.2) may be omitted from
>the list of explicit template-arguments. ...
>----------

This rule means both functions are callable.  The two functions are
overloads of each other.  The compiler uses the partial ordering rules
to determine if one function is more specialised than the other
14.5.5.2 para 1 to 5

Partial ordering applied to these two functions works like this ...

template<typename A>
result<A, typename A::value_type> foo(A const& a) {
   std::cout << "foo<A>" << std::endl;
   return result<A, typename A::value_type>();
}

template<typename R, typename A>
R foo(A const& a) {
   std::cout << "foo<R, A>" << std::endl;
   return R();
}


For the first foo(), synthesize a unique type U for the template type
parameter A and call the second foo  i.e. the call is foo( abc ) where
abc is U const &.  For this call, the compiler is unable to deduce the
type of the template parameter R so deduction fails.

Now this is done in reverse  - for the second foo(), synthesize unique
types U1, U2 for R and A and call the first foo()  - the call is
foo(abc) where abc has type U1 const &.  Deduction succeeds because the
template parameter A of the first function is deduced as U1.  Hence the
second foo is more specialised than the first (para 4 & 5)  so the call
foo<arg2<int> >(s2); is not ambiguous.


Note that when you specify something like foo2<a,b>, there is a rule
14.8.2 para 2 that says  ...
<quote>
The specified template arguments must match the template parameters in
kind (i.e., type, nontype, template),and there must not be more
arguments than there are parameters; otherwise type deduction fails.
<>

Hence for the call foo2<a,b> the compiler is forced to call a function
that has at least two template parameters.  It cannot call a non
template function and it cannot call a template function with one
parameter, but it can call a template function with two *or more*
template parameters if additional trailing parameters can be deduced.

Graeme

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]



