On Sun, 30 Nov 2003 John.Wismar@alldata.com wrote:
Here's the situation I'm trying to remedy, boiled down:
class A { public: int size() const; };
class B { public: int stretch_it(int size) const; int get_total() const; private: std::vector<A> myVec; };
int B::get_total() const { int retVal = 0; for (std::vector<A>::const_iterator it = myVec.begin(); it != myVec.end (); ++it) { retVal += stretch_it(it->size()); } return retVal; }
I'd love to use std::accumulate() or equivalent instead of a hand-coded loop, but I don't know if it's possible to specify a combination of operations like I have here.... Or if the result would be readable!
You can replace the body of get_total with: return std::accumulate(myVec.begin(), myVec.end(), 0, boost::bind(std::plus<int>(), _1, boost::bind(&B::stretch_it, this, boost::bind(&A::size, _2)))); You can decide whether that's better than the hand-coded loop or not :) Doug