Topic: Partial Ordering
Author: "Bo-Staffan Lankinen" <bo_steffan_lankinen@hotmail.com>
Date: Tue, 16 Apr 2002 01:50:52 GMT Raw View
Hello,
According to my reading of the partial ordering rules, the function
templates below are listed in increasing specialization order.
template<class T> void Foo(T);
template<class T> void Foo(T&);
template<class T> void Foo(const T&);
template<class T> void Foo(T*);
template<class T> void Foo(const T*);
This contradicts one of the examples in 14.5.5.2. Is the example erronous or
do I misinterpret the rules of partial ordering?
Bo-Staffan
---
[ 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 ]
Author: "Bo-Staffan Lankinen" <bo_steffan_lankinen@hotmail.com>
Date: Tue, 16 Apr 2002 02:56:38 GMT Raw View
> template<class T> void Foo(T);
> template<class T> void Foo(T&);
> template<class T> void Foo(const T&);
> template<class T> void Foo(T*);
> template<class T> void Foo(const T*);
Correction,
template<class T> void Foo(T);
template<class T> void Foo(T&);
template<class T> void Foo(T*);
template<class T> void Foo(const T*);
Bo-Staffan
---
[ 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 ]
Author: Graeme Prentice <gp1@paradise.net.nz>
Date: Tue, 16 Apr 2002 18:09:30 GMT Raw View
On Tue, 16 Apr 2002 02:56:38 GMT, "Bo-Staffan Lankinen"
<bo_steffan_lankinen@hotmail.com> wrote:
>> template<class T> void Foo(T);
>> template<class T> void Foo(T&);
>> template<class T> void Foo(const T&);
>> template<class T> void Foo(T*);
>> template<class T> void Foo(const T*);
>
>Correction,
>
>template<class T> void Foo(T);
>template<class T> void Foo(T&);
>template<class T> void Foo(T*);
>template<class T> void Foo(const T*);
This is discussed in "C++ standard active issue 214" item 2 suggests
that the standard is not clear whether g(T&) is more specialised than
g(T)
In 14.5.5.2 para 4, the standard says "Using the transformed
function parameter list, perform argument deduction against the other
function tem-plate."
and in section 14.8.2.1 "Deducing template arguments from a function
call" paragraph 2 says that "If P is a reference type, the type
referred to by P is used for type deduction."
which is why I think the intention is that T& is not more specialised
than T so the example in 14.5.5.2 is correct
const T* is more specialised than T* which agrees with the example in
the standard - i.e. when the parameter is T* and the calling
argument is const T*, the deduction produces const T * which is an
exact match, but the reverse deduction fails to produce an exact
match
Similarly const T& is more specialised than T&
but const T is not more specialised than T because in 14.8.2.1 it says
the top level CV qualifiers are ignored for type deduction
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 ]
Author: "Bo-Staffan Lankinen" <bo_steffan_lankinen@hotmail.com>
Date: Tue, 16 Apr 2002 23:21:13 GMT Raw View
> This is discussed in "C++ standard active issue 214" item 2 suggests
> that the standard is not clear whether g(T&) is more specialised than
> g(T)
This issue was submitted 13 Mar 2000 and is still open! When can we expect a
resolution to this issue?
> In 14.5.5.2 para 4, the standard says "Using the transformed
> function parameter list, perform argument deduction against the other
> function tem-plate."
>
> and in section 14.8.2.1 "Deducing template arguments from a function
> call" paragraph 2 says that "If P is a reference type, the type
> referred to by P is used for type deduction."
>
> which is why I think the intention is that T& is not more specialised
> than T so the example in 14.5.5.2 is correct
I agree with you that 14.8.2.1 seems to be the most likely way of deducing
the template arguments and that it results in T& not being more specialized
than T, even though it's, IMO, very non-intuitive.
> const T* is more specialised than T* which agrees with the example in
> the standard - i.e. when the parameter is T* and the calling
> argument is const T*, the deduction produces const T * which is an
> exact match, but the reverse deduction fails to produce an exact
> match
>
> Similarly const T& is more specialised than T&
>
> but const T is not more specialised than T because in 14.8.2.1 it says
> the top level CV qualifiers are ignored for type deduction
Agreed.
Thanks for clearing this up for me.
Bo-Staffan
---
[ 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 ]