1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
5 #ifndef BOOST_HANA_TEST_LAWS_HASHABLE_HPP
6 #define BOOST_HANA_TEST_LAWS_HASHABLE_HPP
8 #include <boost/hana/assert.hpp>
9 #include <boost/hana/bool.hpp>
10 #include <boost/hana/concept/hashable.hpp>
11 #include <boost/hana/core/default.hpp>
12 #include <boost/hana/core/tag_of.hpp>
13 #include <boost/hana/core/when.hpp>
14 #include <boost/hana/equal.hpp>
15 #include <boost/hana/for_each.hpp>
16 #include <boost/hana/hash.hpp>
17 #include <boost/hana/if.hpp>
19 #include <laws/base.hpp>
22 namespace boost { namespace hana { namespace test {
23 template <typename G, typename = when<true>>
24 struct TestHashable : TestHashable<G, laws> {
25 using TestHashable<G, laws>::TestHashable;
29 struct TestHashable<H, laws> {
30 template <typename Xs>
32 hana::for_each(xs, [](auto x) {
33 static_assert(Hashable<decltype(x)>{}, "");
36 hana::for_each(xs, [&](auto const& x) {
37 hana::for_each(xs, [&](auto const& y) {
38 using X = hana::tag_of_t<decltype(x)>;
39 using Y = hana::tag_of_t<decltype(y)>;
40 constexpr bool comparable = !hana::is_default<
41 hana::equal_impl<X, Y>
44 hana::if_(hana::bool_c<comparable>,
45 [](auto const& x, auto const& y) {
49 hana::equal(hana::hash(x), hana::hash(y))
58 }}} // end namespace boost::hana::test
60 #endif // !BOOST_HANA_TEST_LAWS_HASHABLE_HPP