c++11 右值引用、move、完美转发forward<T>

#include <iostream>
#include <string>
using namespace std;

template <typename T>
void PrintT(T& t)
{
cout << "lvalue" << endl;
}

template <typename T>
void PrintT(const T&& t)
{

cout << "rvalue" << endl;
}

template <typename T>
void TestForward(T&& v)
{
PrintT(v);
PrintT(std::forward<T>(v));
PrintT(std::move(v));
}

int main()
{
TestForward(1);

int x = 1;
TestForward(x);
TestForward(x);

return 0;
}

 

posted @ 2016-03-09 18:36  略加思索的河马  阅读(255)  评论(0编辑  收藏  举报