mimic++ v4
Loading...
Searching...
No Matches
TypeTraits.hpp
Go to the documentation of this file.
1// // Copyright Dominic (DNKpp) Koepke 2024 - 2024.
2// // Distributed under the Boost Software License, Version 1.0.
3// // (See accompanying file LICENSE_1_0.txt or copy at
4// // https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_TYPE_TRAITS_HPP
7#define MIMICPP_TYPE_TRAITS_HPP
8
9#pragma once
10
11#include "Fwd.hpp"
12
13#include <concepts>
14#include <cstddef>
15#include <cstdint>
16#include <tuple>
17#include <type_traits>
18
19namespace mimicpp
20{
34 template <typename Return, typename... Params>
35 struct signature_add_noexcept<Return(Params...)>
36 {
37 using type = Return(Params...) noexcept;
38 };
39
40 template <typename Return, typename... Params>
41 struct signature_add_noexcept<Return(Params..., ...)>
42 {
43 using type = Return(Params..., ...) noexcept;
44 };
45
46 template <typename Return, typename... Params>
47 struct signature_add_noexcept<Return(Params...) noexcept>
48 {
49 using type = Return(Params...) noexcept;
50 };
51
52 template <typename Return, typename... Params>
53 struct signature_add_noexcept<Return(Params..., ...) noexcept>
54 {
55 using type = Return(Params..., ...) noexcept;
56 };
57
58 template <typename Return, typename... Params>
59 struct signature_add_noexcept<Return(Params...) const>
60 {
61 using type = Return(Params...) const noexcept;
62 };
63
64 template <typename Return, typename... Params>
65 struct signature_add_noexcept<Return(Params..., ...) const>
66 {
67 using type = Return(Params..., ...) const noexcept;
68 };
69
70 template <typename Return, typename... Params>
71 struct signature_add_noexcept<Return(Params...) const noexcept>
72 {
73 using type = Return(Params...) const noexcept;
74 };
75
76 template <typename Return, typename... Params>
77 struct signature_add_noexcept<Return(Params..., ...) const noexcept>
78 {
79 using type = Return(Params..., ...) const noexcept;
80 };
81
82 template <typename Return, typename... Params>
83 struct signature_add_noexcept<Return(Params...) &>
84 {
85 using type = Return(Params...) & noexcept;
86 };
87
88 template <typename Return, typename... Params>
89 struct signature_add_noexcept<Return(Params..., ...) &>
90 {
91 using type = Return(Params..., ...) & noexcept;
92 };
93
94 template <typename Return, typename... Params>
95 struct signature_add_noexcept<Return(Params...) & noexcept>
96 {
97 using type = Return(Params...) & noexcept;
98 };
99
100 template <typename Return, typename... Params>
101 struct signature_add_noexcept<Return(Params..., ...) & noexcept>
102 {
103 using type = Return(Params..., ...) & noexcept;
104 };
105
106 template <typename Return, typename... Params>
107 struct signature_add_noexcept<Return(Params...) const &>
108 {
109 using type = Return(Params...) const & noexcept;
110 };
111
112 template <typename Return, typename... Params>
113 struct signature_add_noexcept<Return(Params..., ...) const &>
114 {
115 using type = Return(Params..., ...) const & noexcept;
116 };
117
118 template <typename Return, typename... Params>
119 struct signature_add_noexcept<Return(Params...) const & noexcept>
120 {
121 using type = Return(Params...) const & noexcept;
122 };
123
124 template <typename Return, typename... Params>
125 struct signature_add_noexcept<Return(Params..., ...) const & noexcept>
126 {
127 using type = Return(Params..., ...) const & noexcept;
128 };
129
130 template <typename Return, typename... Params>
131 struct signature_add_noexcept<Return(Params...) &&>
132 {
133 using type = Return(Params...) && noexcept;
134 };
135
136 template <typename Return, typename... Params>
137 struct signature_add_noexcept<Return(Params..., ...) &&>
138 {
139 using type = Return(Params..., ...) && noexcept;
140 };
141
142 template <typename Return, typename... Params>
143 struct signature_add_noexcept<Return(Params...) && noexcept>
144 {
145 using type = Return(Params...) && noexcept;
146 };
147
148 template <typename Return, typename... Params>
149 struct signature_add_noexcept<Return(Params..., ...) && noexcept>
150 {
151 using type = Return(Params..., ...) && noexcept;
152 };
153
154 template <typename Return, typename... Params>
155 struct signature_add_noexcept<Return(Params...) const &&>
156 {
157 using type = Return(Params...) const && noexcept;
158 };
159
160 template <typename Return, typename... Params>
161 struct signature_add_noexcept<Return(Params..., ...) const &&>
162 {
163 using type = Return(Params..., ...) const && noexcept;
164 };
165
166 template <typename Return, typename... Params>
167 struct signature_add_noexcept<Return(Params...) const && noexcept>
168 {
169 using type = Return(Params...) const && noexcept;
170 };
171
172 template <typename Return, typename... Params>
173 struct signature_add_noexcept<Return(Params..., ...) const && noexcept>
174 {
175 using type = Return(Params..., ...) const && noexcept;
176 };
177
190 template <typename Return, typename... Params>
191 struct signature_remove_noexcept<Return(Params...)>
192 {
193 using type = Return(Params...);
194 };
195
196 template <typename Return, typename... Params>
197 struct signature_remove_noexcept<Return(Params..., ...)>
198 {
199 using type = Return(Params..., ...);
200 };
201
202 template <typename Return, typename... Params>
203 struct signature_remove_noexcept<Return(Params...) noexcept>
204 {
205 using type = Return(Params...);
206 };
207
208 template <typename Return, typename... Params>
209 struct signature_remove_noexcept<Return(Params..., ...) noexcept>
210 {
211 using type = Return(Params..., ...);
212 };
213
214 template <typename Return, typename... Params>
215 struct signature_remove_noexcept<Return(Params...) const>
216 {
217 using type = Return(Params...) const;
218 };
219
220 template <typename Return, typename... Params>
221 struct signature_remove_noexcept<Return(Params..., ...) const>
222 {
223 using type = Return(Params..., ...) const;
224 };
225
226 template <typename Return, typename... Params>
227 struct signature_remove_noexcept<Return(Params...) const noexcept>
228 {
229 using type = Return(Params...) const;
230 };
231
232 template <typename Return, typename... Params>
233 struct signature_remove_noexcept<Return(Params..., ...) const noexcept>
234 {
235 using type = Return(Params..., ...) const;
236 };
237
238 template <typename Return, typename... Params>
239 struct signature_remove_noexcept<Return(Params...) &>
240 {
241 using type = Return(Params...) &;
242 };
243
244 template <typename Return, typename... Params>
245 struct signature_remove_noexcept<Return(Params..., ...) &>
246 {
247 using type = Return(Params..., ...) &;
248 };
249
250 template <typename Return, typename... Params>
251 struct signature_remove_noexcept<Return(Params...) & noexcept>
252 {
253 using type = Return(Params...) &;
254 };
255
256 template <typename Return, typename... Params>
257 struct signature_remove_noexcept<Return(Params..., ...) & noexcept>
258 {
259 using type = Return(Params..., ...) &;
260 };
261
262 template <typename Return, typename... Params>
263 struct signature_remove_noexcept<Return(Params...) const &>
264 {
265 using type = Return(Params...) const &;
266 };
267
268 template <typename Return, typename... Params>
269 struct signature_remove_noexcept<Return(Params..., ...) const &>
270 {
271 using type = Return(Params..., ...) const &;
272 };
273
274 template <typename Return, typename... Params>
275 struct signature_remove_noexcept<Return(Params...) const & noexcept>
276 {
277 using type = Return(Params...) const &;
278 };
279
280 template <typename Return, typename... Params>
281 struct signature_remove_noexcept<Return(Params..., ...) const & noexcept>
282 {
283 using type = Return(Params..., ...) const &;
284 };
285
286 template <typename Return, typename... Params>
287 struct signature_remove_noexcept<Return(Params...) &&>
288 {
289 using type = Return(Params...) &&;
290 };
291
292 template <typename Return, typename... Params>
293 struct signature_remove_noexcept<Return(Params..., ...) &&>
294 {
295 using type = Return(Params..., ...) &&;
296 };
297
298 template <typename Return, typename... Params>
299 struct signature_remove_noexcept<Return(Params...) && noexcept>
300 {
301 using type = Return(Params...) &&;
302 };
303
304 template <typename Return, typename... Params>
305 struct signature_remove_noexcept<Return(Params..., ...) && noexcept>
306 {
307 using type = Return(Params..., ...) &&;
308 };
309
310 template <typename Return, typename... Params>
311 struct signature_remove_noexcept<Return(Params...) const &&>
312 {
313 using type = Return(Params...) const &&;
314 };
315
316 template <typename Return, typename... Params>
317 struct signature_remove_noexcept<Return(Params..., ...) const &&>
318 {
319 using type = Return(Params..., ...) const &&;
320 };
321
322 template <typename Return, typename... Params>
323 struct signature_remove_noexcept<Return(Params...) const && noexcept>
324 {
325 using type = Return(Params...) const &&;
326 };
327
328 template <typename Return, typename... Params>
329 struct signature_remove_noexcept<Return(Params..., ...) const && noexcept>
330 {
331 using type = Return(Params..., ...) const &&;
332 };
333
346 template <typename Return, typename... Params>
347 struct signature_decay<Return(Params...)>
348 {
349 using type = Return(Params...);
350 };
351
352 template <typename Return, typename... Params>
353 struct signature_decay<Return(Params...) const>
354 {
355 using type = Return(Params...);
356 };
357
358 template <typename Return, typename... Params>
359 struct signature_decay<Return(Params...) &>
360 {
361 using type = Return(Params...);
362 };
363
364 template <typename Return, typename... Params>
365 struct signature_decay<Return(Params...) const &>
366 {
367 using type = Return(Params...);
368 };
369
370 template <typename Return, typename... Params>
371 struct signature_decay<Return(Params...) &&>
372 {
373 using type = Return(Params...);
374 };
375
376 template <typename Return, typename... Params>
377 struct signature_decay<Return(Params...) const &&>
378 {
379 using type = Return(Params...);
380 };
381
382 template <typename Return, typename... Params>
383 struct signature_decay<Return(Params...) noexcept>
384 {
385 using type = Return(Params...);
386 };
387
388 template <typename Return, typename... Params>
389 struct signature_decay<Return(Params...) const noexcept>
390 {
391 using type = Return(Params...);
392 };
393
394 template <typename Return, typename... Params>
395 struct signature_decay<Return(Params...) & noexcept>
396 {
397 using type = Return(Params...);
398 };
399
400 template <typename Return, typename... Params>
401 struct signature_decay<Return(Params...) const & noexcept>
402 {
403 using type = Return(Params...);
404 };
405
406 template <typename Return, typename... Params>
407 struct signature_decay<Return(Params...) && noexcept>
408 {
409 using type = Return(Params...);
410 };
411
412 template <typename Return, typename... Params>
413 struct signature_decay<Return(Params...) const && noexcept>
414 {
415 using type = Return(Params...);
416 };
417
418 template <typename Return, typename... Params>
419 struct signature_decay<Return(Params..., ...)>
420 {
421 using type = Return(Params..., ...);
422 };
423
424 template <typename Return, typename... Params>
425 struct signature_decay<Return(Params..., ...) const>
426 {
427 using type = Return(Params..., ...);
428 };
429
430 template <typename Return, typename... Params>
431 struct signature_decay<Return(Params..., ...) &>
432 {
433 using type = Return(Params..., ...);
434 };
435
436 template <typename Return, typename... Params>
437 struct signature_decay<Return(Params..., ...) const &>
438 {
439 using type = Return(Params..., ...);
440 };
441
442 template <typename Return, typename... Params>
443 struct signature_decay<Return(Params..., ...) &&>
444 {
445 using type = Return(Params..., ...);
446 };
447
448 template <typename Return, typename... Params>
449 struct signature_decay<Return(Params..., ...) const &&>
450 {
451 using type = Return(Params..., ...);
452 };
453
454 template <typename Return, typename... Params>
455 struct signature_decay<Return(Params..., ...) noexcept>
456 {
457 using type = Return(Params..., ...);
458 };
459
460 template <typename Return, typename... Params>
461 struct signature_decay<Return(Params..., ...) const noexcept>
462 {
463 using type = Return(Params..., ...);
464 };
465
466 template <typename Return, typename... Params>
467 struct signature_decay<Return(Params..., ...) & noexcept>
468 {
469 using type = Return(Params..., ...);
470 };
471
472 template <typename Return, typename... Params>
473 struct signature_decay<Return(Params..., ...) const & noexcept>
474 {
475 using type = Return(Params..., ...);
476 };
477
478 template <typename Return, typename... Params>
479 struct signature_decay<Return(Params..., ...) && noexcept>
480 {
481 using type = Return(Params..., ...);
482 };
483
484 template <typename Return, typename... Params>
485 struct signature_decay<Return(Params..., ...) const && noexcept>
486 {
487 using type = Return(Params..., ...);
488 };
489
502 template <typename Signature>
503 requires std::is_function_v<Signature>
504 struct signature_return_type<Signature>
505 : public signature_return_type<signature_decay_t<Signature>>
506 {
507 };
508
509 template <typename Return, typename... Params>
510 struct signature_return_type<Return(Params...)>
511 {
512 using type = Return;
513 };
514
515 template <typename Return, typename... Params>
516 struct signature_return_type<Return(Params..., ...)>
517 {
518 using type = Return;
519 };
520
533 template <std::size_t index, typename Signature>
534 requires std::is_function_v<Signature>
535 struct signature_param_type<index, Signature>
536 : public signature_param_type<
537 index,
538 signature_decay_t<Signature>>
539 {
540 };
541
542 template <std::size_t index, typename Return, typename... Params>
543 struct signature_param_type<index, Return(Params...)>
544 : public std::tuple_element<index, std::tuple<Params...>>
545 {
546 };
547
560 template <typename Signature>
561 requires std::is_function_v<Signature>
562 struct signature_param_list<Signature>
563 : public signature_param_list<
564 signature_decay_t<Signature>>
565 {
566 };
567
568 template <typename Return, typename... Params>
569 struct signature_param_list<Return(Params...)>
570 {
571 using type = std::tuple<Params...>;
572 };
573
578 namespace detail
579 {
580 template <typename First, typename Second, bool reversed = false>
582 : public std::conditional_t<
583 reversed,
584 std::false_type,
585 is_overloadable_with<Second, First, true>>
586 {
587 };
588
589 template <typename First, typename Second>
590 requires (
591 !std::same_as<
592 signature_param_list_t<signature_decay_t<First>>,
593 signature_param_list_t<signature_decay_t<Second>>>)
594 struct is_overloadable_with<First, Second, false>
595 : public std::true_type
596 {
597 };
598
599 template <typename Return1, typename Return2, typename... Params, bool reversed>
600 struct is_overloadable_with<Return1(Params...), Return2(Params...) const, reversed>
601 : public std::true_type
602 {
603 };
604
605 template <typename Return1, typename Return2, typename... Params, bool reversed>
606 struct is_overloadable_with<Return1(Params...) &, Return2(Params...) const &, reversed>
607 : public std::true_type
608 {
609 };
610
611 template <typename Return1, typename Return2, typename... Params, bool reversed>
612 struct is_overloadable_with<Return1(Params...) &, Return2(Params...) &&, reversed>
613 : public std::true_type
614 {
615 };
616
617 template <typename Return1, typename Return2, typename... Params, bool reversed>
618 struct is_overloadable_with<Return1(Params...) &, Return2(Params...) const &&, reversed>
619 : public std::true_type
620 {
621 };
622
623 template <typename Return1, typename Return2, typename... Params, bool reversed>
624 struct is_overloadable_with<Return1(Params...) const &, Return2(Params...) &&, reversed>
625 : public std::true_type
626 {
627 };
628
629 template <typename Return1, typename Return2, typename... Params, bool reversed>
630 struct is_overloadable_with<Return1(Params...) const &, Return2(Params...) const &&, reversed>
631 : public std::true_type
632 {
633 };
634
635 template <typename Return1, typename Return2, typename... Params, bool reversed>
636 struct is_overloadable_with<Return1(Params...) &&, Return2(Params...) const &&, reversed>
637 : public std::true_type
638 {
639 };
640 }
641
650 template <typename First, typename Second>
652 : public detail::is_overloadable_with<
653 signature_remove_noexcept_t<First>,
654 signature_remove_noexcept_t<Second>>
655 {
656 };
657
670 template <typename First>
671 struct is_overload_set<First>
672 : public std::true_type
673 {
674 };
675
676 template <typename First, typename Second, typename... Others>
677 struct is_overload_set<First, Second, Others...>
678 : public std::conjunction<
679 is_overloadable_with<First, Second>,
680 is_overload_set<First, Others...>,
681 is_overload_set<Second, Others...>>
682 {
683 };
684
701 template <>
702 struct uint_with_size<1u>
703 {
704 using type = std::uint8_t;
705 };
706
710 template <>
711 struct uint_with_size<2u>
712 {
713 using type = std::uint16_t;
714 };
715
719 template <>
720 struct uint_with_size<4u>
721 {
722 using type = std::uint32_t;
723 };
724
728 template <>
729 struct uint_with_size<8u>
730 {
731 using type = std::uint64_t;
732 };
733
737}
738
739#endif
Definition BoostTest.hpp:20
Primary template, purposely undefined.
Definition Fwd.hpp:137
Definition TypeTraits.hpp:655
Return(Params...,...) &noexcept type
Definition TypeTraits.hpp:91
Return(Params...,...) &&noexcept type
Definition TypeTraits.hpp:139
Return(Params...,...) &&noexcept type
Definition TypeTraits.hpp:151
Return(Params...,...) &noexcept type
Definition TypeTraits.hpp:103
Return(Params...,...) const noexcept type
Definition TypeTraits.hpp:67
Return(Params...,...) const &noexcept type
Definition TypeTraits.hpp:115
Return(Params...,...) const &&noexcept type
Definition TypeTraits.hpp:163
Return(Params...,...) const &&noexcept type
Definition TypeTraits.hpp:175
Return(Params...,...) const &noexcept type
Definition TypeTraits.hpp:127
Return(Params...,...) const noexcept type
Definition TypeTraits.hpp:79
Return(Params...,...) noexcept type
Definition TypeTraits.hpp:55
Return(Params...,...) noexcept type
Definition TypeTraits.hpp:43
Return(Params...) &noexcept type
Definition TypeTraits.hpp:85
Return(Params...) &&noexcept type
Definition TypeTraits.hpp:133
Return(Params...) &&noexcept type
Definition TypeTraits.hpp:145
Return(Params...) &noexcept type
Definition TypeTraits.hpp:97
Return(Params...) const noexcept type
Definition TypeTraits.hpp:61
Return(Params...) const &noexcept type
Definition TypeTraits.hpp:109
Return(Params...) const &&noexcept type
Definition TypeTraits.hpp:157
Return(Params...) const &&noexcept type
Definition TypeTraits.hpp:169
Return(Params...) const &noexcept type
Definition TypeTraits.hpp:121
Return(Params...) const noexcept type
Definition TypeTraits.hpp:73
Return(Params...) noexcept type
Definition TypeTraits.hpp:49
Return(Params...) noexcept type
Definition TypeTraits.hpp:37
Primary template, purposely undefined.
Definition Fwd.hpp:28
Return(Params...,...) type
Definition TypeTraits.hpp:433
Return(Params...,...) type
Definition TypeTraits.hpp:445
Return(Params...,...) type
Definition TypeTraits.hpp:481
Return(Params...,...) type
Definition TypeTraits.hpp:469
Return(Params...,...) type
Definition TypeTraits.hpp:427
Return(Params...,...) type
Definition TypeTraits.hpp:439
Return(Params...,...) type
Definition TypeTraits.hpp:451
Return(Params...,...) type
Definition TypeTraits.hpp:487
Return(Params...,...) type
Definition TypeTraits.hpp:475
Return(Params...,...) type
Definition TypeTraits.hpp:463
Return(Params...,...) type
Definition TypeTraits.hpp:457
Return(Params...,...) type
Definition TypeTraits.hpp:421
Return(Params...) type
Definition TypeTraits.hpp:361
Return(Params...) type
Definition TypeTraits.hpp:373
Return(Params...) type
Definition TypeTraits.hpp:409
Return(Params...) type
Definition TypeTraits.hpp:397
Return(Params...) type
Definition TypeTraits.hpp:355
Return(Params...) type
Definition TypeTraits.hpp:367
Return(Params...) type
Definition TypeTraits.hpp:379
Return(Params...) type
Definition TypeTraits.hpp:415
Return(Params...) type
Definition TypeTraits.hpp:403
Return(Params...) type
Definition TypeTraits.hpp:391
Return(Params...) type
Definition TypeTraits.hpp:385
Return(Params...) type
Definition TypeTraits.hpp:349
Primary template, purposely undefined.
Definition Fwd.hpp:60
std::tuple< Params... > type
Definition TypeTraits.hpp:571
Primary template, purposely undefined.
Definition Fwd.hpp:108
Primary template, purposely undefined.
Definition Fwd.hpp:92
Return(Params...,...) & type
Definition TypeTraits.hpp:247
Return(Params...,...) && type
Definition TypeTraits.hpp:295
Return(Params...,...) && type
Definition TypeTraits.hpp:307
Return(Params...,...) & type
Definition TypeTraits.hpp:259
Return(Params...,...) const type
Definition TypeTraits.hpp:223
Return(Params...,...) const & type
Definition TypeTraits.hpp:271
Return(Params...,...) const && type
Definition TypeTraits.hpp:319
Return(Params...,...) const && type
Definition TypeTraits.hpp:331
Return(Params...,...) const & type
Definition TypeTraits.hpp:283
Return(Params...,...) const type
Definition TypeTraits.hpp:235
Return(Params...,...) type
Definition TypeTraits.hpp:211
Return(Params...,...) type
Definition TypeTraits.hpp:199
Return(Params...) & type
Definition TypeTraits.hpp:241
Return(Params...) && type
Definition TypeTraits.hpp:289
Return(Params...) && type
Definition TypeTraits.hpp:301
Return(Params...) & type
Definition TypeTraits.hpp:253
Return(Params...) const type
Definition TypeTraits.hpp:217
Return(Params...) const & type
Definition TypeTraits.hpp:265
Return(Params...) const && type
Definition TypeTraits.hpp:313
Return(Params...) const && type
Definition TypeTraits.hpp:325
Return(Params...) const & type
Definition TypeTraits.hpp:277
Return(Params...) const type
Definition TypeTraits.hpp:229
Return(Params...) type
Definition TypeTraits.hpp:205
Return(Params...) type
Definition TypeTraits.hpp:193
Primary template, purposely undefined.
Definition Fwd.hpp:44
Return type
Definition TypeTraits.hpp:518
Return type
Definition TypeTraits.hpp:512
Primary template, purposely undefined.
Definition Fwd.hpp:76
std::uint8_t type
Definition TypeTraits.hpp:704
std::uint16_t type
Definition TypeTraits.hpp:713
std::uint32_t type
Definition TypeTraits.hpp:722
std::uint64_t type
Definition TypeTraits.hpp:731
Primary template, purposely undefined.
Definition Fwd.hpp:154