Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

distance


Iterator Operation

Summary

Computes the distance between two iterators.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <iterator>
template <class ForwardIterator>
 iterator_traits<ForwardIterator>::difference_type
 distance (ForwardIterator first,
                ForwardIterator last);

template <class ForwardIterator, class Distance>
 void distance (ForwardIterator first,
                ForwardIterator last,
                Distance& n);

Description

The distance template function computes the distance between two iterators. The first version returns that value, while the second version increments n by that value. The last iterator must be reachable from the first iterator.

Note that the second version of this function is obsolete. It is included for backward compatibility and to support compilers that do not include partial specialization. The first version of the function is not available with compilers that do not support partial specialization, since it depends on iterator_traits, which itself depends on that particular language feature.

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you have to write:

vector <int, allocator,int> >

instead of:

vector <int>

If your compiler does not support partial specialization, then you can't use the version of distance that returns the distance. Instead you have to use the version that increments a reference parameter.

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

Sequences, Random Access Iterators



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998