diff --git a/include/boost/hana/map.hpp b/include/boost/hana/map.hpp index 45537b12a..85b6f6801 100644 --- a/include/boost/hana/map.hpp +++ b/include/boost/hana/map.hpp @@ -13,6 +13,7 @@ Distributed under the Boost Software License, Version 1.0. #include #include +#include #include #include #include @@ -39,7 +40,6 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include -#include #include #include #include @@ -53,6 +53,7 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include +#include #include #include @@ -368,20 +369,30 @@ namespace boost { namespace hana { return hana::false_c; } + template + struct compare_at_key { + const M1 &m1; + const M2 &m2; + + template + constexpr auto operator()(const K& key) const { + return hana::equal(hana::at_key(m1, key), hana::at_key(m2, key)); + } + }; + template static constexpr auto equal_helper(M1 const& m1, M2 const& m2, hana::true_) { - return hana::all_of(hana::keys(m1), hana::demux(equal)( - hana::partial(hana::find, m1), - hana::partial(hana::find, m2) - )); + return hana::all_of( + hana::keys(m1), + equal_impl::compare_at_key{m1, m2}); } template static constexpr auto apply(M1 const& m1, M2 const& m2) { - return equal_impl::equal_helper(m1, m2, hana::bool_c< - decltype(hana::length(m1.storage))::value == - decltype(hana::length(m2.storage))::value - >); + return equal_impl::equal_helper(m1, m2, + hana::to_set(hana::keys(m1)) == + hana::to_set(hana::keys(m2)) + ); } }; diff --git a/test/map/equal.cpp b/test/map/equal.cpp index 7309793c4..0db4b96fb 100644 --- a/test/map/equal.cpp +++ b/test/map/equal.cpp @@ -10,6 +10,8 @@ #include #include +#include + namespace hana = boost::hana; @@ -94,4 +96,15 @@ int main() { != hana::make_map(p<1, 1>(), p<2, 2>()) ); + + auto map_unique_1 = hana::make_map(hana::make_pair( + hana::integral_constant{}, + ConstexprMoveOnly<0>{}) + ); + auto map_unique_2 = hana::make_map(hana::make_pair( + hana::integral_constant{}, + ConstexprMoveOnly<1>{}) + ); + BOOST_HANA_CONSTANT_ASSERT(map_unique_1 == map_unique_1); + BOOST_HANA_CONSTANT_ASSERT(map_unique_1 != map_unique_2); }