: - ?
, ( ), . () . , , "" , rvalue-reference, . N1377:
rvalue rvalue, lvalues . :
struct A {};
void h(const A&);
void h(A&&);
void g(const A&);
void g(A&&);
void f(A&& a)
{
g(a);
h(a);
}
rvalue "a" f(), , a lvalue. , g() h() const A & (lvalue) . "a" rvalue f : " " g(), , , "a", "a" h().
, h(a) , :
h(std::move(a));
Casey , lvalues:
#include <utility>
#include <type_traits>
template<class T>
class parse
{
static_assert(!std::is_lvalue_reference<T>::value,
"parse: T can not be an lvalue-reference type");
public:
void operator()(T const& arg, int n) const { }
void operator()(T&& arg , int n) const { }
};
template<class T>
void split(T&& arg, int n)
{
typedef typename std::decay<T>::type Td;
for (auto i = 0; i < n - 1; ++i)
parse<Td>()(arg , i);
parse<Td>()(std::forward<T>(arg), n - 1);
}
, , parse<T> , std::decay. static_assert, , . static_assert , . static_assert .
. , parse lvalue, , :
template<class T>
class parse<T&>
{
public:
void operator()(T const& arg, int n) const { }
};
decay:
template<class T>
void split(T&& arg, int n)
{
for (auto i = 0; i < n - 1; ++i)
parse<T>()(arg , i);
parse<T>()(std::forward<T>(arg), n - 1);
}
parse<T&>.