如何检查 C++11 中的类型是否相等?
std::uint32_t == unsigned; //#1
还有一个片段
template<typename T> struct A{
string s = T==unsigned ? "unsigned" : "other";
}
原文由 kyb 发布,翻译遵循 CC BY-SA 4.0 许可协议
如何检查 C++11 中的类型是否相等?
std::uint32_t == unsigned; //#1
还有一个片段
template<typename T> struct A{
string s = T==unsigned ? "unsigned" : "other";
}
原文由 kyb 发布,翻译遵循 CC BY-SA 4.0 许可协议
3 回答1.3k 阅读✓ 已解决
1 回答1k 阅读✓ 已解决
4 回答813 阅读
1 回答886 阅读
1 回答916 阅读
1 回答686 阅读
1 回答791 阅读
您可以使用
std::is_same<T,U>::value
从 C++11 开始。Here,
T
, andU
are the types, andvalue
will betrue
if they are equivalent, andfalse
如果不是。请注意,这是在编译时评估的。
请参阅 http://en.cppreference.com/w/cpp/types/is_same