鉴于布尔值的容器(一个例子是的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