function template
std::for_each
<algorithm>
template <class InputIterator, class Function> Function for_each (InputIterator first, InputIterator last, Function f);
Apply function to range
Applies function
f
to each of the elements in the range
[first,last)
.
The behavior of this template function is equivalent to:
| |
Example
| |
Output:
myvector contains: 10 20 30 myvector contains: 10 20 30 |
std::find
<algorithm>
template <class InputIterator, class T> InputIterator find ( InputIterator first, InputIterator last, const T& value );
Find value in range
Returns an iterator to the first element in the range
[first,last)
that compares equal to
value
, or
last
if not found.
The behavior of this function template is equivalent to:
| |
std::find_if
<algorithm>
template <class InputIterator, class Predicate> InputIterator find_if ( InputIterator first, InputIterator last, Predicate pred );
Find element in range
Returns an iterator to the first element in the range
[first,last)
for which applying
pred
to it, is true.
The behavior of this function template is equivalent to:
| |
std::find_end
<algorithm>
template <class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_end ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2 ); template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 find_end ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred );
Find last subsequence in range
Searches the range
[first1,last1)
for the last occurrence of the sequence defined by
[first2,last2)
, and returns an iterator to its first element.
The sequence of elements in [first2,last2) is compared to the possible subsequences of successive elements within [first1,last1) by either applying the == comparison operator to each element, or the template parameter comp (for the second version).
The behavior of this function template is equivalent to:
| |
std::find_first_of
<algorithm>
template <class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_first_of ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2 ); template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 find_first_of ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred );
Find element from set in range
Returns an interator to the first occurrence in the range
[first1,last1)
of any of the elements in
[first2,last2)
.
All the elements in [first2,last2) are compared to the each of the values in [first,last) until a match is found. The comparison is performed by either applying the == operator, or the template parameter comp (for the second version).
The behavior of this function template is equivalent to:
| |
Example
| |
Output:
First match is: A First match is: a |
std::count
<algorithm>
template <class InputIterator, class T> typename iterator_traits<InputIterator>::difference_type count ( ForwardIterator first, ForwardIterator last, const T& value );
Count appearances of value in range
Returns the number of elements in the range
[first,last)
that compare equal to
value
.
The behavior of this function template is equivalent to:
| |
std::count_if
<algorithm>
template <class InputIterator, class Predicate> typename iterator_traits<InputIterator>::difference_type count_if ( ForwardIterator first, ForwardIterator last, Predicate pred );
Return number of elements in range satisfying condition
Returns the number of elements in the range
[first,last)
for which condition
pred
is true.
The behavior of this function template is equivalent to:
| |
std::mismatch
<algorithm>
template <class InputIterator1, class InputIterator2> pair<InputIterator1, InputIterator2> mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 ); template <class InputIterator1, class InputIterator2, class BinaryPredicate> pair<InputIterator1, InputIterator2> mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred );
Return first position where two ranges differ
Compares the elements in the range
[first1,last1)
against those in the range beginning at
first2
sequentially, and returns where the first mismatch happens.
The elements are compared by either applying the == comparison operator to each pair of corresponding elements, or the template parameter comp (for the second version).
The function returns a pair of iterators to the first element in each range which differs in both sequences.
The behavior of this function template is equivalent to:
| |
std::equal
<algorithm>
template <class InputIterator1, class InputIterator2> bool equal ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 ); template <class InputIterator1, class InputIterator2, class BinaryPredicate> bool equal ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred );
Test whether the elements in two ranges are equal
Compares the elements in the range
[first1,last1)
with those in the range beginning at
first2
, and returns
true
if the elements in both ranges are considered equal.
The elements are compared by either applying the == comparison operator to each pair of corresponding elements, or the template parameter pred (for the second version).
The behavior of this function template is equivalent to:
| |
std::search
<algorithm>
template <class ForwardIterator1, class ForwardIterator2> ForwardIterator1 search ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2 ); template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 search ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2. BinaryPredicate pred );
Find subsequence in range
Searches the range
[first1,last1)
for the first occurrence of the sequence defined by
[first2,last2)
, and returns an iterator to its first element.
The sequence of elements in [first2,last2) is compared to the possible subsequences of successive elements within [first1,last1) by either applying the == comparison operator or the template parameter pred (for the second version).
The behavior of this function template is equivalent to:
| |
std::search_n
<algorithm>
template <class ForwardIterator, class Size, class T> ForwardIterator search_n ( ForwardIterator first, ForwardIterator last, Size count, const T& value ); template <class ForwardIterator, class Size, class T, class BinaryPredicate> ForwardIterator search_n ( ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred );
Find succession of equal values in range
Searches the range
[first,last)
for a succession of
count
elements, each of them comparing equal (or some other predicate) to
value
.
In the first version, the comparison is performed by applying the == comparison operator between the elements being iterated and value . In the second version, pred is applied to these, and a return value of true (or non-zero) is interpreted as an equivalence.
The behavior of this function template is equivalent to:
| |