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
17namespace boost { namespace accumulators
18{
19
20namespace 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 // make this accumulator serializeable
47 template<class Archive>
48 void serialize(Archive & ar, const unsigned int file_version)
49 {
50 ar & cnt;
51 }
52
53 private:
54 std::size_t cnt;
55 };
56
57} // namespace impl
58
59///////////////////////////////////////////////////////////////////////////////
60// tag::count
61//
62namespace tag
63{
64 struct count
65 : depends_on<>
66 {
67 /// INTERNAL ONLY
68 ///
69 typedef mpl::always<accumulators::impl::count_impl> impl;
70 };
71}
72
73///////////////////////////////////////////////////////////////////////////////
74// extract::count
75//
76namespace extract
77{
78 extractor<tag::count> const count = {};
79
80 BOOST_ACCUMULATORS_IGNORE_GLOBAL(count)
81}
82
83using extract::count;
84
85}} // namespace boost::accumulators
86
87#endif
88

source code of include/boost/accumulators/statistics/count.hpp