Namespaces
Variants
Views
Actions

std::adjacent_find

From cppreference.com
< cpp‎ | algorithm
Revision as of 14:49, 6 June 2011 by P12 (Talk | contribs)

Template:cpp/algorithm/sidebar Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <algorithm>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
template< class ForwardIterator >
ForwardIterator adjacent_find( ForwardIterator first, ForwardIterator last );
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class ForwardIterator, BinaryPredicate p >
ForwardIterator adjacent_find( ForwardIterator first, ForwardIterator last, BinaryPredicate p );
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Searches the range [first, last) for two consecutive identical elements. The first version uses operator== to compare the elements, the second version uses the given binary predicate p.

Template:params

first, last - the range of elements to examine
p - binary predicate which returns ​true if the elements should be treated as equal.

The signature of the predicate function should be equivalent to the following:

 bool pred(const Type1 &a, const Type2 &b);

While the signature does not need to have const &, the function must not modify the objects passed to it and must be able to accept all values of type (possibly const) Type1 and Type2 regardless of value category (thus, Type1 & is not allowed, nor is Type1 unless for Type1 a move is equivalent to a copy(since C++11)).
The types Type1 and Type2 must be such that an object of type ForwardIterator can be dereferenced and then implicitly converted to both of them. ​

Template:returns

an iterator to the first of the identical elements. If no such elements are found, last is returned

Template:eq fun cpp Template:example cpp

Template:complex

linear in the distance between first and last

Template:see also

Template:cpp/algorithm/dcl list unique