File indexing completed on 2025-01-18 09:38:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_GREATER_HPP
0011 #define BOOST_HANA_GREATER_HPP
0012
0013 #include <boost/hana/fwd/greater.hpp>
0014
0015 #include <boost/hana/concept/orderable.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/common.hpp>
0018 #include <boost/hana/core/to.hpp>
0019 #include <boost/hana/core/dispatch.hpp>
0020 #include <boost/hana/detail/concepts.hpp>
0021 #include <boost/hana/detail/has_common_embedding.hpp>
0022 #include <boost/hana/detail/nested_than.hpp> // required by fwd decl
0023 #include <boost/hana/if.hpp>
0024
0025
0026 namespace boost { namespace hana {
0027
0028 template <typename X, typename Y>
0029 constexpr decltype(auto) greater_t::operator()(X&& x, Y&& y) const {
0030 using T = typename hana::tag_of<X>::type;
0031 using U = typename hana::tag_of<Y>::type;
0032 using Greater = BOOST_HANA_DISPATCH_IF(decltype(greater_impl<T, U>{}),
0033 hana::Orderable<T>::value &&
0034 hana::Orderable<U>::value
0035 );
0036
0037 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0038 static_assert(hana::Orderable<T>::value,
0039 "hana::greater(x, y) requires 'x' to be Orderable");
0040
0041 static_assert(hana::Orderable<U>::value,
0042 "hana::greater(x, y) requires 'y' to be Orderable");
0043 #endif
0044
0045 return Greater::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
0046 }
0047
0048 template <typename T, typename U, bool condition>
0049 struct greater_impl<T, U, when<condition>> : default_ {
0050 template <typename X, typename Y>
0051 static constexpr decltype(auto) apply(X&& x, Y&& y) {
0052 return hana::less(static_cast<Y&&>(y),
0053 static_cast<X&&>(x));
0054 }
0055 };
0056
0057
0058 template <typename T, typename U>
0059 struct greater_impl<T, U, when<
0060 detail::has_nontrivial_common_embedding<Orderable, T, U>::value
0061 >> {
0062 using C = typename hana::common<T, U>::type;
0063 template <typename X, typename Y>
0064 static constexpr decltype(auto) apply(X&& x, Y&& y) {
0065 return hana::greater(hana::to<C>(static_cast<X&&>(x)),
0066 hana::to<C>(static_cast<Y&&>(y)));
0067 }
0068 };
0069 }}
0070
0071 #endif