# advance

### Synopsis

    template<
          typename Iterator
        , typename N
        >
    struct advance
    {
        typedef unspecified type;
    };

### Description

Returns an new iterator `i` such as `distance< Iterator,i >::type::value == N::value`.

### Definition

    #include "boost/mpl/advance.hpp"

### Parameters

Parameter | Requirement | Description
--- | --- | ---
`Iterator` | A model of Input Iterator |
`N` | A model of Integral Constant |

### Expression semantics

Expression | Expression type | Precondition | Semantics | Postcondition
--- | --- | --- | --- | ---
`typedef advance<Iterator,N>::type i;` | A model of Input Iterator | `Iterator` and every iterator between `Iterator` and `i` (inclusive) is nonsingular; `N::value` must be nonnegative if `Iterator` is a model of Input Iterator or Forward Iterator | Equivalent to `typedef Iterator::next i1; typedef i1::next i2; .. typedef in-1::next i;` if `N::value > 0`, and `typedef Iterator::prior i1; typedef i1::prior i2; .. typedef in-1::prior i;` otherwise; if `N::value == 0`, the algorithm has no effect. | `distance< Iterator,i >::type::value == N::value`

### Complexity

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

### Example

    typedef vector_c<int,0,1,2,3,4,5,6,7,8,9> numbers;
    typedef begin<numbers>::type first;
    typedef end<numbers>::type last;
    typedef advance_c<first,10>::type iter1;
    typedef advance_c<last,-10>::type iter2;
    BOOST_MPL_ASSERT_IS_SAME(iter1, last);
    BOOST_MPL_ASSERT_IS_SAME(iter2, first);

### See also

Iterators, Sequence, `distance`, `begin`, `end`

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