min.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // min.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_MIN_HPP_EAN_28_10_2005
  8. #define BOOST_ACCUMULATORS_STATISTICS_MIN_HPP_EAN_28_10_2005
  9. #include <limits>
  10. #include <boost/mpl/placeholders.hpp>
  11. #include <boost/accumulators/framework/accumulator_base.hpp>
  12. #include <boost/accumulators/framework/extractor.hpp>
  13. #include <boost/accumulators/framework/parameters/sample.hpp>
  14. #include <boost/accumulators/numeric/functional.hpp>
  15. #include <boost/accumulators/framework/depends_on.hpp>
  16. #include <boost/accumulators/statistics_fwd.hpp>
  17. namespace boost { namespace accumulators
  18. {
  19. namespace impl
  20. {
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // min_impl
  23. template<typename Sample>
  24. struct min_impl
  25. : accumulator_base
  26. {
  27. // for boost::result_of
  28. typedef Sample result_type;
  29. template<typename Args>
  30. min_impl(Args const &args)
  31. : min_(numeric::as_max(args[sample | Sample()]))
  32. {
  33. }
  34. template<typename Args>
  35. void operator ()(Args const &args)
  36. {
  37. numeric::min_assign(this->min_, args[sample]);
  38. }
  39. result_type result(dont_care) const
  40. {
  41. return this->min_;
  42. }
  43. // make this accumulator serializeable
  44. template<class Archive>
  45. void serialize(Archive & ar, const unsigned int file_version)
  46. {
  47. ar & min_;
  48. }
  49. private:
  50. Sample min_;
  51. };
  52. } // namespace impl
  53. ///////////////////////////////////////////////////////////////////////////////
  54. // tag::min
  55. //
  56. namespace tag
  57. {
  58. struct min
  59. : depends_on<>
  60. {
  61. /// INTERNAL ONLY
  62. ///
  63. typedef accumulators::impl::min_impl<mpl::_1> impl;
  64. };
  65. }
  66. ///////////////////////////////////////////////////////////////////////////////
  67. // extract::min
  68. //
  69. namespace extract
  70. {
  71. extractor<tag::min> const min = {};
  72. BOOST_ACCUMULATORS_IGNORE_GLOBAL(min)
  73. }
  74. using extract::min;
  75. }} // namespace boost::accumulators
  76. #endif