Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Function template distance()

The boost::iterators::distance function template is an adapted version of std::distance for the Boost iterator traversal concepts.

Header
<boost/iterator/distance.hpp>
Synopsis
template <typename Iterator>
constexpr typename iterator_difference<Iterator>::type
distance(Iterator first, Iterator last);
Description

Computes the (signed) distance from first to last.

Requirements

Iterator should model Single Pass Iterator.

Preconditions

If Iterator models Random Access Traversal Iterator, [first, last) or [last, first) should be valid; otherwise [first, last) should be valid.

Complexity

If Iterator models Random Access Traversal Iterator, it takes constant time; otherwise it takes linear time.

Notes
Acknowledgements

Contributed by Michel Morin.


PrevUpHomeNext