Component type: function

Prototype

template<class InputIterator, class Predicate>

InputIterator find_if(InputIterator first, InputIterator last, Predicate pred);

Description

Returns the first iterator i in the range [first, last) such that pred(*i) is true. Returns last if no such iterator exists.

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

• 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.

Preconditions

• [first, last) is a valid range.

• For each iterator i in the range [first, last), *i is in the domain of Predicate.

Complexity

Linear: at most last – first applications of Pred.

Example

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);

See also

find.

adjacent_find

Category: algorithms

Component type: function

Prototype

Adjacent_find is an overloaded name; there are actually two adjacent_find functions.

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);

Description

The first version of adjacent_find returns the first iterator i such that i and i+1 are both valid iterators in [first, last), and such that *i == *(i+1). It returns last if no such iterator exists.

The second version of adjacent_find returns the first iterator i such that i and i+1 are both valid iterators in [first, last), and such that binary_pred(*i, *(i+1)) is true. It returns last if no such iterator exists.

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

For the first version:

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator 's value type is Equality Comparable.

For the second version:

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator's value type is convertible to BinaryPredicate's first argument type and to its second argument type.

Preconditions

• [first, last) is a valid range.

Complexity

Linear. If first == last then no comparison are performed; otherwise, at most (last – first) – 1 comparisons.

Example

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;

See also

find, mismatch, equal, search

find_first_of

Category: algorithms

Component type: function

Prototype

find_first_of is an overloaded name; there are actually two find_first_of functions.

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);

Description

Find_first_of is similar to find, in that it performs linear

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату