fiber
Loading...
Searching...
No Matches
functional.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
5
6namespace fiber{
7
8 template<class A, class B>
9 constexpr bool equal(A a, B b){
10 if constexpr (std::is_signed_v<A> && std::is_unsigned_v<B>){
11 if(sizeof(A) > sizeof(B)){
12 using UInt = std::make_unsigned<A>::type;
13 return (a < 0) ? false : (static_cast<UInt>(a) == static_cast<UInt>(b));
14 }else{
15 using UInt = std::make_unsigned<B>::type;
16 return (a < 0) ? false : (static_cast<UInt>(a) == static_cast<UInt>(b));
17 }
18 }else if constexpr (std::is_unsigned_v<A> && std::is_signed_v<B>){
19 if(sizeof(A) > sizeof(B)){
20 using UInt = std::make_unsigned<A>::type;
21 return (b < 0) ? false : (static_cast<UInt>(a) == static_cast<UInt>(b));
22 }else{
23 using UInt = std::make_unsigned<B>::type;
24 return (b < 0) ? false : (static_cast<UInt>(a) == static_cast<UInt>(b));
25 }
26 }else{
27 return a == b;
28 }
29 }
30
31 template<std::integral A, std::integral B>
32 constexpr bool not_equal(A a, B b){
33 if constexpr (std::is_signed_v<A> && std::is_unsigned_v<B>){
34 if(sizeof(A) > sizeof(B)){
35 using UInt = std::make_unsigned<A>::type;
36 return (a < 0) ? true : (static_cast<UInt>(a) != static_cast<UInt>(b));
37 }else{
38 using UInt = std::make_unsigned<B>::type;
39 return (a < 0) ? true : (static_cast<UInt>(a) != static_cast<UInt>(b));
40 }
41 }else if constexpr (std::is_unsigned_v<A> && std::is_signed_v<B>){
42 if(sizeof(A) > sizeof(B)){
43 using UInt = std::make_unsigned<A>::type;
44 return (b < 0) ? true : (static_cast<UInt>(a) != static_cast<UInt>(b));
45 }else{
46 using UInt = std::make_unsigned<B>::type;
47 return (b < 0) ? true : (static_cast<UInt>(a) != static_cast<UInt>(b));
48 }
49 }else{
50 return a != b;
51 }
52 }
53
54 template<std::integral A, std::integral B>
55 constexpr bool less_equal(A a, B b){
56 if constexpr (std::is_signed_v<A> && std::is_unsigned_v<B>){
57 if(sizeof(A) > sizeof(B)){
58 using UInt = std::make_unsigned<A>::type;
59 return (a < 0) ? true : (static_cast<UInt>(a) <= static_cast<UInt>(b));
60 }else{
61 using UInt = std::make_unsigned<B>::type;
62 return (a < 0) ? true : (static_cast<UInt>(a) <= static_cast<UInt>(b));
63 }
64 }else if constexpr (std::is_unsigned_v<A> && std::is_signed_v<B>){
65 if(sizeof(A) > sizeof(B)){
66 using UInt = std::make_unsigned<A>::type;
67 return (b < 0) ? false : (static_cast<UInt>(a) <= static_cast<UInt>(b));
68 }else{
69 using UInt = std::make_unsigned<B>::type;
70 return (b < 0) ? false : (static_cast<UInt>(a) <= static_cast<UInt>(b));
71 }
72 }else{
73 return a <= b;
74 }
75 }
76
77 template<std::integral A, std::integral B>
78 constexpr bool less(A a, B b){
79 if constexpr (std::is_signed_v<A> && std::is_unsigned_v<B>){
80 if(sizeof(A) > sizeof(B)){
81 using UInt = std::make_unsigned<A>::type;
82 return (a < 0) ? true : (static_cast<UInt>(a) < static_cast<UInt>(b));
83 }else{
84 using UInt = std::make_unsigned<B>::type;
85 return (a < 0) ? true : (static_cast<UInt>(a) < static_cast<UInt>(b));
86 }
87 }else if constexpr (std::is_unsigned_v<A> && std::is_signed_v<B>){
88 if(sizeof(A) > sizeof(B)){
89 using UInt = std::make_unsigned<A>::type;
90 return (b < 0) ? false : (static_cast<UInt>(a) < static_cast<UInt>(b));
91 }else{
92 using UInt = std::make_unsigned<B>::type;
93 return (b < 0) ? false : (static_cast<UInt>(a) < static_cast<UInt>(b));
94 }
95 }else{
96 return a < b;
97 }
98 }
99
100 template<std::integral A, std::integral B>
101 constexpr bool greater_equal(A a, B b){
102 if constexpr (std::is_signed_v<A> && std::is_unsigned_v<B>){
103 if(sizeof(A) > sizeof(B)){
104 using UInt = std::make_unsigned<A>::type;
105 return (a < 0) ? false : (static_cast<UInt>(a) >= static_cast<UInt>(b));
106 }else{
107 using UInt = std::make_unsigned<B>::type;
108 return (a < 0) ? false : (static_cast<UInt>(a) >= static_cast<UInt>(b));
109 }
110 }else if constexpr (std::is_unsigned_v<A> && std::is_signed_v<B>){
111 if(sizeof(A) > sizeof(B)){
112 using UInt = std::make_unsigned<A>::type;
113 return (b < 0) ? true : (static_cast<UInt>(a) >= static_cast<UInt>(b));
114 }else{
115 using UInt = std::make_unsigned<B>::type;
116 return (b < 0) ? true : (static_cast<UInt>(a) >= static_cast<UInt>(b));
117 }
118 }else{
119 return a >= b;
120 }
121 }
122
123 template<std::integral A, std::integral B>
124 constexpr bool greater(A a, B b){
125 if constexpr (std::is_signed_v<A> && std::is_unsigned_v<B>){
126 if(sizeof(A) > sizeof(B)){
127 using UInt = std::make_unsigned<A>::type;
128 return (a < 0) ? false : (static_cast<UInt>(a) > static_cast<UInt>(b));
129 }else{
130 using UInt = std::make_unsigned<B>::type;
131 return (a < 0) ? false : (static_cast<UInt>(a) > static_cast<UInt>(b));
132 }
133 }else if constexpr (std::is_unsigned_v<A> && std::is_signed_v<B>){
134 if(sizeof(A) > sizeof(B)){
135 using UInt = std::make_unsigned<A>::type;
136 return (b < 0) ? true : (static_cast<UInt>(a) > static_cast<UInt>(b));
137 }else{
138 using UInt = std::make_unsigned<B>::type;
139 return (b < 0) ? true : (static_cast<UInt>(a) > static_cast<UInt>(b));
140 }
141 }else{
142 return a > b;
143 }
144 }
145
146} // namespace fiber
Definition Duration.hpp:17
constexpr bool equal(A a, B b)
Definition functional.hpp:9
constexpr bool greater_equal(A a, B b)
Definition functional.hpp:101
constexpr bool not_equal(A a, B b)
Definition functional.hpp:32
constexpr bool less_equal(A a, B b)
Definition functional.hpp:55
constexpr bool greater(A a, B b)
Definition functional.hpp:124
constexpr bool less(A a, B b)
Definition functional.hpp:78