std::experimental::ranges::adjacent_find
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 Proj =
ranges::identity,
IndirectRelation<
projected
<I, Proj>> Pred =
ranges::equal_to
<>
>
|
(1) | (ranges TS) |
template
< ForwardRange R, class Proj =
ranges::identity,
IndirectRelation<
projected
<
ranges::iterator_t
<R>, Proj>> Pred =
ranges::equal_to
<>
>
|
(2) | (ranges TS) |
[
first
,
last
)
for two consecutive identical elements. Elements are compared using pred after being projected with proj
Notwithstanding the declarations depicted above, the actual number and order of template parameters for algorithm declarations is unspecified. Thus, if explicit template arguments are used when calling an algorithm, the program is probably non-portable.
Parameters
first, last | - | the range of elements to examine |
r | - | the range of elements to examine |
pred | - | predicate to use to compare the projected elements |
proj | - | projection to apply to the elements |
Return value
An iterator to the first of the first pair of identical elements, that is, the first iterator i
such that both i
and i + 1
are in the range [
first,
last)
and
ranges::invoke
(pred, ranges::invoke
(proj, *i), ranges::invoke
(proj, *
(i +
1
)
)
)
!
=
false
If no such elements are found, an iterator that compares equal to last is returned.
Complexity
If the range is nonempty, exactly min((result - first) + 1, (last - first) - 1)
applications of the predicate where result
is the return value, and at most twice as many applications of the projection.
Possible implementation
template<ForwardIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectRelation<projected<I, Proj>> Pred = ranges::equal_to<>> I adjacent_find(I first, S last, Pred pred = Pred{}, Proj proj = Proj{}) { if (first == last) return first; I next = first; ++next; while (next != last) { if (ranges::invoke(pred, ranges::invoke(proj, *first), ranges::invoke(proj, *next))) return first; ++next; ++first; } return next; } |
Example
This section is incomplete Reason: no example |
See also
finds the first two adjacent items that are equal (or satisfy a given predicate) (function template) |
|
removes consecutive duplicate elements in a range (function template) |