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

Random Access Iterators

Library:  Iterators

Local Index

No Entries


An iterator that reads, writes, and allows random access to a container


NOTE -- For a complete discussion of iterators, see the Iterators section of this reference.

Iterators are a generalization of pointers that allow a C++ program to uniformly interact with different data structures. Random access iterators can read, write, and allow random access to the containers they serve. These iterators satisfy the requirements listed below.

Key to Iterator Requirements

The following key pertains to the iterator requirements listed below:

a and b

values of type X


value of distance type

u, Distance, tmp and m



value of type X&


value of type T

Requirements for Random Access Iterators

The following expressions must be valid for random access iterators:

X u

u might have a singular value


X() might be singular


copy constructor, a == X(a)

X u(a)

copy constructor, u == a

X u = a

assignment, u == a

a == b, a != b

return value convertible to bool

r = a

assignment, r == a


return value convertible to T&


equivalent to (*a).m


returns X&


return value convertible to const X&


returns T&


returns X&


return value convertible to const X&


returns T&

r += n

Semantics of --r or ++r n times depending on the sign of n

a + n, n + a

returns type X

r -= n

returns X&, behaves as r += -n

a - n

returns type X

b - a

returns distance


*(a+n), return value convertible to T

a < b

total ordering relation

a > b

total ordering relation opposite to <

a <= b

!(a < b)

a >= b

!(a > b)

Like forward iterators, random access iterators have the condition that a == b implies *a == *b.

There are no restrictions on the number of passes an algorithm may make through the structure.

All relational operators return a value convertible to bool.

See Also

Iterators, Forward Iterators, Bidirectional Iterators

Standards Conformance

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

Previous fileTop of DocumentContentsIndex pageNext file