// Using the STL generic reverse algorithm with a vector 
// of objects of a minimal type.

#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;

class U { 
 public: 
  unsigned long id;
  U() : id(0) { }
  U(unsigned long x) : id(x) { }
};

// Define == on U objects (needed for vector ==).
bool operator==(const U& x, const U& y) 
{ 
  return x.id == y.id; 
}

int main()
{
  vector<U> vector1, vector2;
  const int N = 1000;
  int k;
  for (k = 0; k != N; ++k) 
    vector1.push_back(U(k));
  for (k = 0; k != N; ++k) 
    vector2.push_back(U(N-1-k));
  cout << "Using generic reverse algorithm with a vector "
       << "of user-defined objects" << endl;
  reverse(vector1.begin(), vector1.end());
  assert(vector1 == vector2);
  return 0;
}
