std::experimental::ranges::adjacent_find (3) - Linux Manuals
std::experimental::ranges::adjacent_find: std::experimental::ranges::adjacent_find
Command to display std::experimental::ranges::adjacent_find
manual in Linux: $ man 3 std::experimental::ranges::adjacent_find
NAME
std::experimental::ranges::adjacent_find - std::experimental::ranges::adjacent_find
Synopsis
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)
I adjacent_find(I first, S last, Pred pred = Pred{}, Proj proj = Proj{});
template< ForwardRange R, class Proj = ranges::identity,
IndirectRelation<projected<ranges::iterator_t<R>, Proj>> Pred = ranges::equal_to<> > (2) (ranges TS)
ranges::safe_iterator_t<R> adjacent_find(R&& r, Pred pred = Pred{}, Proj proj = Proj{});
1) Searches the range [first, last) for two consecutive identical elements. Elements are compared using pred after being projected with proj.
2) Same as (1), but uses r as the source range, as if using ranges::begin(r) as first and ranges::end(r) as last.
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)
adjacent_find (function template)
removes consecutive duplicate elements in a range
unique (function template)
Pages related to std::experimental::ranges::adjacent_find
- std::experimental::ranges::advance (3) - std::experimental::ranges::advance
- std::experimental::ranges::all_of,std::experimental::ranges::any_of, (3) - std::experimental::ranges::all_of,std::experimental::ranges::any_of,
- std::experimental::ranges::all_of,std::experimental::ranges::any_of,std::experimental::ranges::none_of (3) - std::experimental::ranges::all_of,std::experimental::ranges::any_of,std::experimental::ranges::none_of
- std::experimental::ranges::Assignable (3) - std::experimental::ranges::Assignable
- std::experimental::ranges::BidirectionalIterator (3) - std::experimental::ranges::BidirectionalIterator
- std::experimental::ranges::BidirectionalRange (3) - std::experimental::ranges::BidirectionalRange
- std::experimental::ranges::Boolean (3) - std::experimental::ranges::Boolean
- std::experimental::ranges::BoundedRange (3) - std::experimental::ranges::BoundedRange
- std::experimental::ranges::Common (3) - std::experimental::ranges::Common
- std::experimental::ranges::CommonReference (3) - std::experimental::ranges::CommonReference
- std::experimental::ranges::Constructible (3) - std::experimental::ranges::Constructible
- std::experimental::ranges::ConvertibleTo (3) - std::experimental::ranges::ConvertibleTo
- std::experimental::ranges::CopyConstructible (3) - std::experimental::ranges::CopyConstructible
- std::experimental::ranges::Copyable (3) - std::experimental::ranges::Copyable
- std::experimental::ranges::DefaultConstructible (3) - std::experimental::ranges::DefaultConstructible
- std::experimental::ranges::DerivedFrom (3) - std::experimental::ranges::DerivedFrom
- std::experimental::ranges::Destructible (3) - std::experimental::ranges::Destructible
- std::experimental::ranges::EqualityComparable, (3) - std::experimental::ranges::EqualityComparable,
- std::experimental::ranges::EqualityComparable,std::experimental::ranges::EqualityComparableWith (3) - std::experimental::ranges::EqualityComparable,std::experimental::ranges::EqualityComparableWith
- std::experimental::ranges::ForwardIterator (3) - std::experimental::ranges::ForwardIterator
- std::experimental::ranges::ForwardRange (3) - std::experimental::ranges::ForwardRange
- std::experimental::ranges::Incrementable (3) - std::experimental::ranges::Incrementable
- std::experimental::ranges::IndirectRelation (3) - std::experimental::ranges::IndirectRelation
- std::experimental::ranges::IndirectStrictWeakOrder (3) - std::experimental::ranges::IndirectStrictWeakOrder
- std::experimental::ranges::IndirectUnaryInvocable, (3) - std::experimental::ranges::IndirectUnaryInvocable,
- std::experimental::ranges::IndirectUnaryInvocable,std::experimental::ranges::IndirectRegularUnaryInvocable (3) - std::experimental::ranges::IndirectUnaryInvocable,std::experimental::ranges::IndirectRegularUnaryInvocable
- std::experimental::ranges::IndirectUnaryPredicate (3) - std::experimental::ranges::IndirectUnaryPredicate
- std::experimental::ranges::IndirectlyComparable (3) - std::experimental::ranges::IndirectlyComparable
- std::experimental::ranges::IndirectlyCopyable (3) - std::experimental::ranges::IndirectlyCopyable
- std::experimental::ranges::IndirectlyCopyableStorable (3) - std::experimental::ranges::IndirectlyCopyableStorable
- std::experimental::ranges::IndirectlyMovable (3) - std::experimental::ranges::IndirectlyMovable