Ticket #7409: count.hpp

File count.hpp, 3.0 KB (added by anonymous, 10 years ago)
Line 
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 <iostream>
12#include <boost/mpl/always.hpp>
13#include <boost/accumulators/framework/accumulator_base.hpp>
14#include <boost/accumulators/framework/extractor.hpp>
15#include <boost/accumulators/framework/depends_on.hpp>
16#include <boost/accumulators/statistics_fwd.hpp>
17
18namespace boost { namespace accumulators
19{
20
21namespace impl
22{
23
24 ///////////////////////////////////////////////////////////////////////////////
25 // count_impl
26 struct count_impl
27 : accumulator_base
28 {
29 // for boost::result_of
30 typedef std::size_t result_type;
31
32 count_impl(dont_care)
33 : cnt(0)
34 {
35 }
36
37 void operator ()(dont_care)
38 {
39 std::cout << "count_impl::operator() called" << std::endl;
40 ++this->cnt;
41 }
42
43 result_type result(dont_care) const
44 {
45 return this->cnt;
46 }
47
48 private:
49 std::size_t cnt;
50 };
51
52} // namespace impl
53
54///////////////////////////////////////////////////////////////////////////////
55// tag::count
56//
57namespace tag
58{
59 struct count
60 : depends_on<>
61 {
62 /// INTERNAL ONLY
63 ///
64 typedef mpl::always<accumulators::impl::count_impl> impl;
65 };
66}
67
68///////////////////////////////////////////////////////////////////////////////
69// extract::count
70//
71namespace extract
72{
73 extractor<tag::count> const count = {};
74
75 BOOST_ACCUMULATORS_IGNORE_GLOBAL(count)
76}
77
78using extract::count;
79
80namespace impl
81{
82 ///////////////////////////////////////////////////////////////////////////////
83 // alt_count_impl
84 struct alt_count_impl
85 : accumulator_base
86 {
87 // for boost::result_of
88 typedef std::size_t result_type;
89
90 alt_count_impl(dont_care)
91 : cnt(0)
92 {
93 }
94
95 void operator ()(dont_care)
96 {
97 std::cout << "alt_count_impl::operator() called" << std::endl;
98 ++this->cnt;
99 }
100
101 result_type result(dont_care) const
102 {
103 return this->cnt;
104 }
105
106 private:
107 std::size_t cnt;
108 };
109
110} // namespace impl
111
112///////////////////////////////////////////////////////////////////////////////
113// tag::alt_count
114//
115namespace tag
116{
117 struct alt_count
118 : depends_on<>
119 {
120 /// INTERNAL ONLY
121 ///
122 typedef mpl::always<accumulators::impl::alt_count_impl> impl;
123 };
124}
125
126// for the purposes of feature-based dependency resolution,
127// immediate_mean provides the same feature as mean
128template<>
129struct feature_of<tag::alt_count>
130 : feature_of<tag::count>
131{
132};
133
134
135}} // namespace boost::accumulators
136
137#endif