The capabilities of iterators varies with the type of object they belong to. In particular, iterators for arrays and vectors can be used for arithmetic, which apply to the underlying subscript. For instance,
Array and vector iterators can also be subscripted, with subscript zero being where the iterator is pointing, and the subscript relative to that. So after the two statements above, p[2] has the value 17, and p[-2] is valid and has the value 18.
Iterators for lists can only be increment and decremented, using ++ and --. Attempts at general arithmetic will not compile.
Iterators are classified in the following categories.
Random Access | The array and vector iterators are random access, having all iterator capabilities. |
Bidirectional | Lists have bidirectional iterators. They can move forwards and backwards, but no general arithmetic or subscripting. |
Forward | Forward are similar to bidirectional, but can only move forward (increment), but not backward (decrement). The forward_list container has these. |
Input | Input iterators can only be moved forward, and can only be referenced (use * on the right of assignment), not stored (cannot use * on the left of an assignemnt). After being referenced, they must be incremented before they can be referenced again. These are similar to restrictions to Java iterators. |
Output | Similar to input, but can only be stored. |