13template <
typename A,
typename B>
14requires same_as<std::decay_t<A>, std::decay_t<B>>
15constexpr auto min(A&& a, B&& b) {
16 return gcem::min(std::forward<A>(a), std::forward<B>(b));
18template <
typename A,
typename B>
19requires same_as<std::decay_t<A>, std::decay_t<B>>
20constexpr auto max(A&& a, B&& b) {
21 return gcem::max(std::forward<A>(a), std::forward<B>(b));
32template <
template <
typename>
typename Comparator,
typename T0,
typename T1,
34requires requires(T0 a, T1 b, Comparator<std::decay_t<T0>> comp) {
35 { comp(a, b) } -> std::convertible_to<bool>;
36 } && same_as<std::decay_t<T0>, std::decay_t<T1>> &&
37 (same_as<std::decay_t<T0>, std::decay_t<TRest>> && ...)
39 if constexpr (
sizeof...(TRest) == 0) {
40 return Comparator<std::decay_t<T0>>{}(a, b) ? std::forward<T0>(a)
41 : std::forward<T1>(b);
43 return tatooine::compare_variadic<Comparator>(
45 tatooine::compare_variadic<Comparator>(std::forward<T1>(b),
46 std::forward<TRest>(rest)...));
51constexpr auto max(T0&& a) ->
decltype(
auto) {
52 return std::forward<T0>(a);
55template <
typename T0,
typename T1,
typename T2,
typename... TRest>
56requires requires(T0&& a, T1&& b) {
57 { a > b } -> std::convertible_to<bool>;
59constexpr auto max(T0&& a, T1&& b, T2&& c, TRest&&... rest) ->
decltype(
auto) {
60 return compare_variadic<std::greater>(
61 std::forward<T0>(a), std::forward<T1>(b), std::forward<T2>(c),
62 std::forward<TRest>(rest)...);
65template <
typename T0,
typename T1,
typename T2,
typename... TRest>
66requires requires(T0&& a, T1&& b) {
67 { a > b } -> std::convertible_to<bool>;
69constexpr auto min(T0&& a, T1&& b, T2&& c, TRest&&... rest) ->
decltype(
auto) {
70 return compare_variadic<std::less>(std::forward<T0>(a), std::forward<T1>(b),
72 std::forward<TRest>(rest)...);
75template <
typename T, std::size_t N, std::size_t... Is>
76constexpr auto min(std::array<T, N>
const& arr,
77 std::index_sequence<Is...> ) {
78 return min(arr[Is]...);
81template <
typename T, std::
size_t N>
82constexpr auto min(std::array<T, N>
const& arr) {
83 return min(arr, std::make_index_sequence<N>{});
86template <
typename T, std::size_t N, std::size_t... Is>
87constexpr auto max(std::array<T, N>
const& arr,
88 std::index_sequence<Is...> ) {
89 return max(arr[Is]...);
92template <
typename T, std::
size_t N>
93constexpr auto max(std::array<T, N>
const& arr) {
94 return max(arr, std::make_index_sequence<N>{});
98 std::decay_t<
decltype(base)> p = 1;
99 for (std::decay_t<
decltype(exp)> i = 0; i < exp; ++i) {
105template <
integral Int>
106constexpr auto factorial(Int
const i) -> std::decay_t<Int> {
Definition: concepts.h:33
Definition: concepts.h:21
Definition: algorithm.h:6
constexpr auto abs(arithmetic auto const x)
Definition: math.h:26
constexpr auto cos(arithmetic auto const x)
Definition: math.h:28
constexpr auto log(arithmetic auto const x)
Definition: math.h:23
constexpr auto pow(arithmetic auto const x)
Definition: math.h:30
constexpr auto max(A &&a, B &&b)
Definition: math.h:20
constexpr auto compare_variadic(T0 &&a, T1 &&b, TRest &&... rest)
Definition: math.h:38
constexpr auto ipow(integral auto const base, integral auto const exp)
Definition: math.h:97
constexpr auto min(A &&a, B &&b)
Definition: math.h:15
constexpr auto sin(arithmetic auto const x)
Definition: math.h:27
constexpr auto sqrt(arithmetic auto const x)
Definition: math.h:29
constexpr auto log2(arithmetic auto const x)
Definition: math.h:24
constexpr auto factorial(Int const i) -> std::decay_t< Int >
Definition: math.h:106