stlab.adobe.com Adobe Systems Incorporated

advance

algorithms.gif
function.gif
iterators.gif
Categories: algorithms, iterators Component type: function

Prototype

template <class InputIterator, class Distance>
void advance(InputIterator& i, Distance n);

Description

Advance(i, n) increments the iterator i by the distance n. If n > 0 it is equivalent to executing ++i n times, and if n < 0 it is equivalent to executing --i n times. If n == 0, the call has no effect.

Definition

Defined in the standard header iterator, and in the nonstandard backward-compatibility header iterator.h.

Requirements on types

  • InputIterator is a model of InputIterator.
  • Distance is an integral type that is convertible to InputIterator's distance type.

Preconditions

Complexity

Constant time if InputIterator is a model of RandomAccessIterator, otherwise linear time.

Example

List<int> L;
L.push_back(0);
L.push_back(1);

List<int>::iterator i = L.begin();
advance(i, 2);
assert(i == L.end());

Notes

See also

distance, InputIterator, BidirectionalIterator, RandomAccessIterator, iterator_traits, Iterators.

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google