#ifndef MLN_ACCU_ACCUMULATOTS_COUNT_HPP # define MLN_ACCU_ACCUMULATOTS_COUNT_HPP /// \file /// \brief Header file for counting accumulator. # include # include # include namespace mln { namespace accu { namespace accumulators { /// \brief The counting accumulator. /// \tparam CountType is underlying the counter type (it must be incrementable, /// and decrementable. template struct count; } namespace features { template struct count; } namespace extractor { template inline auto count(const Accumulator& acc) -> decltype(extract(exact(acc), features::count<> ())) { return extract(exact(acc), features::count<> ()); } } namespace features { template struct count : simple_feature< count > { template struct apply { typedef accumulators::count type; }; template accumulators::count make() { return accumulators::count (); } }; } namespace accumulators { template struct count : accumulator_base< count, dontcare, CountType, features::count<> > { typedef dontcare argument_type; typedef CountType result_type; typedef boost::mpl::set< features::count<> > provides; count() : m_count (0) { } void init() { m_count = 0; } void take(const dontcare&) { ++m_count; } void untake(const dontcare&) { --m_count; } template void take(const Accumulator& other) { m_count += extractor::count(other); } friend result_type extract(const count& accu, features::count<> ) { return accu.m_count; } private: CountType m_count; }; } } } #endif // !MLN_ACCU_ACCUMULATOTS_COUNT_HPP