find_if
 |
 |
| 类别:算法 |
组件类型:函数 |
原型
template<class InputIterator, class Predicate>
InputIterator find_if(InputIterator first, InputIterator last,
Predicate pred);
描述
返回范围i在[first, last)中第一个使得pred(*i)为真的迭代器。 如果没有这样的迭代器存在,则返回last。定义
定义于标准头文件 algorithm 和非标准的向后兼容头文件 algo.h 中。类型需求
先决条件
-
[first, last)是一个有效的范围。
- 对于每个迭代器i在[first, last),*i 在 Predicate 的定义域内。
复杂度
线性:最多last - first次Pred.
的应用。
list<int> L;
L.push_back(-3);
L.push_back(0);
L.push_back(3);
L.push_back(-2);
list<int>::iterator result = find_if(L.begin(), L.end(),
bind2nd(greater<int>(), 0));
assert(result == L.end() || *result > 0);
示例
另请参阅
find.
版权所有 © 1999 Silicon Graphics, Inc. 保留所有权利。
商标信息