File indexing completed on 2025-01-18 09:38:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_MIN_HPP
0011 #define BOOST_HANA_MIN_HPP
0012
0013 #include <boost/hana/fwd/min.hpp>
0014
0015 #include <boost/hana/concept/orderable.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/if.hpp>
0019 #include <boost/hana/less.hpp>
0020
0021
0022 namespace boost { namespace hana {
0023
0024 template <typename X, typename Y>
0025 constexpr decltype(auto) min_t::operator()(X&& x, Y&& y) const {
0026 using T = typename hana::tag_of<X>::type;
0027 using U = typename hana::tag_of<Y>::type;
0028 using Min = BOOST_HANA_DISPATCH_IF(decltype(min_impl<T, U>{}),
0029 hana::Orderable<T>::value &&
0030 hana::Orderable<U>::value
0031 );
0032
0033 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0034 static_assert(hana::Orderable<T>::value,
0035 "hana::min(x, y) requires 'x' to be Orderable");
0036
0037 static_assert(hana::Orderable<U>::value,
0038 "hana::min(x, y) requires 'y' to be Orderable");
0039 #endif
0040
0041 return Min::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
0042 }
0043
0044
0045 template <typename T, typename U, bool condition>
0046 struct min_impl<T, U, when<condition>> : default_ {
0047 template <typename X, typename Y>
0048 static constexpr decltype(auto) apply(X&& x, Y&& y) {
0049 decltype(auto) cond = hana::less(x, y);
0050 return hana::if_(static_cast<decltype(cond)&&>(cond),
0051 static_cast<X&&>(x),
0052 static_cast<Y&&>(y)
0053 );
0054 }
0055 };
0056 }}
0057
0058 #endif