Component type: function
template<class InputIterator, class Predicate>
InputIterator find_if(InputIterator first, InputIterator last, Predicate pred);
Returns the first iterator
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.
• For each iterator
Linear: at most
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.
adjacent_find
Category: algorithms
Component type: function
template <class ForwardIterator>
ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class BinaryPredicate>
ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred);
The first version of
The second version of
Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.
For the first version:
For the second version:
Linear. If
Find the first element that is greater than its successor.
int A[] = {1, 2, 3, 4, 6, 5, 7, 8};
const int N = sizeof(A) / sizeof(int);
const int* p = adjacent_find(A, A + N, greater <int>());
cout << 'Element ' << p – A << ' is out of order: ' << *p << ' > ' << *(p + 1) << '.' << endl;
find_first_of
Category: algorithms
Component type: function
template <class InputIterator, class ForwardIterator>
InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2);
template <class InputIterator, class ForwardIterator, class BinaryPredicate>
InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryPredicate comp);
