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) 4 5 #ifndef BOOST_HANA_TEST_LAWS_GROUP_HPP 6 #define BOOST_HANA_TEST_LAWS_GROUP_HPP 7 8 #include <boost/hana/assert.hpp> 9 #include <boost/hana/bool.hpp> 10 #include <boost/hana/concept/comparable.hpp> 11 #include <boost/hana/core/when.hpp> 12 #include <boost/hana/concept/group.hpp> 13 #include <boost/hana/lazy.hpp> 14 15 #include <laws/base.hpp> 16 17 18 namespace boost { namespace hana { namespace test { 19 template <typename G, typename = when<true>> 20 struct TestGroup : TestGroup<G, laws> { 21 using TestGroup<G, laws>::TestGroup; 22 }; 23 24 template <typename G> 25 struct TestGroup<G, laws> { 26 template <typename Xs> TestGroupboost::hana::test::TestGroup27 TestGroup(Xs xs) { 28 hana::for_each(xs, [](auto x) { 29 static_assert(Group<decltype(x)>{}, ""); 30 }); 31 32 #ifdef BOOST_HANA_WORKAROUND_MSVC_DECLTYPEAUTO_RETURNTYPE_662735 33 zero<G>(); // force adding zero<G>'s member function to pending temploid list 34 #endif 35 36 foreach2(xs, [](auto x, auto y) { 37 38 // left inverse 39 BOOST_HANA_CHECK(hana::equal( 40 hana::plus(x, hana::negate(x)), 41 zero<G>() 42 )); 43 44 // right inverse 45 BOOST_HANA_CHECK(hana::equal( 46 hana::plus(hana::negate(x), x), 47 zero<G>() 48 )); 49 50 // default definition of minus 51 BOOST_HANA_CHECK(hana::equal( 52 hana::minus(x, y), 53 hana::plus(x, hana::negate(y)) 54 )); 55 56 BOOST_HANA_CHECK(hana::equal( 57 hana::minus(y, x), 58 hana::plus(y, hana::negate(x)) 59 )); 60 61 // default definition of negate 62 BOOST_HANA_CHECK(hana::equal( 63 hana::negate(hana::negate(x)), 64 x 65 )); 66 }); 67 } 68 }; 69 70 template <typename C> 71 struct TestGroup<C, when<Constant<C>::value>> 72 : TestGroup<C, laws> 73 { 74 template <typename Xs> TestGroupboost::hana::test::TestGroup75 TestGroup(Xs xs) : TestGroup<C, laws>{xs} { __anon30b830040302boost::hana::test::TestGroup76 foreach2(xs, [](auto x, auto y) { 77 78 BOOST_HANA_CHECK(hana::equal( 79 hana::negate(hana::value(x)), 80 hana::value(hana::negate(x)) 81 )); 82 83 BOOST_HANA_CHECK(hana::equal( 84 hana::minus(hana::value(x), hana::value(y)), 85 hana::value(hana::minus(x, y)) 86 )); 87 88 }); 89 } 90 }; 91 }}} // end namespace boost::hana::test 92 93 #endif // !BOOST_HANA_TEST_LAWS_GROUP_HPP 94