| Description | Default | |
|---|---|---|
T | The iterator's value type | |
Distance | The iterator's distance type | ptrdiff_t |
Assignable
None
The distance type must be a signed integral type.
None.
None.
None.
[1] It is not required that a Random Access Iterator inherit from the base
The Iterator Tags overview,
Iterator functions
distance
Categories: algorithms, iterators
Component type: function
template <class InputIterator>
inline iterator_traits<InputIterator>::difference_type distance(InputIterator first, InputIterator last);
template <class InputIterator, class Distance>
void distance(InputIterator first, InputIterator last, Distance& n);
Finds the distance between
The second version of
Both interfaces are currently supported [3], for reasons of backward compatibility, but eventually the older version will be removed.
Defined in the standard header iterator, and in the nonstandard backward-compatibility header iterator.h.
For the first version:
For the second version:
•
Constant time if
int main() {
list<int> L;
L.push_back(0);
L.push_back(1);
assert(distance(L.begin(), L.end()) == L.size());
