c++11右值引用

1.  參考:c++11之左值、純右值、將亡值   https://blog.csdn.net/StephenZou14/article/details/77817114

 

 

2. 

std::forword()原型, 頭文件<utility>

lvalue (1)
template <class T> T&& forward (typename remove_reference<T>::type& arg) noexcept;
rvalue (2)
template <class T> T&& forward (typename remove_reference<T>::type&& arg) noexcept;

 

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

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章