给定一个 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/