File indexing completed on 2025-01-30 09:43:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_LESS_EQUAL_HPP
0011 #define BOOST_HANA_LESS_EQUAL_HPP
0012
0013 #include <boost/hana/fwd/less_equal.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/has_common_embedding.hpp>
0021 #include <boost/hana/detail/nested_than.hpp> // required by fwd decl
0022 #include <boost/hana/less.hpp>
0023 #include <boost/hana/not.hpp>
0024
0025 #include <type_traits>
0026
0027
0028 namespace boost { namespace hana {
0029
0030 template <typename X, typename Y>
0031 constexpr auto less_equal_t::operator()(X&& x, Y&& y) const {
0032 using T = typename hana::tag_of<X>::type;
0033 using U = typename hana::tag_of<Y>::type;
0034 using LessEqual = BOOST_HANA_DISPATCH_IF(
0035 decltype(less_equal_impl<T, U>{}),
0036 hana::Orderable<T>::value &&
0037 hana::Orderable<U>::value
0038 );
0039
0040 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0041 static_assert(hana::Orderable<T>::value,
0042 "hana::less_equal(x, y) requires 'x' to be Orderable");
0043
0044 static_assert(hana::Orderable<U>::value,
0045 "hana::less_equal(x, y) requires 'y' to be Orderable");
0046 #endif
0047
0048 return LessEqual::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
0049 }
0050
0051
0052 template <typename T, typename U, bool condition>
0053 struct less_equal_impl<T, U, when<condition>> : default_ {
0054 template <typename X, typename Y>
0055 static constexpr decltype(auto) apply(X&& x, Y&& y) {
0056 return hana::not_(hana::less(static_cast<Y&&>(y),
0057 static_cast<X&&>(x)));
0058 }
0059 };
0060
0061
0062 template <typename T, typename U>
0063 struct less_equal_impl<T, U, when<
0064 detail::has_nontrivial_common_embedding<Orderable, T, U>::value
0065 >> {
0066 using C = typename hana::common<T, U>::type;
0067 template <typename X, typename Y>
0068 static constexpr decltype(auto) apply(X&& x, Y&& y) {
0069 return hana::less_equal(hana::to<C>(static_cast<X&&>(x)),
0070 hana::to<C>(static_cast<Y&&>(y)));
0071 }
0072 };
0073 }}
0074
0075 #endif