.. Iterators/Iterator Metafunctions//distance |20 distance ======== Synopsis -------- .. parsed-literal:: template< typename First , typename Last > struct distance { typedef |unspecified| type; }; Description ----------- Returns the distance between ``First`` and ``Last`` iterators, that is, an |Integral Constant| ``n`` such that ``advance::type`` is identical to ``Last``. Header ------ .. parsed-literal:: #include Parameters ---------- +---------------+---------------------------+-----------------------------------+ | Parameter | Requirement | Description | +===============+===========================+===================================+ | ``First``, | |Forward Iterator| | Iterators to compute a | | ``Last`` | | distance between. | +---------------+---------------------------+-----------------------------------+ Model Of -------- |Tag Dispatched Metafunction| Expression semantics -------------------- For any |Forward Iterator|\ s ``first`` and ``last``: .. parsed-literal:: typedef distance::type n; :Return type: |Integral Constant|. :Precondition: [``first``, ``last``) is a valid range. :Semantics: Equivalent to .. parsed-literal:: typedef iter_fold< iterator_range , long_<0> , next<_1> >::type n; :Postcondition: ``is_same< advance::type, last >::value == true``. Complexity ---------- Amortized constant time if ``first`` and ``last`` are |Random Access Iterator|\ s, otherwise linear time. Example ------- .. parsed-literal:: typedef range_c::type range; typedef begin::type first; typedef end::type last; BOOST_MPL_ASSERT_RELATION( (distance::value), ==, 10); See also -------- |Iterators|, |Tag Dispatched Metafunction|, |advance|, |next|, |prior|