1 | /////////////////////////////////////////////////////////////////////////////// |
---|---|
2 | // count.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_COUNT_HPP_EAN_28_10_2005 |
9 | #define BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005 |
10 | |
11 | #include <boost/mpl/always.hpp> |
12 | #include <boost/accumulators/framework/accumulator_base.hpp> |
13 | #include <boost/accumulators/framework/extractor.hpp> |
14 | #include <boost/accumulators/framework/depends_on.hpp> |
15 | #include <boost/accumulators/statistics_fwd.hpp> |
16 | |
17 | namespace boost { namespace accumulators |
18 | { |
19 | |
20 | namespace impl |
21 | { |
22 | |
23 | /////////////////////////////////////////////////////////////////////////////// |
24 | // count_impl |
25 | struct count_impl |
26 | : accumulator_base |
27 | { |
28 | // for boost::result_of |
29 | typedef std::size_t result_type; |
30 | |
31 | count_impl(dont_care) |
32 | : cnt(0) |
33 | { |
34 | } |
35 | |
36 | void operator ()(dont_care) |
37 | { |
38 | ++this->cnt; |
39 | } |
40 | |
41 | result_type result(dont_care) const |
42 | { |
43 | return this->cnt; |
44 | } |
45 | |
46 | private: |
47 | std::size_t cnt; |
48 | }; |
49 | |
50 | } // namespace impl |
51 | |
52 | /////////////////////////////////////////////////////////////////////////////// |
53 | // tag::count |
54 | // |
55 | namespace tag |
56 | { |
57 | struct count |
58 | : depends_on<> |
59 | { |
60 | /// INTERNAL ONLY |
61 | /// |
62 | typedef mpl::always<accumulators::impl::count_impl> impl; |
63 | }; |
64 | } |
65 | |
66 | /////////////////////////////////////////////////////////////////////////////// |
67 | // extract::count |
68 | // |
69 | namespace extract |
70 | { |
71 | extractor<tag::count> const count = {}; |
72 | |
73 | BOOST_ACCUMULATORS_IGNORE_GLOBAL(count) |
74 | } |
75 | |
76 | using extract::count; |
77 | |
78 | }} // namespace boost::accumulators |
79 | |
80 | #endif |
81 |