1/*!
2@file
3Defines `boost::hana::min`.
4
5Copyright Louis Dionne 2013-2022
6Distributed under the Boost Software License, Version 1.0.
7(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8 */
9
10#ifndef BOOST_HANA_MIN_HPP
11#define BOOST_HANA_MIN_HPP
12
13#include <boost/hana/fwd/min.hpp>
14
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>
20
21
22namespace boost { namespace hana {
23 //! @cond
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
31 );
32
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");
36
37 static_assert(hana::Orderable<U>::value,
38 "hana::min(x, y) requires 'y' to be Orderable");
39 #endif
40
41 return Min::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
42 }
43 //! @endcond
44
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),
51 static_cast<X&&>(x),
52 static_cast<Y&&>(y)
53 );
54 }
55 };
56}} // end namespace boost::hana
57
58#endif // !BOOST_HANA_MIN_HPP
59

source code of boost/libs/hana/include/boost/hana/min.hpp