std::is_same<A,B>::value == 第 1 行为 true,第 2 行为 false
std::is_same<A,B>::value == true in line 1, false in line 2
我的代码在一行中返回true,另一行返回false。
例如,
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;
}
有人可以解释一下为什么会引发静态断言错误?
这是因为 static_assert
是静态(即:编译时间)断言。它不在乎上面的if
语句(在运行时评估)。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- arr[-1]在c++中的奇怪行为
- 继承期间显示未知行为的子类
- 如何在c++中使用引用实现类似python的行为
- G锁定铸造到基础上会释放模拟行为
- 在C++中对T*类型执行std::move的意外行为
- std::当在256字节边界上写入整数时,流的奇怪行为
- 不知道某个东西是否被忽略会引入未定义的行为吗
- 奇怪的构造函数行为
- 重载运算符new[]的行为取决于析构函数
- 不同语言中相同代码的不同行为
- 处理除以零会导致<csignal>意外行为
- Why is UINT32_MAX + 1 = 0?
- 试图理解类对象的行为
- C++错误:"error: int aaa::bbb is protected within this context"
- c++11评估顺序(未定义的行为)
- 从结构寻址时,MMAP变量的行为很奇怪
- IS是INT_MAX (-1)不确定的行为
- 编译器行为和"register storage class specifier is deprecated"