Maipa's Standard Library Extension 1.5.6
mstd
Loading...
Searching...
No Matches
management_types.hpp
1/*
2 * mstd - Maipa's Standard Library
3 *
4 * Licensed under the BSD 3-Clause License with Attribution Requirement.
5 * See the LICENSE file for details: https://github.com/MAIPA01/mstd/blob/main/LICENSE
6 *
7 * Copyright (c) 2025, Patryk Antosik (MAIPA01)
8 */
9
10#pragma once
11#ifndef _MSTD_MANAGEMENT_TYPES_HPP_
12 #define _MSTD_MANAGEMENT_TYPES_HPP_
13
14 #include <mstd/config.hpp>
15
17_MSTD_WARNING("this is only available for c++17 and greater!");
18 #else
19
20 #include <mstd/management_utils.hpp>
21
22namespace mstd {
23 #pragma region ARE_ALL
24 template<template<class> class Test, class... Ts>
25 static _MSTD_CONSTEXPR17 const bool are_all_v = (Test<Ts>::value && ...);
26 #pragma endregion
27
28 #pragma region INDEX_SEQUENCE_FROM_TO
29
30 template<size_t Start, size_t... Indices>
31 _MSTD_CONSTEXPR20 std::index_sequence<(Start + Indices)...> shift_index_sequence(const std::index_sequence<Indices...>&) {
32 return {};
33 }
34
35 template<size_t Start, size_t End>
36 using make_index_sequence_from_to = decltype(shift_index_sequence<Start>(std::make_index_sequence<End - Start>()));
37
38 template<size_t Start, size_t Size>
39 using make_index_sequence_from = decltype(shift_index_sequence<Start>(std::make_index_sequence<Size>()));
40
41 template<size_t Start, class... Ts>
42 using make_index_sequence_for_from = decltype(shift_index_sequence<Start>(std::index_sequence_for<Ts...>()));
43 #pragma endregion
44
45 #pragma region UNIVERSAL_CHECKS
46
47 template<template<class> class Check, class... Ts>
48 struct all_check : std::bool_constant<(Check<Ts>::value && ...)> {};
49 template<template<class> class Check, class... Ts>
50 constexpr bool all_check_v = all_check<Check, Ts...>::value;
51
52 template<template<class> class Check, class... Ts>
53 struct any_check : std::bool_constant<(Check<Ts>::value || ...)> {};
54 template<template<class> class Check, class... Ts>
55 constexpr bool any_check_v = any_check<Check, Ts...>::value;
56 #pragma endregion
57
58 #pragma region NUMERIC_TYPES
59
60 template<class T>
62
63 template<class T>
64 struct is_signed_integral : std::bool_constant<is_signed_integral_v<T> > {};
65 template<class T>
67
68 template<class T>
69 struct is_unsigned_integral : std::bool_constant<is_unsigned_integral_v<T> > {};
70
71 template<class... Ns>
72 struct are_arithmetic : all_check<std::is_arithmetic, Ns...> {};
73 template<class... Ns>
74 constexpr bool are_arithmetic_v = are_arithmetic<Ns...>::value;
75
76 template<class... Ns>
77 struct are_signed : all_check<std::is_signed, Ns...> {};
78 template<class... Ns>
79 constexpr bool are_signed_v = are_signed<Ns...>::value;
80
81 template<class... Ns>
82 struct are_unsigned : all_check<std::is_unsigned, Ns...> {};
83 template<class... Ns>
84 constexpr bool are_unsigned_v = are_unsigned<Ns...>::value;
85
86 template<class... Ns>
87 struct are_floating_points : all_check<std::is_floating_point, Ns...> {};
88 template<class... Ns>
90
91 template<class... Ns>
92 struct are_integrals : all_check<std::is_integral, Ns...> {};
93 template<class... Ns>
94 constexpr bool are_integrals_v = are_integrals<Ns...>::value;
95
96 template<class... Ns>
98 template<class... Ns>
100
101 template<class... Ns>
103 template<class... Ns>
105
111 template<class T> concept integral = std::is_integral_v<T>;
114 #endif
115 #pragma endregion
116
117 #pragma region COMPARE_ARITHMETIC
118
119 namespace utils {
120 template<auto A>
121 struct abs_impl : std::conditional_t<std::is_unsigned_v<decltype(A)>, std::integral_constant<decltype(A), A>,
122 std::integral_constant<decltype(A), (A > 0 ? A : -A)> > {};
123 } // namespace utils
124
125 template<auto A>
126 static _MSTD_CONSTEXPR17 const auto abs_v = utils::abs_impl<A>::value;
127
129 template<auto A, auto B, auto Eps, arithmetic AT = decltype(A), arithmetic BT = decltype(B),
130 floating_point EpsT = decltype(Eps)>
132 (std::is_floating_point_v<AT> || std::is_floating_point_v<BT>) ? (abs_v<A - B> < Eps) : (A == B);
133 #else
134 template<auto A, auto B, class AT = decltype(A), class BT = decltype(B),
135 std::enable_if_t<(std::is_arithmetic_v<AT> && std::is_arithmetic_v<BT>), bool> = true>
136 _MSTD_CONSTEXPR17 const bool is_eq_arithmetic_v = (A == B);
137 #endif
138
140 template<auto A, auto B, auto Eps, arithmetic AT = decltype(A), arithmetic BT = decltype(B),
141 floating_point EpsT = decltype(Eps)>
143 #else
144 template<auto A, auto B, class AT = decltype(A), class BT = decltype(B),
145 std::enable_if_t<(std::is_arithmetic_v<AT> && std::is_arithmetic_v<BT>), bool> = true>
146 _MSTD_CONSTEXPR17 const bool is_neq_arithmetic_v = !is_eq_arithmetic_v<A, B>;
147 #endif
148
149 #pragma endregion
150
151 #pragma region LOGIC_EXPRESIONS
152
153 template<auto A, auto B>
154 struct is_eq : std::bool_constant<(A == B)> {};
155
156 template<auto A, auto B>
158
159 template<auto A, auto B>
160 struct is_neq : std::bool_constant<(A != B)> {};
161
162 template<auto A, auto B>
164
165 template<auto A, auto B>
166 struct is_gt : std::bool_constant<(A > B)> {};
167
168 template<auto A, auto B>
170
171 template<auto A, auto B>
172 struct is_gteq : std::bool_constant<(A >= B)> {};
173
174 template<auto A, auto B>
176
177 template<auto A, auto B>
178 struct is_lt : std::bool_constant<(A < B)> {};
179
180 template<auto A, auto B>
182
183 template<auto A, auto B>
184 struct is_lteq : std::bool_constant<(A <= B)> {};
185
186 template<auto A, auto B>
188 #pragma endregion
189
190 #pragma region IS_IN
191 template<template<class, class> class Cmp, class T, class U, class... Us>
192 _MSTD_CONSTEXPR17 const bool is_type_in_v = (Cmp<T, U>::value || (sizeof...(Us) > 0 ? (Cmp<T, Us>::value || ...) : false));
193
194 template<template<auto, auto> class Cmp, auto A, auto B, auto... Cs>
195 _MSTD_CONSTEXPR17 const bool is_value_in_v = (Cmp<A, B>::value || (sizeof...(Cs) > 0 ? (Cmp<A, Cs>::value || ...) : false));
196
197 template<class T, class U, class... Us>
199 template<auto A, auto B, auto... Cs>
201 #pragma endregion
202
203 #pragma region IN_RANGE
204 template<auto A, auto Min, auto Max>
206 #pragma endregion
207
208 #pragma region IS_BASED_ON
209 template<class T, template<class...> class U>
211 template<template<class...> class U, class... Vs>
212 _MSTD_CONSTEXPR17 const bool is_based_on_v<U<Vs...>, U> = true;
213 #pragma endregion
214
215 #pragma region UNIQUE_TYPES
216
217 template<class... Ts>
219 using as_tuple = std::tuple<Ts...>;
220 static _MSTD_CONSTEXPR17 const size_t types_num = sizeof...(Ts);
221 };
222
223 namespace utils {
224 template<class T, class U>
225 struct unique_impl {};
226
227 template<class T, class... Us>
229
230 template<class... Ts, class T, class... Us>
231 struct unique_impl<types_holder<Ts...>, types_holder<T, Us...> >
232 : std::conditional_t<is_same_type_in_v<T, Ts...>, unique_impl<types_holder<Ts...>, types_holder<Us...> >,
233 unique_impl<types_holder<Ts..., T>, types_holder<Us...> > > {};
234
235 template<class... Ts>
237 using type = types_holder<Ts...>;
238 };
239 } // namespace utils
240
241 template<class... Ts>
243 #pragma endregion
244
245 #pragma region IF
246
247 namespace utils {
248 template<bool Condition, auto TrueValue, auto FalseValue>
249 struct if_impl {
250 static _MSTD_CONSTEXPR17 const auto value = FalseValue;
251 };
252
253 template<auto TrueValue, auto FalseValue>
254 struct if_impl<true, TrueValue, FalseValue> {
255 static _MSTD_CONSTEXPR17 const auto value = TrueValue;
256 };
257 } // namespace utils
258
259 template<bool Condition, auto TrueValue, auto FalseValue>
261 #pragma endregion
262
263 #pragma region ID_MANAGER
265 template<unsigned_integral IdT>
266 #else
267 template<class IdT, std::enable_if_t<mstd::is_unsigned_integral_v<IdT>, bool> = true>
268 #endif
269 class base_id_manager;
270
271 using id_manager = base_id_manager<size_t>;
272 using id8_manager = base_id_manager<uint8_t>;
273 using id16_manager = base_id_manager<uint16_t>;
274 using id32_manager = base_id_manager<uint32_t>;
275 using id64_manager = base_id_manager<uint64_t>;
276 #pragma endregion
277
278 #pragma region FLAGS
280 template<class BitsEnum>
281 #else
282 template<class BitsEnum, std::enable_if_t<std::is_enum_v<BitsEnum>, bool> = true>
283 #endif
284 _MSTD_REQUIRES(std::is_enum_v<BitsEnum>)
285 class flags;
286 #pragma endregion
287} // namespace mstd
288
289 #endif
290#endif
Definition flags.hpp:29
#define _MSTD_HAS_CXX17
Definition config.hpp:45
#define _MSTD_CONSTEXPR17
Definition config.hpp:76
#define _MSTD_HAS_CXX20
Definition config.hpp:52
#define _MSTD_REQUIRES(condition)
Definition config.hpp:86
#define _MSTD_TYPENAME17
Definition config.hpp:82
#define _MSTD_CONSTEXPR20
Definition config.hpp:84
Definition function_traits.hpp:23
Definition arithmetic_types.hpp:23
constexpr bool is_signed_integral_v
Definition management_types.hpp:61
static _MSTD_CONSTEXPR17 const bool are_all_v
Definition management_types.hpp:25
constexpr bool are_arithmetic_v
Definition management_types.hpp:74
constexpr bool any_check_v
Definition management_types.hpp:55
_MSTD_CONSTEXPR17 const bool is_neq_v
Definition management_types.hpp:163
_MSTD_CONSTEXPR17 const bool is_gt_v
Definition management_types.hpp:169
_MSTD_CONSTEXPR17 const bool is_lteq_v
Definition management_types.hpp:187
constexpr bool are_unsigned_integrals_v
Definition management_types.hpp:104
constexpr bool is_unsigned_integral_v
Definition management_types.hpp:66
_MSTD_CONSTEXPR17 const bool is_eq_value_in_v
Definition management_types.hpp:200
_MSTD_CONSTEXPR17 const bool is_based_on_v
Definition management_types.hpp:210
_MSTD_CONSTEXPR17 const bool is_type_in_v
Definition management_types.hpp:192
constexpr bool are_unsigned_v
Definition management_types.hpp:84
_MSTD_CONSTEXPR17 const bool is_same_type_in_v
Definition management_types.hpp:198
decltype(shift_index_sequence< Start >(std::make_index_sequence< Size >())) make_index_sequence_from
Definition management_types.hpp:39
constexpr bool are_signed_integrals_v
Definition management_types.hpp:99
_MSTD_CONSTEXPR17 const bool is_eq_v
Definition management_types.hpp:157
_MSTD_CONSTEXPR20 std::index_sequence<(Start+Indices)... > shift_index_sequence(const std::index_sequence< Indices... > &)
Definition management_types.hpp:31
_MSTD_CONSTEXPR17 const bool is_value_in_v
Definition management_types.hpp:195
decltype(shift_index_sequence< Start >(std::index_sequence_for< Ts... >())) make_index_sequence_for_from
Definition management_types.hpp:42
_MSTD_CONSTEXPR17 const bool is_gteq_v
Definition management_types.hpp:175
_MSTD_CONSTEXPR17 const bool is_in_range_v
Definition management_types.hpp:205
constexpr bool are_integrals_v
Definition management_types.hpp:94
constexpr bool are_signed_v
Definition management_types.hpp:79
static _MSTD_CONSTEXPR17 const auto if_v
Definition management_types.hpp:260
constexpr bool are_floating_points_v
Definition management_types.hpp:89
_MSTD_TYPENAME17 utils::unique_impl< types_holder<>, types_holder< Ts... > >::type unique_types
Definition management_types.hpp:242
base_id_manager< uint64_t > id64_manager
Definition management_types.hpp:275
constexpr bool all_check_v
Definition management_types.hpp:50
base_id_manager< size_t > id_manager
Definition management_types.hpp:271
_MSTD_CONSTEXPR17 const bool is_based_on_v< U< Vs... >, U >
Definition management_types.hpp:212
base_id_manager< uint16_t > id16_manager
Definition management_types.hpp:273
static _MSTD_CONSTEXPR17 const auto abs_v
Definition management_types.hpp:126
decltype(shift_index_sequence< Start >(std::make_index_sequence< End - Start >())) make_index_sequence_from_to
Definition management_types.hpp:36
base_id_manager< uint8_t > id8_manager
Definition management_types.hpp:272
_MSTD_CONSTEXPR17 const bool is_lt_v
Definition management_types.hpp:181
base_id_manager< uint32_t > id32_manager
Definition management_types.hpp:274
Definition management_types.hpp:48
Definition management_types.hpp:53
Definition management_types.hpp:72
Definition management_types.hpp:87
Definition management_types.hpp:92
Definition management_types.hpp:97
Definition management_types.hpp:77
Definition management_types.hpp:102
Definition management_types.hpp:82
Definition management_types.hpp:154
Definition management_types.hpp:166
Definition management_types.hpp:172
Definition management_types.hpp:178
Definition management_types.hpp:184
Definition management_types.hpp:160
Definition management_types.hpp:64
Definition management_types.hpp:69
Definition management_types.hpp:218
static _MSTD_CONSTEXPR17 const size_t types_num
Definition management_types.hpp:220
std::tuple< Ts... > as_tuple
Definition management_types.hpp:219
Definition management_types.hpp:122
Definition management_types.hpp:254
static _MSTD_CONSTEXPR17 const auto value
Definition management_types.hpp:255
Definition management_types.hpp:249
static _MSTD_CONSTEXPR17 const auto value
Definition management_types.hpp:250
types_holder< Ts... > type
Definition management_types.hpp:237
Definition management_types.hpp:225