1 ///////////////////////////////////////////////////////////////////////////////
2 // min.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_MIN_HPP_EAN_28_10_2005
9 #define BOOST_ACCUMULATORS_STATISTICS_MIN_HPP_EAN_28_10_2005
10 
11 #include <limits>
12 #include <boost/mpl/placeholders.hpp>
13 #include <boost/accumulators/framework/accumulator_base.hpp>
14 #include <boost/accumulators/framework/extractor.hpp>
15 #include <boost/accumulators/framework/parameters/sample.hpp>
16 #include <boost/accumulators/numeric/functional.hpp>
17 #include <boost/accumulators/framework/depends_on.hpp>
18 #include <boost/accumulators/statistics_fwd.hpp>
19 
20 namespace boost { namespace accumulators
21 {
22 
23 namespace impl
24 {
25     ///////////////////////////////////////////////////////////////////////////////
26     // min_impl
27     template<typename Sample>
28     struct min_impl
29       : accumulator_base
30     {
31         // for boost::result_of
32         typedef Sample result_type;
33 
34         template<typename Args>
min_implboost::accumulators::impl::min_impl35         min_impl(Args const &args)
36           : min_(numeric::as_max(args[sample | Sample()]))
37         {
38         }
39 
40         template<typename Args>
operator ()boost::accumulators::impl::min_impl41         void operator ()(Args const &args)
42         {
43             numeric::min_assign(this->min_, args[sample]);
44         }
45 
resultboost::accumulators::impl::min_impl46         result_type result(dont_care) const
47         {
48             return this->min_;
49         }
50 
51         // make this accumulator serializeable
52         template<class Archive>
serializeboost::accumulators::impl::min_impl53         void serialize(Archive & ar, const unsigned int file_version)
54         {
55             ar & min_;
56         }
57 
58     private:
59         Sample min_;
60     };
61 
62 } // namespace impl
63 
64 ///////////////////////////////////////////////////////////////////////////////
65 // tag::min
66 //
67 namespace tag
68 {
69     struct min
70       : depends_on<>
71     {
72         /// INTERNAL ONLY
73         ///
74         typedef accumulators::impl::min_impl<mpl::_1> impl;
75     };
76 }
77 
78 ///////////////////////////////////////////////////////////////////////////////
79 // extract::min
80 //
81 namespace extract
82 {
83     extractor<tag::min> const min = {};
84 
85     BOOST_ACCUMULATORS_IGNORE_GLOBAL(min)
86 }
87 
88 using extract::min;
89 
90 }} // namespace boost::accumulators
91 
92 #endif
93