function template
<iterator>
std::distance
template<class InputIterator> typename iterator_traits<InputIterator>::difference_type distance (InputIterator first, InputIterator last);
Return distance between iterators
Calculates the number of elements between
first and
last.
If it is a random-access iterator, the function uses operator- to calculate this. Otherwise, the function uses the increase operator ( operator++) repeatedly.
Parameters
-
first
- Iterator pointing to the initial element. last
- Iterator pointing to the final element. This must be reachable from first.
Return value
The number of elements between first and last.Example
| |
Output:
The distance is: 10