-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconcepts.hpp
74 lines (62 loc) · 2.32 KB
/
concepts.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include <concepts>
#include <type_traits>
namespace fly {
/**
* Concept that is satisfied if the provided types are the same types, after removing cv-qualifiers.
*/
template <typename T, typename U>
concept SameAs = std::same_as<std::remove_cvref_t<T>, std::remove_cvref_t<U>>;
/**
* Concept that is satisfied if any type in a sequence of types are the same as a specific type.
* Examples:
*
* fly::SameAsAny<int, int, int> // Satisfied.
* fly::SameAsAny<int, int, const int &> // Satisfied.
* fly::SameAsAny<int, int, bool> // Satisfied.
* fly::SameAsAny<int, bool, bool> // Unsatisfied.
*/
template <typename T, typename... Us>
concept SameAsAny = (fly::SameAs<T, Us> || ...);
/**
* Concept that is satisfied if all types in a sequence of types are the same as a specific type.
* Examples:
*
* fly::SameAsAll<int, int, int> // Satisfied.
* fly::SameAsAll<int, int, const int &> // Satisfied.
* fly::SameAsAll<int, int, bool> // Unsatisfied.
* fly::SameAsAll<int, bool, bool> // Unsatisfied.
*/
template <typename T, typename... Us>
concept SameAsAll = (fly::SameAs<T, Us> && ...);
/**
* Concept that is satisified if the given type is the provided size.
*/
template <typename T, std::size_t Size>
concept SizeOfTypeIs = (sizeof(T) == Size);
/**
* Concept that is satisified if the given type is an integral, non-boolean type.
*/
template <typename T>
concept Integral = std::is_integral_v<std::remove_cvref_t<T>> && !fly::SameAs<T, bool>;
/**
* Concept that is satisified if the given type is a signed integral, non-boolean type.
*/
template <typename T>
concept SignedIntegral = fly::Integral<T> && std::is_signed_v<std::remove_cvref_t<T>>;
/**
* Concept that is satisified if the given type is an unsigned integral, non-boolean type.
*/
template <typename T>
concept UnsignedIntegral = fly::Integral<T> && std::is_unsigned_v<std::remove_cvref_t<T>>;
/**
* Concept that is satisified if the given type is a floating-point type.
*/
template <typename T>
concept FloatingPoint = std::is_floating_point_v<std::remove_cvref_t<T>>;
/**
* Concept that is satisified if the first given type is derived from the second given type.
*/
template <typename Derived, typename Base>
concept DerivedFrom = std::is_base_of_v<std::remove_cvref_t<Base>, std::remove_cvref_t<Derived>>;
} // namespace fly