[alg.search] (original) (raw)

26 Algorithms library [algorithms]

26.6 Non-modifying sequence operations [alg.nonmodifying]

26.6.15 Search [alg.search]

template<class ForwardIterator1, class ForwardIterator2> constexpr ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator1 search(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);template<class ForwardIterator1, class ForwardIterator2,class BinaryPredicate> constexpr ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,class BinaryPredicate> ForwardIterator1 search(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);

Returns: The first iterator i in the range [first1, last1 - (last2 - first2)] such that for every non-negative integer n less than last2 - first2the following corresponding conditions hold:*(i + n) == *(first2 + n), pred(*(i + n), *(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.

template<[forward_iterator](iterator.concept.forward#concept:forward%5Fiterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward%5Fiterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I2,[sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I2> S2, class Pred = ranges::equal_to,class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly%5Fcomparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2> constexpr subrange<I1> ranges::search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});template<[forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to,class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly%5Fcomparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2> constexpr borrowed_subrange_t<R1> ranges::search(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

Returns:

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

template<class ForwardIterator, class Size, class T = iterator_traits<ForwardIterator>::value_type> constexpr ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);template<class ExecutionPolicy, class ForwardIterator, class Size,class T = iterator_traits<ForwardIterator>::value_type> ForwardIterator search_n(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Size count, const T& value);template<class ForwardIterator, class Size, class T = iterator_traits<ForwardIterator>::value_type,class BinaryPredicate> constexpr ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred);template<class ExecutionPolicy, class ForwardIterator, class Size,class T = iterator_traits<ForwardIterator>::value_type,class BinaryPredicate> ForwardIterator search_n(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred);

Let E be pred(*(i + n), value) != falsefor the overloads with a parameter pred, and *(i + n) == value otherwise.

Returns: The first iterator i in the range [first, last - count] such that for every non-negative integer n less than countthe condition E is true.

Returns last if no such iterator is found.

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

template<[forward_iterator](iterator.concept.forward#concept:forward%5Fiterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S,class Pred = ranges::equal_to, class Proj = identity,class T = projected_value_t<I, Proj>> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly%5Fcomparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]")<I, const T*, Pred, Proj> constexpr subrange<I> ranges::search_n(I first, S last, iter_difference_t<I> count,const T& value, Pred pred = {}, Proj proj = {});template<[forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R, class Pred = ranges::equal_to,class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly%5Fcomparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]")<iterator_t<R>, const T*, Pred, Proj> constexpr borrowed_subrange_t<R> ranges::search_n(R&& r, range_difference_t<R> count,const T& value, Pred pred = {}, Proj proj = {});

Returns: {i, i + count}where i is the first iterator 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).

Returns {last, last} if no such iterator is found.

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

template<class ForwardIterator, class Searcher> constexpr ForwardIterator search(ForwardIterator first, ForwardIterator last, const Searcher& searcher);

Effects: Equivalent to: return searcher(first, last).first;