1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2005 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_ACCUMULATORS_STATISTICS_SUM_HPP_EAN_28_10_2005
9 #define BOOST_ACCUMULATORS_STATISTICS_SUM_HPP_EAN_28_10_2005
11 #include <boost/mpl/placeholders.hpp>
12 #include <boost/accumulators/framework/accumulator_base.hpp>
13 #include <boost/accumulators/framework/extractor.hpp>
14 #include <boost/accumulators/numeric/functional.hpp>
15 #include <boost/accumulators/framework/parameters/sample.hpp>
16 #include <boost/accumulators/framework/parameters/weight.hpp>
17 #include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
18 #include <boost/accumulators/framework/depends_on.hpp>
19 #include <boost/accumulators/statistics_fwd.hpp>
20 #include <boost/accumulators/statistics/count.hpp>
22 namespace boost { namespace accumulators
27 ///////////////////////////////////////////////////////////////////////////////
29 template<typename Sample, typename Tag>
33 // for boost::result_of
34 typedef Sample result_type;
36 template<typename Args>
37 sum_impl(Args const &args)
38 : sum(args[parameter::keyword<Tag>::get() | Sample()])
42 template<typename Args>
43 void operator ()(Args const &args)
45 // what about overflow?
46 this->sum += args[parameter::keyword<Tag>::get()];
49 result_type result(dont_care) const
54 template<class Archive>
55 void serialize(Archive & ar, const unsigned int file_version)
66 ///////////////////////////////////////////////////////////////////////////////
68 // tag::sum_of_weights
69 // tag::sum_of_variates
78 typedef accumulators::impl::sum_impl<mpl::_1, tag::sample> impl;
84 typedef mpl::true_ is_weight_accumulator;
87 typedef accumulators::impl::sum_impl<mpl::_2, tag::weight> impl;
90 template<typename VariateType, typename VariateTag>
91 struct sum_of_variates
96 typedef mpl::always<accumulators::impl::sum_impl<VariateType, VariateTag> > impl;
99 struct abstract_sum_of_variates
105 ///////////////////////////////////////////////////////////////////////////////
107 // extract::sum_of_weights
108 // extract::sum_of_variates
112 extractor<tag::sum> const sum = {};
113 extractor<tag::sum_of_weights> const sum_of_weights = {};
114 extractor<tag::abstract_sum_of_variates> const sum_of_variates = {};
116 BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum)
117 BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_of_weights)
118 BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_of_variates)
122 using extract::sum_of_weights;
123 using extract::sum_of_variates;
125 // So that mean can be automatically substituted with
126 // weighted_mean when the weight parameter is non-void.
128 struct as_weighted_feature<tag::sum>
130 typedef tag::weighted_sum type;
134 struct feature_of<tag::weighted_sum>
135 : feature_of<tag::sum>
138 template<typename VariateType, typename VariateTag>
139 struct feature_of<tag::sum_of_variates<VariateType, VariateTag> >
140 : feature_of<tag::abstract_sum_of_variates>
144 }} // namespace boost::accumulators