Boost logo

Boost Users :

From: Terry G (tjgolubi_at_[hidden])
Date: 2006-11-18 15:10:51


This doesn't compile.
How best to accomplish this using generic STL or Boost algorithms/adapters?

terry

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cstdlib>

#include <boost/bind.hpp>
#include <boost/mem_fn.hpp>

using namespace std;
using namespace boost;

class MyInt {
  int _value;
public:
  explicit MyInt(int x=0) : _value(x) { }
  int value() const { return _value; }
}; // MyInt

int main() {
  vector<MyInt> v;

  // Do this:
  // for (int i=0; i!=30; ++i) v.push_back(MyInt(rand()));
  generate_n(back_inserter(v), 30, bind(MyInt, bind(rand)));

  // Now print v.
  transform(v.begin(), v.end(), ostream_iterator<int>(cout, "\n"),
      mem_fn(&MyInt::value));

  return 0;
} // main


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net