adjacent_difference
calculates the differences of adjacent elements in the range [first, last)
. That is, *first
is assigned to *result
, and, for each iterator i
in the range [first + 1, last)
, the difference of *i
and *(i - 1)
is assigned to *(result + (i - first))
.
This version of adjacent_difference
uses operator-
to calculate differences.
- Parameters
-
first | The beginning of the input range. |
last | The end of the input range. |
result | The beginning of the output range. |
- Returns
- The iterator
result + (last - first)
- Template Parameters
-
InputIterator | is a model of Input Iterator, and x and y are objects of InputIterator's value_type , then x - is defined, and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types , and the return type of x - y is convertible to a type in OutputIterator's set of value_types . |
OutputIterator | is a model of Output Iterator. |
The following code snippet demonstrates how to use adjacent_difference
to compute the difference between adjacent elements of a range.
...
int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
- See also
- https://en.cppreference.com/w/cpp/algorithm/adjacent_difference
-
inclusive_scan