有没有像&QUOT东西;的std ::和"或QUOT;的std ::或QUOT;? [英] Is there anything like "std::and" or "std::or"?
本文介绍了有没有像&QUOT东西;的std ::和"或QUOT;的std ::或QUOT;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于布尔值的容器(一个例子是的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
这篇关于有没有像&QUOT东西;的std ::和&QUOT;或QUOT;的std ::或QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文