acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_template_after_initial_concepts.h
1// Created by camilo on 2022-11-11 21:16 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5#include "acme/prototype/prototype/hash32.h"
6
7
8namespace comparison
9{
10
11constexpr ::i32 get_bool_int( bool b){return b? 1:0;}
12
13 template < typename TYPE >
15 {
16 public:
17
18
19 using EQUALITY = for_type < TYPE >;
20 using ORDERING = for_type < TYPE >;
21
22
23 constexpr bool equals(const TYPE & a, const TYPE & b) const { return a == b; }
24 constexpr auto order(const TYPE & a, const TYPE & b) const { return a <=> b; }
25
26
27 };
28
29template < >
30class comparison < bool >
31{
32public:
33
34
35 using EQUALITY = for_type < bool >;
36 using ORDERING = for_type < bool >;
37
38
39 constexpr bool equals(bool a, bool b) const { return get_bool_int(a) == get_bool_int(b); }
40 constexpr auto order(bool a, bool b) const { return get_bool_int(a) <=> get_bool_int(b); }
41
42
43};
44
45
46 template < prototype_fundamental TYPE >
47 class comparison < TYPE >
48 {
49 public:
50
51
52 using EQUALITY = for_type < TYPE >;
53 using ORDERING = for_type < TYPE >;
54
55
56 constexpr bool equals(TYPE a, TYPE b) const { return a == b; }
57 constexpr auto order(TYPE a, TYPE b) const { return a <=> b; }
58
59
60 };
61
62
63 //template < prototype_character CHARACTER >
64 //class comparison :
65 // public comparison < CHARACTER >
66 //{
67 //public:
68 //
69 //
70 // //using EQUALITY_TRAITS = EQUALITY_TRAITS_TAG;
71 // //using COMPARISON_TRAITS = COMPARISON_TRAITS_TAG;
72 //
73 //
74 // //constexpr bool equals(CHARACTER a, CHARACTER b) const { return a == b; }
75 // //constexpr ::std::strong_ordering compare(CHARACTER a, CHARACTER b) const { return a <=> b; }
76 //
77 //
78 //};
79
80
81
82
83} // namespace comparison
84
85
86
87// block_cast and literal_cast work together
88// block_cast converts from a potentially smaller literal type to a potentially larger block type through memory copy
89// literal_cast converts from a potentially larger block type to a potentially smaller literal type through memory copy
90// so the block type must be larger or equal in size to the literal type
91
92
93
94template < typename LITERAL >
95class literal_cast
96{
97public:
98
99
100 LITERAL m_literal;
101
102
103 template < typename BLOCK >
104 literal_cast(const BLOCK & block)
105 {
106
107 static_assert(sizeof(m_literal) <= sizeof(block));
108
109 memory_copy(&m_literal, &block, sizeof(m_literal));
110
111 }
112
113
114 operator LITERAL &() { return m_literal; }
115
116 operator const LITERAL &() const { return m_literal; }
117
118
119};
120
121
122template < typename BLOCK >
123class block_cast
124{
125public:
126
127
128 BLOCK m_block{};
129
130
131 template < typename LITERAL >
132 block_cast(const LITERAL & literal)
133 {
134
135 static_assert(sizeof(m_block) >= sizeof(literal));
136
137 memory_copy(&m_block, &literal, sizeof(literal));
138
139 }
140
141 operator BLOCK &() { return m_block; }
142
143 operator const BLOCK &() const { return m_block; }
144
145
146};
147
148
149
150template < typename T1, typename T2>
151T1 as(const T2& t2)
152{
153
154 return (T1)t2;
155
156}
157
158
159inline constexpr std::strong_ordering to_strong_ordering(std::partial_ordering po) {
160 if (po == std::partial_ordering::less) {
161 return std::strong_ordering::less;
162 }
163 else if (po == std::partial_ordering::equivalent) {
164 return std::strong_ordering::equal; // Note: equivalent maps to equal for strong_ordering
165 }
166 else if (po == std::partial_ordering::greater) {
167 return std::strong_ordering::greater;
168 }
169 // Handle the 'unordered' case if it's possible and needs specific handling,
170 // otherwise, this indicates an invalid state for strong_ordering.
171 // For example, you might throw an exception or return a default strong_ordering value
172 // if 'unordered' is not expected.
173 // throw std::runtime_error("Cannot convert unordered partial_ordering to strong_ordering");
174 return std::strong_ordering::equal; // Or some other appropriate default/error handling
175}
176
177
178
179inline constexpr std::partial_ordering to_partial_ordering(std::strong_ordering strongordering) {
180 if (strongordering == std::strong_ordering::less) {
181 return std::partial_ordering::less;
182 }
183 else if (strongordering == std::strong_ordering::equal) {
184 return std::partial_ordering::equivalent; // Note: equivalent maps to equal for strong_ordering
185 }
186 else if (strongordering == std::strong_ordering::greater) {
187 return std::partial_ordering::greater;
188 }
189 // Handle the 'unordered' case if it's possible and needs specific handling,
190 // otherwise, this indicates an invalid state for strong_ordering.
191 // For example, you might throw an exception or return a default strong_ordering value
192 // if 'unordered' is not expected.
193 // throw std::runtime_error("Cannot convert unordered partial_ordering to strong_ordering");
194 return std::partial_ordering::equivalent; // Or some other appropriate default/error handling
195}
196
197
198
199template < >
200inline constexpr std::strong_ordering as <::std::strong_ordering, ::std::partial_ordering >(
201 const std::partial_ordering& partialordering)
202{
203
204 return to_strong_ordering(partialordering);
205
206}
207
208
209
210template < >
211inline constexpr std::partial_ordering as <::std::partial_ordering, ::std::strong_ordering >(
212 const std::strong_ordering& strongordering)
213{
214
215 return to_partial_ordering(strongordering);
216
217}
218
219
220template<prototype_floating FLOATING_TYPE, ::i32 t_iDimension, enum_matrix_major t_emajor = e_matrix_major_column>
221struct matrix_type;
222
223
224
Definition _template_after_initial_concepts.h:15
Definition block.h:46
Matrix class.
Definition matrix.h:73