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

distance

Description

Returns the distance between 2 iterators.

Synopsis
template<
    typename I,
    typename J
    >
typename result_of::distance<I, J>::type distance(I const& i, J const& j);

Table 1.5. Parameters

Parameter

Requirement

Description

i, j

Models of Forward Iterator into the same sequence

The start and end points of the distance to be measured

Expression Semantics
distance(i,j);

Return type: int

Semantics: Returns the distance between iterators i and j.

Header
#include <boost/fusion/iterator/distance.hpp>
#include <boost/fusion/include/distance.hpp>
Example
typedef vector<int,int,int> vec;

vec v(1,2,3);
assert(distance(begin(v), next(next(begin(v)))) == 2);

PrevUpHomeNext