max.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // max.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_MAX_HPP_EAN_28_10_2005
  8. #define BOOST_ACCUMULATORS_STATISTICS_MAX_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. // max_impl
  23. template<typename Sample>
  24. struct max_impl
  25. : accumulator_base
  26. {
  27. // for boost::result_of
  28. typedef Sample result_type;
  29. template<typename Args>
  30. max_impl(Args const &args)
  31. : max_(numeric::as_min(args[sample | Sample()]))
  32. {
  33. }
  34. template<typename Args>
  35. void operator ()(Args const &args)
  36. {
  37. numeric::max_assign(this->max_, args[sample]);
  38. }
  39. result_type result(dont_care) const
  40. {
  41. return this->max_;
  42. }
  43. private:
  44. Sample max_;
  45. };
  46. } // namespace impl
  47. ///////////////////////////////////////////////////////////////////////////////
  48. // tag::max
  49. //
  50. namespace tag
  51. {
  52. struct max
  53. : depends_on<>
  54. {
  55. /// INTERNAL ONLY
  56. ///
  57. typedef accumulators::impl::max_impl<mpl::_1> impl;
  58. };
  59. }
  60. ///////////////////////////////////////////////////////////////////////////////
  61. // extract::max
  62. //
  63. namespace extract
  64. {
  65. extractor<tag::max> const max = {};
  66. BOOST_ACCUMULATORS_IGNORE_GLOBAL(max)
  67. }
  68. using extract::max;
  69. }} // namespace boost::accumulators
  70. #endif