std::any_of
来源:互联网 发布:进入编程模式错误 编辑:程序博客网 时间:2024/06/16 18:22
函数定义(VS2013):
参数及其返回值:
first,last
分别指向一个序列中初始及末尾位置的输入迭代器。这个范围即 [first,last) ,包括 first 到 last 间的所有元素,包括 first 指向的元素,但不包括 last 指向的元素。
pred
一元谓词(Unary)函数,以范围中的一个元素为参数,然后返回一个可转换成 bool 类型的值。
其返回值表明指定元素是否满足当前函数所检测的条件。
该函数不能修改其参数。
可以是函数指针(Function pointer)类型或函数对象(Function object)或 lambda bind 等类型。
返回
当范围中存在某个元素传入 pred 后返回 ture,则 any_of 返回 ture,否则返回 false。
当范围为空,返回 false。
例子:
#include <iostream>#include <functional>#include <vector>#include <algorithm>using namespace std;function<bool(int)> is_has_odd = [](int x) -> bool{ return x % 2 ? true : false;};int main(){ vector<int> even = { 2, 3, 4, 6, 8, 10, 12, 14, 16 }; if (any_of(even.begin(), even.end(), is_has_odd)) { cout << "yes" << endl; } else { cout << "no" << endl; } return 0;}
运行结果:
0 0
- std::any_of
- all_of, any_of, none_of
- any_of 源码剖析
- STL algorithm(03):any_of
- std
- std
- std
- 算法之旅,直奔<algorithm>之三 any_of
- STL algorithm算法any_of译文及使用(3)
- Boost 学习之算法篇 any_of 与 any_of_equal
- Boost算法库——C++11算法(any_of)
- std::map&&std::set
- std::map & std::hash_map
- std::min std::max
- std::function std::bind
- std::function std::bind
- std::copy() & std::back_inserter()
- std::ref, std::cref
- activity_main cannot be resolved or is not a field
- bzoj 3240 [Noi2013]矩阵游戏
- hihocoder #1107 : Shortest Proper Prefix
- android应用程序和数据库文件绑定
- UVA 1374 Power Calculus
- std::any_of
- 520开通我的CSDN.NET账号
- [POJ 2182] Lost Cows · 树状数组
- 设计模式---单例模式(多线程下的单例模式)
- 自己实现字符串连接函数strcat
- Qt 生成一张图片
- 自己编写函数,实现库函数里的strcpy函数
- Java类集框架之LinkedList源码剖析
- PendingIntent和Intent的区别