rolling_count.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. };
  37. } // namespace impl
  38. ///////////////////////////////////////////////////////////////////////////////
  39. // tag::rolling_count
  40. //
  41. namespace tag
  42. {
  43. struct rolling_count
  44. : depends_on< rolling_window_plus1 >
  45. {
  46. /// INTERNAL ONLY
  47. ///
  48. typedef accumulators::impl::rolling_count_impl< mpl::_1 > impl;
  49. #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
  50. /// tag::rolling_window::window_size named parameter
  51. static boost::parameter::keyword<tag::rolling_window_size> const window_size;
  52. #endif
  53. };
  54. } // namespace tag
  55. ///////////////////////////////////////////////////////////////////////////////
  56. // extract::rolling_count
  57. //
  58. namespace extract
  59. {
  60. extractor<tag::rolling_count> const rolling_count = {};
  61. BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_count)
  62. }
  63. using extract::rolling_count;
  64. }} // namespace boost::accumulators
  65. #endif