1. 参考:c++11之左值、纯右值、将亡值 https://blog.youkuaiyun.com/StephenZou14/article/details/77817114
2.
std::forword()原型, 头文件<utility>
lvalue (1) | |
---|---|
rvalue (2) | |
If arg is an lvalue reference, the function returns arg with its type unchanged.
Otherwise, the function returns an rvalue reference (T&&
) that refers to arg that can be used to pass an rvalue.
std::move()原型,头文件<utility>
template <class T> typename remove_reference<T>::type&& move (T&& arg) noexcept;
Return an rvalue reference that refers to arg.
3.
pure rvalue 就是计算的中间结果,或字面量(处理字符串字面量),即C++11以前的右值。
expiring value 就是表达式返回的右值引用,如std::move()返回的值,或其他返回T&&的函数的返回值。
#include <type_traits> // std::is_lvalue_reference std::is_rvalue_reference
int i[10] = {0,1,2,3,4,5,6,7,8,9};
cout << boolalpha;
cout << is_lvalue_reference<decltype(i[100])>::value << endl;
cout << is_rvalue_reference<decltype(i[100])>::value << endl;
cout << is_lvalue_reference<decltype("abc")>::value << endl;
cout << is_rvalue_reference<decltype("abc")>::value << endl;
4. 参考
https://en.cppreference.com/w/cpp/utility/forward
https://en.cppreference.com/w/cpp/language/value_category
http://www.stroustrup.com/terminology.pdf