Files
cppdraft_translate/cppdraft/alg/adjacent/find.md
2025-10-25 03:02:53 +03:00

5.0 KiB

[alg.adjacent.find]

26 Algorithms library [algorithms]

26.6 Non-modifying sequence operations [alg.nonmodifying]

26.6.10 Adjacent find [alg.adjacent.find]

🔗

`template 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);

template<forward_iterator I, sentinel_for S, class Proj = identity, indirect_binary_predicate<projected<I, Proj>, projected<I, Proj>> Pred = ranges::equal_to> constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {}); template<forward_range R, class Proj = identity, indirect_binary_predicate<projected<iterator_t, Proj>, projected<iterator_t, Proj>> Pred = ranges::equal_to> constexpr borrowed_iterator_t ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_binary_predicate<projected<I, Proj>, projected<I, Proj>> Pred = ranges::equal_to> I ranges::adjacent_find(Ep&& exec, I first, S last, Pred pred = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_binary_predicate<projected<iterator_t, Proj>, projected<iterator_t, Proj>> Pred = ranges::equal_to> borrowed_iterator_t ranges::adjacent_find(Ep&& exec, R&& r, Pred pred = {}, Proj proj = {}); `

1

#

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;

bool(invoke(pred, invoke(proj, *i), invoke(proj, *(i + 1)))) for the overloads with both parameters pred and proj.

2

#

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.

3

#

Complexity: For the non-parallel algorithm overloads, exactly min((i - first) + 1, (last - first) - 1) applications of the corresponding predicate, where i is adjacent_find's return value.

For the parallel algorithm overloads,O(last - first) applications of the corresponding predicate.

No more than twice as many applications of any projection.