/* @copyright Louis Dionne 2014 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #include #include #include #include #include #include #include using namespace boost::hana; struct EqClass; template struct X { using hana_datatype = EqClass; }; template struct Y { using hana_datatype = EqClass; }; template constexpr X x{}; template constexpr Y y{}; namespace boost { namespace hana { template <> struct Comparable::instance : Comparable::equal_mcd { template static constexpr auto equal_impl(T, U) { return type == type; } }; }} constexpr struct _predicate { template class X, template class Y> constexpr auto operator()(X, Y) const { return bool_<(i < j)>; } } pred{}; int main() { BOOST_HANA_CONSTEXPR_LAMBDA auto check = [](auto sorted_list) { auto perms = fmap(partial(sort_by, pred), permutations(sorted_list)); BOOST_HANA_STATIC_ASSERT(all(_ == sorted_list, perms)); }; check(list()); check(list(x<1>)); check(list(x<1>, x<2>)); check(list(x<1>, x<2>, x<3>)); // check stability BOOST_HANA_STATIC_ASSERT(sort_by(pred, list(x<1>, y<1>)) == list(x<1>, y<1>)); BOOST_HANA_STATIC_ASSERT(sort_by(pred, list(y<1>, x<1>)) == list(y<1>, x<1>)); BOOST_HANA_STATIC_ASSERT(sort_by(pred, list(x<1>, y<1>, x<2>, y<2>)) == list(x<1>, y<1>, x<2>, y<2>)); BOOST_HANA_STATIC_ASSERT(sort_by(pred, list(x<1>, x<2>, y<1>, y<2>)) == list(x<1>, y<1>, x<2>, y<2>)); BOOST_HANA_STATIC_ASSERT(sort_by(pred, list(y<1>, x<1>, x<2>, y<2>)) == list(y<1>, x<1>, x<2>, y<2>)); BOOST_HANA_STATIC_ASSERT(sort_by(pred, list(x<2>, y<1>, y<2>, x<1>)) == list(y<1>, x<1>, x<2>, y<2>)); BOOST_HANA_STATIC_ASSERT(sort_by(pred, list(x<1>, x<3>, y<1>, x<2>, y<3>)) == list(x<1>, y<1>, x<2>, x<3>, y<3>)); }