Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

The MPL Reference Manual: advance
Front Page / Iterators / Iterator Metafunctions / advance

advance

Synopsis

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.

Parameters

Parameter Requirement Description
Iterator Forward Iterator An iterator to advance.
N Integral Constant A distance.

Expression semantics

For a Forward Iterator iter and arbitrary Integral Constant n:

typedef advance::type j;
Return type:

Forward Iterator.

Precondition:

If Iterator is a Forward Iterator, n::value must be nonnegative.

Semantics:

Equivalent to:

typedef iter i0;
typedef next::type i1;
...
typedef nextn-1>::type j;

if n::value > 0, and

typedef iter i0;
typedef prior::type i1;
...
typedef priorn-1>::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

typedef range_c numbers;
typedef begin::type first;
typedef end::type last;

typedef advanceint_<10> >::type i1;
typedef advanceint_<-10> >::type i2;

BOOST_MPL_ASSERT(( boost::is_same ));
BOOST_MPL_ASSERT(( boost::is_same ));