C++ 模板中的类型获取
1. 类型判断
严格类型比较:
std::is_same<T1, T2>::value
cout << std::is_same<int, int>::value << endl; // true cout << std::is_same<int, long>::value << endl; // false cout << std::is_same<int, unsigned int>::value << endl; // false cout << std::is_same<int, const int>::value << endl; // false cout << std::is_same<int, int&>::value << endl; // false cout << std::is_same<int, int*>::value << endl; // false
退化类型比较:
std::decay<T>::type
cout << std::is_same<int, std::decay<int>::type>::value << endl; // ture cout << std::is_same<int, std::decay<long>