max.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // make this accumulator serializeable
  44. template<class Archive>
  45. void serialize(Archive & ar, const unsigned int file_version)
  46. {
  47. ar & max_;
  48. }
  49. private:
  50. Sample max_;
  51. };
  52. } // namespace impl
  53. ///////////////////////////////////////////////////////////////////////////////
  54. // tag::max
  55. //
  56. namespace tag
  57. {
  58. struct max
  59. : depends_on<>
  60. {
  61. /// INTERNAL ONLY
  62. ///
  63. typedef accumulators::impl::max_impl<mpl::_1> impl;
  64. };
  65. }
  66. ///////////////////////////////////////////////////////////////////////////////
  67. // extract::max
  68. //
  69. namespace extract
  70. {
  71. extractor<tag::max> const max = {};
  72. BOOST_ACCUMULATORS_IGNORE_GLOBAL(max)
  73. }
  74. using extract::max;
  75. }} // namespace boost::accumulators
  76. #endif