3 Defines `boost::hana::min`.
5 @copyright Louis Dionne 2013-2016
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_MIN_HPP
11 #define BOOST_HANA_MIN_HPP
13 #include <boost/hana/fwd/min.hpp>
15 #include <boost/hana/concept/orderable.hpp>
16 #include <boost/hana/config.hpp>
17 #include <boost/hana/core/dispatch.hpp>
18 #include <boost/hana/if.hpp>
19 #include <boost/hana/less.hpp>
22 BOOST_HANA_NAMESPACE_BEGIN
24 template <typename X, typename Y>
25 constexpr decltype(auto) min_t::operator()(X&& x, Y&& y) const {
26 using T = typename hana::tag_of<X>::type;
27 using U = typename hana::tag_of<Y>::type;
28 using Min = BOOST_HANA_DISPATCH_IF(decltype(min_impl<T, U>{}),
29 hana::Orderable<T>::value &&
30 hana::Orderable<U>::value
33 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
34 static_assert(hana::Orderable<T>::value,
35 "hana::min(x, y) requires 'x' to be Orderable");
37 static_assert(hana::Orderable<U>::value,
38 "hana::min(x, y) requires 'y' to be Orderable");
41 return Min::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
45 template <typename T, typename U, bool condition>
46 struct min_impl<T, U, when<condition>> : default_ {
47 template <typename X, typename Y>
48 static constexpr decltype(auto) apply(X&& x, Y&& y) {
49 decltype(auto) cond = hana::less(x, y);
50 return hana::if_(static_cast<decltype(cond)&&>(cond),
56 BOOST_HANA_NAMESPACE_END
58 #endif // !BOOST_HANA_MIN_HPP