hello,
I need to sum a vector and divide the sum by the number of element:
if the filed _missed is "true", the value mustn't take into account....
My accumulate compute the sum properly but HOW can I retrive the numbers summed???
Thanks,
I need to sum a vector and divide the sum by the number of element:
if the filed _missed is "true", the value mustn't take into account....
Code:
class Value {
public:
double _value;
bool _missed;
bool getMissed() const { return _missed; }
//other methods....
};
class Other {
vector<Value> _values;
static double sum_values(const double& accum, const Value& right) {
if ( right.getMissed() ) return accum;
return accum + right._value;
}
void computeMean() {
double mean = std::accumulate( _values.begin(), _values.end(), 0.0,
Other::sum_values );
}
};
Thanks,
Comment