c++ - 有没有像 "std::and"或 "std::or"这样的东西?

标签 c++ algorithm boolean std short-circuiting

给定一个 boolean 值容器(例如 std::vector<bool> ),是否有标准函数返回 true如果所有值都是 true (“和”)或 true如果至少一个值为 true (“或”),短路评估?

我挖了槽www.cplusplus.com今天早上,但找不到任何附近的东西。

最佳答案

is there a standard function that returns true if all the values are true ("and")

std::all_of(vec.begin(), vec.end(), [](bool x) { return x; } )

or true if at least one value is true ("or")

std::any_of(vec.begin(), vec.end(), [](bool x) { return x; } )

with short circuit evalutation?

我刚刚将打印语句插入到 lambda 中,是的,两个函数都执行短路。

关于c++ - 有没有像 "std::and"或 "std::or"这样的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6506659/

相关文章:

c++ - 对于什么 T `std::declval<T>()` 没有匹配函数?

c++ - MFC CFindFile::FindNextFile 用法

c++ - 如何测试 Audio Session 的相等性

algorithm - 将迭代算法转换为递归算法的问题

java - 为什么Java中的 boolean 值只接受真或假?为什么不是 1 或 0 呢?

c++ - 将 boost::function 转换为 std::function

algorithm - 路由信息协议(protocol)实现

c++ - 将多重集排序为升序子序列,每个可用元素出现一次

ios - BOOL 方法有问题

c++ - boolean 值的最小大小是多少?