Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Accumulators: how to use with object data members?
From: er (erwann.rogard_at_[hidden])
Date: 2009-04-12 13:15:44


>
> accumulator_set< double, features< tag::variance > > acc;
> acc = for_each( v.begin(), v.end(), ??????? );

using namespace std;
using namespace boost;

struct data{
     data(double value):value_(value){}
     double value_;
};

int main()
{

     typedef std::vector<data> vec_t;

     vec_t vec;
     vec.push_back(data(2.0));
     vec.push_back(data(1.0));

     typedef accumulators::accumulator_set< double,
accumulators::features< accumulators::tag::moment<2> > > acc_t;

     acc_t acc;

     for_each(
         begin(vec),
         end(vec),
         bind<void>(
             ref(acc),
             bind<double>(
                 &data::value_,
                 _1
             )
         )
     );

     double result = accumulators::moment<2>(acc); // = 4 + 1 /2 = 2.5

NB: acc = has been ommitted.


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