mp_min_element.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef BOOST_MP11_DETAIL_MP_MIN_ELEMENT_HPP_INCLUDED
  2. #define BOOST_MP11_DETAIL_MP_MIN_ELEMENT_HPP_INCLUDED
  3. // Copyright 2015-2017 Peter Dimov.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. //
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. #include <boost/mp11/detail/mp_fold.hpp>
  10. #include <boost/mp11/list.hpp>
  11. #include <boost/mp11/utility.hpp>
  12. namespace boost
  13. {
  14. namespace mp11
  15. {
  16. // mp_min_element<L, P>
  17. namespace detail
  18. {
  19. template<template<class...> class P> struct select_min
  20. {
  21. template<class T1, class T2> using fn = mp_if<P<T1, T2>, T1, T2>;
  22. };
  23. } // namespace detail
  24. template<class L, template<class...> class P> using mp_min_element = mp_fold_q<mp_rest<L>, mp_first<L>, detail::select_min<P>>;
  25. template<class L, class Q> using mp_min_element_q = mp_min_element<L, Q::template fn>;
  26. // mp_max_element<L, P>
  27. namespace detail
  28. {
  29. template<template<class...> class P> struct select_max
  30. {
  31. template<class T1, class T2> using fn = mp_if<P<T2, T1>, T1, T2>;
  32. };
  33. } // namespace detail
  34. template<class L, template<class...> class P> using mp_max_element = mp_fold_q<mp_rest<L>, mp_first<L>, detail::select_max<P>>;
  35. template<class L, class Q> using mp_max_element_q = mp_max_element<L, Q::template fn>;
  36. } // namespace mp11
  37. } // namespace boost
  38. #endif // #ifndef BOOST_MP11_DETAIL_MP_MIN_ELEMENT_HPP_INCLUDED