22 Iterators library [iterators]

22.4 Iterator primitives [iterator.primitives]

22.4.3 Range iterator operations [range.iter.ops]

22.4.3.1 ranges​::​advance [range.iter.op.advance]

template<Iterator I> constexpr void ranges::advance(I& i, iter_difference_t<I> n);
Expects: If I does not model BidirectionalIterator, n is not negative.
Effects:
  • If I models RandomAccessIterator, equivalent to i += n.
  • Otherwise, if n is non-negative, increments i by n.
  • Otherwise, decrements i by -n.
template<Iterator I, Sentinel<I> S> constexpr void ranges::advance(I& i, S bound);
Expects: [i, bound) denotes a range.
Effects:
  • If I and S model Assignable<I&, S>, equivalent to i = std::move(bound).
  • Otherwise, if S and I model SizedSentinel<S, I>, equivalent to ranges::advance(i, bound - i).
  • Otherwise, while bool(i != bound) is true, increments i.
template<Iterator I, Sentinel<I> S> constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
Expects: If n > 0, [i, bound) denotes a range.
If n == 0, [i, bound) or [bound, i) denotes a range.
If n < 0, [bound, i) denotes a range, I models BidirectionalIterator, and I and S model Same<I, S>.
Effects:
  • If S and I model SizedSentinel<S, I>:
    • If ​, equivalent to ranges::advance(i, bound).
    • Otherwise, equivalent to ranges::advance(i, n).
  • Otherwise,
    • if n is non-negative, while bool(i != bound) is true, increments i but at most n times.
    • Otherwise, while bool(i != bound) is true, decrements i but at most -n times.
Returns: n - M, where M is the difference between the ending and starting positions of i.