Here is a namespace for wrapping boost accumulators for use in a broader code base. I love these accumulators but re-typedefing them everywhere is ugly and a pain.

I am not interested in C++11 alternatives. My code base does not put the starting bracket on a new line. My code base uses doxygen. Most of the style choices are deliberate.

I'm interested in any issues with using this in a broader code base. If anyone has tips on doxygen style for this type of thing, that would be helpful too.


#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/min.hpp>
#include <boost/accumulators/statistics/mean.hpp>

//! The Accumulators namespace provides min, max, and average accumulators to the broader code base.
    This namespace defines accumulator types from boost. Also provided are specific extactors
    that will return the accumulator's current value.
namespace Accumulators{

    typedef boost::accumulators::accumulator_set< double,
        boost::accumulators::stats< boost::accumulators::tag::min>  > MinAccumulator;

    typedef boost::accumulators::accumulator_set< double,
        boost::accumulators::stats< boost::accumulators::tag::max>  > MaxAccumulator;

    typedef boost::accumulators::accumulator_set< double,
        boost::accumulators::stats< boost::accumulators::tag::mean> > MeanAccumulator;

    inline double extractMin(const MinAccumulator &acc){
        return  boost::accumulators::min(acc);

    inline double extractMax(const MaxAccumulator &acc){
        return  boost::accumulators::max(acc);

    inline double extractMean(const MeanAccumulator &acc){
        return  boost::accumulators::mean(acc);

I would use this in another locations by including.

#include <Accumulators.h>

Then creating a one.

Accumulators::MaxAccumulator myMax;

Adding values

myMax(42); //... this is defined by boost

And then extracting the value for some other use.


Any issues with this or improvements that you can come up with?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.