gpt4 book ai didi

c++ - Boost::tribool:奇怪的行为,还是错误?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:17:38 26 4
gpt4 key购买 nike

我正在探索 boost::tribool并对以下行为感到惊讶。

{
using namespace boost;

boost::tribool t(indeterminate);

assert(t==indeterminate); // This assertion fails!
}

但是,如果我这样做,断言就会通过。

assert(indeterminate(t));

两种情况下都没有编译器警告或错误。谁能很好地解释为什么会这样??

最佳答案

我认为答案在 documentation 中:

比较两个不确定值的结果是不确定的(不正确)——我们不知道这些值是什么,所以我们无法判断它们是否相等;

indeterminate函数可用于测试 tribool 是否处于不确定状态。

关于c++ - Boost::tribool:奇怪的行为,还是错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3495428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com