Boost logo

Boost :

From: Neal D. Becker (ndbecker2_at_[hidden])
Date: 2004-11-09 07:15:02


Michiel Salters wrote:

> The boost::function template works with boost::ref according to the docs,
> so try boost::function< int ( int ) > ( boost::ref( Op() ) )
>

Thanks. AFAICT, the best solution seems to be another set of algorithms,
like this:

struct Op {
  int operator() (int x) { return 1 + x;}
  Op() {}
private:
  Op (const Op&);
  
};

template<typename in_t, typename out_t, typename func>
void transform_r (in_t const& in, out_t& out, func& f) {
  std::transform<typename boost::range_const_iterator<in_t>::type,typename
boost::range_iterator<out_t>::type,func&>
    (boost::begin (in), boost::end (in), boost::begin (out), f);
}

int main() {
  vector<int> x (4);
  vector<int> y (4);
  Op o;
  transform_r (x, y, o);
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk