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

advance()

Library:  Iterators


Function

Local Index

No Entries

Summary

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

Synopsis

#include <iterator>

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

Description

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.

Example

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