Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

advance


Iterator Operation

Summary

Moves an iterator forward or backward (if available) by a certain distance.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

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

Description

The advance template function 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

Program Output :

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you have to write:

vector<int,allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

Sequences, Random Access Iterators, distance



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998