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
61 ///////////////////////////////////////////////////////////////////////////////
63 // tag::sum_of_weights
64 // tag::sum_of_variates
73 typedef accumulators::impl::sum_impl
<mpl::_1
, tag::sample
> impl
;
79 typedef mpl::true_ is_weight_accumulator
;
82 typedef accumulators::impl::sum_impl
<mpl::_2
, tag::weight
> impl
;
85 template<typename VariateType
, typename VariateTag
>
86 struct sum_of_variates
91 typedef mpl::always
<accumulators::impl::sum_impl
<VariateType
, VariateTag
> > impl
;
94 struct abstract_sum_of_variates
100 ///////////////////////////////////////////////////////////////////////////////
102 // extract::sum_of_weights
103 // extract::sum_of_variates
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
= {};
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.
119 struct as_weighted_feature
<tag::sum
>
121 typedef tag::weighted_sum type
;
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