.. Iterators/Iterator Metafunctions//advance |10 advance ======= Synopsis -------- .. parsed-literal:: template< typename Iterator , typename N > struct advance { typedef |unspecified| type; }; Description ----------- Moves ``Iterator`` by the distance ``N``. For |bidirectional| and |random access| iterators, the distance may be negative. Header ------ .. parsed-literal:: #include Parameters ---------- +---------------+---------------------------+-----------------------------------+ | Parameter | Requirement | Description | +===============+===========================+===================================+ | ``Iterator`` | |Forward Iterator| | An iterator to advance. | +---------------+---------------------------+-----------------------------------+ | ``N`` | |Integral Constant| | A distance. | +---------------+---------------------------+-----------------------------------+ Model Of -------- |Tag Dispatched Metafunction| Expression semantics -------------------- For a |Forward Iterator| ``iter`` and arbitrary |Integral Constant| ``n``: .. parsed-literal:: typedef advance::type j; :Return type: |Forward Iterator|. :Precondition: If ``Iterator`` is a |Forward Iterator|, ``n::value`` must be nonnegative. :Semantics: Equivalent to: .. parsed-literal:: typedef iter i0; typedef next::type i1; |...| typedef next::type j; if ``n::value > 0``, and .. parsed-literal:: typedef iter i0; typedef prior::type i1; |...| typedef prior::type j; otherwise. :Postcondition: ``j`` is dereferenceable or past-the-end; ``distance::value == n::value`` if ``n::value > 0``, and ``distance::value == n::value`` otherwise. Complexity ---------- Amortized constant time if ``iter`` is a model of |Random Access Iterator|, otherwise linear time. Example ------- .. parsed-literal:: typedef range_c numbers; typedef begin::type first; typedef end::type last; typedef advance >::type i1; typedef advance >::type i2; BOOST_MPL_ASSERT(( boost::is_same )); BOOST_MPL_ASSERT(( boost::is_same )); See also -------- |Iterators|, |Tag Dispatched Metafunction|, |distance|, |next| .. |bidirectional| replace:: `bidirectional`_ .. _bidirectional: `Bidirectional Iterator`_ .. |random access| replace:: `random access`_ .. _random access: `Random Access Iterator`_