tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
helper_traits.h
Go to the documentation of this file.
1#ifndef HELPERTRAITS_H
2#define HELPERTRAITS_H
3
19template <my_size_t First, my_size_t... Rest>
20consteval bool all_equal()
21{
22 return ((Rest == First) && ...);
23}
24
32template <my_size_t N>
33consteval bool dims_match(const my_size_t lhs[N], const my_size_t rhs[N])
34{
35 for (my_size_t i = 0; i < N; ++i)
36 {
37 if (lhs[i] != rhs[i])
38 return false;
39 }
40 return true;
41}
42
48template <my_size_t... Vals>
50{
51 static_assert(sizeof...(Vals) > 0, "max_value requires at least one value");
52 my_size_t arr[] = {Vals...};
53 my_size_t result = arr[0];
54 for (my_size_t i = 1; i < sizeof...(Vals); ++i)
55 {
56 if (arr[i] > result)
57 result = arr[i];
58 }
59 return result;
60}
61
67template <my_size_t... Vals>
69{
70 static_assert(sizeof...(Vals) > 0, "min_value requires at least one value");
71 my_size_t arr[] = {Vals...};
72 my_size_t result = arr[0];
73 for (my_size_t i = 1; i < sizeof...(Vals); ++i)
74 {
75 if (arr[i] < result)
76 result = arr[i];
77 }
78 return result;
79}
80
88template <my_size_t... Dims>
89struct Pack
90{
91};
92
99template <my_size_t... A, my_size_t... B>
101{
102 if constexpr (sizeof...(A) != sizeof...(B))
103 {
104 return false;
105 }
106 else
107 {
108 return ((A == B) && ...);
109 }
110}
111
118template <my_size_t... A, my_size_t... B>
120{
121 if constexpr (sizeof...(A) != sizeof...(B))
122 return false;
123 else
124 return (max_value<A...>() == max_value<B...>()) && (min_value<A...>() == min_value<B...>());
125}
126
132template <my_size_t... Vals>
133consteval bool all_unique()
134{
135 static_assert(sizeof...(Vals) > 0, "all_unique requires at least one value");
136 my_size_t arr[] = {Vals...};
137 for (my_size_t i = 0; i < sizeof...(Vals); ++i)
138 {
139 for (my_size_t j = i + 1; j < sizeof...(Vals); ++j)
140 {
141 if (arr[i] == arr[j])
142 return false;
143 }
144 }
145 return true;
146}
147
153template <my_size_t... Vals>
154consteval bool is_sequential()
155{
156 static_assert(sizeof...(Vals) > 0, "is_sequential requires at least one value");
157 my_size_t arr[] = {Vals...};
158 for (my_size_t i = 0; i < sizeof...(Vals); ++i)
159 {
160 if (arr[i] != i)
161 return false;
162 }
163 return true;
164}
165
170template <my_size_t... Is>
172{
173};
174
182template <my_size_t N, my_size_t... Is>
183struct make_index_seq : make_index_seq<N - 1, N - 1, Is...>
184{
185};
186
188template <my_size_t... Is>
189struct make_index_seq<0, Is...>
190{
191 using type = index_seq<Is...>;
192};
194
195#endif // HELPERTRAITS_H
#define my_size_t
Size/index type used throughout the library.
Definition config.h:126
consteval bool packs_are_identical(Pack< A... >, Pack< B... >)
Element-wise equality comparison of two packs.
Definition helper_traits.h:100
consteval bool dims_match(const my_size_t lhs[N], const my_size_t rhs[N])
Element-wise equality check of two compile-time arrays.
Definition helper_traits.h:33
consteval my_size_t max_value()
Compile-time maximum of a non-type parameter pack.
Definition helper_traits.h:49
consteval bool all_equal()
Check if all values in a parameter pack are equal.
Definition helper_traits.h:20
consteval bool same_min_max(Pack< A... >, Pack< B... >)
Check if two packs have the same min and max values, regardless of order.
Definition helper_traits.h:119
consteval bool is_sequential()
Check if a pack forms the identity permutation {0, 1, …, N−1}.
Definition helper_traits.h:154
consteval my_size_t min_value()
Compile-time minimum of a non-type parameter pack.
Definition helper_traits.h:68
consteval bool all_unique()
Check if all values in a pack are unique.
Definition helper_traits.h:133
Wrapper struct for carrying a non-type parameter pack.
Definition helper_traits.h:90
Compile-time index sequence (lightweight std::index_sequence alternative).
Definition helper_traits.h:172
Recursive generator for index_seq<0, 1, …, N−1>.
Definition helper_traits.h:184