fix doc example typo
[boost.git] / boost / accumulators / statistics / sum.hpp
blob857f3af9de670ec88d35ddca5a3799eb4eb06f97
1 ///////////////////////////////////////////////////////////////////////////////
2 // sum.hpp
3 //
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
25 namespace impl
27 ///////////////////////////////////////////////////////////////////////////////
28 // sum_impl
29 template<typename Sample, typename Tag>
30 struct sum_impl
31 : accumulator_base
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
51 return this->sum;
54 private:
56 Sample sum;
59 } // namespace impl
61 ///////////////////////////////////////////////////////////////////////////////
62 // tag::sum
63 // tag::sum_of_weights
64 // tag::sum_of_variates
66 namespace tag
68 struct sum
69 : depends_on<>
71 /// INTERNAL ONLY
72 ///
73 typedef accumulators::impl::sum_impl<mpl::_1, tag::sample> impl;
76 struct sum_of_weights
77 : depends_on<>
79 typedef mpl::true_ is_weight_accumulator;
80 /// INTERNAL ONLY
81 ///
82 typedef accumulators::impl::sum_impl<mpl::_2, tag::weight> impl;
85 template<typename VariateType, typename VariateTag>
86 struct sum_of_variates
87 : depends_on<>
89 /// INTERNAL ONLY
90 ///
91 typedef mpl::always<accumulators::impl::sum_impl<VariateType, VariateTag> > impl;
94 struct abstract_sum_of_variates
95 : depends_on<>
100 ///////////////////////////////////////////////////////////////////////////////
101 // extract::sum
102 // extract::sum_of_weights
103 // extract::sum_of_variates
105 namespace extract
107 extractor<tag::sum> const sum = {};
108 extractor<tag::sum_of_weights> const sum_of_weights = {};
109 extractor<tag::abstract_sum_of_variates> const sum_of_variates = {};
112 using extract::sum;
113 using extract::sum_of_weights;
114 using extract::sum_of_variates;
116 // So that mean can be automatically substituted with
117 // weighted_mean when the weight parameter is non-void.
118 template<>
119 struct as_weighted_feature<tag::sum>
121 typedef tag::weighted_sum type;
124 template<>
125 struct feature_of<tag::weighted_sum>
126 : feature_of<tag::sum>
129 template<typename VariateType, typename VariateTag>
130 struct feature_of<tag::sum_of_variates<VariateType, VariateTag> >
131 : feature_of<tag::abstract_sum_of_variates>
135 }} // namespace boost::accumulators
137 #endif