11 Algorithms library [algorithms]

11.3 Non-modifying sequence operations [alg.nonmodifying]

11.3.13 Search [alg.search]

template <ForwardIterator I1, Sentinel<I1> S1, ForwardIterator I2, Sentinel<I2> S2, class Pred = equal_to<>, class Proj1 = identity, class Proj2 = identity> requires IndirectlyComparable<I1, I2, Pred, Proj1, Proj2> I1 search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}); template <ForwardRange Rng1, ForwardRange Rng2, class Pred = equal_to<>, class Proj1 = identity, class Proj2 = identity> requires IndirectlyComparable<iterator_t<Rng1>, iterator_t<Rng2>, Pred, Proj1, Proj2> safe_iterator_t<Rng1> search(Rng1&& rng1, Rng2&& rng2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{});

Effects: Finds a subsequence of equal values in a sequence.

Returns: The first iterator i in the range [first1,last1 - (last2-first2)) such that for every non-negative integer n less than last2 - first2 the following condition holds:

invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n))) != false.

Returns first1 if [first2,last2) is empty, otherwise returns last1 if no such iterator is found.

Complexity: At most (last1 - first1) * (last2 - first2) applications of the corresponding predicate and projections.

template <ForwardIterator I, Sentinel<I> S, class T, class Pred = equal_to<>, class Proj = identity> requires IndirectlyComparable<I, const T*, Pred, Proj> I search_n(I first, S last, difference_type_t<I> count, const T& value, Pred pred = Pred{}, Proj proj = Proj{}); template <ForwardRange Rng, class T, class Pred = equal_to<>, class Proj = identity> requires IndirectlyComparable<iterator_t<Rng>, const T*, Pred, Proj> safe_iterator_t<Rng> search_n(Rng&& rng, difference_type_t<iterator_t<Rng>> count, const T& value, Pred pred = Pred{}, Proj proj = Proj{});

Effects: Finds a subsequence of equal values in a sequence.

Returns: The first iterator i in the range [first,last-count) such that for every non-negative integer n less than count the following condition holds: invoke(pred, invoke(proj, *(i + n)), value) != false. Returns last if no such iterator is found.

Complexity: At most last - first applications of the corresponding predicate and projection.