std::ranges::subrange<I,S,K>::next - cppreference.com (original) (raw)
Returns a subrange whose _[begin](../subrange.html#begin "cpp/ranges/subrange")_ is incremented (or decremented if n is negative). The actual increment (or decrement) operation is performed by advance().
- Returns a copy of *this.
Equivalent to: auto tmp = *this;
tmp.advance(n);
return tmp;.
- Returns a
subrangemoved from *this.
Equivalent to: advance(n);
return std::move(*this);.
[edit] Parameter
| n | - | number of maximal increments of the iterator |
|---|
[edit] Return value
As described above.
[edit] Notes
The difference between this function and advance() is that the latter performs the increment (or decrement) in place.
[edit] Example
#include #include #include #include int main() { std::array arr{1, 2, 3, 4, 5, 6, 7}; std::ranges::subrange sub{std::next(arr.begin(), 2), std::prev(arr.end(), 2)}; std::println("1) sub: {}", sub); std::println("2) sub: {}", sub.next()); std::println("3) sub: {}", sub.next(2)); }
Output:
- sub: [3, 4, 5]
- sub: [4, 5]
- sub: [5]
[edit] See also
| | obtains a copy of the subrange with its iterator decremented by a given distance (public member function) [edit] | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | | advances the iterator by given distance (public member function) [edit] | | | increment an iterator (function template) [edit] | | | increment an iterator by a given distance or to a bound(algorithm function object)[edit] |