forked from p12tic/cppreference-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_traits
More file actions
446 lines (376 loc) · 16.7 KB
/
type_traits
File metadata and controls
446 lines (376 loc) · 16.7 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/* Copyright (C) 2015 Povilas Kanapickas <povilas@radix.lt>
This file is part of cppreference-doc
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
Unported License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
*/
#ifndef CPPREFERENCE_TYPE_TRAITS_H
#define CPPREFERENCE_TYPE_TRAITS_H
#if CPPREFERENCE_STDVER>= 2011
#include <cstddef> // for size_t
namespace std {
template<class T, T v>
struct integral_constant {
typedef T value_type;
typedef integral_constant<T, v> type;
static constexpr T value = v;
constexpr operator value_type() const;
constexpr T operator()() const;
};
typedef integral_constant<bool, false> false_type;
typedef integral_constant<bool, true> true_type;
#if CPPREFERENCE_STDVER >= 2017
template<bool B>
using bool_constant = integral_constant<bool, B>;
#endif
// SIMPLIFIED: the actual base type depends on T
// primary type categories
template<class T> struct is_void : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER>= 2014
template<class T> struct is_null_pointer : integral_constant<bool, false> {};
#endif
template<class T> struct is_integral : integral_constant<bool, false> {};
template<class T> struct is_floating_point : integral_constant<bool, false> {};
template<class T> struct is_array : integral_constant<bool, false> {};
template<class T> struct is_enum : integral_constant<bool, false> {};
template<class T> struct is_union : integral_constant<bool, false> {};
template<class T> struct is_class : integral_constant<bool, false> {};
template<class T> struct is_function : integral_constant<bool, false> {};
template<class T> struct is_pointer : integral_constant<bool, false> {};
template<class T> struct is_lvalue_reference : integral_constant<bool, false> {};
template<class T> struct is_rvalue_reference : integral_constant<bool, false> {};
template<class T> struct is_member_object_pointer : integral_constant<bool, false> {};
template<class T> struct is_member_function_pointer : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_void_v = false;
template<class T> inline constexpr bool is_null_pointer_v = false;
template<class T> inline constexpr bool is_integral_v = false;
template<class T> inline constexpr bool is_floating_point_v = false;
template<class T> inline constexpr bool is_array_v = false;
template<class T> inline constexpr bool is_enum_v = false;
template<class T> inline constexpr bool is_union_v = false;
template<class T> inline constexpr bool is_class_v = false;
template<class T> inline constexpr bool is_function_v = false;
template<class T> inline constexpr bool is_pointer_v = false;
template<class T> inline constexpr bool is_lvalue_reference_v = false;
template<class T> inline constexpr bool is_rvalue_reference_v = false;
template<class T> inline constexpr bool is_member_object_pointer_v = false;
template<class T> inline constexpr bool is_member_function_pointer_v = false;
#endif
// composite type categories
template<class T> struct is_fundamental : integral_constant<bool, false> {};
template<class T> struct is_arithmetic : integral_constant<bool, false> {};
template<class T> struct is_scalar : integral_constant<bool, false> {};
template<class T> struct is_object : integral_constant<bool, false> {};
template<class T> struct is_compound : integral_constant<bool, false> {};
template<class T> struct is_reference : integral_constant<bool, false> {};
template<class T> struct is_member_pointer : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_fundamental_v = false;
template<class T> inline constexpr bool is_arithmetic_v = false;
template<class T> inline constexpr bool is_scalar_v = false;
template<class T> inline constexpr bool is_object_v = false;
template<class T> inline constexpr bool is_compound_v = false;
template<class T> inline constexpr bool is_reference_v = false;
template<class T> inline constexpr bool is_member_pointer_v = false;
#endif
// type properties
template<class T> struct is_const : integral_constant<bool, false> {};
template<class T> struct is_volatile : integral_constant<bool, false> {};
template<class T> struct is_trivial : integral_constant<bool, false> {};
template<class T> struct is_trivially_copyable : integral_constant<bool, false> {};
template<class T> struct is_standard_layout : integral_constant<bool, false> {};
template<class T> struct is_pod : integral_constant<bool, false> {};
template<class T> struct is_literal_type : integral_constant<bool, false> {};
template<class T> struct is_empty : integral_constant<bool, false> {};
template<class T> struct is_polymorphic : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> struct is_final : integral_constant<bool, false> {};
#endif
template<class T> struct is_abstract : integral_constant<bool, false> {};
template<class T> struct is_signed : integral_constant<bool, false> {};
template<class T> struct is_unsigned : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_const_v = false;
template<class T> inline constexpr bool is_volatile_v = false;
template<class T> inline constexpr bool is_trivial_v = false;
template<class T> inline constexpr bool is_trivially_copyable_v = false;
template<class T> inline constexpr bool is_standard_layout_v = false;
template<class T> inline constexpr bool is_pod_v = false;
template<class T> inline constexpr bool is_literal_type_v = false;
template<class T> inline constexpr bool is_empty_v = false;
template<class T> inline constexpr bool is_polymorphic_v = false;
template<class T> inline constexpr bool is_final_v = false;
template<class T> inline constexpr bool is_abstract_v = false;
template<class T> inline constexpr bool is_signed_v = false;
template<class T> inline constexpr bool is_unsigned_v = false;
#endif
// supported operations
template<class T, class... Args> struct is_constructible : integral_constant<bool, false> {};
template<class T, class... Args> struct is_trivially_constructible : integral_constant<bool, false> {};
template<class T, class... Args> struct is_nothrow_constructible : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T, class... Args> inline constexpr bool is_constructible_v = false;
template<class T, class... Args> inline constexpr bool is_trivially_constructible_v = false;
template<class T, class... Args> inline constexpr bool is_nothrow_constructible_v = false;
#endif
template<class T> struct is_default_constructible : integral_constant<bool, false> {};
template<class T> struct is_trivially_default_constructible : integral_constant<bool, false> {};
template<class T> struct is_nothrow_default_constructible : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_default_constructible_v = false;
template<class T> inline constexpr bool is_trivially_default_constructible_v = false;
template<class T> inline constexpr bool is_nothrow_default_constructible_v = false;
#endif
template<class T> struct is_copy_constructible : integral_constant<bool, false> {};
template<class T> struct is_trivially_copy_constructible : integral_constant<bool, false> {};
template<class T> struct is_nothrow_copy_constructible : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_copy_constructible_v = false;
template<class T> inline constexpr bool is_trivially_copy_constructible_v = false;
template<class T> inline constexpr bool is_nothrow_copy_constructible_v = false;
#endif
template<class T> struct is_move_constructible : integral_constant<bool, false> {};
template<class T> struct is_trivially_move_constructible : integral_constant<bool, false> {};
template<class T> struct is_nothrow_move_constructible : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_move_constructible_v = false;
template<class T> inline constexpr bool is_trivially_move_constructible_v = false;
template<class T> inline constexpr bool is_nothrow_move_constructible_v = false;
#endif
template<class T, class U> struct is_assignable : integral_constant<bool, false> {};
template<class T, class U> struct is_trivially_assignable : integral_constant<bool, false> {};
template<class T, class U> struct is_nothrow_assignable : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T, class U> inline constexpr bool is_assignable_v = false;
template<class T, class U> inline constexpr bool is_trivially_assignable_v = false;
template<class T, class U> inline constexpr bool is_nothrow_assignable_v = false;
#endif
template<class T> struct is_copy_assignable : integral_constant<bool, false> {};
template<class T> struct is_trivially_copy_assignable : integral_constant<bool, false> {};
template<class T> struct is_nothrow_copy_assignable : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_copy_assignable_v = false;
template<class T> inline constexpr bool is_trivially_copy_assignable_v = false;
template<class T> inline constexpr bool is_nothrow_copy_assignable_v = false;
#endif
template<class T> struct is_move_assignable : integral_constant<bool, false> {};
template<class T> struct is_trivially_move_assignable : integral_constant<bool, false> {};
template<class T> struct is_nothrow_move_assignable : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_move_assignable_v = false;
template<class T> inline constexpr bool is_trivially_move_assignable_v = false;
template<class T> inline constexpr bool is_nothrow_move_assignable_v = false;
#endif
template<class T> struct is_destructible : integral_constant<bool, false> {};
template<class T> struct is_trivially_destructible : integral_constant<bool, false> {};
template<class T> struct is_nothrow_destructible : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool is_destructible_v = false;
template<class T> inline constexpr bool is_trivially_destructible_v = false;
template<class T> inline constexpr bool is_nothrow_destructible_v = false;
#endif
template<class T> struct has_virtual_destructor : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr bool has_virtual_destructor_v = false;
#endif
// property queries
template<class T> struct alignment_of : integral_constant<size_t, 0> {};
template<class T> struct rank : integral_constant<size_t, 0> {};
template<class T, unsigned I = 0> struct extent : integral_constant<size_t, 0> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T> inline constexpr size_t alignment_of_v = 0;
template<class T> inline constexpr size_t rank_v = 0;
template<class T, unsigned I = 0> inline constexpr size_t extent_v = 0;
#endif
// type relationships
template<class T, class U> struct is_same : integral_constant<bool, false> {};
template<class Base, class Derived> struct is_base_of : integral_constant<bool, false> {};
template<class From, class To> struct is_convertible : integral_constant<bool, false> {};
#if CPPREFERENCE_STDVER >= 2014
template<class T, class U> inline constexpr bool is_same_v = false;
template<class Base, class Derived> inline constexpr bool is_base_of_v = false;
template<class From, class To> inline constexpr bool is_convertible_v = false;
#endif
// const-volatility specifiers
template<class T> struct remove_cv {
typedef T type; // SIMPLIFIED type
};
template<class T> struct remove_const {
typedef T type; // SIMPLIFIED type
};
template<class T> struct remove_volatile {
typedef T type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using remove_cv_t = T; // SIMPLIFIED typedef
template<class T>
using remove_const_t = T; // SIMPLIFIED typedef
template<class T>
using remove_volatile_t = T; // SIMPLIFIED typedef
#endif
template<class T> struct add_cv {
typedef T type; // SIMPLIFIED type
};
template<class T> struct add_const {
typedef T type; // SIMPLIFIED type
};
template<class T> struct add_volatile {
typedef T type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using add_cv_t = T; // SIMPLIFIED typedef
template<class T>
using add_const_t = T; // SIMPLIFIED typedef
template<class T>
using add_volatile_t = T; // SIMPLIFIED typedef
#endif
// references
template<class T> struct remove_reference {
typedef T type; // SIMPLIFIED type
};
template<class T> struct add_lvalue_reference {
typedef T type; // SIMPLIFIED type
};
template<class T> struct add_rvalue_reference {
typedef T type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using remove_reference_t = T; // SIMPLIFIED typedef
template<class T>
using add_lvalue_reference_t = T; // SIMPLIFIED typedef
template<class T>
using add_rvalue_reference_t = T; // SIMPLIFIED typedef
#endif
// pointers
template<class T> struct remove_pointer {
typedef T type; // SIMPLIFIED type
};
template<class T> struct add_pointer {
typedef T* type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using remove_pointer_t = T; // SIMPLIFIED typedef
template<class T>
using add_pointer_t = T*; // SIMPLIFIED typedef
#endif
// sign modifiers
template<class T> struct make_signed {
typedef T type; // SIMPLIFIED type
};
template<class T> struct make_unsigned {
typedef T type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using make_signed_t = T; // SIMPLIFIED typedef
template<class T>
using make_unsigned_t = T; // SIMPLIFIED typedef
#endif
// arrays
template<class T> struct remove_extent {
typedef T type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using remove_extent_t = T; // SIMPLIFIED typedef
#endif
template<class T> struct remove_all_extents {
typedef T type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using remove_all_extents_t = T; // SIMPLIFIED typedef
#endif
// miscellaneous transformations
template<size_t Len, size_t Align = 0> struct aligned_storage {
typedef int type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<size_t Len, size_t Align = 0>
using aligned_storage_t = int; // SIMPLIFIED typedef
#endif
template<size_t Len, class... Types> struct aligned_union {
typedef int type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<size_t Len, class... Types>
using aligned_union_t = int; // SIMPLIFIED typedef
#endif
template<class T> struct decay {
typedef T type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using decay_t = T; // SIMPLIFIED typedef
#endif
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS
template<bool, class T = void> struct enable_if {
typedef int type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<bool, class T = void>
using enable_if_t = int; // SIMPLIFIED typedef
#endif
#else
template<bool, class T = void> struct enable_if {};
template<class T>
struct enable_if<true, T> {
typedef T type;
};
#if CPPREFERENCE_STDVER >= 2014
template<bool B, class T = void>
using enable_if_t = typename enable_if<B, T>::type;
#endif
#endif // CPPREFERENCE_SIMPLIFY_TYPEDEFS
template<bool, class T, class F> struct conditional {
typedef int type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<bool, class T, class F>
using conditional_t = int; // SIMPLIFIED typedef
#endif
template<class... T> struct common_type {
typedef int type;
};
#if CPPREFERENCE_STDVER >= 2014
template<class... T>
using common_type_t = int;
#endif
template<class T> struct underlying_type {
typedef int type; // SIMPLIFIED type
};
#if CPPREFERENCE_STDVER >= 2014
template<class T>
using underlying_type_t = int; // SIMPLIFIED typedef
#endif
#if CPPREFERENCE_STDVER < 2020
template<class F, class... ArgTypes>
class result_of {
typedef int type;
}; // SIMPLIFIED: removed specializations
#endif
#if CPPREFERENCE_STDVER >= 2014 && CPPREFERENCE_STDVER < 2020
template<class F, class... ArgTypes>
using result_of_t = int; // SIMPLIFIED typedef
#endif
#if CPPREFERENCE_STDVER >= 2017
template<class F, class... ArgTypes>
class invoke_result {
typedef int type;
}; // SIMPLIFIED: removed specializations
template<class F, class... ArgTypes>
using invoke_result_t = int; // SIMPLIFIED typedef
#endif
} // namespace std
#endif // CPPREFERENCE_STDVER>= 2011
#endif // CPPREFERENCE_TYPE_TRAITS_H