std::adjacent_find
Defined in header <algorithm>
|
||
template< class ForwardIt > ForwardIt adjacent_find( ForwardIt first, ForwardIt last ); |
(1) | (constexpr since C++20) |
template< class ExecutionPolicy, class ForwardIt > ForwardIt adjacent_find( ExecutionPolicy&& policy, |
(2) | (since C++17) |
template< class ForwardIt, class BinaryPred > ForwardIt adjacent_find( ForwardIt first, ForwardIt last, |
(3) | (constexpr since C++20) |
template< class ExecutionPolicy, class ForwardIt, class BinaryPred > ForwardIt adjacent_find( ExecutionPolicy&& policy, |
(4) | (since C++17) |
Searches the range [
first,
last)
for two consecutive equal elements.
std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> is true. |
(until C++20) |
std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>> is true. |
(since C++20) |
Contents |
[edit] Parameters
first, last | - | the pair of iterators defining the range of elements to examine |
policy | - | the execution policy to use |
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) |
Type requirements | ||
-ForwardIt must meet the requirements of LegacyForwardIterator.
| ||
-BinaryPred must meet the requirements of BinaryPredicate.
|
[edit] Return value
An iterator to the first of the first pair of identical elements, that is, the first iterator it such that *it == *(it + 1) for (1,2) or p(*it, *(it + 1)) != false for (3,4).
If no such elements are found, last is returned.
[edit] Complexity
Given result as the return value of adjacent_find
, M as std::distance(first, result) and N as std::distance(first, last):