ereOn ereOn - 20 days ago 8
C++ Question

Is there anything like "std::and" or "std::or"?

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 ?

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

Answer

You can implement by:

AND:

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

OR:

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