有什么像“std ::和”或“std ::或”? [英] Is there anything like "std::and" or "std::or"?

查看:160
本文介绍了有什么像“std ::和”或“std ::或”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个布尔值的容器(例如 std :: vector< bool> )是否有一个标准函数返回 true 如果所有值都是 true (and)或 true true (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 ?

我挖槽了 www.cplusplus.com 今天早上,但找不到任何关闭。

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

推荐答案

您可以执行:

AND:

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

这篇关于有什么像“std ::和”或“std ::或”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆