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_MONOID_HPP
6 #define BOOST_HANA_TEST_LAWS_MONOID_HPP
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/functional/capture.hpp>
13 #include <boost/hana/lazy.hpp>
14 #include <boost/hana/concept/monoid.hpp>
16 #include <laws/base.hpp>
19 namespace boost { namespace hana { namespace test {
20 template <typename M, typename = when<true>>
21 struct TestMonoid : TestMonoid<M, laws> {
22 using TestMonoid<M, laws>::TestMonoid;
26 struct TestMonoid<M, laws> {
27 template <typename Xs>
29 hana::for_each(xs, hana::capture(xs)([](auto xs, auto a) {
30 static_assert(Monoid<decltype(a)>{}, "");
33 BOOST_HANA_CHECK(hana::equal(
34 hana::plus(zero<M>(), a),
39 BOOST_HANA_CHECK(hana::equal(
40 hana::plus(a, zero<M>()),
45 hana::capture(xs, a)([](auto xs, auto a, auto b) {
47 hana::capture(a, b)([](auto a, auto b, auto c) {
49 BOOST_HANA_CHECK(equal(
50 hana::plus(a, hana::plus(b, c)),
51 hana::plus(hana::plus(a, b), c)
61 struct TestMonoid<C, when<Constant<C>::value>>
64 template <typename Xs>
65 TestMonoid(Xs xs) : TestMonoid<C, laws>{xs} {
67 BOOST_HANA_CHECK(hana::equal(
68 hana::value(zero<C>()),
69 zero<typename C::value_type>()
72 foreach2(xs, [](auto x, auto y) {
73 BOOST_HANA_CHECK(hana::equal(
74 hana::plus(hana::value(x), hana::value(y)),
75 hana::value(hana::plus(x, y))
80 }}} // end namespace boost::hana::test
82 #endif // !BOOST_HANA_TEST_LAWS_MONOID_HPP