◆ adjacent_difference() [1/4]

template<typename DerivedPolicy , typename InputIterator , typename OutputIterator >
__host__ __device__ OutputIterator thrust::adjacent_difference ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
InputIterator  first,
InputIterator  last,
OutputIterator  result 

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.

The algorithm's execution is parallelized as determined by exec.

execThe execution policy to use for parallelization.
firstThe beginning of the input range.
lastThe end of the input range.
resultThe beginning of the output range.
The iterator result + (last - first)
Template Parameters
DerivedPolicyThe name of the derived execution policy.
InputIteratoris 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.
OutputIteratoris a model of Output Iterator.
Note that result is permitted to be the same iterator as first. This is useful for computing differences "in place".

The following code snippet demonstrates how to use adjacent_difference to compute the difference between adjacent elements of a range using the thrust::device execution policy:

int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
thrust::device_vector<int> d_data(h_data, h_data + 8);
thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin());
// d_result is now [1, 1, -1, 1, -1, 1, -1, 1]
See also