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; }