/*! @file Defines `boost::hana::lexicographical_compare`. Copyright Louis Dionne 2013-2022 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_LEXICOGRAPHICAL_COMPARE_HPP #define BOOST_HANA_LEXICOGRAPHICAL_COMPARE_HPP #include #include #include #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr auto lexicographical_compare_t::operator()(Xs const& xs, Ys const& ys) const { return hana::lexicographical_compare(xs, ys, hana::less); } template constexpr auto lexicographical_compare_t::operator()(Xs const& xs, Ys const& ys, Pred const& pred) const { using It1 = typename hana::tag_of::type; using It2 = typename hana::tag_of::type; using LexicographicalCompare = BOOST_HANA_DISPATCH_IF( lexicographical_compare_impl, hana::Iterable::value && hana::Iterable::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Iterable::value, "hana::lexicographical_compare(xs, ys, pred) requires 'xs' to be Iterable"); static_assert(hana::Iterable::value, "hana::lexicographical_compare(xs, ys, pred) requires 'ys' to be Iterable"); #endif return LexicographicalCompare::apply(xs, ys, pred); } //! @endcond template struct lexicographical_compare_impl> : default_ { template static constexpr auto helper2(Xs const&, Ys const&, Pred const&, hana::true_) { return hana::false_c; } template static constexpr auto helper2(Xs const& xs, Ys const& ys, Pred const& pred, hana::false_) { return apply(hana::drop_front(xs), hana::drop_front(ys), pred); } template static constexpr auto helper2(Xs const& xs, Ys const& ys, Pred const& pred, bool is_greater) { return is_greater ? false : apply(hana::drop_front(xs), hana::drop_front(ys), pred); } template static constexpr auto helper1(Xs const&, Ys const&, Pred const&, hana::true_) { return hana::true_c; } template static constexpr auto helper1(Xs const& xs, Ys const& ys, Pred const& pred, hana::false_) { return helper2(xs, ys, pred, hana::if_(pred(hana::front(ys), hana::front(xs)), hana::true_c, hana::false_c)); } template static constexpr auto helper1(Xs const& xs, Ys const& ys, Pred const& pred, bool is_less) { return is_less ? true : helper2(xs, ys, pred, hana::if_(pred(hana::front(ys), hana::front(xs)), hana::true_c, hana::false_c)); } template static constexpr auto helper(Xs const&, Ys const& ys, Pred const&, hana::true_) { return hana::not_(hana::is_empty(ys)); } template static constexpr auto helper(Xs const& xs, Ys const& ys, Pred const& pred, hana::false_) { return helper1(xs, ys, pred, hana::if_(pred(hana::front(xs), hana::front(ys)), hana::true_c, hana::false_c)); } template static constexpr auto apply(Xs const& xs, Ys const& ys, Pred const& pred) { return helper(xs, ys, pred, hana::bool_c< decltype(hana::is_empty(xs))::value || decltype(hana::is_empty(ys))::value >); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_LEXICOGRAPHICAL_COMPARE_HPP