Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
adjacent_difference
Prototype

template<
    class SinglePassRange,
    class OutputIterator
    >
OutputIterator adjacent_difference(
    const SinglePassRange& source_rng,
    OutputIterator out_it);

template<
    class SinglePassRange,
    class OutputIterator,
    class BinaryOperation
    >
OutputIterator adjacent_difference(
    const SinglePassRange& source_rng,
    OutputIterator out_it,
    BinaryOperation op);

Description

adjacent_difference calculates the differences of adjacent_elements in rng.

The first version of adjacent_difference uses operator-() to calculate the differences. The second version uses BinaryOperation instead of operator-().

Definition

Defined in the header file boost/range/numeric.hpp

Requirements
For the first version
  1. SinglePassRange is a model of the Single Pass Range Concept.
  2. OutputIterator is a model of the OutputIteratorConcept.
  3. If x and y are objects of SinglePassRange's value type, then x - y is defined.
  4. The value type of SinglePassRange is convertible to a type in OutputIterator's set of value types.
  5. The return type of x - y is convertible to a type in OutputIterator's set of value types.
For the second version
  1. SinglePassRange is a model of the Single Pass Range Concept.
  2. OutputIterator is a model of the OutputIteratorConcept.
  3. BinaryOperation is a model of the BinaryFunctionConcept.
  4. The value type of SinglePassRange is convertible to BinaryOperation's first and second argument types.
  5. The value type of SinglePassRange is convertible to a type in OutputIterator's set of value types.
  6. The result type of BinaryOperation is convertible to a type in OutputIterator's set of value types.
Precondition:

[result, result + distance(rng)) is a valid range.

Complexity

Linear. If empty(rng) then zero applications, otherwise distance(rng) - 1 applications are performed.


PrevUpHomeNext