有没有像&QUOT东西;的std ::和"或QUOT;的std ::或QUOT;?东西、QUOT、std

2023-09-11 05:33:49 作者:犹清

鉴于布尔值的容器(一个例子是的std ::矢量<布尔> ),是否有一个标准的函数,返回如果所有的值(和)或者如果至少有一个价值是(或),短路evalutation?

Given a container of boolean values (An example is std::vector<bool>), is there a standard function that returns true if all the values are true ("and") or true if at least one value is true ("or"), with short circuit evalutation ?

我槽 www.cplusplus.com 今天上午挖,但找不到任何接近。

I digged trough www.cplusplus.com this morning but couldn't find anything close.

推荐答案

您可以实现:

std::find(vector.begin(), vector.end(), false) == vector.end() // all the values are true

std::find(vector.begin(), vector.end(), true) != vector.end() //at least one value is true