Boost logo

Boost :

From: jsiek_at_[hidden]
Date: 2000-01-15 03:32:22

Hi Jim,

I'm afraid there is already a good solution to the problem you
describe, and it is by one of our members here at boost, Nicolai
Jusuttis. With his compose library, and with the member function
functor from the standard, you can do the same things that your
library does. Here's the example you gave rewritten using the compose



#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <boost/compose.hpp>

using namespace std;
using namespace boost;

class Person
  Person(const string& n) : _name(n) { }
  const string& GetName ( ) const { return _name; }
  string _name;

typedef vector < Person* > PersonVector ;
typedef PersonVector::iterator PersonVecIter ;
typedef PersonVector::const_iterator PersonVecConstIter ;

  const char* names[] = { "fred", "walter", "joe", "suzy", "jim" };
  PersonVector aPersonVec;
  for (int i = 0; i < sizeof(names)/sizeof(const char*); ++i)
    aPersonVec.push_back(new Person(names[i]));

  // sort the people by name
  sort(aPersonVec.begin(), aPersonVec.end(),

  // print out the names of the people
  transform(aPersonVec.begin(), aPersonVec.end(),
            ostream_iterator<string>(cout, " "),
  cout << endl;

  for (int i = 0; i < aPersonVec.size(); ++i)
    delete aPersonVec[i];

  return 0;

Boost list run by bdawes at, gregod at, cpdaniel at, john at