Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide


Library:  Iterators


Local Index

No Entries


A function that advances an iterator forward or backward (if available) by a certain distance


#include <iterator>

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


The advance() function template allows an iterator to be advanced through a container by some arbitrary distance. For bidirectional and random access iterators, this distance may be negative. For random access iterators, this function uses operator+=() and operator-=() for constant time implementations. For input, forward, and bidirectional iterators, advance() uses operator++() for linear time implementations. advance() also uses operator--() with bidirectional iterators for linear time implementations of negative distances.

If n is positive, advance() increments iterator reference i by n. For negative n, advance() decrements reference i. Remember that advance() accepts a negative argument n for random access and bidirectional iterators only.


See Also

Sequences, Random Access Iterators, distance()

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 24.3.4

Previous fileTop of DocumentContentsIndex pageNext file