Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:03

0001 /*!
0002 @file
0003 Defines `boost::hana::greater`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
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     //! @cond
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     //! @endcond
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     // Cross-type overload
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 }} // end namespace boost::hana
0070 
0071 #endif // !BOOST_HANA_GREATER_HPP