/*! @file Defines `boost::hana::less`. @copyright Louis Dionne 2013-2017 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_LESS_HPP #define BOOST_HANA_LESS_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include // required by fwd decl #include #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr auto less_t::operator()(X&& x, Y&& y) const { using T = typename hana::tag_of::type; using U = typename hana::tag_of::type; using Less = BOOST_HANA_DISPATCH_IF(decltype(less_impl{}), hana::Orderable::value && hana::Orderable::value && !is_default>::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Orderable::value, "hana::less(x, y) requires 'x' to be Orderable"); static_assert(hana::Orderable::value, "hana::less(x, y) requires 'y' to be Orderable"); static_assert(!is_default>::value, "hana::less(x, y) requires 'x' and 'y' to be embeddable " "in a common Orderable"); #endif return Less::apply(static_cast(x), static_cast(y)); } //! @endcond template struct less_impl> : default_ { template static constexpr auto apply(Args&& ...) = delete; }; // Cross-type overload template struct less_impl::value && !detail::LessThanComparable::value >> { using C = typename hana::common::type; template static constexpr decltype(auto) apply(X&& x, Y&& y) { return hana::less(hana::to(static_cast(x)), hana::to(static_cast(y))); } }; ////////////////////////////////////////////////////////////////////////// // Model for LessThanComparable data types ////////////////////////////////////////////////////////////////////////// template struct less_impl::value>> { template static constexpr decltype(auto) apply(X&& x, Y&& y) { return static_cast(x) < static_cast(y); } }; ////////////////////////////////////////////////////////////////////////// // Model for Constants wrapping an Orderable ////////////////////////////////////////////////////////////////////////// template struct less_impl::value && Orderable::value >> { template static constexpr auto apply(X const&, Y const&) { constexpr auto is_less = hana::less(hana::value(), hana::value()); constexpr bool truth_value = hana::if_(is_less, true, false); return hana::bool_c; } }; ////////////////////////////////////////////////////////////////////////// // Model for Products ////////////////////////////////////////////////////////////////////////// template struct less_impl::value && hana::Product::value>> { template static constexpr decltype(auto) apply(X const& x, Y const& y) { return hana::or_( hana::less(hana::first(x), hana::first(y)), hana::and_( hana::less_equal(hana::first(x), hana::first(y)), hana::less(hana::second(x), hana::second(y)) ) ); } }; ////////////////////////////////////////////////////////////////////////// // Model for Sequences ////////////////////////////////////////////////////////////////////////// template struct less_impl::value && hana::Sequence::value >> { template static constexpr auto apply(Xs const& xs, Ys const& ys) { return hana::lexicographical_compare(xs, ys); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_LESS_HPP