nCine 2025.08.r507-936d9b8
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 <typename T>
111{
112 static constexpr bool value = __is_constructible(T, T &&);
113};
114
115template <class T>
117{
118 static constexpr bool value = __is_constructible(T, const T &);
119};
120
121template <class T>
123{
124 static constexpr bool value = __is_trivially_copyable(T);
125};
126
127template <class T, typename = void>
129{
130 static constexpr bool value = false;
131};
132template <class T>
133struct isDestructible<T, decltype(declVal<T &>().~T())>
134{
135 static constexpr bool value = (true && !__is_union(T));
136};
137
138// Use `__has_trivial_destructor()` only on GCC
139#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
140template <class T>
142{
143 static constexpr bool value = __has_trivial_destructor(T);
144};
145
146template <class T>
147struct isTriviallyDestructible
148{
149 static constexpr bool value = isDestructible<T>::value && hasTrivialDestructor<T>::value;
150};
151#else
152template <class T>
154{
155 static constexpr bool value = __is_trivially_destructible(T);
156};
157#endif
158
159template <bool B, typename T, typename F>
161{
162 using type = T;
163};
164template <typename T, typename F>
165struct conditional<false, T, F>
166{
167 using type = F;
168};
169
170template <bool Condition, typename T = void>
172{
173};
174template <typename T>
175struct enableIf<true, T>
176{
177 using type = T;
178};
179
180template <typename T, typename U>
181struct isSame
182{
183 static constexpr bool value = false;
184};
185template <typename T>
186struct isSame<T, T>
187{
188 static constexpr bool value = true;
189};
190
191template <class T>
193{
194 static constexpr bool value = false;
195};
196template <>
198{
199 static constexpr bool value = true;
200};
201template <>
203{
204 static constexpr bool value = true;
205};
206template <>
208{
209 static constexpr bool value = true;
210};
211template <>
213{
214 static constexpr bool value = true;
215};
216template <>
218{
219 static constexpr bool value = true;
220};
221template <>
223{
224 static constexpr bool value = true;
225};
226template <>
228{
229 static constexpr bool value = true;
230};
231template <>
233{
234 static constexpr bool value = true;
235};
236template <>
238{
239 static constexpr bool value = true;
240};
241template <>
243{
244 static constexpr bool value = true;
245};
246template <>
248{
249 static constexpr bool value = true;
250};
251
252}
253
254#endif
A unique pointer implementation.
Definition UniquePtr.h:118
Definition type_traits.h:79
Definition type_traits.h:82
Definition type_traits.h:161
Definition type_traits.h:10
Definition type_traits.h:26
Definition type_traits.h:172
Definition type_traits.h:94
Definition type_traits.h:117
Definition type_traits.h:129
Definition type_traits.h:88
Definition type_traits.h:193
Definition type_traits.h:50
Definition type_traits.h:111
Definition type_traits.h:182
Definition type_traits.h:105
Definition type_traits.h:123
Definition type_traits.h:154
Definition type_traits.h:61
Definition type_traits.h:34