// 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_TEST_LAWS_MONOID_HPP #define BOOST_HANA_TEST_LAWS_MONOID_HPP #include #include #include #include #include #include #include #include namespace boost { namespace hana { namespace test { template > struct TestMonoid : TestMonoid { using TestMonoid::TestMonoid; }; template struct TestMonoid { template TestMonoid(Xs xs) { #ifdef BOOST_HANA_WORKAROUND_MSVC_DECLTYPEAUTO_RETURNTYPE_662735 zero(); // force adding zero's member function to pending temploid list #endif hana::for_each(xs, hana::capture(xs)([](auto xs, auto a) { static_assert(Monoid{}, ""); // left identity BOOST_HANA_CHECK(hana::equal( hana::plus(zero(), a), a )); // right identity BOOST_HANA_CHECK(hana::equal( hana::plus(a, zero()), a )); hana::for_each(xs, hana::capture(xs, a)([](auto xs, auto a, auto b) { hana::for_each(xs, hana::capture(a, b)([](auto a, auto b, auto c) { // associativity BOOST_HANA_CHECK(equal( hana::plus(a, hana::plus(b, c)), hana::plus(hana::plus(a, b), c) )); })); })); })); } }; template struct TestMonoid::value>> : TestMonoid { template TestMonoid(Xs xs) : TestMonoid{xs} { BOOST_HANA_CHECK(hana::equal( hana::value(zero()), zero() )); foreach2(xs, [](auto x, auto y) { BOOST_HANA_CHECK(hana::equal( hana::plus(hana::value(x), hana::value(y)), hana::value(hana::plus(x, y)) )); }); } }; }}} // end namespace boost::hana::test #endif // !BOOST_HANA_TEST_LAWS_MONOID_HPP