1#ifndef LIBTEDDY_DETAILS_OPERATORS_HPP
2#define LIBTEDDY_DETAILS_OPERATORS_HPP
4#include <libteddy/details/tools.hpp>
5#include <libteddy/details/types.hpp>
15 [[nodiscard]]
auto constexpr operator() (int32
const t, Ts... ts)
const
18 Op
const& op =
static_cast<Op const&
>(*this);
19 return op(t, op(ts...));
23template<
int32 Id,
bool IsCommutative>
26 [[nodiscard]]
static auto constexpr get_id() -> int32
31 [[nodiscard]]
static auto constexpr is_commutative() ->
bool
47 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
50 int32
const mi = utils::min(l, r);
51 int32
const ma = utils::max(l, r);
52 return mi == 0 ? mi : ma;
60 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
63 int const mi = utils::min(l, r);
64 int const ma = utils::max(l, r);
65 return mi == 0 ? ma : mi;
73 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
77 int const ma = utils::max(l, r);
78 return ma == Nondetermined ? ma : xi;
86 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
89 int32
const mi = utils::min(l, r);
90 int32
const ma = utils::max(l, r);
91 return mi == 0 ? mi : ma == Undefined ? mi : ma;
99 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
102 int32
const mi = utils::min(l, r);
103 int32
const ma = utils::max(l, r);
104 return ma == Nondetermined ? ma : 1 - mi;
112 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
117 int32
const mi = utils::min(l, r);
118 int32
const ma = utils::max(l, r);
119 int32
const ema = utils::max(l | r, 1);
120 return (mi & 1) | (ma & 1) ? 0 : ema;
128 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
131 int32
const ma = utils::max(l, r);
132 int32
const ne =
static_cast<int32
>(l == r);
133 return ma == Nondetermined ? ma : ne;
141 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
144 int32
const ma = utils::max(l, r);
145 int32
const eq =
static_cast<int32
>(l == r);
146 return ma == Nondetermined ? ma : eq;
156 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
159 int32
const ma = utils::max(l, r);
160 int32
const ne =
static_cast<int32
>(l != r);
161 return ma == Nondetermined ? ma : ne;
169 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
172 int32
const ma = utils::max(l, r);
173 int32
const le =
static_cast<int32
>(l < r);
174 return ma == Nondetermined ? ma : le;
180 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
183 int32
const ma = utils::max(l, r);
184 int32
const le =
static_cast<int32
>(l <= r);
185 return ma == Nondetermined ? ma : le;
191 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
194 int32
const ma = utils::max(l, r);
195 int32
const ge =
static_cast<int32
>(l > r);
196 return ma == Nondetermined ? ma : ge;
202 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
205 int32
const ma = utils::max(l, r);
206 int32
const ge =
static_cast<int32
>(l >= r);
208 return ma == Nondetermined ? Nondetermined : ge;
214 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
217 int32
const mi = utils::min(l, r);
218 int32
const ma = utils::max(l, r);
219 return mi == 0 || ma != Nondetermined ? mi : ma;
227 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
230 return utils::max(l, r);
243 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
246 int32
const ma = utils::max(l, r);
247 return l == M - 1 || r == M - 1 ? M - 1 : ma;
256 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
259 int32
const ma = utils::max(l, r);
260 int32
const pl = (l + r) % M;
261 return ma == Nondetermined ? ma : pl;
270 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
273 int32
const mi = utils::min(l, r);
274 int32
const ma = utils::max(l, r);
275 int32
const ml = (l * r) % M;
276 return mi == 0 ? 0 : ma == Nondetermined ? Nondetermined : ml;
282 [[nodiscard]]
auto constexpr operator() (int32
const l, int32
const r)
const
285 int32
const ma = utils::max(l, r);
286 int32
const im =
static_cast<int32
>(not l || r);
287 return l == 0 ? 1 : ma == Nondetermined ? Nondetermined : im;
292template<
class Operation>
298 Operation::is_commutative()
Definition operators.hpp:293
Contains definitions of all binary operations for apply function.
Definition operators.hpp:13
Definition operators.hpp:25
Definition operators.hpp:46
Definition operators.hpp:140
Definition operators.hpp:201
Definition operators.hpp:190
Definition operators.hpp:281
Definition operators.hpp:179
Definition operators.hpp:168
Same as MAX but short-circuits for M – should be faster.
Definition operators.hpp:242
Definition operators.hpp:226
Definition operators.hpp:213
Definition operators.hpp:269
Definition operators.hpp:98
Definition operators.hpp:111
Definition operators.hpp:155
Definition operators.hpp:59
Definition operators.hpp:85
Definition operators.hpp:255
Definition operators.hpp:127
Definition operators.hpp:72