【发布时间】:2013-11-07 08:28:42
【问题描述】:
受到this question 上的一位 cmets 的启发,我想在我的代码中编写此代码,因为我可能做出了错误的假设,如果我将代码移植到两种类型不相同的平台上,则需要进行调查。
static_assert(typeid(float) == typeid(GLfloat), "GLfloat is unexpected type");
但是因为error: call to non-constexpr function ‘bool std::type_info::operator==(const std::type_info&) const’ 没有编译
但是我可以这样写:-
static_assert(sizeof(float) == sizeof(GLfloat), "GLfloat is unexpected size");
而且它按预期工作。 如果我的假设在新平台上是错误的,这很可能足以给我一个编译时错误,但我想知道是否有任何方法可以实现我真正想要的 - 比较实际类型?
【问题讨论】:
标签: c++