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

PrevUpHomeNext

Algorithms

Function template advance()
Function template distance()
Function templates next() and prior()

The boost::iterators::advance function template is an adapted version of std::advance for the Boost iterator traversal concepts.

Header
<boost/iterator/advance.hpp>
Synopsis
template <typename Iterator, typename Distance>
constexpr void advance(Iterator& it, Distance n);
Description

Moves it forward by n increments (or backward by |n| decrements if n is negative).

Requirements

Iterator should model Incrementable Iterator.

Preconditions

Let iti be the iterator obtained by incrementing (or decrementing if n is negative) it by i. All the iterators iti for i = 0, 1, 2, ..., |n| should be valid.

If Iterator does not model Bidirectional Traversal Iterator, n should be non-negative.

Complexity

If Iterator models Random Access Traversal Iterator, it takes constant time; otherwise it takes linear time.

Notes
  • This function is not a customization point and is protected against being found by argument-dependent lookup (ADL).
  • This function is constexpr only in C++14 or later.
Acknowledgements

Contributed by Michel Morin.


PrevUpHomeNext