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. 详细介绍Windows下也能够使用osw性能升级历史

    1.Windows系统历史性能分析困难背景 在Linux/Unix上.要追朔历史性能,一般採用部署nmon进行性能监控採集与存储的方式实现.可是却没有在Windows上的版本号. Windows系统假 ...

  2. springboot整合mybatisplus使用记录

    1. springboot项目基本配置 springboot基本pom依赖 <parent> <groupId>org.springframework.boot</gro ...

  3. CentOS单机安装k8s并部署.NET 6程序 压测 记录

    前面部分依照CentOS单机安装k8s并部署.NET 6程序来进行,内存.cpu.centos版本一致,之前222元买的三年8M 2c4g腾讯云轻量服务器,这个教程算是写的很详细的了,基本可以一致执行 ...

  4. 深入剖析CVE-2021-40444-Cabless利用链

    背景 CVE-2021-40444为微软MHTML远程命令执行漏洞,攻击者可通过传播Microsoft Office文档,诱导目标点击文档从而在目标机器上执行任意代码.该漏洞最初的利用思路是使用下载c ...

  5. png图片隐写

  6. sql server 数据字符串替换函数

    sql server 替换函数 replace 函数参数 REPLACE(string_expression, string_pattern, string_replacement) 1.string ...

  7. Windows原理深入学习系列-访问控制列表

    这是[信安成长计划]的第 19 篇文章 0x00 目录 0x01 介绍 0x02 DACL 0x03 创建DACL 0x04 文件读取测试 0x05 进程注入测试 0x06 原理分析 Win10_x6 ...

  8. 截图工具snipaste

    下载地址: https://zh.snipaste.com/download.html 使用: 按F1截图,截图后按F3悬浮

  9. Java基础--序列化和反序列化

    作用:在很多应用中,需要对某些对象进行序列化,让它们离开内存空间,入住物理硬盘,以便长期保存.比如最常见的是Web服务器中的Session对象,当有 10万用户并发访问,就有可能出现10万个Sessi ...

  10. Sonic+p4(1)

    知识: Docker容器(打包环境加应用) 静态镜像运行container docker run(start)形成拓扑 目的:switch1获取switch2的网络统计数据 start.sh启动拓扑, ...