xxxxxxxxxx
OutputIterator adjacent_difference (InputIterator first,
InputIterator last,
OutputIterator result,
BinaryOperation binary_op);
Parameters :
first, last, result are same as above.
binary_op
Binary operation taking as arguments two elements of the type
pointed by InputIterator, and returning the result of the
replacement for the difference operation.
This can either be a function pointer or a function object.
Return Type :
An iterator pointing to past the last element of the destination
sequence where resulting elements have been stored.
xxxxxxxxxx
// CPP program to illustrate
// std :: adjacent_difference
#include <iostream> // std::cout
#include <numeric> // std::adjacent_difference
// Driver code
int main()
{
int val[] = { 1, 2, 3, 5, 9, 11, 12 };
int n = sizeof(val) / sizeof(val[0]);
int result[7];
// Array contains
std::cout << "Array contains :";
for (int i = 0; i < n; i++)
std::cout << " " << val[i];
std::cout << "\n";
// Using default std :: adjacent_difference
std::adjacent_difference(val, val + 7, result);
std::cout << "Using default adjacent_difference: ";
for (int i = 1; i < n; i++)
std::cout << result[i] << ' ';
std::cout << '\n';
return 0;
}