[英]std::is_same<A,B>::value == true in line 1, false in line 2
I have a code that returns true in one line, false in the other. 我有一个代码,其中一行返回true,另一行返回false。
For example, 例如,
struct Z{
static const int value = 10;
};
struct A : Z{
};
struct B : Z{
};
int main(){
if(std::is_same<A,B>::value){
static_assert(std::is_same<A,B>::value , "why am i here?");
}
return 0;
}
Can someone please explain why it throws a static assert error? 有人可以解释为什么它引发一个静态的断言错误吗?
This is because static_assert
is a static (that is: compile time) assert. 这是因为static_assert
是静态(即:编译时)断言。 It does not care about the if
statement (evaluated at run-time) above. 它不在乎上面的if
语句(在运行时评估)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.