help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function template overloading and parameter deduction c++03 standard


From: John V. Shahid
Subject: Re: function template overloading and parameter deduction c++03 standard conformance
Date: Sun, 23 Sep 2007 19:05:25 -0400

On Fri, 2007-09-21 at 14:07 -0700, petr.zika@gmail.com wrote:
> It may seem that if it compiles in the new version, it was simply a
> bug fixed, but I found some discussion regarding similar problem,
> stating that the code is invalid in c++03 standard and that the c++0x
> standard will contain modifications allowing such construct to work.

The problem seems to be resulting from a buggy implementation of
"Partial ordering" of template functions. From the compiler output that
you've attached, the problem is that the function call is ambiguous in
some sense since the template parameter in the first function can be
"const int", which makes it a legal candidate. The template parameter of
the second function "P" can also be deduced to be "int" which also makes
the second function a candidate, thus the ambiguity. "Partial ordering"
of template functions solves this issue, by saying that the second
function (i.e. template <typename T, typename P> T foo(const P &p) ) is
the valid candidate for the function call, since it's more specific than
the first. I'm not sure when "Partial ordering" was introduced in the C
++ standard. As a matter of fact the old G++ might have been implemented
before the introduction of "Partial ordering" concept. By the way, my
reference is "Thinking in C++ 2ed" which was written a year or two ago.
This makes believe that the code is valid according to the current C++
standards, and won't be addressed by the next version of the standard.

-- 
John V. Shahid <jvshahid@gmail.com>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]