advance (InputIterator& i, Distance n) | Function |
distance (InputIterator first, InputIterator last, Distance& n) | Function |
Since only random access iterators provide + and - operators, the library provides two template functions advance and distance. These functions use + and - for random access iterators (and are, therefore,constant time for them); for input, forward and bidirectional iterators they use ++ to provide linear time implementations. advance takes a negative argument n for random access and bidirectional iterators only. advance increments (or decrements for negative n) iterator reference i by n. distance increments n by the number of times it takes to get from first to last.
templateinline void advance(InputIterator& i, Distance n); template inline void distance(InputIterator first, InputIterator last, Distance& n);
distance must be a three argument function storing the result into a reference instead of returning the result because the distance type cannot be deduced from built-in iterator types such as int*.
|
|