|
| |
|
| Category: algorithms | | Component type: function |
template<class InputIterator, class Predicate>
InputIterator find_if(InputIterator first, InputIterator last,
Predicate pred);
Returns the first iterator
i in the range
[first, last) such that
pred(*i) is true. Returns
last if no such iterator exists.
Defined in the standard header
algorithm, and in the nonstandard backward-compatibility header
algo.h.
-
Predicate is a model of Predicate.
-
InputIterator is a model of InputIterator.
-
The value type of InputIterator is convertible to the argument type of Predicate.
-
[first, last) is a valid range.
-
For each iterator
i in the range [first, last), *i is in the domain of Predicate.
Linear: at most
last - first applications of
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.