Topic: template parameter deduction for rvalue bount to reference
Author: "Michael Kochetkov" <mkochetk@trustworks.commm>
Date: 2000/05/02 Raw View
"Christopher Eltschka" <celtschk@physik.tu-muenchen.de> wrote in message
news:38FC95C1.5A199FF1@physik.tu-muenchen.de...
> Is the following code legal?
>
> template<class T> void f(T&) {}
>
> void g()
> {
> f(1);
> }
>
> Given that the type of 1 is int, one possible view is that this
> should instantiate f<int>(int&), and therefore the call should fail.
> Indeed, that's also what g++ does.
>
> OTOH, given that this call would fail, IMHO it would be reasonable
> to instantiate f<int const>(int const&), since this will work,
> is obviously the intention, and after all makes sense (1 _is_
> a constant).
>
> Now looking into CD2, it seems that f<int> is taken; I might
> have missed something though. Does the standard demand
> f<int> here?
> If so, was the choice f<int const> ever considered, and if
> so, why was it rejected?
> Does anyone else share my opinion that the most reasonable
> behaviour would be to instantiate (and call) f<int const>?
8.3.5/3 -- "Any cv-qualifier modifying a parameter type is deleted." ...
"Such cv-qualifiers affect only the definition of the parameter within the
body of the function..."
14.8.2.1/2 -- I consider that T is not a reference type in your case, so
cv-qualifier is ignored for type deduction.
Resume:
template<> void f(int&) {} comes into being. It is wrong and you do need the
explicit template argument list,i.e f<const int>(1).
With regards,
Michael Kochetkov.
>
> ---
> [ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
>
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Hyman Rosen <hymie@prolifics.com>
Date: 2000/05/02 Raw View
In article <3909d0b2@news.telekom.ru>,
"Michael Kochetkov" <mkochetk@trustworks.commm> wrote:
> 8.3.5/3 -- "Any cv-qualifier modifying a parameter type is deleted."
But this is not the case here because of the reference.
Is there a good argument as to why constants should not have const T
type?
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 2000/04/19 Raw View
Is the following code legal?
template<class T> void f(T&) {}
void g()
{
f(1);
}
Given that the type of 1 is int, one possible view is that this
should instantiate f<int>(int&), and therefore the call should fail.
Indeed, that's also what g++ does.
OTOH, given that this call would fail, IMHO it would be reasonable
to instantiate f<int const>(int const&), since this will work,
is obviously the intention, and after all makes sense (1 _is_
a constant).
Now looking into CD2, it seems that f<int> is taken; I might
have missed something though. Does the standard demand
f<int> here?
If so, was the choice f<int const> ever considered, and if
so, why was it rejected?
Does anyone else share my opinion that the most reasonable
behaviour would be to instantiate (and call) f<int const>?
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]