24 Algorithms library [algorithms]

24.5 Non-modifying sequence operations [alg.nonmodifying]

24.5.8 Adjacent find [alg.adjacent.find]

template<class ForwardIterator> constexpr ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last); template<class ExecutionPolicy, class ForwardIterator> ForwardIterator adjacent_find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last); template<class ForwardIterator, class BinaryPredicate> constexpr ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate> ForwardIterator adjacent_find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, BinaryPredicate pred); namespace ranges { template<ForwardIterator I, Sentinel<I> S, class Proj = identity, IndirectRelation<projected<I, Proj>> Pred = ranges::equal_to<>> constexpr I adjacent_find(I first, S last, Pred pred = {}, Proj proj = {}); template<ForwardRange R, class Proj = identity, IndirectRelation<projected<iterator_t<R>, Proj>> Pred = ranges::equal_to<>> constexpr safe_iterator_t<R> adjacent_find(R&& r, Pred pred = {}, Proj proj = {}); }
Let E be:
  • *i == *(i + 1) for the overloads with no parameter pred,
  • pred(*i, *(i + 1)) != false for the overloads with a parameter pred and no parameter proj,
  • invoke(pred, invoke(proj, *i), invoke(proj, *(i + 1))) != false for the overloads with both parameters pred and proj.
Returns: The first iterator i such that both i and i + 1 are in the range [first, last) for which E holds.
Returns last if no such iterator is found.
Complexity: For the overloads with no ExecutionPolicy, exactly
applications of the corresponding predicate, where i is adjacent_­find's return value.
For the overloads with an ExecutionPolicy, applications of the corresponding predicate, and no more than twice as many applications of any projection.