rolling_count.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // rolling_count.hpp
  3. //
  4. // Copyright 2008 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. #ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_COUNT_HPP_EAN_26_12_2008
  8. #define BOOST_ACCUMULATORS_STATISTICS_ROLLING_COUNT_HPP_EAN_26_12_2008
  9. #include <boost/mpl/placeholders.hpp>
  10. #include <boost/accumulators/framework/accumulator_base.hpp>
  11. #include <boost/accumulators/framework/extractor.hpp>
  12. #include <boost/accumulators/numeric/functional.hpp>
  13. #include <boost/accumulators/framework/parameters/sample.hpp>
  14. #include <boost/accumulators/framework/depends_on.hpp>
  15. #include <boost/accumulators/statistics_fwd.hpp>
  16. #include <boost/accumulators/statistics/rolling_window.hpp>
  17. namespace boost { namespace accumulators
  18. {
  19. namespace impl
  20. {
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // rolling_count_impl
  23. // returns the count of elements in the rolling window
  24. template<typename Sample>
  25. struct rolling_count_impl
  26. : accumulator_base
  27. {
  28. typedef std::size_t result_type;
  29. rolling_count_impl(dont_care)
  30. {}
  31. template<typename Args>
  32. result_type result(Args const &args) const
  33. {
  34. return static_cast<std::size_t>(rolling_window_plus1(args).size()) - is_rolling_window_plus1_full(args);
  35. }
  36. // serialization is done by accumulators it depends on
  37. template<class Archive>
  38. void serialize(Archive & ar, const unsigned int file_version) {}
  39. };
  40. } // namespace impl
  41. ///////////////////////////////////////////////////////////////////////////////
  42. // tag::rolling_count
  43. //
  44. namespace tag
  45. {
  46. struct rolling_count
  47. : depends_on< rolling_window_plus1 >
  48. {
  49. /// INTERNAL ONLY
  50. ///
  51. typedef accumulators::impl::rolling_count_impl< mpl::_1 > impl;
  52. #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
  53. /// tag::rolling_window::window_size named parameter
  54. static boost::parameter::keyword<tag::rolling_window_size> const window_size;
  55. #endif
  56. };
  57. } // namespace tag
  58. ///////////////////////////////////////////////////////////////////////////////
  59. // extract::rolling_count
  60. //
  61. namespace extract
  62. {
  63. extractor<tag::rolling_count> const rolling_count = {};
  64. BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_count)
  65. }
  66. using extract::rolling_count;
  67. }} // namespace boost::accumulators
  68. #endif