di 0.1.0
Loading...
Searching...
No Matches
abs_diff.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/meta/language.h"
5#include "di/types/prelude.h"
6
7namespace di::math {
8namespace detail {
9 struct AbsDiffFunction {
10 template<concepts::Integral T, typename U = meta::MakeUnsigned<T>>
11 constexpr auto operator()(T a, T b) const -> U {
12 if (a < b) {
13 return U(b) - U(a);
14 }
15 return U(a) - U(b);
16 }
17
18 template<concepts::Pointer T>
19 requires(concepts::Object<meta::RemovePointer<T>>)
20 constexpr auto operator()(T a, T b) const -> uptr {
21 if (a < b) {
22 return b - a;
23 }
24 return a - b;
25 }
26 };
27}
28
29constexpr inline auto abs_diff = function::curry_back(detail::AbsDiffFunction {}, meta::c_<2ZU>);
30}
31
32namespace di {
33using math::abs_diff;
34}
constexpr auto curry_back
Definition curry_back.h:141
Definition abs.h:10
constexpr auto abs_diff
Definition abs_diff.h:29
constexpr auto c_
A value of type Constexpr<val>.
Definition constexpr.h:252
uintptr_t uptr
Definition integers.h:36
Definition any_storable.h:9