]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/less_equal.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / hana / less_equal.hpp
1 /*!
2 @file
3 Defines `boost::hana::less_equal`.
4
5 @copyright Louis Dionne 2013-2017
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)
8 */
9
10 #ifndef BOOST_HANA_LESS_EQUAL_HPP
11 #define BOOST_HANA_LESS_EQUAL_HPP
12
13 #include <boost/hana/fwd/less_equal.hpp>
14
15 #include <boost/hana/concept/orderable.hpp>
16 #include <boost/hana/config.hpp>
17 #include <boost/hana/core/common.hpp>
18 #include <boost/hana/core/to.hpp>
19 #include <boost/hana/core/dispatch.hpp>
20 #include <boost/hana/detail/has_common_embedding.hpp>
21 #include <boost/hana/detail/nested_than.hpp> // required by fwd decl
22 #include <boost/hana/less.hpp>
23 #include <boost/hana/not.hpp>
24
25 #include <type_traits>
26
27
28 BOOST_HANA_NAMESPACE_BEGIN
29 //! @cond
30 template <typename X, typename Y>
31 constexpr auto less_equal_t::operator()(X&& x, Y&& y) const {
32 using T = typename hana::tag_of<X>::type;
33 using U = typename hana::tag_of<Y>::type;
34 using LessEqual = BOOST_HANA_DISPATCH_IF(
35 decltype(less_equal_impl<T, U>{}),
36 hana::Orderable<T>::value &&
37 hana::Orderable<U>::value
38 );
39
40 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
41 static_assert(hana::Orderable<T>::value,
42 "hana::less_equal(x, y) requires 'x' to be Orderable");
43
44 static_assert(hana::Orderable<U>::value,
45 "hana::less_equal(x, y) requires 'y' to be Orderable");
46 #endif
47
48 return LessEqual::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
49 }
50 //! @endcond
51
52 template <typename T, typename U, bool condition>
53 struct less_equal_impl<T, U, when<condition>> : default_ {
54 template <typename X, typename Y>
55 static constexpr decltype(auto) apply(X&& x, Y&& y) {
56 return hana::not_(hana::less(static_cast<Y&&>(y),
57 static_cast<X&&>(x)));
58 }
59 };
60
61 // Cross-type overload
62 template <typename T, typename U>
63 struct less_equal_impl<T, U, when<
64 detail::has_nontrivial_common_embedding<Orderable, T, U>::value
65 >> {
66 using C = typename hana::common<T, U>::type;
67 template <typename X, typename Y>
68 static constexpr decltype(auto) apply(X&& x, Y&& y) {
69 return hana::less_equal(hana::to<C>(static_cast<X&&>(x)),
70 hana::to<C>(static_cast<Y&&>(y)));
71 }
72 };
73 BOOST_HANA_NAMESPACE_END
74
75 #endif // !BOOST_HANA_LESS_EQUAL_HPP