<分区>
Possible Duplicate:
Program to implement the is_same_type type trait in c++
我希望我的模板函数根据两个类型名称是否相等来做一些不同的事情:
template <typename T1, typename T2> f()
{
if (T1==T2) ...;
else ...;
}
我知道“if(T1==T2)”行不通,但是,有办法吗?
标签 c++
<分区>
Possible Duplicate:
Program to implement the is_same_type type trait in c++
我希望我的模板函数根据两个类型名称是否相等来做一些不同的事情:
template <typename T1, typename T2> f()
{
if (T1==T2) ...;
else ...;
}
我知道“if(T1==T2)”行不通,但是,有办法吗?
最佳答案
您可以查看 boost::is_same
或 std::is_same
在 C++11 中。
所以,它会是这样的:
template <typename T1, typename T2> f()
{
if (boost::is_same<T1,T2>::value) ...;
else ...;
}
关于c++ - 模板函数可以比较两个类型名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13654309/