检查C++中两种类型是否相等

kyb*_*kyb 10 c++ type-traits c++11

如何检查C++ 11中的类型是否相等?

 std::uint32_t == unsigned;  //#1
Run Code Online (Sandbox Code Playgroud)

另一个片段

template<typename T> struct A{ 
  string s = T==unsigned ? "unsigned" : "other";
}
Run Code Online (Sandbox Code Playgroud)

小智 12

您可以std::is_same<T,U>::value从C++ 11开始使用.

在这里,TU是类型,并且value将是true如果他们是等价的,false如果他们不.

请注意,这是在编译时评估的.

http://en.cppreference.com/w/cpp/types/is_same