/* CSE 333 Su12 lecture 13 demo: sharedsort.cc */
/* Gribble/Perkins */

// shared_ptrs can safely be stored in STL containers, but if they
// are compared for order (e.g., <), an ordering on the shared_ptrs
// is used instead of using the ordering on the data they point to.

#include <boost/shared_ptr.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>

using boost::shared_ptr;
using std::vector;

bool sortfunction(shared_ptr<int> x, shared_ptr<int> y) {
  return *x < *y;
}

void printfunction(shared_ptr<int> x) {
  std::cout << *x << std::endl;
}

int main(int argc, char **argv) {
  vector<shared_ptr<int> > vec;

  vec.push_back(shared_ptr<int>(new int(9)));
  vec.push_back(shared_ptr<int>(new int(5)));
  vec.push_back(shared_ptr<int>(new int(7)));

  std::sort(vec.begin(), vec.end(), &sortfunction);
  std::for_each(vec.begin(), vec.end(), &printfunction);
  return EXIT_SUCCESS;
}