# distance

### Synopsis

    template<
          typename First
        , typename Last
        >
    struct distance
    {
        typedef unspecified type;
    };

### Description

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

### Definition

    #include "boost/mpl/distance.hpp"

### Parameters

Parameter | Requirement | Description
--- | --- | ---
`First`, `Last` | A 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 range |  | `is_same< advance< First,d >::type, Last >::value`

### Complexity

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

### Example

    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 Content | Reference
Last edited July 17, 2002 6:47 am