]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/include/boost/accumulators/statistics/sum.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / accumulators / include / boost / accumulators / statistics / sum.hpp
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)
7
8 #ifndef BOOST_ACCUMULATORS_STATISTICS_SUM_HPP_EAN_28_10_2005
9 #define BOOST_ACCUMULATORS_STATISTICS_SUM_HPP_EAN_28_10_2005
10
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>
21
22 namespace boost { namespace accumulators
23 {
24
25 namespace impl
26 {
27 ///////////////////////////////////////////////////////////////////////////////
28 // sum_impl
29 template<typename Sample, typename Tag>
30 struct sum_impl
31 : accumulator_base
32 {
33 // for boost::result_of
34 typedef Sample result_type;
35
36 template<typename Args>
37 sum_impl(Args const &args)
38 : sum(args[parameter::keyword<Tag>::get() | Sample()])
39 {
40 }
41
42 template<typename Args>
43 void operator ()(Args const &args)
44 {
45 // what about overflow?
46 this->sum += args[parameter::keyword<Tag>::get()];
47 }
48
49 result_type result(dont_care) const
50 {
51 return this->sum;
52 }
53
54 private:
55
56 Sample sum;
57 };
58
59 } // namespace impl
60
61 ///////////////////////////////////////////////////////////////////////////////
62 // tag::sum
63 // tag::sum_of_weights
64 // tag::sum_of_variates
65 //
66 namespace tag
67 {
68 struct sum
69 : depends_on<>
70 {
71 /// INTERNAL ONLY
72 ///
73 typedef accumulators::impl::sum_impl<mpl::_1, tag::sample> impl;
74 };
75
76 struct sum_of_weights
77 : depends_on<>
78 {
79 typedef mpl::true_ is_weight_accumulator;
80 /// INTERNAL ONLY
81 ///
82 typedef accumulators::impl::sum_impl<mpl::_2, tag::weight> impl;
83 };
84
85 template<typename VariateType, typename VariateTag>
86 struct sum_of_variates
87 : depends_on<>
88 {
89 /// INTERNAL ONLY
90 ///
91 typedef mpl::always<accumulators::impl::sum_impl<VariateType, VariateTag> > impl;
92 };
93
94 struct abstract_sum_of_variates
95 : depends_on<>
96 {
97 };
98 }
99
100 ///////////////////////////////////////////////////////////////////////////////
101 // extract::sum
102 // extract::sum_of_weights
103 // extract::sum_of_variates
104 //
105 namespace extract
106 {
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 = {};
110
111 BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum)
112 BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_of_weights)
113 BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_of_variates)
114 }
115
116 using extract::sum;
117 using extract::sum_of_weights;
118 using extract::sum_of_variates;
119
120 // So that mean can be automatically substituted with
121 // weighted_mean when the weight parameter is non-void.
122 template<>
123 struct as_weighted_feature<tag::sum>
124 {
125 typedef tag::weighted_sum type;
126 };
127
128 template<>
129 struct feature_of<tag::weighted_sum>
130 : feature_of<tag::sum>
131 {};
132
133 template<typename VariateType, typename VariateTag>
134 struct feature_of<tag::sum_of_variates<VariateType, VariateTag> >
135 : feature_of<tag::abstract_sum_of_variates>
136 {
137 };
138
139 }} // namespace boost::accumulators
140
141 #endif