Re: Implicit move of an lvalue
on Thu Apr 05 2012, Gene Bushuyev <publicfilter-AT-gbresearch.com> wrote:
On Apr 4, 10:21 am, "Alf P. Steinbach" <alf.p.steinbach
+use...@gmail.com> wrote:
However, I would suggest the in my view simpler and more direct
template< class Type >
void f( Type&& that)
{
A b(std::move(that));
}
template< class Type >
void f( Type& that ); // No way (lvalue => ambiguous).
which simply catches any lvalue actual argument with the second
signature, which (in that case) produces an ambiguity error, and just
for good measure is left unimplemented.
You can be even more direct about it and make function deleted:
template< class Type > void f( Type& that ) = delete;
Though I must say, the original issue sounds too contrived, and the
example demonstrates incorrect use, not the language problem. When the
perfect forwarding syntax is used it's always the intention to
forward
I'm not entirely sure of that. For the same reason we made it that
rvalue references only bind to rvalues, you could get into a situation
like this:
template <class A>
typename some_trait<A>::type f(A const& x)
{
return g(x);
}
template <class A>
typename other_trait<A>::type f(A&& x)
{
return g(std::move(x));
}
if the first overload gets eliminated due to SFINAE, we have a similar
problem.
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]