Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Rogue Wave C++ Standard Library Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

adjacent_difference()

Module:  Standard C++ Library   Library:  Numerics


Function

Local Index

No Entries

Summary

A generalized numeric operation that outputs a sequence of the differences between each adjacent pair of elements in a range

Synopsis

#include <numeric>

namespace std {
  template <class InputIterator, class OutputIterator>
  OutputIterator adjacent_difference(InputIterator start,
                                     InputIterator finish,
                                     OutputIterator result);
  template <class InputIterator,
            class OutputIterator,
            class BinaryOperation>
  OutputIterator adjacent_difference(InputIterator start,
                                     InputIterator finish,
                                     OutputIterator result,
                                     BinaryOperation bin_op);
}

Description

adjacent_difference() fills a sequence with the differences between successive elements in a container. The result is a sequence in which the first element is equal to the first element of the sequence being processed, and the remaining elements are equal to the calculated differences between adjacent elements. For instance, applying adjacent_difference() to {1,2,3,5} produces a result of {1,1,1,2}.

By default, subtraction is used to compute the difference, but you can supply any binary operator. The binary operator is then applied to adjacent elements. For example, by supplying the plus (+) operator, the result of applying adjacent_difference() to {1,2,3,5} is the sequence {1,3,5,8}.

Complexity

This algorithm performs exactly (finish-start) - 1 applications of the default operation (-) or binary_op.

Example

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 26.4.4



Previous fileTop of DocumentContentsIndex pageNext file

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2 of the user's guide.