count.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifndef BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005
  8. #define BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005
  9. #include <boost/mpl/always.hpp>
  10. #include <boost/accumulators/framework/accumulator_base.hpp>
  11. #include <boost/accumulators/framework/extractor.hpp>
  12. #include <boost/accumulators/framework/depends_on.hpp>
  13. #include <boost/accumulators/statistics_fwd.hpp>
  14. namespace boost { namespace accumulators
  15. {
  16. namespace impl
  17. {
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // count_impl
  20. struct count_impl
  21. : accumulator_base
  22. {
  23. // for boost::result_of
  24. typedef std::size_t result_type;
  25. count_impl(dont_care)
  26. : cnt(0)
  27. {
  28. }
  29. void operator ()(dont_care)
  30. {
  31. ++this->cnt;
  32. }
  33. result_type result(dont_care) const
  34. {
  35. return this->cnt;
  36. }
  37. private:
  38. std::size_t cnt;
  39. };
  40. } // namespace impl
  41. ///////////////////////////////////////////////////////////////////////////////
  42. // tag::count
  43. //
  44. namespace tag
  45. {
  46. struct count
  47. : depends_on<>
  48. {
  49. /// INTERNAL ONLY
  50. ///
  51. typedef mpl::always<accumulators::impl::count_impl> impl;
  52. };
  53. }
  54. ///////////////////////////////////////////////////////////////////////////////
  55. // extract::count
  56. //
  57. namespace extract
  58. {
  59. extractor<tag::count> const count = {};
  60. BOOST_ACCUMULATORS_IGNORE_GLOBAL(count)
  61. }
  62. using extract::count;
  63. }} // namespace boost::accumulators
  64. #endif