3 Defines `boost::hana::greater_equal`.
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_GREATER_EQUAL_HPP
11 #define BOOST_HANA_GREATER_EQUAL_HPP
13 #include <boost/hana/fwd/greater_equal.hpp>
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/concepts.hpp>
21 #include <boost/hana/detail/has_common_embedding.hpp>
22 #include <boost/hana/detail/nested_than.hpp> // required by fwd decl
23 #include <boost/hana/if.hpp>
24 #include <boost/hana/not.hpp>
27 BOOST_HANA_NAMESPACE_BEGIN
29 template <typename X, typename Y>
30 constexpr decltype(auto) greater_equal_t::operator()(X&& x, Y&& y) const {
31 using T = typename hana::tag_of<X>::type;
32 using U = typename hana::tag_of<Y>::type;
33 using GreaterEqual = BOOST_HANA_DISPATCH_IF(
34 decltype(greater_equal_impl<T, U>{}),
35 hana::Orderable<T>::value &&
36 hana::Orderable<U>::value
39 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
40 static_assert(hana::Orderable<T>::value,
41 "hana::greater_equal(x, y) requires 'x' to be Orderable");
43 static_assert(hana::Orderable<U>::value,
44 "hana::greater_equal(x, y) requires 'y' to be Orderable");
47 return GreaterEqual::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
51 template <typename T, typename U, bool condition>
52 struct greater_equal_impl<T, U, when<condition>> : default_ {
53 template <typename X, typename Y>
54 static constexpr decltype(auto) apply(X x, Y y) {
55 return hana::not_(hana::less(static_cast<X&&>(x),
56 static_cast<Y&&>(y)));
60 // Cross-type overload
61 template <typename T, typename U>
62 struct greater_equal_impl<T, U, when<
63 detail::has_nontrivial_common_embedding<Orderable, T, U>::value
65 using C = typename hana::common<T, U>::type;
66 template <typename X, typename Y>
67 static constexpr decltype(auto) apply(X&& x, Y&& y) {
68 return hana::greater_equal(hana::to<C>(static_cast<X&&>(x)),
69 hana::to<C>(static_cast<Y&&>(y)));
72 BOOST_HANA_NAMESPACE_END
74 #endif // !BOOST_HANA_GREATER_EQUAL_HPP