Boost C++ Libraries 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 for the latest Boost documentation.



      typename First
    , typename Last
struct distance
    typedef unspecified type;


Finds the distance between First and Last, that is, an Integral Constant D such as advance< First,D >::type is identical to Last.


#include "boost/mpl/distance.hpp"


 Parameter  Requirement  Description  
First, LastA model of Input Iterator

Expression semantics

 Expression  Expression type  Precondition  Semantics  Postcondition 
typedef distance<First,Last>::type d;A model of Integral Constant[First, Last) is a valid rangeis_same< advance< First,d >::type, Last >::value


Amortized constant time if Iterator is a model of Random Access Iterator, otherwise linear time.


typedef range_c<int,0,10>::type range;
BOOST_STATIC_ASSERT((distance< begin<range>::type,end<range>::type >::type::value == 10));

See also

Iterators, Sequence, advance, begin, end

Table of Contents
Last edited July 17, 2002 6:47 am