The comparison between the consecutive elements is performed by either applying the == comparison operator, or the template parameter comp (for the second version) between them.
The behavior of this function template is equivalent to:
| 1 2 3 4 5 6 7 8 9 10 |
|
Parameters
- first, last
- Forward iterators to the initial and final positions of the searched sequence. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
- pred
- Binary predicate taking two elements as argument and returning the result of the comparison between them, with true (non-zero) meaning that they are to be considered equal, and false (zero) for not-equal. This can either be a pointer to a function or an object whose class overloads operator().
Return value
An iterator to the first element of the first pair of equal consecutive elements in the range [first,last).If no such pair is found, the function returns last.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
Output:
the first consecutive repeated elements are: 30 the second consecutive repeated elements are: 10 |
Complexity
At most, performs as many comparisons or applications of pred as the number of elements in the range [first,last) minus one.See also
| find | Find value in range (function template) |
| find_if | Find element in range (function template) |
| unique | Remove consecutive duplicates in range (function template) |
