11 Algorithms library [algorithms]

11.3 Non-modifying sequence operations [alg.nonmodifying]

11.3.8 Adjacent find [alg.adjacent.find]

template <ForwardIterator I, Sentinel<I> S, class Proj = identity, IndirectRelation<projected<I, Proj>> Pred = equal_to<>> I adjacent_find(I first, S last, Pred pred = Pred{}, Proj proj = Proj{}); template <ForwardRange Rng, class Proj = identity, IndirectRelation<projected<iterator_t<Rng>, Proj>> Pred = equal_to<>> safe_iterator_t<Rng> adjacent_find(Rng&& rng, Pred pred = Pred{}, Proj proj = Proj{});

Returns: The first iterator i such that both i and i + 1 are in the range [first,last) for which the following corresponding condition holds: invoke(pred, invoke(proj, *i), invoke(proj, *(i + 1))) != false. Returns last if no such iterator is found.

Complexity: For a nonempty range, exactly min((i - first) + 1, (last - first) - 1) applications of the corresponding predicate, where i is adjacent_find's return value, and no more than twice as many applications of the projection.