-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_traits.hpp
285 lines (262 loc) · 15.6 KB
/
type_traits.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#ifndef _WT_TYPE_TRAITS_HPP_
#define _WT_TYPE_TRAITS_HPP_
namespace wt{
template<typename T,T v>
struct integral_constant{
static constexpr T value = v;
using value_type = T;
using type = integral_constant<T,v>;
constexpr operator value_type() const noexcept
{
return value;
}
constexpr value_type operator()() const noexcept
{
return value;
}
};
template<bool B>
using bool_constant = integral_constant<bool,B>;
using true_type = bool_constant<true>;
using false_type = bool_constant<false>;
template <typename T> struct is_integral : false_type{};
// template <typename T> struct is_void : false_type{};
// template <typename T> struct is_null_pointer : false_type{};
// template <typename T> struct is_floating_point : false_type{};
// template <typename T> struct is_array : false_type{};
// template <typename T> struct is_enum : false_type{};
// template <typename T> struct is_union : false_type{};
// template <typename T> struct is_class : false_type{};
// template <typename T> struct is_function : false_type{};
// template <typename T> struct is_pointer : false_type{};
// template <typename T> struct is_lvalue_reference : false_type{};
// template <typename T> struct is_rvalue_reference : false_type{};
// template <typename T> struct is_member_object_pointer : false_type{};
// template <typename T> struct is_member_function_pointer : false_type{};
// template <typename T> struct is_fundamental : false_type{};
// template <typename T> struct is_arithmetic : false_type{};
// template <typename T> struct is_scalar : false_type{};
// template <typename T> struct is_object : false_type{};
// template <typename T> struct is_compound : false_type{};
// template <typename T> struct is_reference : false_type{};
// template <typename T> struct is_member_pointer : false_type{};
// template <typename T> struct is_const : false_type{};
// template <typename T> struct is_volatile : false_type{};
// template <typename T> struct is_standard_layout : false_type{};
// template <typename T> struct is_pod : false_type{};
// template <typename T> struct is_literal_type : false_type{};
// template <typename T> struct is_empty : false_type{};
// template <typename T> struct is_polymorphic : false_type{};
// template <typename T> struct is_final : false_type{};
// template <typename T> struct is_abstract : false_type{};
// template <typename T> struct is_signed : false_type{};
// template <typename T> struct is_unsigned : false_type{};
template <typename T> struct is_trivially_default_constructible : false_type{};
template <typename T> struct is_trivially_copy_constructible : false_type{};
template <typename T> struct is_trivially_move_constructible : false_type{};
template <typename T> struct is_trivially_copy_assignable : false_type{};
template <typename T> struct is_trivially_move_assignable : false_type{};
template <typename T> struct is_trivially_destructible : false_type{};
template <typename T> struct is_pod : false_type{};
// partial specilization
template <> struct is_trivially_default_constructible<bool> : true_type{};
template <> struct is_trivially_default_constructible<char> : true_type{};
template <> struct is_trivially_default_constructible<signed char> : true_type{};
template <> struct is_trivially_default_constructible<unsigned char> : true_type{};
template <> struct is_trivially_default_constructible<wchar_t> : true_type{};
template <> struct is_trivially_default_constructible<short> : true_type{};
template <> struct is_trivially_default_constructible<unsigned short> : true_type{};
template <> struct is_trivially_default_constructible<int> : true_type{};
template <> struct is_trivially_default_constructible<unsigned int> : true_type{};
template <> struct is_trivially_default_constructible<long> : true_type{};
template <> struct is_trivially_default_constructible<unsigned long> : true_type{};
template <> struct is_trivially_default_constructible<long long> : true_type{};
template <> struct is_trivially_default_constructible<unsigned long long> : true_type{};
template <> struct is_trivially_default_constructible<float> : true_type{};
template <> struct is_trivially_default_constructible<double> : true_type{};
template <> struct is_trivially_default_constructible<long double> : true_type{};
template <> struct is_trivially_default_constructible<char*> : true_type{};
template <> struct is_trivially_default_constructible<signed char*> : true_type{};
template <> struct is_trivially_default_constructible<unsigned char*> : true_type{};
template <> struct is_trivially_default_constructible<const char*> : true_type{};
template <> struct is_trivially_default_constructible<const signed char*> : true_type{};
template <> struct is_trivially_default_constructible<const unsigned char*> : true_type{};
template <typename Tp>
struct is_trivially_default_constructible<Tp*> : true_type{};
template <> struct is_trivially_copy_constructible<bool> : true_type{};
template <> struct is_trivially_copy_constructible<char> : true_type{};
template <> struct is_trivially_copy_constructible<signed char> : true_type{};
template <> struct is_trivially_copy_constructible<unsigned char> : true_type{};
template <> struct is_trivially_copy_constructible<wchar_t> : true_type{};
template <> struct is_trivially_copy_constructible<short> : true_type{};
template <> struct is_trivially_copy_constructible<unsigned short> : true_type{};
template <> struct is_trivially_copy_constructible<int> : true_type{};
template <> struct is_trivially_copy_constructible<unsigned int> : true_type{};
template <> struct is_trivially_copy_constructible<long> : true_type{};
template <> struct is_trivially_copy_constructible<unsigned long> : true_type{};
template <> struct is_trivially_copy_constructible<long long> : true_type{};
template <> struct is_trivially_copy_constructible<unsigned long long> : true_type{};
template <> struct is_trivially_copy_constructible<float> : true_type{};
template <> struct is_trivially_copy_constructible<double> : true_type{};
template <> struct is_trivially_copy_constructible<long double> : true_type{};
template <> struct is_trivially_copy_constructible<char*> : true_type{};
template <> struct is_trivially_copy_constructible<signed char*> : true_type{};
template <> struct is_trivially_copy_constructible<unsigned char*> : true_type{};
template <> struct is_trivially_copy_constructible<const char*> : true_type{};
template <> struct is_trivially_copy_constructible<const signed char*> : true_type{};
template <> struct is_trivially_copy_constructible<const unsigned char*> : true_type{};
template <typename Tp>
struct is_trivially_copy_constructible<Tp*> : true_type{};
template <> struct is_trivially_move_constructible<bool> : true_type{};
template <> struct is_trivially_move_constructible<char> : true_type{};
template <> struct is_trivially_move_constructible<signed char> : true_type{};
template <> struct is_trivially_move_constructible<unsigned char> : true_type{};
template <> struct is_trivially_move_constructible<wchar_t> : true_type{};
template <> struct is_trivially_move_constructible<short> : true_type{};
template <> struct is_trivially_move_constructible<unsigned short> : true_type{};
template <> struct is_trivially_move_constructible<int> : true_type{};
template <> struct is_trivially_move_constructible<unsigned int> : true_type{};
template <> struct is_trivially_move_constructible<long> : true_type{};
template <> struct is_trivially_move_constructible<unsigned long> : true_type{};
template <> struct is_trivially_move_constructible<long long> : true_type{};
template <> struct is_trivially_move_constructible<unsigned long long> : true_type{};
template <> struct is_trivially_move_constructible<float> : true_type{};
template <> struct is_trivially_move_constructible<double> : true_type{};
template <> struct is_trivially_move_constructible<long double> : true_type{};
template <> struct is_trivially_move_constructible<char*> : true_type{};
template <> struct is_trivially_move_constructible<signed char*> : true_type{};
template <> struct is_trivially_move_constructible<unsigned char*> : true_type{};
template <> struct is_trivially_move_constructible<const char*> : true_type{};
template <> struct is_trivially_move_constructible<const signed char*> : true_type{};
template <> struct is_trivially_move_constructible<const unsigned char*> : true_type{};
template <typename Tp>
struct is_trivially_move_constructible<Tp*> : true_type{};
template <> struct is_trivially_copy_assignable<bool> : true_type{};
template <> struct is_trivially_copy_assignable<char> : true_type{};
template <> struct is_trivially_copy_assignable<signed char> : true_type{};
template <> struct is_trivially_copy_assignable<unsigned char> : true_type{};
template <> struct is_trivially_copy_assignable<wchar_t> : true_type{};
template <> struct is_trivially_copy_assignable<short> : true_type{};
template <> struct is_trivially_copy_assignable<unsigned short> : true_type{};
template <> struct is_trivially_copy_assignable<int> : true_type{};
template <> struct is_trivially_copy_assignable<unsigned int> : true_type{};
template <> struct is_trivially_copy_assignable<long> : true_type{};
template <> struct is_trivially_copy_assignable<unsigned long> : true_type{};
template <> struct is_trivially_copy_assignable<long long> : true_type{};
template <> struct is_trivially_copy_assignable<unsigned long long> : true_type{};
template <> struct is_trivially_copy_assignable<float> : true_type{};
template <> struct is_trivially_copy_assignable<double> : true_type{};
template <> struct is_trivially_copy_assignable<long double> : true_type{};
template <> struct is_trivially_copy_assignable<char*> : true_type{};
template <> struct is_trivially_copy_assignable<signed char*> : true_type{};
template <> struct is_trivially_copy_assignable<unsigned char*> : true_type{};
template <> struct is_trivially_copy_assignable<const char*> : true_type{};
template <> struct is_trivially_copy_assignable<const signed char*> : true_type{};
template <> struct is_trivially_copy_assignable<const unsigned char*> : true_type{};
template <typename Tp>
struct is_trivially_copy_assignable<Tp*> : true_type{};
template <> struct is_trivially_move_assignable<bool> : true_type{};
template <> struct is_trivially_move_assignable<char> : true_type{};
template <> struct is_trivially_move_assignable<signed char> : true_type{};
template <> struct is_trivially_move_assignable<unsigned char> : true_type{};
template <> struct is_trivially_move_assignable<wchar_t> : true_type{};
template <> struct is_trivially_move_assignable<short> : true_type{};
template <> struct is_trivially_move_assignable<unsigned short> : true_type{};
template <> struct is_trivially_move_assignable<int> : true_type{};
template <> struct is_trivially_move_assignable<unsigned int> : true_type{};
template <> struct is_trivially_move_assignable<long> : true_type{};
template <> struct is_trivially_move_assignable<unsigned long> : true_type{};
template <> struct is_trivially_move_assignable<long long> : true_type{};
template <> struct is_trivially_move_assignable<unsigned long long> : true_type{};
template <> struct is_trivially_move_assignable<float> : true_type{};
template <> struct is_trivially_move_assignable<double> : true_type{};
template <> struct is_trivially_move_assignable<long double> : true_type{};
template <> struct is_trivially_move_assignable<char*> : true_type{};
template <> struct is_trivially_move_assignable<signed char*> : true_type{};
template <> struct is_trivially_move_assignable<unsigned char*> : true_type{};
template <> struct is_trivially_move_assignable<const char*> : true_type{};
template <> struct is_trivially_move_assignable<const signed char*> : true_type{};
template <> struct is_trivially_move_assignable<const unsigned char*> : true_type{};
template <typename Tp>
struct is_trivially_move_assignable<Tp*> : true_type{};
template <> struct is_trivially_destructible<bool> : true_type{};
template <> struct is_trivially_destructible<char> : true_type{};
template <> struct is_trivially_destructible<signed char> : true_type{};
template <> struct is_trivially_destructible<unsigned char> : true_type{};
template <> struct is_trivially_destructible<wchar_t> : true_type{};
template <> struct is_trivially_destructible<short> : true_type{};
template <> struct is_trivially_destructible<unsigned short> : true_type{};
template <> struct is_trivially_destructible<int> : true_type{};
template <> struct is_trivially_destructible<unsigned int> : true_type{};
template <> struct is_trivially_destructible<long> : true_type{};
template <> struct is_trivially_destructible<unsigned long> : true_type{};
template <> struct is_trivially_destructible<long long> : true_type{};
template <> struct is_trivially_destructible<unsigned long long> : true_type{};
template <> struct is_trivially_destructible<float> : true_type{};
template <> struct is_trivially_destructible<double> : true_type{};
template <> struct is_trivially_destructible<long double> : true_type{};
template <> struct is_trivially_destructible<char*> : true_type{};
template <> struct is_trivially_destructible<signed char*> : true_type{};
template <> struct is_trivially_destructible<unsigned char*> : true_type{};
template <> struct is_trivially_destructible<const char*> : true_type{};
template <> struct is_trivially_destructible<const signed char*> : true_type{};
template <> struct is_trivially_destructible<const unsigned char*> : true_type{};
template <typename Tp>
struct is_trivially_destructible<Tp*> : true_type{};
template <> struct is_pod<bool> : true_type{};
template <> struct is_pod<char> : true_type{};
template <> struct is_pod<signed char> : true_type{};
template <> struct is_pod<unsigned char> : true_type{};
template <> struct is_pod<wchar_t> : true_type{};
template <> struct is_pod<short> : true_type{};
template <> struct is_pod<unsigned short> : true_type{};
template <> struct is_pod<int> : true_type{};
template <> struct is_pod<unsigned int> : true_type{};
template <> struct is_pod<long> : true_type{};
template <> struct is_pod<unsigned long> : true_type{};
template <> struct is_pod<long long> : true_type{};
template <> struct is_pod<unsigned long long> : true_type{};
template <> struct is_pod<float> : true_type{};
template <> struct is_pod<double> : true_type{};
template <> struct is_pod<long double> : true_type{};
template <> struct is_pod<char*> : true_type{};
template <> struct is_pod<signed char*> : true_type{};
template <> struct is_pod<unsigned char*> : true_type{};
template <> struct is_pod<const char*> : true_type{};
template <> struct is_pod<const signed char*> : true_type{};
template <> struct is_pod<const unsigned char*> : true_type{};
template <typename Tp>
struct is_pod<Tp*> : true_type{};
template <> struct is_integral<bool> : true_type{};
template <> struct is_integral<char> : true_type{};
template <> struct is_integral<signed char> : true_type{};
template <> struct is_integral<unsigned char> : true_type{};
template <> struct is_integral<wchar_t> : true_type{};
template <> struct is_integral<short> : true_type{};
template <> struct is_integral<unsigned short> : true_type{};
template <> struct is_integral<int> : true_type{};
template <> struct is_integral<unsigned int> : true_type{};
template <> struct is_integral<long> : true_type{};
template <> struct is_integral<unsigned long> : true_type{};
template <> struct is_integral<long long> : true_type{};
template <> struct is_integral<unsigned long long> : true_type{};
//////////////////////
// remove_reference //
//////////////////////
template <typename T>
struct remove_reference {
typedef T type;
};
template <typename T>
struct remove_reference<T&> {
typedef T type;
};
template <typename T>
struct remove_reference<T&&> {
typedef T type;
};
// alias
template <typename T>
using remove_reference_t = typename remove_reference<T>::type;
} // namespace wt
#endif