Namespaces
Variants
Views
Actions

std::ranges::subrange<I,S,K>::next

From cppreference.com
< cpp‎ | ranges‎ | subrange
 
 
 
std::ranges::subrange
Member functions
Observers
Iterator operations
subrange::next
(C++20)
Deduction guides
Non-member functions
(C++20)
Helper types
(C++20)
 
[[nodiscard]] constexpr subrange next(std::iter_difference_t<I> n = 1) const&
    requires std::forward_iterator<I>;
(1) (since C++20)
[[nodiscard]] constexpr subrange next(std::iter_difference_t<I> n = 1) &&;
(2) (since C++20)
1) Obtains a subrange whose iterator is incremented by min(n, size()) times or decremented by -n times respect to that of *this, when n >= 0 or n < 0 respectively. Equivalent to auto tmp = *this; tmp.advance(n); return tmp;.
2) Increments the stored iterator by min(n, size()) times or decremented it by -n times, when n >= 0 or n < 0 respectively, and then move-constructs the result from *this. Equivalent to advance(n); return std::move(*this);.

The behavior is undefined if:

  • I does not model bidirectional_iterator and n < 0, or
  • the stored iterator is decremented after becoming a non-decrementable value.

Contents

[edit] Parameter

n - number of maximal increments of the iterator

[edit] Return value

A subrange whose iterator is incremented by min(n, size()) times or decremented by -n times respect to the original value of that of *this, when n >= 0 or n < 0 respectively.

[edit] Complexity

Generally min(n, size()) increments or -n decrements on the iterator, when n >= 0 or n < 0 respectively.

Constant if I models random_access_iterator, and either n < 0 or std::sized_sentinel_for<S, I> is modeled.

[edit] Notes

A call to (2) may leave *this in a valid but unspecified state, depending on the behavior of the move constructor of I and S.

[edit] Example

[edit] See also

(C++20)
decrements the iterator by a given distance and returns the original subrange
(public member function) [edit]
(C++20)
advances the iterator by given distance
(public member function) [edit]
(C++11)
increment an iterator
(function template) [edit]
increment an iterator by a given distance or to a bound
(niebloid) [edit]