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.
Sexually transmitted infections (STIs)
STD stands for “sexually transmitted disease,” and STI stands for “sexually transmitted infection.” But no matter which term people use, they're talking about the same thing: infections that get passed from one person to another during sex.
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?
I just inserted print statements into the lambda, and yes, both functions perform short-circuiting.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With