algo/adjdiff1.cpp

The following code example is taken from the book
The C++ Standard Library - A Tutorial and Reference
by Nicolai M. Josuttis, Addison-Wesley, 1999
© Copyright Nicolai M. Josuttis 1999


#include "algostuff.hpp"
using namespace std;

int main()
{
   deque<int> coll;

   INSERT_ELEMENTS(coll,1,6);
   PRINT_ELEMENTS(coll);

   // print all differences between elements
   adjacent_difference (coll.begin(), coll.end(),         // source
                        ostream_iterator<int>(cout," ")); // dest.
   cout << endl;

   // print all sums with the predecessors
   adjacent_difference (coll.begin(), coll.end(),         // source
                        ostream_iterator<int>(cout," "),  // dest.
                        plus<int>());                     // operation
   cout << endl;

   // print all products between elements
   adjacent_difference (coll.begin(), coll.end(),         // source
                        ostream_iterator<int>(cout," "),  // dest.
                        multiplies<int>());               // operation
   cout << endl;
}