< cpp‎ | experimental‎ | ranges
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
2D Graphics
Iterators library
Iterator concepts
Indirect callable concepts
Common algorithm requirements
Concept utilities
Iterator utilities and operations
Iterator traits
Iterator adaptors
Stream iterators
namespace {

    constexpr /* unspecified */ advance = /* unspecified */;

(ranges TS)
(customization point object)
Call signature
template< Iterator I >
constexpr void advance( I& i, ranges::difference_type_t<I> n );
template< Iterator I, Sentinel<I> S >
constexpr void advance( I& i, S bound );
template< Iterator I, Sentinel<I> S >
constexpr ranges::difference_type_t<I> advance( I& i, ranges::difference_type_t<I> n, S bound );

Advances the iterator i n times, or until bound is reached, whichever comes first.

1) If I models RandomAccessIterator, equivalent to i += n. Otherwise, increments (or decrements if n is negative) i n times. The behavior is undefined if n is negative and I does not model BidirectionalIterator.
2) If Assignable<I&, S> is satisfied, equivalent to i = std::move(bound).
Otherwise, if [ibound) does not denote a range, the behavior is undefined.
Otherwise, if SizedSentinel<S, I> is satisfied, equivalent to ranges::advance(i, bound - i).
Otherwise, increments i until i == bound.
3) If SizedSentinel<S, I> is satisfied, equivalent to ranges::advance(i, bound) if |n| >= |bound - i|, and ranges::advance(i, n) otherwise.
Otherwise, increments (or decrements if n is negative) i either n times or until i == bound, whichever comes first.
If n > 0, [ibound) shall denote a range; if n == 0, either [ibound) or [boundi) shall denote a range; if n < 0, [boundi) shall denote a range, I and S shall be the same type, and I must model BidirectionalIterator. Otherwise, the behavior is undefined.


[edit] Customization point objects

The name ranges::advance denotes a customization point object, which is a function object of a literal Semiregular class type (denoted, for exposition purposes, as AdvanceT). All instances of AdvanceT are equal. Thus, ranges::advance can be copied freely and its copies can be used interchangeably.

Given a set of types Args..., if std::declval<Args>()... meet the requirements for arguments to ranges::advance above, AdvanceT will satisfy ranges::Invocable<const AdvanceT, Args...>. Otherwise, no function call operator of AdvanceT participates in overload resolution.

In every translation unit in which ranges::advance is defined, it refers to the same instance of the customization point object. (This means that it can be used freely in things like inline functions and function templates without violating the one-definition rule.)

[edit] Return value

1,2) (none)
3) The number of increment/decrements not performed due to reaching bound. In other words, n - M, where M is the distance from the starting position of i to the ending position and is negative if the ending position is before the starting position.

[edit] Example

[edit] See also

advances an iterator by given distance
(function template) [edit]
returns the distance between an iterator and a sentinel, or between the beginning and the end of a range
(function template) [edit]
increment an iterator
(function template) [edit]
decrement an iterator
(function template) [edit]