Iterator
Behaviors
|
 |
The interfaces provided by the
various categories of iterators are fairly simple. Assuming i
and j are both iterators, and n
is an integer, following is a list of all the iterator functions, arranged in
order from the most general to the most specific.
Common to all iterator types
| ++ i |
Advance one element and return a reference to i |
| i ++ |
Advance one element and return the previous value of i |
Input
| * i |
Return a read-only reference to the element at i's
current position. |
| i == j |
Return true if i and j
are both positioned at the same element. |
| i != j |
Return true if i and j
are positioned at different elements. |
Output
| * i |
Return a writeable reference to the element at i's
current position. |
| i = j |
Set i's position to the same as j's. |
Bidirectional
| --i
| Retreat one element and return i's new value. |
| i--
| Retreat one element and return i's previous
value. |
Random access
| i += n |
Advance by n locations and return a reference
to i. |
| i -= n |
Retreat by n locations and return a reference
to i. |
| i + n |
Return an iterator that is positioned n
elements ahead of i's
current position. |
| i - n |
Return an iterator that is positioned n
elements behind i's current
position. |
| i [ n ] |
Return a reference to the n th element from i's
current position. |
According to this hierarchy of
interfaces, a regular C pointer is considered a random access iterator.
Therefore, STL algorithms can accept regular C pointers as well as STL
iterators. In addition, many proprietary class libraries define iterator
objects with the characteristics just described. The STL algorithms can also
accept these iterators as arguments.
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.