GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/functional/monoid.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 5 5 100.0%
Functions: 0 0 -%
Branches: 0 0 -%

Line Branch Exec Source
1 //======================================================================================================================
2 /*
3 KUMI - Compact Tuple Tools
4 Copyright : KUMI Project Contributors
5 SPDX-License-Identifier: BSL-1.0
6 */
7 //======================================================================================================================
8 #pragma once
9
10 namespace kumi::function
11 {
12 //====================================================================================================================
13 /**
14 @ingroup kumi_functional
15 @class numeric_add
16 @brief Addition monoid whose identity element is `0`.
17 **/
18 //====================================================================================================================
19 struct numeric_add
20 {
21 /// Identity/neutral element of the monoid
22 static constexpr auto identity{0};
23
24 template<typename T1, typename T2>
25 [[nodiscard]] KUMI_ABI constexpr auto operator()(T1&& a, T2&& b) const noexcept(noexcept(KUMI_FWD(a) + KUMI_FWD(b)))
26 requires requires { KUMI_FWD(a) + KUMI_FWD(b); }
27 {
28 129 return KUMI_FWD(a) + KUMI_FWD(b);
29 }
30 };
31
32 //====================================================================================================================
33 /**
34 @ingroup kumi_functional
35 @class numeric_prod
36 @brief Multiplication monoid whose identity element is `1`.
37 **/
38 //====================================================================================================================
39 struct numeric_prod
40 {
41 /// Identity/neutral element of the monoid
42 static constexpr auto identity{1};
43
44 template<typename T1, typename T2>
45 [[nodiscard]] KUMI_ABI constexpr auto operator()(T1&& a, T2&& b) const noexcept(noexcept(KUMI_FWD(a) * KUMI_FWD(b)))
46 requires requires { KUMI_FWD(a) * KUMI_FWD(b); }
47 {
48 61 return KUMI_FWD(a) * KUMI_FWD(b);
49 }
50 };
51
52 //====================================================================================================================
53 /**
54 @ingroup kumi_functional
55 @class boolean_and
56 @brief `logical and` monoid whose identity element is `true`.
57 **/
58 //====================================================================================================================
59 struct boolean_and
60 {
61 /// Identity/neutral element of the monoid
62 static constexpr bool identity{true};
63
64 template<typename T1, typename T2>
65 [[nodiscard]] KUMI_ABI constexpr auto operator()(T1&& a, T2&& b) const noexcept(noexcept(KUMI_FWD(a) & KUMI_FWD(b)))
66 requires requires { KUMI_FWD(a) & KUMI_FWD(b); }
67 {
68 38 return KUMI_FWD(a) & KUMI_FWD(b);
69 }
70 };
71
72 //====================================================================================================================
73 /**
74 @ingroup kumi_functional
75 @class boolean_or
76 @brief `logical or` monoid whose identity element is `false`.
77 **/
78 //====================================================================================================================
79 struct boolean_or
80 {
81 /// Identity/neutral element of the monoid
82 static constexpr bool identity{false};
83
84 template<typename T1, typename T2>
85 [[nodiscard]] KUMI_ABI constexpr auto operator()(T1&& a, T2&& b) const noexcept(noexcept(KUMI_FWD(a) | KUMI_FWD(b)))
86 requires requires { KUMI_FWD(a) | KUMI_FWD(b); }
87 {
88 55 return KUMI_FWD(a) | KUMI_FWD(b);
89 }
90 };
91
92 //====================================================================================================================
93 /**
94 @ingroup kumi_functional
95 @class boolean_xor
96 @brief `logical xor` monoid whose identity element is `false`.
97 **/
98 //====================================================================================================================
99 struct boolean_xor
100 {
101 /// Identity/neutral element of the monoid
102 static constexpr bool identity{false};
103
104 template<typename T1, typename T2>
105 [[nodiscard]] KUMI_ABI constexpr auto operator()(T1&& a, T2&& b) const noexcept(noexcept(KUMI_FWD(a) ^ KUMI_FWD(b)))
106 requires requires { KUMI_FWD(a) ^ KUMI_FWD(b); }
107 {
108 42 return KUMI_FWD(a) ^ KUMI_FWD(b);
109 }
110 };
111
112 //==================================================================================================================
113 /**
114 @ingroup kumi_functional
115 @brief Callable object matching the `kumi::numeric_add` monoid, usable with kumi::algorithm.
116 **/
117 //==================================================================================================================
118 inline constexpr kumi::function::numeric_add plus{};
119
120 //==================================================================================================================
121 /**
122 @ingroup kumi_functional
123 @brief Callable object matching the `kumi::numeric_prod` monoid, usable with kumi::algorithm.
124 **/
125 //==================================================================================================================
126 inline constexpr kumi::function::numeric_prod multiplies{};
127
128 //==================================================================================================================
129 /**
130 @ingroup kumi_functional
131 @brief Callable object matching the `kumi::boolean_and` monoid, usable with kumi::algorithm.
132 **/
133 //==================================================================================================================
134 inline constexpr kumi::function::boolean_and bit_and{};
135
136 //==================================================================================================================
137 /**
138 @ingroup kumi_functional
139 @brief Callable object matching the `kumi::boolean_or` monoid, usable with kumi::algorithm.
140 **/
141 //==================================================================================================================
142 inline constexpr kumi::function::boolean_or bit_or{};
143
144 //==================================================================================================================
145 /**
146 @ingroup kumi_functional
147 @brief Callable object matching the `kumi::boolean_xor` monoid, usable with kumi::algorithm.
148 **/
149 //==================================================================================================================
150 inline constexpr kumi::function::boolean_xor bit_xor{};
151 }
152