// 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_RING_HPP #define BOOST_HANA_TEST_LAWS_RING_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace hana { namespace test { template > struct TestRing : TestRing { using TestRing::TestRing; }; template struct TestRing { template TestRing(Xs xs) { #ifdef BOOST_HANA_WORKAROUND_MSVC_DECLTYPEAUTO_RETURNTYPE_662735 one(); // force adding one's member function to pending temploid list #endif hana::for_each(xs, hana::capture(xs)([](auto xs, auto x) { static_assert(Ring{}, ""); foreach2(xs, hana::capture(x)([](auto x, auto y, auto z) { // associativity BOOST_HANA_CHECK(hana::equal( hana::mult(x, hana::mult(y, z)), hana::mult(hana::mult(x, y), z) )); // distributivity BOOST_HANA_CHECK(hana::equal( hana::mult(x, hana::plus(y, z)), hana::plus(hana::mult(x, y), hana::mult(x, z)) )); })); // right identity BOOST_HANA_CHECK(hana::equal( hana::mult(x, one()), x )); // left identity BOOST_HANA_CHECK(hana::equal( hana::mult(one(), x), x )); // power BOOST_HANA_CHECK(hana::equal( hana::power(x, int_c<0>), one() )); BOOST_HANA_CHECK(hana::equal( hana::power(x, int_c<1>), x )); BOOST_HANA_CHECK(hana::equal( hana::power(x, int_c<2>), hana::mult(x, x) )); BOOST_HANA_CHECK(hana::equal( hana::power(x, int_c<3>), hana::mult(hana::mult(x, x), x) )); BOOST_HANA_CHECK(hana::equal( hana::power(x, int_c<4>), hana::mult(hana::mult(hana::mult(x, x), x), x) )); BOOST_HANA_CHECK(hana::equal( hana::power(x, int_c<5>), hana::mult(hana::mult(hana::mult(hana::mult(x, x), x), x), x) )); })); } }; template struct TestRing::value>> : TestRing { template TestRing(Xs xs) : TestRing{xs} { BOOST_HANA_CHECK(hana::equal( hana::value(one()), one() )); foreach2(xs, [](auto x, auto y) { BOOST_HANA_CHECK(hana::equal( hana::mult(hana::value(x), hana::value(y)), hana::value(hana::mult(x, y)) )); }); } }; }}} // end namespace boost::hana::test #endif // !BOOST_HANA_TEST_LAWS_RING_HPP