Iterators are made to be as abstract as possible; an iterator could be a pointer into an array, a location in a stream which reads from stdin
when you increment it, anything. As such, the standard arithmetic operators are only implemented for random-access iterators so that they don't hide potentially expensive operations behind simple syntax.
In order to increment/decrement any iterator by an arbitrary amount, you can use std::advance
:
std::advance(it, 3); //increment by three
std::advance(it, -1); //decrement once
C++11 provides std::next
and std::prev
which carry this out in a more functional manner:
auto new_it = std::next(it,3); //increment by three
auto new_it = std::prev(it); //decrement once