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

新手上路,请多包涵

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

  std::uint32_t == unsigned;  //#1

还有一个片段

template<typename T> struct A{
  string s = T==unsigned ? "unsigned" : "other";
}

原文由 kyb 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 561
1 个回答

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

Here, T , and U are the types, and value will be true if they are equivalent, and false 如果不是。

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

请参阅 http://en.cppreference.com/w/cpp/types/is_same

原文由 user6420285 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题