Versatile data structure for combined statistics
It sounds like you would like the Boost Accumulators library:


  Boost.Accumulators is both a library for incremental statistical
  computation as well as an extensible framework for incremental
  calculation in general. The library deals primarily with the concept
  of an accumulator, which is a primitive computational entity that
  accepts data one sample at a time and maintains some internal state.
  These accumulators may offload some of their computations on other
  accumulators, on which they depend. Accumulators are grouped within an
  accumulator set. Boost.Accumulators resolves the inter-dependencies
  between accumulators in a set and ensures that accumulators are
  processed in the proper order.