std::experimental::ranges::search_n
Technical Specification | ||||
Filesystem library (filesystem TS) | ||||
Library fundamentals (library fundamentals TS) | ||||
Library fundamentals 2 (library fundamentals TS v2) | ||||
Library fundamentals 3 (library fundamentals TS v3) | ||||
Extensions for parallelism (parallelism TS) | ||||
Extensions for parallelism 2 (parallelism TS v2) | ||||
Extensions for concurrency (concurrency TS) | ||||
Extensions for concurrency 2 (concurrency TS v2) | ||||
Concepts (concepts TS) | ||||
Ranges (ranges TS) | ||||
Reflection (reflection TS) | ||||
Mathematical special functions (special functions TR) | ||||
Experimental Non-TS | ||||
Pattern Matching | ||||
Linear Algebra | ||||
std::execution | ||||
Contracts | ||||
2D Graphics |
Non-modifying sequence operations | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
Modifying sequence operations | ||||||||||||||||||||||||||||
Partitioning operations | ||||||||||||||||||||||||||||
Sorting operations | ||||||||||||||||||||||||||||
Binary search operations | ||||||||||||||||||||||||||||
Set operations (on sorted ranges) | ||||||||||||||||||||||||||||
Heap operations | ||||||||||||||||||||||||||||
Minimum/maximum operations | ||||||||||||||||||||||||||||
Permutations | ||||||||||||||||||||||||||||
Defined in header <experimental/ranges/algorithm>
|
||
template
< ForwardIterator I, Sentinel<I> S, class T,
class Pred =
ranges::equal_to
<>, class Proj =
ranges::identity
>
|
(1) | (ranges TS) |
template
< ForwardRange R, class T, class Pred =
ranges::equal_to
<>,
class Proj =
ranges::identity
>
|
(2) | (ranges TS) |
[
first
,
last
)
for the first sequence of count elements whose projected values are each equal to the given value value according to the predicate pred
Parameters
first, last | - | the range of elements to examine |
r | - | the range of elements to examine |
count | - | the length of the sequence to search for |
value | - | the value to search for |
pred | - | the predicate that compares the projected elements with value |
proj | - | the projection to apply to the elements |
Return value
Iterator to the beginning of the found sequence in the range
[
first
,
last
)
. If no such sequence is found, an iterator that compares equal to last
Complexity
At most last - first applications of the predicate and the projection.
Possible implementation
template<ForwardIterator I, Sentinel<I> S, class T, class Pred = ranges::equal_to<>, class Proj = ranges::identity> requires IndirectlyComparable<I, const T*, Pred, Proj> I search_n(I first, S last, ranges::difference_type_t<I> count, const T& value, Pred pred = Pred{}, Proj proj = Proj{}) { for (; first != last; ++first) { if (!ranges::invoke(pred, ranges::invoke(proj, *first), value)) continue; I candidate = first; ranges::difference_type_t<I> cur_count = 0; while (true) { ++cur_count; if (cur_count == count) // success return candidate; ++first; if (first == last) // exhausted the list return first; if (!ranges::invoke(pred, ranges::invoke(proj, *first), value)) // too few in a row break; } } return first; } |
Example
This section is incomplete Reason: no example |
See also
searches for the first occurrence of a number consecutive copies of an element in a range (function template) |
|
finds the last sequence of elements in a certain range (function template) |
|
finds the first element satisfying specific criteria (function template) |
|
searches for a range of elements (function template) |