count.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. // make this accumulator serializeable
  38. template<class Archive>
  39. void serialize(Archive & ar, const unsigned int file_version)
  40. {
  41. ar & cnt;
  42. }
  43. private:
  44. std::size_t cnt;
  45. };
  46. } // namespace impl
  47. ///////////////////////////////////////////////////////////////////////////////
  48. // tag::count
  49. //
  50. namespace tag
  51. {
  52. struct count
  53. : depends_on<>
  54. {
  55. /// INTERNAL ONLY
  56. ///
  57. typedef mpl::always<accumulators::impl::count_impl> impl;
  58. };
  59. }
  60. ///////////////////////////////////////////////////////////////////////////////
  61. // extract::count
  62. //
  63. namespace extract
  64. {
  65. extractor<tag::count> const count = {};
  66. BOOST_ACCUMULATORS_IGNORE_GLOBAL(count)
  67. }
  68. using extract::count;
  69. }} // namespace boost::accumulators
  70. #endif