all_of


功能描述

如果在[first,last)范围内的数组进行判断,

如果pred返回true返回true

否则返回false

等同于

template<class InputIterator, class UnaryPredicate>
bool all_of (InputIterator first, InputIterator last, UnaryPredicate pred)
{
while (first!=last) {
if (!pred(*first)) return false;
++first;
}
return true;
}

参数

  • first last 数组的范围[first,last)
  • pred 单个参数的函数,接受前面数组给的每个元素,判断并给出返回值

范例

#include <iostream>
#include <algorithm>
#include <array> int main(){
std::array<int,8> foo = {3,5,7,12,13,17,19,23};
if(std :: all_of(foo.begin(),foo.begin() + 3,[](int i){return i%2;}))
std::cout << "All the elements are odd numbers.\n";
else
std::cout << "Not all the elements are odd numbers.\n";
return 0;
}

输出:

Not all the elements are odd numbers.

C++_STL_all_of的更多相关文章

随机推荐

  1. suse 12 配置ip,dns,网关,hostname,ssh以及关闭防火墙

    suse-linux:~ # cat /etc/issue Welcome to SUSE Linux Enterprise Server 12 SP3 (x86_64) - Kernel \r (\ ...

  2. WebKit Inside: DOM树的构建

    当客户端App主进程创建WKWebView对象时,会创建另外两个子进程:渲染进程与网络进程.主进程WKWebView发起请求时,先将请求转发给渲染进程,渲染进程再转发给网络进程,网络进程请求服务器.如 ...

  3. [题解]UVA10700 Camel trading

    链接:http://vjudge.net/problem/viewProblem.action?id=21358 描述:给出一个算式,算式里面有加法和乘法,可以任意添加括号从而改变计算顺序.求可能得到 ...

  4. 单网口RFC2544测试——信而泰网络测试仪实操

    一.测试拓扑 拓扑说明 测试仪一个端口和DUT一个端口相连 DUT假设是一台交换设备,它能够把测试仪发送的流量直接转发回来 注意:要求DUT必须能够把收到的流量环回出来,否则没有办法测试 二.测试思路 ...

  5. Oracle 数据库用户锁定与解锁,用户锁定最大密码失败次数设置方法,ORA-28000: the account is locked问题解决方法

    转至:https://blog.csdn.net/qq_38161040/article/details/108274161 用户多次密码输入错误达到一定值就会被锁定. -- 用户锁定方法 alter ...

  6. Weblogic补丁升级问题

    转至:https://blog.csdn.net/weixin_44659716/article/details/105132466 一.版本信息1)中间件版本 Weblogic10.3.6.02) ...

  7. 2019CCPC Final K. Russian Dolls on the Christmas Tree

    题目大意 一棵 \(n(1\leq n\leq 2\times 10^5)\) 个节点以 \(1\) 为根的树,分别求以 \(1\sim n\) 为根的子树中有多少个节点编号连续的段. \(T(1\l ...

  8. QT:中文字符串与“常量中有字符串”报错

    解决方法参照: (10条消息) Qt5.9 win7系统 中文字符串报错:常量中有字符串_Be busy living or busy dying-CSDN博客 主要是用QStringLiteral( ...

  9. WIN10:IE浏览器的默认主页以及通过链接搜索的默认引擎

    主页设置: 地址栏搜索引擎:

  10. ELK监控nginx日志总结

    ELK介绍 ELK即ElasticSearch + Logstash + kibana ES:作为存储引擎 Logstash:用来采集日志 Kibana可以将ES中的数据进行可视化,可以进行数据分析中 ...