|
Boost Users : |
Subject: [Boost-users] [accumulators] accumulator "adapters"?
From: Pete Bartlett (pete_at_[hidden])
Date: 2013-01-25 11:05:52
Dear all,
The accumulators library is a very nice way to get a set of statistics for a stream of numbers, doubles, say.
Now letâs suppose Iâm receiving a stream of boost::optional<double>s â e.g. letâs suppose Iâm receiving simulation results and some simulations fail.
It would be neat if I could somehow write and âadaptor accumulatorâ that took this stream of optionals and then, if they are not empty, pass them to an underlying accumulator.
In rough terms:
template<typename UnderlyingAccumulator , typename Sample > struct accumulator_adaptor
{
template<typename Args> void operator()( Args const& args)
{
Sample const& s = args[sample];
if( s )
{
m_underlying_accumulator( *s ) ; //doesnât compile UnderlyingAccumulator expects an Args, not a Sample
}
}
private:
UnderlyingAccumulator m_underlying_accumulator;
};
(we might also define another accumulator that just counts the number of âbadâ samples.
Then by adding an appropriate feature adaptor, one could write something like
accumulator_set< boost::optional<double> , tag::accumulator_adaptor< mean > , tag::bad_samples_count >
For the data 1.0,2.0,boost::optional<double>(),4.0
This would return a mean of 7/3 and a bad_samples_count of 1.
Is it possible for me to implement such an adaptor that would work for an arbitrary underlying accumulator?
Thanks for your interest,
Pete
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