]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/test/_include/laws/ring.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / _include / laws / ring.hpp
CommitLineData
b32b8144 1// Copyright Louis Dionne 2013-2017
7c673cae
FG
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_RING_HPP
6#define BOOST_HANA_TEST_LAWS_RING_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/concept/constant.hpp>
12#include <boost/hana/concept/monoid.hpp>
13#include <boost/hana/concept/ring.hpp>
14#include <boost/hana/core/when.hpp>
15#include <boost/hana/equal.hpp>
16#include <boost/hana/functional/capture.hpp>
17#include <boost/hana/lazy.hpp>
18#include <boost/hana/mult.hpp>
19#include <boost/hana/not_equal.hpp>
20#include <boost/hana/one.hpp>
21#include <boost/hana/plus.hpp>
22#include <boost/hana/power.hpp>
23#include <boost/hana/value.hpp>
24
25#include <laws/base.hpp>
26
27
28namespace boost { namespace hana { namespace test {
29 template <typename R, typename = when<true>>
30 struct TestRing : TestRing<R, laws> {
31 using TestRing<R, laws>::TestRing;
32 };
33
34 template <typename R>
35 struct TestRing<R, laws> {
36 template <typename Xs>
37 TestRing(Xs xs) {
38 hana::for_each(xs, hana::capture(xs)([](auto xs, auto x) {
b32b8144 39 static_assert(Ring<decltype(x)>{}, "");
7c673cae
FG
40
41 foreach2(xs, hana::capture(x)([](auto x, auto y, auto z) {
42 // associativity
43 BOOST_HANA_CHECK(hana::equal(
44 hana::mult(x, hana::mult(y, z)),
45 hana::mult(hana::mult(x, y), z)
46 ));
47
48 // distributivity
49 BOOST_HANA_CHECK(hana::equal(
50 hana::mult(x, hana::plus(y, z)),
51 hana::plus(hana::mult(x, y), hana::mult(x, z))
52 ));
53 }));
54
55 // right identity
56 BOOST_HANA_CHECK(hana::equal(
57 hana::mult(x, one<R>()), x
58 ));
59
60 // left identity
61 BOOST_HANA_CHECK(hana::equal(
62 hana::mult(one<R>(), x), x
63 ));
64
65 // power
66 BOOST_HANA_CHECK(hana::equal(
67 hana::power(x, int_c<0>),
68 one<R>()
69 ));
70
71 BOOST_HANA_CHECK(hana::equal(
72 hana::power(x, int_c<1>),
73 x
74 ));
75
76 BOOST_HANA_CHECK(hana::equal(
77 hana::power(x, int_c<2>),
78 hana::mult(x, x)
79 ));
80
81 BOOST_HANA_CHECK(hana::equal(
82 hana::power(x, int_c<3>),
83 hana::mult(hana::mult(x, x), x)
84 ));
85
86 BOOST_HANA_CHECK(hana::equal(
87 hana::power(x, int_c<4>),
88 hana::mult(hana::mult(hana::mult(x, x), x), x)
89 ));
90
91 BOOST_HANA_CHECK(hana::equal(
92 hana::power(x, int_c<5>),
93 hana::mult(hana::mult(hana::mult(hana::mult(x, x), x), x), x)
94 ));
95
96 }));
97 }
98 };
99
100 template <typename C>
101 struct TestRing<C, when<Constant<C>::value>>
102 : TestRing<C, laws>
103 {
104 template <typename Xs>
105 TestRing(Xs xs) : TestRing<C, laws>{xs} {
106 BOOST_HANA_CHECK(hana::equal(
107 hana::value(one<C>()),
108 one<typename C::value_type>()
109 ));
110
111 foreach2(xs, [](auto x, auto y) {
112 BOOST_HANA_CHECK(hana::equal(
113 hana::mult(hana::value(x), hana::value(y)),
114 hana::value(hana::mult(x, y))
115 ));
116 });
117 }
118 };
119}}} // end namespace boost::hana::test
120
121#endif // !BOOST_HANA_TEST_LAWS_RING_HPP