max_element.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef BOOST_MPL_MAX_ELEMENT_HPP_INCLUDED
  2. #define BOOST_MPL_MAX_ELEMENT_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/less.hpp>
  14. #include <boost/mpl/iter_fold.hpp>
  15. #include <boost/mpl/begin_end.hpp>
  16. #include <boost/mpl/if.hpp>
  17. #include <boost/mpl/deref.hpp>
  18. #include <boost/mpl/apply.hpp>
  19. #include <boost/mpl/aux_/common_name_wknd.hpp>
  20. #include <boost/mpl/aux_/na_spec.hpp>
  21. namespace boost { namespace mpl {
  22. BOOST_MPL_AUX_COMMON_NAME_WKND(max_element)
  23. namespace aux {
  24. template< typename Predicate >
  25. struct select_max
  26. {
  27. template< typename OldIterator, typename Iterator >
  28. struct apply
  29. {
  30. typedef typename apply2<
  31. Predicate
  32. , typename deref<OldIterator>::type
  33. , typename deref<Iterator>::type
  34. >::type condition_;
  35. typedef typename if_<
  36. condition_
  37. , Iterator
  38. , OldIterator
  39. >::type type;
  40. };
  41. };
  42. } // namespace aux
  43. template<
  44. typename BOOST_MPL_AUX_NA_PARAM(Sequence)
  45. , typename Predicate = less<_,_>
  46. >
  47. struct max_element
  48. : iter_fold<
  49. Sequence
  50. , typename begin<Sequence>::type
  51. , protect< aux::select_max<Predicate> >
  52. >
  53. {
  54. };
  55. BOOST_MPL_AUX_NA_SPEC(1, max_element)
  56. }}
  57. #endif // BOOST_MPL_MAX_ELEMENT_HPP_INCLUDED