Boost logo

Boost Users :

Subject: [Boost-users] Iterating over the output of a member function in std::for_each
From: Andrew Hundt (athundt_at_[hidden])
Date: 2012-03-01 11:52:42

I have a class with an accessor member function that I want to call and
apply the result to a functor using std::for_each. I have a working version
below that uses a for loop and for_each, but the for_each version is
cryptic and cumbersome. Is there a way I can make the for_each version more

    #if 0
       // for loop version:
       for(value_vector_type::iterator it = values.begin();
it!=values.end(); it++){
         avg(it->getValue()); // I want to put this in a for_each loop
      // bind version:
      std::for_each(values.begin(), values.end(), // iterate over all values
          boost::mem_fn(&average_type::operator()), // attach the averaging
functor to the output of the getvalue call
            boost::mem_fn(&value_wrapper_type::getValue), // bind the
getValue call to each element in values

I also have the question posted in stack overflow, with a full

Andrew Hundt

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at