| 1 | /*! |
| 2 | @file |
| 3 | Defines `boost::hana::greater_equal`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 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_GREATER_EQUAL_HPP |
| 11 | #define BOOST_HANA_GREATER_EQUAL_HPP |
| 12 | |
| 13 | #include <boost/hana/fwd/greater_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/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> |
| 25 | |
| 26 | |
| 27 | namespace boost { namespace hana { |
| 28 | //! @cond |
| 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 |
| 37 | ); |
| 38 | |
| 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" ); |
| 42 | |
| 43 | static_assert(hana::Orderable<U>::value, |
| 44 | "hana::greater_equal(x, y) requires 'y' to be Orderable" ); |
| 45 | #endif |
| 46 | |
| 47 | return GreaterEqual::apply(static_cast<X&&>(x), static_cast<Y&&>(y)); |
| 48 | } |
| 49 | //! @endcond |
| 50 | |
| 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))); |
| 57 | } |
| 58 | }; |
| 59 | |
| 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 |
| 64 | >> { |
| 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))); |
| 70 | } |
| 71 | }; |
| 72 | }} // end namespace boost::hana |
| 73 | |
| 74 | #endif // !BOOST_HANA_GREATER_EQUAL_HPP |
| 75 | |