nCine 2025.06.r503-ff15d8d
A cross-platform 2D game engine
Loading...
Searching...
No Matches
type_traits.h
1#ifndef NCTL_TYPETRAITS
2#define NCTL_TYPETRAITS
3
4namespace nctl {
5
6namespace detail {
7
8 template <class T>
10 {
11 using type = T;
12 };
13
14 template <class T>
15 auto tryAddLValueReference(int) -> typeIdentity<T &>;
16 template <class T>
17 auto tryAddLValueReference(...) -> typeIdentity<T>;
18
19 template <class T>
20 auto tryAddRValueReference(int) -> typeIdentity<T &&>;
21 template <class T>
22 auto tryAddRValueReference(...) -> typeIdentity<T>;
23
24 template <class>
25 struct voidType
26 {
27 typedef void type;
28 };
29
30}
31
32template <class T>
34{
35 using type = T;
36};
37template <class T>
38struct removeReference<T &>
39{
40 using type = T;
41};
42template <class T>
43struct removeReference<T &&>
44{
45 using type = T;
46};
47
48template <class T>
50{
51 static constexpr bool value = false;
52};
53template <class T>
55{
56 static constexpr bool value = true;
57};
58
59template <class T>
61{
62 typedef T type;
63};
64template <class T>
65struct removeExtent<T[]>
66{
67 typedef T type;
68};
69template <class T, unsigned int N>
70struct removeExtent<T[N]>
71{
72 typedef T type;
73};
74template <class T>
75using removeExtentT = typename removeExtent<T>::type;
76
77template <class T>
78struct addLValueReference : decltype(detail::tryAddLValueReference<T>(0))
79{};
80template <class T>
81struct addRValueReference : decltype(detail::tryAddRValueReference<T>(0))
82{};
83template <class T>
84typename addRValueReference<T>::type declVal();
85
86template <class T>
87struct isEmpty
88{
89 static constexpr bool value = __is_empty(T);
90};
91
92template <class T, typename = void>
93struct isClass
94{
95 static constexpr bool value = false;
96};
97template <class T>
98struct isClass<T, typename detail::voidType<int T::*>::type>
99{
100 static constexpr bool value = (true && !__is_union(T));
101};
102
103template <class T>
105{
106 static constexpr bool value = __is_trivially_constructible(T);
107};
108
109template <class T>
111{
112 static constexpr bool value = __is_trivially_copyable(T);
113};
114
115template <class T, typename = void>
117{
118 static constexpr bool value = false;
119};
120template <class T>
121struct isDestructible<T, decltype(declVal<T &>().~T())>
122{
123 static constexpr bool value = (true && !__is_union(T));
124};
125
126// Use `__has_trivial_destructor()` only on GCC
127#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
128template <class T>
130{
131 static constexpr bool value = __has_trivial_destructor(T);
132};
133
134template <class T>
135struct isTriviallyDestructible
136{
137 static constexpr bool value = isDestructible<T>::value && hasTrivialDestructor<T>::value;
138};
139#else
140template <class T>
142{
143 static constexpr bool value = __is_trivially_destructible(T);
144};
145#endif
146
147template <class T>
149{
150 static constexpr bool value = false;
151};
152template <>
154{
155 static constexpr bool value = true;
156};
157template <>
159{
160 static constexpr bool value = true;
161};
162template <>
164{
165 static constexpr bool value = true;
166};
167template <>
169{
170 static constexpr bool value = true;
171};
172template <>
174{
175 static constexpr bool value = true;
176};
177template <>
179{
180 static constexpr bool value = true;
181};
182template <>
184{
185 static constexpr bool value = true;
186};
187template <>
189{
190 static constexpr bool value = true;
191};
192template <>
194{
195 static constexpr bool value = true;
196};
197template <>
199{
200 static constexpr bool value = true;
201};
202template <>
204{
205 static constexpr bool value = true;
206};
207
208}
209
210#endif
A unique pointer implementation.
Definition UniquePtr.h:118
Definition type_traits.h:79
Definition type_traits.h:82
Definition type_traits.h:10
Definition type_traits.h:26
Definition type_traits.h:94
Definition type_traits.h:117
Definition type_traits.h:88
Definition type_traits.h:149
Definition type_traits.h:50
Definition type_traits.h:105
Definition type_traits.h:111
Definition type_traits.h:142
Definition type_traits.h:61
Definition type_traits.h:34