]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/std/type_traits
[ARM/FDPIC 01/24] [ARM] FDPIC: Add -mfdpic option support
[thirdparty/gcc.git] / libstdc++-v3 / include / std / type_traits
CommitLineData
c0ffa2ba 1// C++11 <type_traits> -*- C++ -*-
af13a7a6 2
a5544970 3// Copyright (C) 2007-2019 Free Software Foundation, Inc.
af13a7a6
BK
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
af13a7a6
BK
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
748086b7
JJ
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
af13a7a6
BK
24
25/** @file include/type_traits
26 * This is a Standard C++ Library header.
27 */
28
4514bed6
BK
29#ifndef _GLIBCXX_TYPE_TRAITS
30#define _GLIBCXX_TYPE_TRAITS 1
af13a7a6
BK
31
32#pragma GCC system_header
33
734f5023 34#if __cplusplus < 201103L
ab65a4c7 35# include <bits/c++0x_warning.h>
57317d2a 36#else
af13a7a6 37
8fc81078 38#include <bits/c++config.h>
e133ace8 39
21e2806a
JW
40namespace std _GLIBCXX_VISIBILITY(default)
41{
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
43
8e32aa11 44 /**
c0ffa2ba 45 * @defgroup metaprogramming Metaprogramming
13901e4b
JW
46 * @ingroup utilities
47 *
48 * Template utilities for compile-time introspection and modification,
49 * including type classification traits, type property inspection traits
50 * and type transformation traits.
51 *
5b9daa7e
BK
52 * @{
53 */
ac65b7d2
DK
54
55 /// integral_constant
56 template<typename _Tp, _Tp __v>
57 struct integral_constant
58 {
59 static constexpr _Tp value = __v;
60 typedef _Tp value_type;
61 typedef integral_constant<_Tp, __v> type;
352111c5 62 constexpr operator value_type() const noexcept { return value; }
db113eda 63#if __cplusplus > 201103L
a15f7cb8
ESR
64
65#define __cpp_lib_integral_constant_callable 201304
66
352111c5 67 constexpr value_type operator()() const noexcept { return value; }
db113eda 68#endif
ac65b7d2 69 };
33ac58d5 70
c0ffa2ba
BK
71 template<typename _Tp, _Tp __v>
72 constexpr _Tp integral_constant<_Tp, __v>::value;
73
13901e4b 74 /// The type used as a compile-time boolean with true value.
ac65b7d2
DK
75 typedef integral_constant<bool, true> true_type;
76
13901e4b 77 /// The type used as a compile-time boolean with false value.
ac65b7d2
DK
78 typedef integral_constant<bool, false> false_type;
79
f6b640be
JW
80 template<bool __v>
81 using __bool_constant = integral_constant<bool, __v>;
82
46ba1281 83#if __cplusplus > 201402L
f9badf71 84# define __cpp_lib_bool_constant 201505
46ba1281
JW
85 template<bool __v>
86 using bool_constant = integral_constant<bool, __v>;
87#endif
88
123c516a 89 // Meta programming helper types.
53dc5044 90
123c516a
PC
91 template<bool, typename, typename>
92 struct conditional;
53dc5044 93
608a080c 94 template <typename _Type>
0d67cd38
JW
95 struct __type_identity
96 { using type = _Type; };
97
98 template<typename _Tp>
99 using __type_identity_t = typename __type_identity<_Tp>::type;
608a080c 100
dd7b175e 101 template<typename...>
123c516a
PC
102 struct __or_;
103
ac65b7d2
DK
104 template<>
105 struct __or_<>
106 : public false_type
107 { };
108
dd7b175e
PC
109 template<typename _B1>
110 struct __or_<_B1>
111 : public _B1
112 { };
113
123c516a
PC
114 template<typename _B1, typename _B2>
115 struct __or_<_B1, _B2>
116 : public conditional<_B1::value, _B1, _B2>::type
117 { };
118
119 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
120 struct __or_<_B1, _B2, _B3, _Bn...>
121 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
122 { };
53dc5044 123
dd7b175e 124 template<typename...>
123c516a 125 struct __and_;
53dc5044 126
ac65b7d2
DK
127 template<>
128 struct __and_<>
129 : public true_type
130 { };
131
dd7b175e
PC
132 template<typename _B1>
133 struct __and_<_B1>
134 : public _B1
135 { };
136
123c516a
PC
137 template<typename _B1, typename _B2>
138 struct __and_<_B1, _B2>
139 : public conditional<_B1::value, _B2, _B1>::type
140 { };
141
142 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
143 struct __and_<_B1, _B2, _B3, _Bn...>
144 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
145 { };
146
147 template<typename _Pp>
148 struct __not_
4b9840f2 149 : public __bool_constant<!bool(_Pp::value)>
123c516a
PC
150 { };
151
4b9840f2 152#if __cplusplus >= 201703L
c3a6648b 153
b655b8fc
JW
154 template<typename... _Bn>
155 inline constexpr bool __or_v = __or_<_Bn...>::value;
156 template<typename... _Bn>
157 inline constexpr bool __and_v = __and_<_Bn...>::value;
158
068c8ac1 159#define __cpp_lib_logical_traits 201510
c3a6648b
VV
160
161 template<typename... _Bn>
162 struct conjunction
163 : __and_<_Bn...>
164 { };
165
166 template<typename... _Bn>
167 struct disjunction
168 : __or_<_Bn...>
169 { };
170
171 template<typename _Pp>
172 struct negation
173 : __not_<_Pp>
174 { };
137422c8
VV
175
176 template<typename... _Bn>
4b9840f2 177 inline constexpr bool conjunction_v = conjunction<_Bn...>::value;
42183d03 178
137422c8 179 template<typename... _Bn>
4b9840f2 180 inline constexpr bool disjunction_v = disjunction<_Bn...>::value;
42183d03 181
137422c8 182 template<typename _Pp>
4b9840f2 183 inline constexpr bool negation_v = negation<_Pp>::value;
137422c8 184
4b9840f2 185#endif // C++17
c3a6648b 186
608a080c
AP
187 // Forward declarations
188 template<typename>
189 struct is_reference;
190 template<typename>
191 struct is_function;
192 template<typename>
193 struct is_void;
194 template<typename>
195 struct __is_array_unknown_bounds;
196
197 // Helper functions that return false_type for incomplete classes,
198 // incomplete unions and arrays of known bound from those.
199
200 template <typename _T, size_t = sizeof(_T)>
201 constexpr true_type __is_complete_or_unbounded(__type_identity<_T>)
202 { return {}; }
203
204 template <typename _TypeIdentity,
205 typename _NestedType = typename _TypeIdentity::type>
206 constexpr typename __or_<
207 is_reference<_NestedType>,
208 is_function<_NestedType>,
209 is_void<_NestedType>,
210 __is_array_unknown_bounds<_NestedType>
211 >::type __is_complete_or_unbounded(_TypeIdentity)
212 { return {}; }
213
b3618b71
DK
214 // For several sfinae-friendly trait implementations we transport both the
215 // result information (as the member type) and the failure information (no
216 // member type). This is very similar to std::enable_if, but we cannot use
217 // them, because we need to derive from them as an implementation detail.
218
219 template<typename _Tp>
220 struct __success_type
221 { typedef _Tp type; };
222
223 struct __failure_type
224 { };
225
53dc5044
PC
226 template<typename>
227 struct remove_cv;
228
72459cfd
JW
229 template<typename>
230 struct is_const;
231
232 // Primary type categories.
233
53dc5044
PC
234 template<typename>
235 struct __is_void_helper
236 : public false_type { };
53dc5044 237
123c516a
PC
238 template<>
239 struct __is_void_helper<void>
240 : public true_type { };
53dc5044
PC
241
242 /// is_void
243 template<typename _Tp>
244 struct is_void
82b12c4b 245 : public __is_void_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
246 { };
247
248 template<typename>
249 struct __is_integral_helper
250 : public false_type { };
123c516a
PC
251
252 template<>
253 struct __is_integral_helper<bool>
254 : public true_type { };
33ac58d5 255
123c516a
PC
256 template<>
257 struct __is_integral_helper<char>
258 : public true_type { };
259
260 template<>
261 struct __is_integral_helper<signed char>
262 : public true_type { };
263
264 template<>
265 struct __is_integral_helper<unsigned char>
266 : public true_type { };
267
53dc5044 268#ifdef _GLIBCXX_USE_WCHAR_T
123c516a
PC
269 template<>
270 struct __is_integral_helper<wchar_t>
271 : public true_type { };
53dc5044 272#endif
123c516a 273
c124af93
TH
274#ifdef _GLIBCXX_USE_CHAR8_T
275 template<>
276 struct __is_integral_helper<char8_t>
277 : public true_type { };
278#endif
279
123c516a
PC
280 template<>
281 struct __is_integral_helper<char16_t>
282 : public true_type { };
283
284 template<>
285 struct __is_integral_helper<char32_t>
286 : public true_type { };
287
288 template<>
289 struct __is_integral_helper<short>
290 : public true_type { };
291
292 template<>
293 struct __is_integral_helper<unsigned short>
294 : public true_type { };
295
296 template<>
297 struct __is_integral_helper<int>
298 : public true_type { };
299
300 template<>
301 struct __is_integral_helper<unsigned int>
302 : public true_type { };
303
304 template<>
305 struct __is_integral_helper<long>
306 : public true_type { };
307
308 template<>
309 struct __is_integral_helper<unsigned long>
310 : public true_type { };
311
312 template<>
313 struct __is_integral_helper<long long>
314 : public true_type { };
315
316 template<>
317 struct __is_integral_helper<unsigned long long>
318 : public true_type { };
53dc5044 319
78a7c317
DD
320 // Conditionalizing on __STRICT_ANSI__ here will break any port that
321 // uses one of these types for size_t.
322#if defined(__GLIBCXX_TYPE_INT_N_0)
6d585f01 323 template<>
78a7c317 324 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
6d585f01
PC
325 : public true_type { };
326
327 template<>
78a7c317
DD
328 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
329 : public true_type { };
330#endif
331#if defined(__GLIBCXX_TYPE_INT_N_1)
332 template<>
333 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
334 : public true_type { };
335
336 template<>
337 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
338 : public true_type { };
339#endif
340#if defined(__GLIBCXX_TYPE_INT_N_2)
341 template<>
342 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
343 : public true_type { };
344
345 template<>
346 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
347 : public true_type { };
348#endif
349#if defined(__GLIBCXX_TYPE_INT_N_3)
350 template<>
351 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
352 : public true_type { };
353
354 template<>
355 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
6d585f01
PC
356 : public true_type { };
357#endif
358
53dc5044
PC
359 /// is_integral
360 template<typename _Tp>
361 struct is_integral
82b12c4b 362 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
363 { };
364
365 template<typename>
366 struct __is_floating_point_helper
367 : public false_type { };
123c516a
PC
368
369 template<>
370 struct __is_floating_point_helper<float>
371 : public true_type { };
372
373 template<>
374 struct __is_floating_point_helper<double>
375 : public true_type { };
376
377 template<>
378 struct __is_floating_point_helper<long double>
379 : public true_type { };
53dc5044 380
6d585f01
PC
381#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
382 template<>
383 struct __is_floating_point_helper<__float128>
384 : public true_type { };
385#endif
386
53dc5044
PC
387 /// is_floating_point
388 template<typename _Tp>
389 struct is_floating_point
82b12c4b 390 : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
391 { };
392
393 /// is_array
394 template<typename>
395 struct is_array
396 : public false_type { };
397
398 template<typename _Tp, std::size_t _Size>
399 struct is_array<_Tp[_Size]>
400 : public true_type { };
401
402 template<typename _Tp>
403 struct is_array<_Tp[]>
404 : public true_type { };
405
406 template<typename>
407 struct __is_pointer_helper
408 : public false_type { };
123c516a
PC
409
410 template<typename _Tp>
411 struct __is_pointer_helper<_Tp*>
412 : public true_type { };
53dc5044
PC
413
414 /// is_pointer
415 template<typename _Tp>
416 struct is_pointer
82b12c4b 417 : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
418 { };
419
123c516a
PC
420 /// is_lvalue_reference
421 template<typename>
422 struct is_lvalue_reference
423 : public false_type { };
424
53dc5044 425 template<typename _Tp>
123c516a
PC
426 struct is_lvalue_reference<_Tp&>
427 : public true_type { };
428
429 /// is_rvalue_reference
430 template<typename>
431 struct is_rvalue_reference
432 : public false_type { };
53dc5044 433
53dc5044 434 template<typename _Tp>
123c516a
PC
435 struct is_rvalue_reference<_Tp&&>
436 : public true_type { };
437
53dc5044
PC
438 template<typename>
439 struct __is_member_object_pointer_helper
440 : public false_type { };
123c516a
PC
441
442 template<typename _Tp, typename _Cp>
443 struct __is_member_object_pointer_helper<_Tp _Cp::*>
c01f9216 444 : public __not_<is_function<_Tp>>::type { };
53dc5044
PC
445
446 /// is_member_object_pointer
447 template<typename _Tp>
448 struct is_member_object_pointer
82b12c4b
FD
449 : public __is_member_object_pointer_helper<
450 typename remove_cv<_Tp>::type>::type
53dc5044
PC
451 { };
452
453 template<typename>
454 struct __is_member_function_pointer_helper
455 : public false_type { };
123c516a
PC
456
457 template<typename _Tp, typename _Cp>
458 struct __is_member_function_pointer_helper<_Tp _Cp::*>
c01f9216 459 : public is_function<_Tp>::type { };
53dc5044
PC
460
461 /// is_member_function_pointer
462 template<typename _Tp>
463 struct is_member_function_pointer
82b12c4b
FD
464 : public __is_member_function_pointer_helper<
465 typename remove_cv<_Tp>::type>::type
53dc5044
PC
466 { };
467
468 /// is_enum
469 template<typename _Tp>
470 struct is_enum
471 : public integral_constant<bool, __is_enum(_Tp)>
472 { };
473
474 /// is_union
475 template<typename _Tp>
476 struct is_union
477 : public integral_constant<bool, __is_union(_Tp)>
478 { };
479
480 /// is_class
481 template<typename _Tp>
482 struct is_class
483 : public integral_constant<bool, __is_class(_Tp)>
484 { };
485
486 /// is_function
72459cfd 487 template<typename _Tp>
53dc5044 488 struct is_function
72459cfd 489 : public __bool_constant<!is_const<const _Tp>::value> { };
89898034 490
72459cfd
JW
491 template<typename _Tp>
492 struct is_function<_Tp&>
493 : public false_type { };
89898034 494
72459cfd
JW
495 template<typename _Tp>
496 struct is_function<_Tp&&>
497 : public false_type { };
89898034 498
a15f7cb8
ESR
499#define __cpp_lib_is_null_pointer 201309
500
1e673415 501 template<typename>
aa940ab5 502 struct __is_null_pointer_helper
1e673415 503 : public false_type { };
123c516a
PC
504
505 template<>
aa940ab5 506 struct __is_null_pointer_helper<std::nullptr_t>
123c516a 507 : public true_type { };
1e673415 508
aa940ab5
PC
509 /// is_null_pointer (LWG 2247).
510 template<typename _Tp>
511 struct is_null_pointer
512 : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type
513 { };
514
07fd852f 515 /// __is_nullptr_t (deprecated extension).
1e673415
PC
516 template<typename _Tp>
517 struct __is_nullptr_t
aa940ab5 518 : public is_null_pointer<_Tp>
07fd852f 519 { } _GLIBCXX_DEPRECATED;
1e673415 520
c0ffa2ba 521 // Composite type categories.
123c516a
PC
522
523 /// is_reference
524 template<typename _Tp>
525 struct is_reference
526 : public __or_<is_lvalue_reference<_Tp>,
527 is_rvalue_reference<_Tp>>::type
528 { };
529
53dc5044
PC
530 /// is_arithmetic
531 template<typename _Tp>
532 struct is_arithmetic
123c516a 533 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
53dc5044
PC
534 { };
535
536 /// is_fundamental
537 template<typename _Tp>
538 struct is_fundamental
aa940ab5
PC
539 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
540 is_null_pointer<_Tp>>::type
53dc5044
PC
541 { };
542
543 /// is_object
544 template<typename _Tp>
545 struct is_object
123c516a
PC
546 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
547 is_void<_Tp>>>::type
53dc5044
PC
548 { };
549
123c516a 550 template<typename>
53dc5044
PC
551 struct is_member_pointer;
552
553 /// is_scalar
554 template<typename _Tp>
555 struct is_scalar
123c516a 556 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
aa940ab5 557 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
53dc5044
PC
558 { };
559
560 /// is_compound
561 template<typename _Tp>
562 struct is_compound
c01f9216 563 : public __not_<is_fundamental<_Tp>>::type { };
53dc5044 564
53dc5044
PC
565 template<typename _Tp>
566 struct __is_member_pointer_helper
567 : public false_type { };
123c516a
PC
568
569 template<typename _Tp, typename _Cp>
570 struct __is_member_pointer_helper<_Tp _Cp::*>
571 : public true_type { };
53dc5044 572
13901e4b 573 /// is_member_pointer
53dc5044 574 template<typename _Tp>
123c516a 575 struct is_member_pointer
82b12c4b 576 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
577 { };
578
47f79054
JW
579 template<typename, typename>
580 struct is_same;
581
582 template<typename _Tp, typename... _Types>
583 using __is_one_of = __or_<is_same<_Tp, _Types>...>;
584
585 // Check if a type is one of the signed integer types.
586 template<typename _Tp>
587 using __is_signed_integer = __is_one_of<typename remove_cv<_Tp>::type,
588 signed char, signed short, signed int, signed long,
589 signed long long
590#if defined(__GLIBCXX_TYPE_INT_N_0)
591 , signed __GLIBCXX_TYPE_INT_N_0
592#endif
593#if defined(__GLIBCXX_TYPE_INT_N_1)
594 , signed __GLIBCXX_TYPE_INT_N_1
595#endif
596#if defined(__GLIBCXX_TYPE_INT_N_2)
597 , signed __GLIBCXX_TYPE_INT_N_2
598#endif
599#if defined(__GLIBCXX_TYPE_INT_N_3)
600 , signed __GLIBCXX_TYPE_INT_N_3
601#endif
602 >;
603
604 // Check if a type is one of the unsigned integer types.
605 template<typename _Tp>
606 using __is_unsigned_integer = __is_one_of<typename remove_cv<_Tp>::type,
607 unsigned char, unsigned short, unsigned int, unsigned long,
608 unsigned long long
609#if defined(__GLIBCXX_TYPE_INT_N_0)
610 , unsigned __GLIBCXX_TYPE_INT_N_0
611#endif
612#if defined(__GLIBCXX_TYPE_INT_N_1)
613 , unsigned __GLIBCXX_TYPE_INT_N_1
614#endif
615#if defined(__GLIBCXX_TYPE_INT_N_2)
616 , unsigned __GLIBCXX_TYPE_INT_N_2
617#endif
618#if defined(__GLIBCXX_TYPE_INT_N_3)
619 , unsigned __GLIBCXX_TYPE_INT_N_3
620#endif
621 >;
622
623
72459cfd
JW
624 // __void_t (std::void_t for C++11)
625 template<typename...> using __void_t = void;
626
89898034
DK
627 // Utility to detect referenceable types ([defns.referenceable]).
628
72459cfd 629 template<typename _Tp, typename = void>
89898034 630 struct __is_referenceable
72459cfd 631 : public false_type
89898034
DK
632 { };
633
72459cfd
JW
634 template<typename _Tp>
635 struct __is_referenceable<_Tp, __void_t<_Tp&>>
89898034
DK
636 : public true_type
637 { };
638
c0ffa2ba 639 // Type properties.
123c516a 640
53dc5044
PC
641 /// is_const
642 template<typename>
643 struct is_const
644 : public false_type { };
645
646 template<typename _Tp>
647 struct is_const<_Tp const>
648 : public true_type { };
33ac58d5 649
53dc5044
PC
650 /// is_volatile
651 template<typename>
652 struct is_volatile
653 : public false_type { };
654
655 template<typename _Tp>
656 struct is_volatile<_Tp volatile>
657 : public true_type { };
658
123c516a
PC
659 /// is_trivial
660 template<typename _Tp>
661 struct is_trivial
662 : public integral_constant<bool, __is_trivial(_Tp)>
608a080c
AP
663 {
664 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
665 "template argument must be a complete class or an unbounded array");
666 };
123c516a 667
f5e523b7
VV
668 // is_trivially_copyable
669 template<typename _Tp>
670 struct is_trivially_copyable
671 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
608a080c
AP
672 {
673 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
674 "template argument must be a complete class or an unbounded array");
675 };
123c516a
PC
676
677 /// is_standard_layout
678 template<typename _Tp>
679 struct is_standard_layout
680 : public integral_constant<bool, __is_standard_layout(_Tp)>
608a080c
AP
681 {
682 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
683 "template argument must be a complete class or an unbounded array");
684 };
123c516a
PC
685
686 /// is_pod
687 // Could use is_standard_layout && is_trivial instead of the builtin.
688 template<typename _Tp>
689 struct is_pod
690 : public integral_constant<bool, __is_pod(_Tp)>
608a080c
AP
691 {
692 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
693 "template argument must be a complete class or an unbounded array");
694 };
123c516a
PC
695
696 /// is_literal_type
697 template<typename _Tp>
698 struct is_literal_type
699 : public integral_constant<bool, __is_literal_type(_Tp)>
608a080c
AP
700 {
701 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
702 "template argument must be a complete class or an unbounded array");
703 };
123c516a 704
53dc5044
PC
705 /// is_empty
706 template<typename _Tp>
707 struct is_empty
708 : public integral_constant<bool, __is_empty(_Tp)>
209ee624 709 { };
53dc5044
PC
710
711 /// is_polymorphic
712 template<typename _Tp>
713 struct is_polymorphic
714 : public integral_constant<bool, __is_polymorphic(_Tp)>
209ee624 715 { };
53dc5044 716
4db7fcb9
ESR
717#if __cplusplus >= 201402L
718#define __cpp_lib_is_final 201402L
719 /// is_final
720 template<typename _Tp>
721 struct is_final
722 : public integral_constant<bool, __is_final(_Tp)>
209ee624 723 { };
4db7fcb9
ESR
724#endif
725
53dc5044
PC
726 /// is_abstract
727 template<typename _Tp>
728 struct is_abstract
729 : public integral_constant<bool, __is_abstract(_Tp)>
209ee624 730 { };
53dc5044 731
123c516a 732 template<typename _Tp,
6a4b1a00 733 bool = is_arithmetic<_Tp>::value>
123c516a
PC
734 struct __is_signed_helper
735 : public false_type { };
736
53dc5044 737 template<typename _Tp>
6a4b1a00
PC
738 struct __is_signed_helper<_Tp, true>
739 : public integral_constant<bool, _Tp(-1) < _Tp(0)>
53dc5044
PC
740 { };
741
123c516a 742 /// is_signed
53dc5044 743 template<typename _Tp>
123c516a 744 struct is_signed
82b12c4b 745 : public __is_signed_helper<_Tp>::type
123c516a
PC
746 { };
747
748 /// is_unsigned
749 template<typename _Tp>
750 struct is_unsigned
f7632193 751 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>
123c516a
PC
752 { };
753
754
c0ffa2ba 755 // Destructible and constructible type properties.
123c516a 756
13901e4b
JW
757 /**
758 * @brief Utility to simplify expressions used in unevaluated operands
759 * @ingroup utilities
760 */
ec26ff5a
JW
761
762 template<typename _Tp, typename _Up = _Tp&&>
763 _Up
764 __declval(int);
765
766 template<typename _Tp>
767 _Tp
768 __declval(long);
769
53dc5044 770 template<typename _Tp>
ec26ff5a 771 auto declval() noexcept -> decltype(__declval<_Tp>(0));
53dc5044 772
123c516a
PC
773 template<typename, unsigned = 0>
774 struct extent;
775
776 template<typename>
777 struct remove_all_extents;
778
779 template<typename _Tp>
780 struct __is_array_known_bounds
781 : public integral_constant<bool, (extent<_Tp>::value > 0)>
53dc5044
PC
782 { };
783
123c516a
PC
784 template<typename _Tp>
785 struct __is_array_unknown_bounds
f7632193 786 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>
53dc5044 787 { };
33ac58d5 788
62fa805f 789 // In N3290 is_destructible does not say anything about function
2c7a09d7 790 // types and abstract types, see LWG 2049. This implementation
62fa805f
DK
791 // describes function types as non-destructible and all complete
792 // object types as destructible, iff the explicit destructor
2c7a09d7 793 // call expression is wellformed.
62fa805f 794 struct __do_is_destructible_impl
123c516a 795 {
62fa805f 796 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
123c516a
PC
797 static true_type __test(int);
798
799 template<typename>
800 static false_type __test(...);
801 };
53dc5044
PC
802
803 template<typename _Tp>
62fa805f
DK
804 struct __is_destructible_impl
805 : public __do_is_destructible_impl
123c516a
PC
806 {
807 typedef decltype(__test<_Tp>(0)) type;
808 };
53dc5044 809
62fa805f
DK
810 template<typename _Tp,
811 bool = __or_<is_void<_Tp>,
812 __is_array_unknown_bounds<_Tp>,
813 is_function<_Tp>>::value,
814 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
815 struct __is_destructible_safe;
816
817 template<typename _Tp>
818 struct __is_destructible_safe<_Tp, false, false>
819 : public __is_destructible_impl<typename
820 remove_all_extents<_Tp>::type>::type
821 { };
822
823 template<typename _Tp>
824 struct __is_destructible_safe<_Tp, true, false>
825 : public false_type { };
826
827 template<typename _Tp>
828 struct __is_destructible_safe<_Tp, false, true>
829 : public true_type { };
830
831 /// is_destructible
832 template<typename _Tp>
833 struct is_destructible
82b12c4b 834 : public __is_destructible_safe<_Tp>::type
608a080c
AP
835 {
836 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
837 "template argument must be a complete class or an unbounded array");
838 };
62fa805f
DK
839
840 // is_nothrow_destructible requires that is_destructible is
841 // satisfied as well. We realize that by mimicing the
842 // implementation of is_destructible but refer to noexcept(expr)
843 // instead of decltype(expr).
844 struct __do_is_nt_destructible_impl
123c516a 845 {
62fa805f 846 template<typename _Tp>
c01f9216
JW
847 static __bool_constant<noexcept(declval<_Tp&>().~_Tp())>
848 __test(int);
123c516a
PC
849
850 template<typename>
851 static false_type __test(...);
852 };
53dc5044 853
53dc5044 854 template<typename _Tp>
62fa805f
DK
855 struct __is_nt_destructible_impl
856 : public __do_is_nt_destructible_impl
123c516a
PC
857 {
858 typedef decltype(__test<_Tp>(0)) type;
859 };
860
861 template<typename _Tp,
862 bool = __or_<is_void<_Tp>,
62fa805f
DK
863 __is_array_unknown_bounds<_Tp>,
864 is_function<_Tp>>::value,
865 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
866 struct __is_nt_destructible_safe;
53dc5044
PC
867
868 template<typename _Tp>
62fa805f
DK
869 struct __is_nt_destructible_safe<_Tp, false, false>
870 : public __is_nt_destructible_impl<typename
871 remove_all_extents<_Tp>::type>::type
123c516a
PC
872 { };
873
53dc5044 874 template<typename _Tp>
62fa805f 875 struct __is_nt_destructible_safe<_Tp, true, false>
123c516a 876 : public false_type { };
53dc5044
PC
877
878 template<typename _Tp>
62fa805f 879 struct __is_nt_destructible_safe<_Tp, false, true>
123c516a
PC
880 : public true_type { };
881
62fa805f 882 /// is_nothrow_destructible
53dc5044 883 template<typename _Tp>
62fa805f 884 struct is_nothrow_destructible
82b12c4b 885 : public __is_nt_destructible_safe<_Tp>::type
608a080c
AP
886 {
887 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
888 "template argument must be a complete class or an unbounded array");
889 };
890
891 template<typename _Tp, typename... _Args>
892 struct __is_constructible_impl
893 : public __bool_constant<__is_constructible(_Tp, _Args...)>
123c516a
PC
894 { };
895
58487c21
JW
896 /// is_constructible
897 template<typename _Tp, typename... _Args>
898 struct is_constructible
608a080c
AP
899 : public __is_constructible_impl<_Tp, _Args...>
900 {
901 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
902 "template argument must be a complete class or an unbounded array");
903 };
4a27a739 904
123c516a 905 /// is_default_constructible
4a27a739 906 template<typename _Tp>
123c516a 907 struct is_default_constructible
608a080c
AP
908 : public __is_constructible_impl<_Tp>::type
909 {
910 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
911 "template argument must be a complete class or an unbounded array");
912 };
c32097d8 913
89898034 914 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
65cee9bd 915 struct __is_copy_constructible_impl;
123c516a 916
65cee9bd 917 template<typename _Tp>
89898034 918 struct __is_copy_constructible_impl<_Tp, false>
65cee9bd
PC
919 : public false_type { };
920
921 template<typename _Tp>
89898034 922 struct __is_copy_constructible_impl<_Tp, true>
608a080c 923 : public __is_constructible_impl<_Tp, const _Tp&>
65cee9bd
PC
924 { };
925
926 /// is_copy_constructible
927 template<typename _Tp>
928 struct is_copy_constructible
929 : public __is_copy_constructible_impl<_Tp>
608a080c
AP
930 {
931 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
932 "template argument must be a complete class or an unbounded array");
933 };
65cee9bd 934
89898034 935 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
65cee9bd
PC
936 struct __is_move_constructible_impl;
937
938 template<typename _Tp>
89898034 939 struct __is_move_constructible_impl<_Tp, false>
65cee9bd
PC
940 : public false_type { };
941
942 template<typename _Tp>
89898034 943 struct __is_move_constructible_impl<_Tp, true>
608a080c 944 : public __is_constructible_impl<_Tp, _Tp&&>
65cee9bd
PC
945 { };
946
947 /// is_move_constructible
948 template<typename _Tp>
949 struct is_move_constructible
950 : public __is_move_constructible_impl<_Tp>
608a080c
AP
951 {
952 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
953 "template argument must be a complete class or an unbounded array");
954 };
65cee9bd
PC
955
956 template<typename _Tp>
957 struct __is_nt_default_constructible_atom
958 : public integral_constant<bool, noexcept(_Tp())>
959 { };
960
961 template<typename _Tp, bool = is_array<_Tp>::value>
962 struct __is_nt_default_constructible_impl;
963
964 template<typename _Tp>
965 struct __is_nt_default_constructible_impl<_Tp, true>
966 : public __and_<__is_array_known_bounds<_Tp>,
967 __is_nt_default_constructible_atom<typename
f7632193 968 remove_all_extents<_Tp>::type>>
65cee9bd
PC
969 { };
970
971 template<typename _Tp>
972 struct __is_nt_default_constructible_impl<_Tp, false>
973 : public __is_nt_default_constructible_atom<_Tp>
974 { };
975
608a080c
AP
976 template<typename _Tp>
977 using __is_nothrow_default_constructible_impl
978 = __and_<__is_constructible_impl<_Tp>,
979 __is_nt_default_constructible_impl<_Tp>>;
980
65cee9bd
PC
981 /// is_nothrow_default_constructible
982 template<typename _Tp>
983 struct is_nothrow_default_constructible
608a080c
AP
984 : public __is_nothrow_default_constructible_impl<_Tp>::type
985 {
986 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
987 "template argument must be a complete class or an unbounded array");
988 };
e4f32cb0
PC
989
990 template<typename _Tp, typename... _Args>
65cee9bd
PC
991 struct __is_nt_constructible_impl
992 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
993 { };
e4f32cb0
PC
994
995 template<typename _Tp, typename _Arg>
65cee9bd
PC
996 struct __is_nt_constructible_impl<_Tp, _Arg>
997 : public integral_constant<bool,
998 noexcept(static_cast<_Tp>(declval<_Arg>()))>
999 { };
1000
1001 template<typename _Tp>
1002 struct __is_nt_constructible_impl<_Tp>
608a080c 1003 : public __is_nothrow_default_constructible_impl<_Tp>
65cee9bd 1004 { };
e4f32cb0 1005
e4f32cb0 1006 template<typename _Tp, typename... _Args>
608a080c
AP
1007 struct __is_nothrow_constructible_impl
1008 : public __and_<__is_constructible_impl<_Tp, _Args...>,
f7632193 1009 __is_nt_constructible_impl<_Tp, _Args...>>
65cee9bd
PC
1010 { };
1011
608a080c
AP
1012 /// is_nothrow_constructible
1013 template<typename _Tp, typename... _Args>
1014 struct is_nothrow_constructible
1015 : public __is_nothrow_constructible_impl<_Tp, _Args...>::type
1016 {
1017 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1018 "template argument must be a complete class or an unbounded array");
1019 };
1020
89898034 1021 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
65cee9bd
PC
1022 struct __is_nothrow_copy_constructible_impl;
1023
1024 template<typename _Tp>
89898034 1025 struct __is_nothrow_copy_constructible_impl<_Tp, false>
65cee9bd
PC
1026 : public false_type { };
1027
1028 template<typename _Tp>
89898034 1029 struct __is_nothrow_copy_constructible_impl<_Tp, true>
608a080c 1030 : public __is_nothrow_constructible_impl<_Tp, const _Tp&>
65cee9bd
PC
1031 { };
1032
1033 /// is_nothrow_copy_constructible
1034 template<typename _Tp>
1035 struct is_nothrow_copy_constructible
608a080c
AP
1036 : public __is_nothrow_copy_constructible_impl<_Tp>::type
1037 {
1038 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1039 "template argument must be a complete class or an unbounded array");
1040 };
65cee9bd 1041
89898034 1042 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
65cee9bd
PC
1043 struct __is_nothrow_move_constructible_impl;
1044
1045 template<typename _Tp>
89898034 1046 struct __is_nothrow_move_constructible_impl<_Tp, false>
65cee9bd
PC
1047 : public false_type { };
1048
1049 template<typename _Tp>
89898034 1050 struct __is_nothrow_move_constructible_impl<_Tp, true>
608a080c 1051 : public __is_nothrow_constructible_impl<_Tp, _Tp&&>
65cee9bd
PC
1052 { };
1053
1054 /// is_nothrow_move_constructible
1055 template<typename _Tp>
1056 struct is_nothrow_move_constructible
608a080c
AP
1057 : public __is_nothrow_move_constructible_impl<_Tp>::type
1058 {
1059 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1060 "template argument must be a complete class or an unbounded array");
1061 };
65cee9bd 1062
f263981a
PC
1063 /// is_assignable
1064 template<typename _Tp, typename _Up>
1065 struct is_assignable
608a080c
AP
1066 : public __bool_constant<__is_assignable(_Tp, _Up)>
1067 {
1068 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1069 "template argument must be a complete class or an unbounded array");
1070 };
f263981a 1071
89898034 1072 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
f263981a
PC
1073 struct __is_copy_assignable_impl;
1074
1075 template<typename _Tp>
89898034 1076 struct __is_copy_assignable_impl<_Tp, false>
f263981a
PC
1077 : public false_type { };
1078
1079 template<typename _Tp>
89898034 1080 struct __is_copy_assignable_impl<_Tp, true>
608a080c 1081 : public __bool_constant<__is_assignable(_Tp&, const _Tp&)>
f263981a
PC
1082 { };
1083
1084 /// is_copy_assignable
1085 template<typename _Tp>
1086 struct is_copy_assignable
608a080c
AP
1087 : public __is_copy_assignable_impl<_Tp>::type
1088 {
1089 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1090 "template argument must be a complete class or an unbounded array");
1091 };
f263981a 1092
89898034 1093 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
f263981a
PC
1094 struct __is_move_assignable_impl;
1095
1096 template<typename _Tp>
89898034 1097 struct __is_move_assignable_impl<_Tp, false>
f263981a
PC
1098 : public false_type { };
1099
1100 template<typename _Tp>
89898034 1101 struct __is_move_assignable_impl<_Tp, true>
608a080c 1102 : public __bool_constant<__is_assignable(_Tp&, _Tp&&)>
f263981a
PC
1103 { };
1104
1105 /// is_move_assignable
1106 template<typename _Tp>
1107 struct is_move_assignable
608a080c
AP
1108 : public __is_move_assignable_impl<_Tp>::type
1109 {
1110 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1111 "template argument must be a complete class or an unbounded array");
1112 };
f263981a
PC
1113
1114 template<typename _Tp, typename _Up>
1115 struct __is_nt_assignable_impl
1116 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1117 { };
1118
f263981a 1119 template<typename _Tp, typename _Up>
608a080c
AP
1120 struct __is_nothrow_assignable_impl
1121 : public __and_<__bool_constant<__is_assignable(_Tp, _Up)>,
f7632193 1122 __is_nt_assignable_impl<_Tp, _Up>>
f263981a
PC
1123 { };
1124
608a080c
AP
1125 /// is_nothrow_assignable
1126 template<typename _Tp, typename _Up>
1127 struct is_nothrow_assignable
1128 : public __is_nothrow_assignable_impl<_Tp, _Up>
1129 {
1130 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1131 "template argument must be a complete class or an unbounded array");
1132 };
1133
89898034 1134 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
f263981a
PC
1135 struct __is_nt_copy_assignable_impl;
1136
1137 template<typename _Tp>
89898034 1138 struct __is_nt_copy_assignable_impl<_Tp, false>
f263981a
PC
1139 : public false_type { };
1140
1141 template<typename _Tp>
89898034 1142 struct __is_nt_copy_assignable_impl<_Tp, true>
608a080c 1143 : public __is_nothrow_assignable_impl<_Tp&, const _Tp&>
f263981a
PC
1144 { };
1145
1146 /// is_nothrow_copy_assignable
1147 template<typename _Tp>
1148 struct is_nothrow_copy_assignable
1149 : public __is_nt_copy_assignable_impl<_Tp>
608a080c
AP
1150 {
1151 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1152 "template argument must be a complete class or an unbounded array");
1153 };
f263981a 1154
89898034 1155 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
f263981a
PC
1156 struct __is_nt_move_assignable_impl;
1157
1158 template<typename _Tp>
89898034 1159 struct __is_nt_move_assignable_impl<_Tp, false>
f263981a
PC
1160 : public false_type { };
1161
1162 template<typename _Tp>
89898034 1163 struct __is_nt_move_assignable_impl<_Tp, true>
608a080c 1164 : public __is_nothrow_assignable_impl<_Tp&, _Tp&&>
f263981a
PC
1165 { };
1166
1167 /// is_nothrow_move_assignable
65cee9bd 1168 template<typename _Tp>
f263981a
PC
1169 struct is_nothrow_move_assignable
1170 : public __is_nt_move_assignable_impl<_Tp>
608a080c
AP
1171 {
1172 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1173 "template argument must be a complete class or an unbounded array");
1174 };
e4f32cb0 1175
f5e523b7
VV
1176 /// is_trivially_constructible
1177 template<typename _Tp, typename... _Args>
1178 struct is_trivially_constructible
c01f9216 1179 : public __bool_constant<__is_trivially_constructible(_Tp, _Args...)>
608a080c
AP
1180 {
1181 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1182 "template argument must be a complete class or an unbounded array");
1183 };
33ac58d5 1184
f5e523b7
VV
1185 /// is_trivially_default_constructible
1186 template<typename _Tp>
1187 struct is_trivially_default_constructible
608a080c
AP
1188 : public __bool_constant<__is_trivially_constructible(_Tp)>
1189 {
1190 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1191 "template argument must be a complete class or an unbounded array");
1192 };
6a9ecd34 1193
f7632193
VV
1194 struct __do_is_implicitly_default_constructible_impl
1195 {
1196 template <typename _Tp>
1197 static void __helper(const _Tp&);
1198
1199 template <typename _Tp>
1200 static true_type __test(const _Tp&,
1201 decltype(__helper<const _Tp&>({}))* = 0);
1202
1203 static false_type __test(...);
1204 };
1205
1206 template<typename _Tp>
1207 struct __is_implicitly_default_constructible_impl
e9029d55
JW
1208 : public __do_is_implicitly_default_constructible_impl
1209 {
1210 typedef decltype(__test(declval<_Tp>())) type;
1211 };
f7632193
VV
1212
1213 template<typename _Tp>
1214 struct __is_implicitly_default_constructible_safe
e9029d55
JW
1215 : public __is_implicitly_default_constructible_impl<_Tp>::type
1216 { };
f7632193
VV
1217
1218 template <typename _Tp>
1219 struct __is_implicitly_default_constructible
608a080c 1220 : public __and_<__is_constructible_impl<_Tp>,
e9029d55
JW
1221 __is_implicitly_default_constructible_safe<_Tp>>
1222 { };
f7632193 1223
b42cc3ca
VV
1224 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1225 struct __is_trivially_copy_constructible_impl;
1226
f5e523b7 1227 template<typename _Tp>
b42cc3ca
VV
1228 struct __is_trivially_copy_constructible_impl<_Tp, false>
1229 : public false_type { };
1230
1231 template<typename _Tp>
1232 struct __is_trivially_copy_constructible_impl<_Tp, true>
608a080c 1233 : public __and_<__is_copy_constructible_impl<_Tp>,
f5e523b7 1234 integral_constant<bool,
f7632193 1235 __is_trivially_constructible(_Tp, const _Tp&)>>
f5e523b7 1236 { };
33ac58d5 1237
608a080c 1238 /// is_trivially_copy_constructible
b42cc3ca
VV
1239 template<typename _Tp>
1240 struct is_trivially_copy_constructible
1241 : public __is_trivially_copy_constructible_impl<_Tp>
608a080c
AP
1242 {
1243 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1244 "template argument must be a complete class or an unbounded array");
1245 };
b42cc3ca
VV
1246
1247 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1248 struct __is_trivially_move_constructible_impl;
1249
f5e523b7 1250 template<typename _Tp>
b42cc3ca
VV
1251 struct __is_trivially_move_constructible_impl<_Tp, false>
1252 : public false_type { };
1253
1254 template<typename _Tp>
1255 struct __is_trivially_move_constructible_impl<_Tp, true>
608a080c 1256 : public __and_<__is_move_constructible_impl<_Tp>,
f5e523b7 1257 integral_constant<bool,
f7632193 1258 __is_trivially_constructible(_Tp, _Tp&&)>>
f5e523b7 1259 { };
6a9ecd34 1260
608a080c 1261 /// is_trivially_move_constructible
b42cc3ca
VV
1262 template<typename _Tp>
1263 struct is_trivially_move_constructible
1264 : public __is_trivially_move_constructible_impl<_Tp>
608a080c
AP
1265 {
1266 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1267 "template argument must be a complete class or an unbounded array");
1268 };
b42cc3ca 1269
f5e523b7
VV
1270 /// is_trivially_assignable
1271 template<typename _Tp, typename _Up>
1272 struct is_trivially_assignable
b42cc3ca 1273 : public __bool_constant<__is_trivially_assignable(_Tp, _Up)>
608a080c
AP
1274 {
1275 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1276 "template argument must be a complete class or an unbounded array");
1277 };
b42cc3ca
VV
1278
1279 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1280 struct __is_trivially_copy_assignable_impl;
1281
f5e523b7 1282 template<typename _Tp>
b42cc3ca
VV
1283 struct __is_trivially_copy_assignable_impl<_Tp, false>
1284 : public false_type { };
1285
1286 template<typename _Tp>
1287 struct __is_trivially_copy_assignable_impl<_Tp, true>
c01f9216 1288 : public __bool_constant<__is_trivially_assignable(_Tp&, const _Tp&)>
f5e523b7 1289 { };
6a9ecd34 1290
608a080c 1291 /// is_trivially_copy_assignable
b42cc3ca
VV
1292 template<typename _Tp>
1293 struct is_trivially_copy_assignable
1294 : public __is_trivially_copy_assignable_impl<_Tp>
608a080c
AP
1295 {
1296 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1297 "template argument must be a complete class or an unbounded array");
1298 };
b42cc3ca
VV
1299
1300 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1301 struct __is_trivially_move_assignable_impl;
1302
f5e523b7 1303 template<typename _Tp>
b42cc3ca
VV
1304 struct __is_trivially_move_assignable_impl<_Tp, false>
1305 : public false_type { };
1306
1307 template<typename _Tp>
1308 struct __is_trivially_move_assignable_impl<_Tp, true>
c01f9216 1309 : public __bool_constant<__is_trivially_assignable(_Tp&, _Tp&&)>
f5e523b7 1310 { };
6a9ecd34 1311
608a080c 1312 /// is_trivially_move_assignable
b42cc3ca
VV
1313 template<typename _Tp>
1314 struct is_trivially_move_assignable
1315 : public __is_trivially_move_assignable_impl<_Tp>
608a080c
AP
1316 {
1317 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1318 "template argument must be a complete class or an unbounded array");
1319 };
b42cc3ca 1320
6a9ecd34
PC
1321 /// is_trivially_destructible
1322 template<typename _Tp>
1323 struct is_trivially_destructible
608a080c 1324 : public __and_<__is_destructible_safe<_Tp>,
c01f9216 1325 __bool_constant<__has_trivial_destructor(_Tp)>>
608a080c
AP
1326 {
1327 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1328 "template argument must be a complete class or an unbounded array");
1329 };
6a9ecd34 1330
e133ace8 1331
123c516a
PC
1332 /// has_virtual_destructor
1333 template<typename _Tp>
1334 struct has_virtual_destructor
1335 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
608a080c
AP
1336 {
1337 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1338 "template argument must be a complete class or an unbounded array");
1339 };
123c516a 1340
33ac58d5 1341
123c516a
PC
1342 // type property queries.
1343
1344 /// alignment_of
1345 template<typename _Tp>
1346 struct alignment_of
608a080c
AP
1347 : public integral_constant<std::size_t, alignof(_Tp)>
1348 {
1349 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1350 "template argument must be a complete class or an unbounded array");
1351 };
33ac58d5 1352
123c516a
PC
1353 /// rank
1354 template<typename>
1355 struct rank
1356 : public integral_constant<std::size_t, 0> { };
33ac58d5 1357
123c516a
PC
1358 template<typename _Tp, std::size_t _Size>
1359 struct rank<_Tp[_Size]>
1360 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1361
1362 template<typename _Tp>
1363 struct rank<_Tp[]>
1364 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1365
1366 /// extent
1367 template<typename, unsigned _Uint>
1368 struct extent
1369 : public integral_constant<std::size_t, 0> { };
33ac58d5 1370
123c516a
PC
1371 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1372 struct extent<_Tp[_Size], _Uint>
1373 : public integral_constant<std::size_t,
1374 _Uint == 0 ? _Size : extent<_Tp,
1375 _Uint - 1>::value>
1376 { };
1377
1378 template<typename _Tp, unsigned _Uint>
1379 struct extent<_Tp[], _Uint>
1380 : public integral_constant<std::size_t,
1381 _Uint == 0 ? 0 : extent<_Tp,
1382 _Uint - 1>::value>
1383 { };
1384
1385
c0ffa2ba 1386 // Type relations.
123c516a
PC
1387
1388 /// is_same
1389 template<typename, typename>
1390 struct is_same
1391 : public false_type { };
1392
1393 template<typename _Tp>
1394 struct is_same<_Tp, _Tp>
1395 : public true_type { };
b0302c68 1396
939759fc 1397 /// is_base_of
e133ace8
PC
1398 template<typename _Base, typename _Derived>
1399 struct is_base_of
1400 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1401 { };
1402
297f34d7 1403 template<typename _From, typename _To,
123c516a
PC
1404 bool = __or_<is_void<_From>, is_function<_To>,
1405 is_array<_To>>::value>
297f34d7 1406 struct __is_convertible_helper
8df27fcb
JW
1407 {
1408 typedef typename is_void<_To>::type type;
8df27fcb 1409 };
297f34d7 1410
cc28d234
JW
1411#pragma GCC diagnostic push
1412#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
e133ace8 1413 template<typename _From, typename _To>
b0302c68 1414 class __is_convertible_helper<_From, _To, false>
e133ace8 1415 {
8df27fcb
JW
1416 template<typename _To1>
1417 static void __test_aux(_To1) noexcept;
8e7d962a 1418
82b12c4b
FD
1419 template<typename _From1, typename _To1,
1420 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1421 static true_type
8e7d962a
PC
1422 __test(int);
1423
1424 template<typename, typename>
82b12c4b
FD
1425 static false_type
1426 __test(...);
297f34d7 1427
e133ace8 1428 public:
82b12c4b 1429 typedef decltype(__test<_From, _To>(0)) type;
e133ace8 1430 };
cc28d234 1431#pragma GCC diagnostic pop
82b12c4b 1432
b0302c68 1433 /// is_convertible
e133ace8
PC
1434 template<typename _From, typename _To>
1435 struct is_convertible
82b12c4b 1436 : public __is_convertible_helper<_From, _To>::type
e133ace8
PC
1437 { };
1438
608a080c 1439 template<typename _From, typename _To,
ed99e818
JW
1440 bool = __or_<is_void<_From>, is_function<_To>,
1441 is_array<_To>>::value>
1442 struct __is_nt_convertible_helper
1443 : is_void<_To>
1444 { };
1445
cc28d234
JW
1446#pragma GCC diagnostic push
1447#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
ed99e818
JW
1448 template<typename _From, typename _To>
1449 class __is_nt_convertible_helper<_From, _To, false>
1450 {
1451 template<typename _To1>
1452 static void __test_aux(_To1) noexcept;
1453
1454 template<typename _From1, typename _To1>
ce9f305e
JW
1455 static
1456 __bool_constant<noexcept(__test_aux<_To1>(std::declval<_From1>()))>
ed99e818
JW
1457 __test(int);
1458
1459 template<typename, typename>
1460 static false_type
1461 __test(...);
1462
1463 public:
1464 using type = decltype(__test<_From, _To>(0));
1465 };
cc28d234 1466#pragma GCC diagnostic pop
ed99e818 1467
ce9f305e
JW
1468 // is_nothrow_convertible for C++11
1469 template<typename _From, typename _To>
1470 struct __is_nothrow_convertible
1471 : public __is_nt_convertible_helper<_From, _To>::type
1472 { };
1473
1474#if __cplusplus > 201703L
8df27fcb
JW
1475 /// is_nothrow_convertible
1476 template<typename _From, typename _To>
1477 struct is_nothrow_convertible
ed99e818 1478 : public __is_nt_convertible_helper<_From, _To>::type
8df27fcb
JW
1479 { };
1480
1481 /// is_nothrow_convertible_v
1482 template<typename _From, typename _To>
1483 inline constexpr bool is_nothrow_convertible_v
1484 = is_nothrow_convertible<_From, _To>::value;
1485#endif // C++2a
fd735b6a 1486
c0ffa2ba 1487 // Const-volatile modifications.
7b50cdef 1488
123c516a 1489 /// remove_const
7b50cdef 1490 template<typename _Tp>
123c516a
PC
1491 struct remove_const
1492 { typedef _Tp type; };
7b50cdef 1493
123c516a
PC
1494 template<typename _Tp>
1495 struct remove_const<_Tp const>
1496 { typedef _Tp type; };
33ac58d5 1497
123c516a
PC
1498 /// remove_volatile
1499 template<typename _Tp>
1500 struct remove_volatile
1501 { typedef _Tp type; };
7b50cdef 1502
123c516a
PC
1503 template<typename _Tp>
1504 struct remove_volatile<_Tp volatile>
1505 { typedef _Tp type; };
33ac58d5 1506
123c516a
PC
1507 /// remove_cv
1508 template<typename _Tp>
1509 struct remove_cv
1510 {
1511 typedef typename
1512 remove_const<typename remove_volatile<_Tp>::type>::type type;
1513 };
33ac58d5 1514
123c516a
PC
1515 /// add_const
1516 template<typename _Tp>
1517 struct add_const
1518 { typedef _Tp const type; };
33ac58d5 1519
123c516a
PC
1520 /// add_volatile
1521 template<typename _Tp>
1522 struct add_volatile
1523 { typedef _Tp volatile type; };
33ac58d5 1524
123c516a
PC
1525 /// add_cv
1526 template<typename _Tp>
1527 struct add_cv
1528 {
1529 typedef typename
1530 add_const<typename add_volatile<_Tp>::type>::type type;
1531 };
7b50cdef 1532
4457e88c 1533#if __cplusplus > 201103L
a15f7cb8
ESR
1534
1535#define __cpp_lib_transformation_trait_aliases 201304
1536
4457e88c
JW
1537 /// Alias template for remove_const
1538 template<typename _Tp>
1539 using remove_const_t = typename remove_const<_Tp>::type;
1540
1541 /// Alias template for remove_volatile
1542 template<typename _Tp>
1543 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1544
1545 /// Alias template for remove_cv
1546 template<typename _Tp>
1547 using remove_cv_t = typename remove_cv<_Tp>::type;
1548
1549 /// Alias template for add_const
1550 template<typename _Tp>
1551 using add_const_t = typename add_const<_Tp>::type;
1552
1553 /// Alias template for add_volatile
1554 template<typename _Tp>
1555 using add_volatile_t = typename add_volatile<_Tp>::type;
1556
1557 /// Alias template for add_cv
1558 template<typename _Tp>
1559 using add_cv_t = typename add_cv<_Tp>::type;
1560#endif
7b50cdef 1561
123c516a 1562 // Reference transformations.
7b50cdef 1563
123c516a
PC
1564 /// remove_reference
1565 template<typename _Tp>
1566 struct remove_reference
1567 { typedef _Tp type; };
7b50cdef 1568
123c516a
PC
1569 template<typename _Tp>
1570 struct remove_reference<_Tp&>
1571 { typedef _Tp type; };
7b50cdef 1572
123c516a
PC
1573 template<typename _Tp>
1574 struct remove_reference<_Tp&&>
1575 { typedef _Tp type; };
1576
89898034 1577 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
123c516a
PC
1578 struct __add_lvalue_reference_helper
1579 { typedef _Tp type; };
7b50cdef 1580
5e108459 1581 template<typename _Tp>
89898034 1582 struct __add_lvalue_reference_helper<_Tp, true>
123c516a 1583 { typedef _Tp& type; };
5e108459 1584
123c516a 1585 /// add_lvalue_reference
5e108459 1586 template<typename _Tp>
123c516a
PC
1587 struct add_lvalue_reference
1588 : public __add_lvalue_reference_helper<_Tp>
1589 { };
1590
89898034 1591 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
123c516a
PC
1592 struct __add_rvalue_reference_helper
1593 { typedef _Tp type; };
5e108459
PC
1594
1595 template<typename _Tp>
123c516a
PC
1596 struct __add_rvalue_reference_helper<_Tp, true>
1597 { typedef _Tp&& type; };
5e108459 1598
123c516a 1599 /// add_rvalue_reference
5e108459 1600 template<typename _Tp>
123c516a
PC
1601 struct add_rvalue_reference
1602 : public __add_rvalue_reference_helper<_Tp>
1603 { };
5e108459 1604
4457e88c
JW
1605#if __cplusplus > 201103L
1606 /// Alias template for remove_reference
1607 template<typename _Tp>
1608 using remove_reference_t = typename remove_reference<_Tp>::type;
1609
1610 /// Alias template for add_lvalue_reference
1611 template<typename _Tp>
1612 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1613
1614 /// Alias template for add_rvalue_reference
1615 template<typename _Tp>
1616 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1617#endif
7b50cdef 1618
c0ffa2ba 1619 // Sign modifications.
123c516a 1620
7b50cdef
BK
1621 // Utility for constructing identically cv-qualified types.
1622 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1623 struct __cv_selector;
1624
1625 template<typename _Unqualified>
1626 struct __cv_selector<_Unqualified, false, false>
1627 { typedef _Unqualified __type; };
1628
1629 template<typename _Unqualified>
1630 struct __cv_selector<_Unqualified, false, true>
1631 { typedef volatile _Unqualified __type; };
1632
1633 template<typename _Unqualified>
1634 struct __cv_selector<_Unqualified, true, false>
1635 { typedef const _Unqualified __type; };
1636
1637 template<typename _Unqualified>
1638 struct __cv_selector<_Unqualified, true, true>
1639 { typedef const volatile _Unqualified __type; };
1640
1641 template<typename _Qualified, typename _Unqualified,
1642 bool _IsConst = is_const<_Qualified>::value,
1643 bool _IsVol = is_volatile<_Qualified>::value>
b0302c68 1644 class __match_cv_qualifiers
7b50cdef 1645 {
7b50cdef
BK
1646 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1647
1648 public:
33ac58d5 1649 typedef typename __match::__type __type;
7b50cdef
BK
1650 };
1651
7b50cdef
BK
1652 // Utility for finding the unsigned versions of signed integral types.
1653 template<typename _Tp>
e133ace8
PC
1654 struct __make_unsigned
1655 { typedef _Tp __type; };
7b50cdef
BK
1656
1657 template<>
1658 struct __make_unsigned<char>
1659 { typedef unsigned char __type; };
1660
1661 template<>
1662 struct __make_unsigned<signed char>
1663 { typedef unsigned char __type; };
1664
7b50cdef
BK
1665 template<>
1666 struct __make_unsigned<short>
1667 { typedef unsigned short __type; };
1668
1669 template<>
1670 struct __make_unsigned<int>
1671 { typedef unsigned int __type; };
1672
1673 template<>
1674 struct __make_unsigned<long>
1675 { typedef unsigned long __type; };
1676
1677 template<>
1678 struct __make_unsigned<long long>
1679 { typedef unsigned long long __type; };
1680
78a7c317
DD
1681#if defined(__GLIBCXX_TYPE_INT_N_0)
1682 template<>
1683 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1684 { typedef unsigned __GLIBCXX_TYPE_INT_N_0 __type; };
1685#endif
1686#if defined(__GLIBCXX_TYPE_INT_N_1)
1687 template<>
1688 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1689 { typedef unsigned __GLIBCXX_TYPE_INT_N_1 __type; };
1690#endif
1691#if defined(__GLIBCXX_TYPE_INT_N_2)
6d585f01 1692 template<>
78a7c317
DD
1693 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1694 { typedef unsigned __GLIBCXX_TYPE_INT_N_2 __type; };
1695#endif
1696#if defined(__GLIBCXX_TYPE_INT_N_3)
1697 template<>
1698 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1699 { typedef unsigned __GLIBCXX_TYPE_INT_N_3 __type; };
6d585f01
PC
1700#endif
1701
7b50cdef 1702 // Select between integral and enum: not possible to be both.
33ac58d5 1703 template<typename _Tp,
7b50cdef 1704 bool _IsInt = is_integral<_Tp>::value,
7b50cdef 1705 bool _IsEnum = is_enum<_Tp>::value>
b0302c68
PC
1706 class __make_unsigned_selector;
1707
7b50cdef 1708 template<typename _Tp>
b0302c68 1709 class __make_unsigned_selector<_Tp, true, false>
7b50cdef 1710 {
22f1f4c7
JW
1711 using __unsigned_type
1712 = typename __make_unsigned<typename remove_cv<_Tp>::type>::__type;
7b50cdef
BK
1713
1714 public:
22f1f4c7
JW
1715 using __type
1716 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
7b50cdef
BK
1717 };
1718
22f1f4c7
JW
1719 class __make_unsigned_selector_base
1720 {
1721 protected:
1722 template<typename...> struct _List { };
1723
1724 template<typename _Tp, typename... _Up>
1725 struct _List<_Tp, _Up...> : _List<_Up...>
1726 { static constexpr size_t __size = sizeof(_Tp); };
1727
1728 template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
1729 struct __select;
1730
1731 template<size_t _Sz, typename _Uint, typename... _UInts>
1732 struct __select<_Sz, _List<_Uint, _UInts...>, true>
1733 { using __type = _Uint; };
1734
1735 template<size_t _Sz, typename _Uint, typename... _UInts>
1736 struct __select<_Sz, _List<_Uint, _UInts...>, false>
1737 : __select<_Sz, _List<_UInts...>>
1738 { };
1739 };
1740
1741 // Choose unsigned integer type with the smallest rank and same size as _Tp
7b50cdef 1742 template<typename _Tp>
b0302c68 1743 class __make_unsigned_selector<_Tp, false, true>
22f1f4c7 1744 : __make_unsigned_selector_base
7b50cdef 1745 {
a0230468 1746 // With -fshort-enums, an enum may be as small as a char.
22f1f4c7
JW
1747 using _UInts = _List<unsigned char, unsigned short, unsigned int,
1748 unsigned long, unsigned long long>;
1749
1750 using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
73d81d3a 1751
7b50cdef 1752 public:
22f1f4c7
JW
1753 using __type
1754 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1755 };
1756
c124af93
TH
1757 // wchar_t, char8_t, char16_t and char32_t are integral types but are
1758 // neither signed integer types nor unsigned integer types, so must be
22f1f4c7
JW
1759 // transformed to the unsigned integer type with the smallest rank.
1760 // Use the partial specialization for enumeration types to do that.
1761#if defined(_GLIBCXX_USE_WCHAR_T)
1762 template<>
1763 struct __make_unsigned<wchar_t>
1764 {
1765 using __type
1766 = typename __make_unsigned_selector<wchar_t, false, true>::__type;
1767 };
1768#endif
1769
c124af93
TH
1770#ifdef _GLIBCXX_USE_CHAR8_T
1771 template<>
1772 struct __make_unsigned<char8_t>
1773 {
1774 using __type
1775 = typename __make_unsigned_selector<char8_t, false, true>::__type;
1776 };
1777#endif
1778
22f1f4c7
JW
1779 template<>
1780 struct __make_unsigned<char16_t>
1781 {
1782 using __type
1783 = typename __make_unsigned_selector<char16_t, false, true>::__type;
1784 };
1785
1786 template<>
1787 struct __make_unsigned<char32_t>
1788 {
1789 using __type
1790 = typename __make_unsigned_selector<char32_t, false, true>::__type;
7b50cdef
BK
1791 };
1792
7b50cdef
BK
1793 // Given an integral/enum type, return the corresponding unsigned
1794 // integer type.
5b9daa7e
BK
1795 // Primary template.
1796 /// make_unsigned
7b50cdef 1797 template<typename _Tp>
33ac58d5 1798 struct make_unsigned
7b50cdef
BK
1799 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1800
1801 // Integral, but don't define.
1802 template<>
1803 struct make_unsigned<bool>;
1804
1805
1806 // Utility for finding the signed versions of unsigned integral types.
1807 template<typename _Tp>
e133ace8
PC
1808 struct __make_signed
1809 { typedef _Tp __type; };
7b50cdef
BK
1810
1811 template<>
1812 struct __make_signed<char>
1813 { typedef signed char __type; };
1814
1815 template<>
1816 struct __make_signed<unsigned char>
1817 { typedef signed char __type; };
1818
7b50cdef
BK
1819 template<>
1820 struct __make_signed<unsigned short>
1821 { typedef signed short __type; };
1822
1823 template<>
1824 struct __make_signed<unsigned int>
1825 { typedef signed int __type; };
1826
1827 template<>
1828 struct __make_signed<unsigned long>
1829 { typedef signed long __type; };
1830
1831 template<>
1832 struct __make_signed<unsigned long long>
1833 { typedef signed long long __type; };
1834
78a7c317
DD
1835#if defined(__GLIBCXX_TYPE_INT_N_0)
1836 template<>
1837 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
1838 { typedef __GLIBCXX_TYPE_INT_N_0 __type; };
1839#endif
1840#if defined(__GLIBCXX_TYPE_INT_N_1)
1841 template<>
1842 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
1843 { typedef __GLIBCXX_TYPE_INT_N_1 __type; };
1844#endif
1845#if defined(__GLIBCXX_TYPE_INT_N_2)
1846 template<>
1847 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
1848 { typedef __GLIBCXX_TYPE_INT_N_2 __type; };
1849#endif
1850#if defined(__GLIBCXX_TYPE_INT_N_3)
6d585f01 1851 template<>
78a7c317
DD
1852 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
1853 { typedef __GLIBCXX_TYPE_INT_N_3 __type; };
6d585f01
PC
1854#endif
1855
fb8ffd10 1856 // Select between integral and enum: not possible to be both.
33ac58d5 1857 template<typename _Tp,
7b50cdef 1858 bool _IsInt = is_integral<_Tp>::value,
7b50cdef 1859 bool _IsEnum = is_enum<_Tp>::value>
b0302c68
PC
1860 class __make_signed_selector;
1861
7b50cdef 1862 template<typename _Tp>
b0302c68 1863 class __make_signed_selector<_Tp, true, false>
7b50cdef 1864 {
22f1f4c7
JW
1865 using __signed_type
1866 = typename __make_signed<typename remove_cv<_Tp>::type>::__type;
7b50cdef
BK
1867
1868 public:
22f1f4c7
JW
1869 using __type
1870 = typename __match_cv_qualifiers<_Tp, __signed_type>::__type;
7b50cdef
BK
1871 };
1872
22f1f4c7 1873 // Choose signed integer type with the smallest rank and same size as _Tp
7b50cdef 1874 template<typename _Tp>
b0302c68 1875 class __make_signed_selector<_Tp, false, true>
7b50cdef 1876 {
73d81d3a 1877 typedef typename __make_unsigned_selector<_Tp>::__type __unsigned_type;
7b50cdef
BK
1878
1879 public:
73d81d3a 1880 typedef typename __make_signed_selector<__unsigned_type>::__type __type;
7b50cdef
BK
1881 };
1882
22f1f4c7 1883 // wchar_t, char16_t and char32_t are integral types but are neither
d4b695e4 1884 // signed integer types nor unsigned integer types, so must be
22f1f4c7
JW
1885 // transformed to the signed integer type with the smallest rank.
1886 // Use the partial specialization for enumeration types to do that.
1887#if defined(_GLIBCXX_USE_WCHAR_T)
1888 template<>
1889 struct __make_signed<wchar_t>
1890 {
1891 using __type
1892 = typename __make_signed_selector<wchar_t, false, true>::__type;
1893 };
1894#endif
1895
c124af93
TH
1896#if defined(_GLIBCXX_USE_CHAR8_T)
1897 template<>
1898 struct __make_signed<char8_t>
1899 {
1900 using __type
1901 = typename __make_signed_selector<char8_t, false, true>::__type;
1902 };
1903#endif
1904
22f1f4c7
JW
1905 template<>
1906 struct __make_signed<char16_t>
1907 {
1908 using __type
1909 = typename __make_signed_selector<char16_t, false, true>::__type;
1910 };
1911
1912 template<>
1913 struct __make_signed<char32_t>
1914 {
1915 using __type
1916 = typename __make_signed_selector<char32_t, false, true>::__type;
1917 };
1918
7b50cdef
BK
1919 // Given an integral/enum type, return the corresponding signed
1920 // integer type.
5b9daa7e
BK
1921 // Primary template.
1922 /// make_signed
7b50cdef 1923 template<typename _Tp>
33ac58d5 1924 struct make_signed
7b50cdef
BK
1925 { typedef typename __make_signed_selector<_Tp>::__type type; };
1926
1927 // Integral, but don't define.
1928 template<>
1929 struct make_signed<bool>;
cfa9a96b 1930
4457e88c
JW
1931#if __cplusplus > 201103L
1932 /// Alias template for make_signed
1933 template<typename _Tp>
1934 using make_signed_t = typename make_signed<_Tp>::type;
1935
1936 /// Alias template for make_unsigned
1937 template<typename _Tp>
1938 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1939#endif
123c516a 1940
c0ffa2ba 1941 // Array modifications.
123c516a
PC
1942
1943 /// remove_extent
1944 template<typename _Tp>
1945 struct remove_extent
1946 { typedef _Tp type; };
1947
1948 template<typename _Tp, std::size_t _Size>
1949 struct remove_extent<_Tp[_Size]>
1950 { typedef _Tp type; };
1951
1952 template<typename _Tp>
1953 struct remove_extent<_Tp[]>
1954 { typedef _Tp type; };
1955
1956 /// remove_all_extents
1957 template<typename _Tp>
1958 struct remove_all_extents
1959 { typedef _Tp type; };
1960
1961 template<typename _Tp, std::size_t _Size>
1962 struct remove_all_extents<_Tp[_Size]>
1963 { typedef typename remove_all_extents<_Tp>::type type; };
1964
1965 template<typename _Tp>
1966 struct remove_all_extents<_Tp[]>
1967 { typedef typename remove_all_extents<_Tp>::type type; };
1968
4457e88c
JW
1969#if __cplusplus > 201103L
1970 /// Alias template for remove_extent
1971 template<typename _Tp>
1972 using remove_extent_t = typename remove_extent<_Tp>::type;
1973
1974 /// Alias template for remove_all_extents
1975 template<typename _Tp>
1976 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1977#endif
123c516a 1978
c0ffa2ba 1979 // Pointer modifications.
123c516a
PC
1980
1981 template<typename _Tp, typename>
1982 struct __remove_pointer_helper
1983 { typedef _Tp type; };
1984
1985 template<typename _Tp, typename _Up>
1986 struct __remove_pointer_helper<_Tp, _Up*>
1987 { typedef _Up type; };
1988
1989 /// remove_pointer
1990 template<typename _Tp>
1991 struct remove_pointer
1992 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1993 { };
1994
1995 /// add_pointer
89898034
DK
1996 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1997 is_void<_Tp>>::value>
1998 struct __add_pointer_helper
1999 { typedef _Tp type; };
2000
123c516a 2001 template<typename _Tp>
89898034 2002 struct __add_pointer_helper<_Tp, true>
123c516a
PC
2003 { typedef typename remove_reference<_Tp>::type* type; };
2004
89898034 2005 template<typename _Tp>
33ac58d5 2006 struct add_pointer
89898034
DK
2007 : public __add_pointer_helper<_Tp>
2008 { };
2009
4457e88c
JW
2010#if __cplusplus > 201103L
2011 /// Alias template for remove_pointer
2012 template<typename _Tp>
2013 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2014
2015 /// Alias template for add_pointer
2016 template<typename _Tp>
2017 using add_pointer_t = typename add_pointer<_Tp>::type;
2018#endif
123c516a
PC
2019
2020 template<std::size_t _Len>
2021 struct __aligned_storage_msa
33ac58d5 2022 {
123c516a
PC
2023 union __type
2024 {
2025 unsigned char __data[_Len];
33ac58d5 2026 struct __attribute__((__aligned__)) { } __align;
123c516a
PC
2027 };
2028 };
2029
2030 /**
2031 * @brief Alignment type.
2032 *
2033 * The value of _Align is a default-alignment which shall be the
2034 * most stringent alignment requirement for any C++ object type
2035 * whose size is no greater than _Len (3.9). The member typedef
2036 * type shall be a POD type suitable for use as uninitialized
2037 * storage for any object whose size is at most _Len and whose
2038 * alignment is a divisor of _Align.
2039 */
2040 template<std::size_t _Len, std::size_t _Align =
2041 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2042 struct aligned_storage
33ac58d5 2043 {
123c516a
PC
2044 union type
2045 {
2046 unsigned char __data[_Len];
33ac58d5 2047 struct __attribute__((__aligned__((_Align)))) { } __align;
123c516a
PC
2048 };
2049 };
2050
d3718027
RS
2051 template <typename... _Types>
2052 struct __strictest_alignment
2053 {
2054 static const size_t _S_alignment = 0;
2055 static const size_t _S_size = 0;
2056 };
2057
2058 template <typename _Tp, typename... _Types>
2059 struct __strictest_alignment<_Tp, _Types...>
2060 {
2061 static const size_t _S_alignment =
2062 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2063 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2064 static const size_t _S_size =
2065 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2066 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2067 };
2068
2069 /**
2070 * @brief Provide aligned storage for types.
2071 *
2072 * [meta.trans.other]
2073 *
2074 * Provides aligned storage for any of the provided types of at
2075 * least size _Len.
2076 *
2077 * @see aligned_storage
2078 */
2079 template <size_t _Len, typename... _Types>
2080 struct aligned_union
2081 {
2082 private:
2083 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2084
2085 using __strictest = __strictest_alignment<_Types...>;
2086 static const size_t _S_len = _Len > __strictest::_S_size
2087 ? _Len : __strictest::_S_size;
2088 public:
2089 /// The value of the strictest alignment of _Types.
2090 static const size_t alignment_value = __strictest::_S_alignment;
2091 /// The storage.
2092 typedef typename aligned_storage<_S_len, alignment_value>::type type;
2093 };
2094
2095 template <size_t _Len, typename... _Types>
2096 const size_t aligned_union<_Len, _Types...>::alignment_value;
123c516a
PC
2097
2098 // Decay trait for arrays and functions, used for perfect forwarding
2099 // in make_pair, make_tuple, etc.
33ac58d5 2100 template<typename _Up,
123c516a 2101 bool _IsArray = is_array<_Up>::value,
33ac58d5 2102 bool _IsFunction = is_function<_Up>::value>
123c516a
PC
2103 struct __decay_selector;
2104
2105 // NB: DR 705.
33ac58d5 2106 template<typename _Up>
123c516a
PC
2107 struct __decay_selector<_Up, false, false>
2108 { typedef typename remove_cv<_Up>::type __type; };
2109
33ac58d5 2110 template<typename _Up>
123c516a
PC
2111 struct __decay_selector<_Up, true, false>
2112 { typedef typename remove_extent<_Up>::type* __type; };
2113
33ac58d5 2114 template<typename _Up>
123c516a
PC
2115 struct __decay_selector<_Up, false, true>
2116 { typedef typename add_pointer<_Up>::type __type; };
2117
2118 /// decay
33ac58d5
JW
2119 template<typename _Tp>
2120 class decay
2121 {
123c516a
PC
2122 typedef typename remove_reference<_Tp>::type __remove_type;
2123
2124 public:
2125 typedef typename __decay_selector<__remove_type>::__type type;
2126 };
2127
2128 template<typename _Tp>
2129 class reference_wrapper;
2130
2131 // Helper which adds a reference to a type when given a reference_wrapper
2132 template<typename _Tp>
2133 struct __strip_reference_wrapper
2134 {
2135 typedef _Tp __type;
2136 };
2137
2138 template<typename _Tp>
2139 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2140 {
2141 typedef _Tp& __type;
2142 };
2143
123c516a
PC
2144 template<typename _Tp>
2145 struct __decay_and_strip
2146 {
2147 typedef typename __strip_reference_wrapper<
2148 typename decay<_Tp>::type>::__type __type;
2149 };
2150
2151
123c516a 2152 // Primary template.
13901e4b 2153 /// Define a member typedef @c type only if a boolean constant is true.
123c516a 2154 template<bool, typename _Tp = void>
33ac58d5 2155 struct enable_if
123c516a
PC
2156 { };
2157
2158 // Partial specialization for true.
2159 template<typename _Tp>
2160 struct enable_if<true, _Tp>
2161 { typedef _Tp type; };
2162
23df8534
JW
2163 template<typename... _Cond>
2164 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
123c516a 2165
123c516a 2166 // Primary template.
13901e4b 2167 /// Define a member typedef @c type to one of two argument types.
123c516a
PC
2168 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2169 struct conditional
2170 { typedef _Iftrue type; };
2171
2172 // Partial specialization for false.
2173 template<typename _Iftrue, typename _Iffalse>
2174 struct conditional<false, _Iftrue, _Iffalse>
2175 { typedef _Iffalse type; };
2176
5b9daa7e 2177 /// common_type
cfa9a96b
CF
2178 template<typename... _Tp>
2179 struct common_type;
2180
c0ffa2ba 2181 // Sfinae-friendly common_type implementation:
b3618b71
DK
2182
2183 struct __do_common_type_impl
2184 {
2185 template<typename _Tp, typename _Up>
f61a12b3
JW
2186 using __cond_t
2187 = decltype(true ? std::declval<_Tp>() : std::declval<_Up>());
2188
2189 template<typename _Tp, typename _Up>
2190 static __success_type<typename decay<__cond_t<_Tp, _Up>>::type>
2191 _S_test(int);
b3618b71
DK
2192
2193 template<typename, typename>
f61a12b3
JW
2194 static __failure_type
2195 _S_test(...);
b3618b71
DK
2196 };
2197
f61a12b3
JW
2198 // If sizeof...(T) is zero, there shall be no member type.
2199 template<>
2200 struct common_type<>
2201 { };
b3618b71 2202
f61a12b3
JW
2203 // If sizeof...(T) is one, the same type, if any, as common_type_t<T0, T0>.
2204 template<typename _Tp0>
2205 struct common_type<_Tp0>
2206 : public common_type<_Tp0, _Tp0>
2207 { };
b3618b71 2208
f61a12b3
JW
2209 // If sizeof...(T) is two, ...
2210 template<typename _Tp1, typename _Tp2,
2211 typename _Dp1 = typename decay<_Tp1>::type,
2212 typename _Dp2 = typename decay<_Tp2>::type>
2213 struct __common_type_impl
b3618b71 2214 {
f61a12b3
JW
2215 // If is_same_v<T1, D1> is false or is_same_v<T2, D2> is false,
2216 // let C denote the same type, if any, as common_type_t<D1, D2>.
2217 using type = common_type<_Dp1, _Dp2>;
b3618b71
DK
2218 };
2219
f61a12b3
JW
2220 template<typename _Tp1, typename _Tp2>
2221 struct __common_type_impl<_Tp1, _Tp2, _Tp1, _Tp2>
2222 : private __do_common_type_impl
b3618b71 2223 {
f61a12b3
JW
2224 // Otherwise, if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2225 // denotes a valid type, let C denote that type.
2226 using type = decltype(_S_test<_Tp1, _Tp2>(0));
b3618b71
DK
2227 };
2228
f61a12b3
JW
2229 // If sizeof...(T) is two, ...
2230 template<typename _Tp1, typename _Tp2>
2231 struct common_type<_Tp1, _Tp2>
2232 : public __common_type_impl<_Tp1, _Tp2>::type
2233 { };
b3618b71 2234
f61a12b3
JW
2235 template<typename...>
2236 struct __common_type_pack
373c726e
JW
2237 { };
2238
f61a12b3
JW
2239 template<typename, typename, typename = void>
2240 struct __common_type_fold;
2241
2242 // If sizeof...(T) is greater than two, ...
2243 template<typename _Tp1, typename _Tp2, typename... _Rp>
2244 struct common_type<_Tp1, _Tp2, _Rp...>
2245 : public __common_type_fold<common_type<_Tp1, _Tp2>,
2246 __common_type_pack<_Rp...>>
373c726e 2247 { };
cfa9a96b 2248
f61a12b3
JW
2249 // Let C denote the same type, if any, as common_type_t<T1, T2>.
2250 // If there is such a type C, type shall denote the same type, if any,
2251 // as common_type_t<C, R...>.
2252 template<typename _CTp, typename... _Rp>
2253 struct __common_type_fold<_CTp, __common_type_pack<_Rp...>,
2254 __void_t<typename _CTp::type>>
2255 : public common_type<typename _CTp::type, _Rp...>
b3618b71 2256 { };
cfa9a96b 2257
f61a12b3
JW
2258 // Otherwise, there shall be no member type.
2259 template<typename _CTp, typename _Rp>
2260 struct __common_type_fold<_CTp, _Rp, void>
b3618b71 2261 { };
7274deff 2262
3c26b759
JW
2263 template<typename _Tp, bool = is_enum<_Tp>::value>
2264 struct __underlying_type_impl
2265 {
2266 using type = __underlying_type(_Tp);
2267 };
2268
2269 template<typename _Tp>
2270 struct __underlying_type_impl<_Tp, false>
2271 { };
2272
13901e4b 2273 /// The underlying type of an enum.
a47407f6
PC
2274 template<typename _Tp>
2275 struct underlying_type
3c26b759
JW
2276 : public __underlying_type_impl<_Tp>
2277 { };
123c516a 2278
7274deff
PC
2279 template<typename _Tp>
2280 struct __declval_protector
2281 {
2282 static const bool __stop = false;
7274deff
PC
2283 };
2284
2285 template<typename _Tp>
ec26ff5a 2286 auto declval() noexcept -> decltype(__declval<_Tp>(0))
7274deff
PC
2287 {
2288 static_assert(__declval_protector<_Tp>::__stop,
2289 "declval() must not be used!");
ec26ff5a 2290 return __declval<_Tp>(0);
7274deff 2291 }
1041daba 2292
6791489e
JW
2293 // __remove_cvref_t (std::remove_cvref_t for C++11).
2294 template<typename _Tp>
2295 using __remove_cvref_t
2296 = typename remove_cv<typename remove_reference<_Tp>::type>::type;
2297
be7f7822
JW
2298 /// result_of
2299 template<typename _Signature>
2300 class result_of;
2301
c0ffa2ba 2302 // Sfinae-friendly result_of implementation:
83ddb39f 2303
a15f7cb8
ESR
2304#define __cpp_lib_result_of_sfinae 201210
2305
93e95400
JW
2306 struct __invoke_memfun_ref { };
2307 struct __invoke_memfun_deref { };
2308 struct __invoke_memobj_ref { };
2309 struct __invoke_memobj_deref { };
2310 struct __invoke_other { };
2311
2312 // Associate a tag type with a specialization of __success_type.
2313 template<typename _Tp, typename _Tag>
2314 struct __result_of_success : __success_type<_Tp>
2315 { using __invoke_type = _Tag; };
2316
83ddb39f
DK
2317 // [func.require] paragraph 1 bullet 1:
2318 struct __result_of_memfun_ref_impl
2319 {
2320 template<typename _Fp, typename _Tp1, typename... _Args>
93e95400 2321 static __result_of_success<decltype(
83ddb39f 2322 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
93e95400 2323 ), __invoke_memfun_ref> _S_test(int);
83ddb39f
DK
2324
2325 template<typename...>
2326 static __failure_type _S_test(...);
2327 };
2328
2329 template<typename _MemPtr, typename _Arg, typename... _Args>
2330 struct __result_of_memfun_ref
2331 : private __result_of_memfun_ref_impl
2332 {
2333 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2334 };
2335
2336 // [func.require] paragraph 1 bullet 2:
2337 struct __result_of_memfun_deref_impl
2338 {
2339 template<typename _Fp, typename _Tp1, typename... _Args>
93e95400 2340 static __result_of_success<decltype(
83ddb39f 2341 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
93e95400 2342 ), __invoke_memfun_deref> _S_test(int);
83ddb39f
DK
2343
2344 template<typename...>
2345 static __failure_type _S_test(...);
2346 };
2347
2348 template<typename _MemPtr, typename _Arg, typename... _Args>
2349 struct __result_of_memfun_deref
2350 : private __result_of_memfun_deref_impl
2351 {
2352 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2353 };
2354
2355 // [func.require] paragraph 1 bullet 3:
2356 struct __result_of_memobj_ref_impl
2357 {
2358 template<typename _Fp, typename _Tp1>
93e95400 2359 static __result_of_success<decltype(
83ddb39f 2360 std::declval<_Tp1>().*std::declval<_Fp>()
93e95400 2361 ), __invoke_memobj_ref> _S_test(int);
83ddb39f
DK
2362
2363 template<typename, typename>
2364 static __failure_type _S_test(...);
2365 };
2366
2367 template<typename _MemPtr, typename _Arg>
2368 struct __result_of_memobj_ref
2369 : private __result_of_memobj_ref_impl
2370 {
2371 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2372 };
2373
2374 // [func.require] paragraph 1 bullet 4:
2375 struct __result_of_memobj_deref_impl
2376 {
2377 template<typename _Fp, typename _Tp1>
93e95400 2378 static __result_of_success<decltype(
83ddb39f 2379 (*std::declval<_Tp1>()).*std::declval<_Fp>()
93e95400 2380 ), __invoke_memobj_deref> _S_test(int);
83ddb39f
DK
2381
2382 template<typename, typename>
2383 static __failure_type _S_test(...);
2384 };
2385
be7f7822 2386 template<typename _MemPtr, typename _Arg>
83ddb39f
DK
2387 struct __result_of_memobj_deref
2388 : private __result_of_memobj_deref_impl
2389 {
2390 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2391 };
2392
2393 template<typename _MemPtr, typename _Arg>
2394 struct __result_of_memobj;
be7f7822
JW
2395
2396 template<typename _Res, typename _Class, typename _Arg>
83ddb39f 2397 struct __result_of_memobj<_Res _Class::*, _Arg>
be7f7822 2398 {
6791489e 2399 typedef __remove_cvref_t<_Arg> _Argval;
83ddb39f
DK
2400 typedef _Res _Class::* _MemPtr;
2401 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2402 is_base_of<_Class, _Argval>>::value,
2403 __result_of_memobj_ref<_MemPtr, _Arg>,
2404 __result_of_memobj_deref<_MemPtr, _Arg>
2405 >::type::type type;
be7f7822
JW
2406 };
2407
83ddb39f
DK
2408 template<typename _MemPtr, typename _Arg, typename... _Args>
2409 struct __result_of_memfun;
be7f7822
JW
2410
2411 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
83ddb39f 2412 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
be7f7822 2413 {
81c7cf71 2414 typedef typename remove_reference<_Arg>::type _Argval;
83ddb39f 2415 typedef _Res _Class::* _MemPtr;
81c7cf71 2416 typedef typename conditional<is_base_of<_Class, _Argval>::value,
83ddb39f
DK
2417 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2418 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2419 >::type::type type;
be7f7822
JW
2420 };
2421
93e95400
JW
2422 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2423 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2424 // as the object expression
93e95400 2425
7dcc645c 2426 // Used by result_of, invoke etc. to unwrap a reference_wrapper.
81c7cf71 2427 template<typename _Tp, typename _Up = __remove_cvref_t<_Tp>>
7dcc645c
JW
2428 struct __inv_unwrap
2429 {
2430 using type = _Tp;
2431 };
f3d7dd52 2432
7dcc645c
JW
2433 template<typename _Tp, typename _Up>
2434 struct __inv_unwrap<_Tp, reference_wrapper<_Up>>
2435 {
2436 using type = _Up&;
2437 };
93e95400 2438
be7f7822 2439 template<bool, bool, typename _Functor, typename... _ArgTypes>
83ddb39f 2440 struct __result_of_impl
be7f7822 2441 {
83ddb39f 2442 typedef __failure_type type;
be7f7822
JW
2443 };
2444
2445 template<typename _MemPtr, typename _Arg>
83ddb39f 2446 struct __result_of_impl<true, false, _MemPtr, _Arg>
7dcc645c
JW
2447 : public __result_of_memobj<typename decay<_MemPtr>::type,
2448 typename __inv_unwrap<_Arg>::type>
c4db9a77 2449 { };
be7f7822 2450
83ddb39f
DK
2451 template<typename _MemPtr, typename _Arg, typename... _Args>
2452 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
7dcc645c
JW
2453 : public __result_of_memfun<typename decay<_MemPtr>::type,
2454 typename __inv_unwrap<_Arg>::type, _Args...>
c4db9a77 2455 { };
be7f7822 2456
83ddb39f
DK
2457 // [func.require] paragraph 1 bullet 5:
2458 struct __result_of_other_impl
2459 {
2460 template<typename _Fn, typename... _Args>
93e95400 2461 static __result_of_success<decltype(
83ddb39f 2462 std::declval<_Fn>()(std::declval<_Args>()...)
93e95400 2463 ), __invoke_other> _S_test(int);
83ddb39f
DK
2464
2465 template<typename...>
2466 static __failure_type _S_test(...);
2467 };
2468
be7f7822 2469 template<typename _Functor, typename... _ArgTypes>
83ddb39f
DK
2470 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2471 : private __result_of_other_impl
be7f7822 2472 {
83ddb39f 2473 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
be7f7822
JW
2474 };
2475
7dcc645c 2476 // __invoke_result (std::invoke_result for C++11)
83ddb39f 2477 template<typename _Functor, typename... _ArgTypes>
7dcc645c 2478 struct __invoke_result
83ddb39f
DK
2479 : public __result_of_impl<
2480 is_member_object_pointer<
2481 typename remove_reference<_Functor>::type
2482 >::value,
2483 is_member_function_pointer<
2484 typename remove_reference<_Functor>::type
2485 >::value,
7dcc645c 2486 _Functor, _ArgTypes...
83ddb39f
DK
2487 >::type
2488 { };
c0ffa2ba 2489
7dcc645c
JW
2490 template<typename _Functor, typename... _ArgTypes>
2491 struct result_of<_Functor(_ArgTypes...)>
2492 : public __invoke_result<_Functor, _ArgTypes...>
2493 { };
2494
e112d53a 2495#if __cplusplus >= 201402L
4457e88c
JW
2496 /// Alias template for aligned_storage
2497 template<size_t _Len, size_t _Align =
2498 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2499 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2500
d3718027
RS
2501 template <size_t _Len, typename... _Types>
2502 using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
2503
4457e88c
JW
2504 /// Alias template for decay
2505 template<typename _Tp>
2506 using decay_t = typename decay<_Tp>::type;
2507
2508 /// Alias template for enable_if
2509 template<bool _Cond, typename _Tp = void>
2510 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2511
2512 /// Alias template for conditional
2513 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2514 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2515
2516 /// Alias template for common_type
2517 template<typename... _Tp>
2518 using common_type_t = typename common_type<_Tp...>::type;
2519
2520 /// Alias template for underlying_type
2521 template<typename _Tp>
2522 using underlying_type_t = typename underlying_type<_Tp>::type;
2523
2524 /// Alias template for result_of
2525 template<typename _Tp>
2526 using result_of_t = typename result_of<_Tp>::type;
e112d53a
JW
2527#endif // C++14
2528
2529 // __enable_if_t (std::enable_if_t for C++11)
2530 template<bool _Cond, typename _Tp = void>
2531 using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
4457e88c 2532
e112d53a 2533#if __cplusplus >= 201703L || !defined(__STRICT_ANSI__) // c++17 or gnu++11
bd1eb5e0
JW
2534#define __cpp_lib_void_t 201411
2535 /// A metafunction that always yields void, used for detecting valid types.
2536 template<typename...> using void_t = void;
2537#endif
2538
6af6bef4
JW
2539 /// Implementation of the detection idiom (negative case).
2540 template<typename _Default, typename _AlwaysVoid,
2541 template<typename...> class _Op, typename... _Args>
2542 struct __detector
2543 {
2544 using value_t = false_type;
2545 using type = _Default;
2546 };
2547
2548 /// Implementation of the detection idiom (positive case).
2549 template<typename _Default, template<typename...> class _Op,
2550 typename... _Args>
2551 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2552 {
2553 using value_t = true_type;
2554 using type = _Op<_Args...>;
2555 };
2556
2557 // Detect whether _Op<_Args...> is a valid type, use _Default if not.
2558 template<typename _Default, template<typename...> class _Op,
2559 typename... _Args>
2560 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2561
2562 // _Op<_Args...> if that is a valid type, otherwise _Default.
2563 template<typename _Default, template<typename...> class _Op,
2564 typename... _Args>
2565 using __detected_or_t
2566 = typename __detected_or<_Default, _Op, _Args...>::type;
2567
c0ffa2ba 2568 /// @} group metaprogramming
847e9cf8 2569
033b71ce
PC
2570 /**
2571 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2572 * member type _NTYPE.
2573 */
82b12c4b 2574#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
847e9cf8 2575 template<typename _Tp, typename = __void_t<>> \
82b12c4b 2576 struct __has_##_NTYPE \
847e9cf8
JW
2577 : false_type \
2578 { }; \
2579 template<typename _Tp> \
2580 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2581 : true_type \
033b71ce
PC
2582 { };
2583
26b5ace7
DK
2584 template <typename _Tp>
2585 struct __is_swappable;
ddb63209 2586
26b5ace7
DK
2587 template <typename _Tp>
2588 struct __is_nothrow_swappable;
ddb63209 2589
a2863bde
VV
2590 template<typename... _Elements>
2591 class tuple;
2592
2593 template<typename>
2594 struct __is_tuple_like_impl : false_type
2595 { };
2596
2597 template<typename... _Tps>
2598 struct __is_tuple_like_impl<tuple<_Tps...>> : true_type
2599 { };
2600
2601 // Internal type trait that allows us to sfinae-protect tuple_cat.
2602 template<typename _Tp>
2603 struct __is_tuple_like
6791489e 2604 : public __is_tuple_like_impl<__remove_cvref_t<_Tp>>::type
a2863bde
VV
2605 { };
2606
ddb63209 2607 template<typename _Tp>
7a91c710 2608 _GLIBCXX20_CONSTEXPR
ddb63209 2609 inline
a2863bde
VV
2610 typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>,
2611 is_move_constructible<_Tp>,
ddb63209
VV
2612 is_move_assignable<_Tp>>::value>::type
2613 swap(_Tp&, _Tp&)
2614 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
2615 is_nothrow_move_assignable<_Tp>>::value);
2616
2617 template<typename _Tp, size_t _Nm>
7a91c710 2618 _GLIBCXX20_CONSTEXPR
ddb63209 2619 inline
26b5ace7 2620 typename enable_if<__is_swappable<_Tp>::value>::type
ddb63209 2621 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
26b5ace7 2622 noexcept(__is_nothrow_swappable<_Tp>::value);
ddb63209 2623
26b5ace7 2624 namespace __swappable_details {
ddb63209
VV
2625 using std::swap;
2626
26b5ace7
DK
2627 struct __do_is_swappable_impl
2628 {
2629 template<typename _Tp, typename
2630 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
2631 static true_type __test(int);
2632
2633 template<typename>
2634 static false_type __test(...);
2635 };
2636
2637 struct __do_is_nothrow_swappable_impl
2638 {
2639 template<typename _Tp>
2640 static __bool_constant<
2641 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
2642 > __test(int);
2643
2644 template<typename>
2645 static false_type __test(...);
2646 };
2647
6b9539e2 2648 } // namespace __swappable_details
ddb63209 2649
26b5ace7
DK
2650 template<typename _Tp>
2651 struct __is_swappable_impl
2652 : public __swappable_details::__do_is_swappable_impl
2653 {
2654 typedef decltype(__test<_Tp>(0)) type;
2655 };
2656
2657 template<typename _Tp>
ddb63209 2658 struct __is_nothrow_swappable_impl
26b5ace7
DK
2659 : public __swappable_details::__do_is_nothrow_swappable_impl
2660 {
2661 typedef decltype(__test<_Tp>(0)) type;
2662 };
ddb63209 2663
26b5ace7
DK
2664 template<typename _Tp>
2665 struct __is_swappable
2666 : public __is_swappable_impl<_Tp>::type
ddb63209
VV
2667 { };
2668
26b5ace7 2669 template<typename _Tp>
ddb63209 2670 struct __is_nothrow_swappable
26b5ace7 2671 : public __is_nothrow_swappable_impl<_Tp>::type
ddb63209
VV
2672 { };
2673
6b9539e2
DK
2674#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
2675#define __cpp_lib_is_swappable 201603
2676 /// Metafunctions used for detecting swappable types: p0185r1
2677
2678 /// is_swappable
2679 template<typename _Tp>
2680 struct is_swappable
2681 : public __is_swappable_impl<_Tp>::type
608a080c
AP
2682 {
2683 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2684 "template argument must be a complete class or an unbounded array");
2685 };
6b9539e2
DK
2686
2687 /// is_nothrow_swappable
2688 template<typename _Tp>
2689 struct is_nothrow_swappable
2690 : public __is_nothrow_swappable_impl<_Tp>::type
608a080c
AP
2691 {
2692 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2693 "template argument must be a complete class or an unbounded array");
2694 };
6b9539e2
DK
2695
2696#if __cplusplus >= 201402L
2697 /// is_swappable_v
2698 template<typename _Tp>
288695f7
DK
2699 _GLIBCXX17_INLINE constexpr bool is_swappable_v =
2700 is_swappable<_Tp>::value;
6b9539e2
DK
2701
2702 /// is_nothrow_swappable_v
2703 template<typename _Tp>
288695f7
DK
2704 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_v =
2705 is_nothrow_swappable<_Tp>::value;
6b9539e2
DK
2706#endif // __cplusplus >= 201402L
2707
2708 namespace __swappable_with_details {
2709 using std::swap;
2710
2711 struct __do_is_swappable_with_impl
2712 {
2713 template<typename _Tp, typename _Up, typename
2714 = decltype(swap(std::declval<_Tp>(), std::declval<_Up>())),
2715 typename
2716 = decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))>
2717 static true_type __test(int);
2718
2719 template<typename, typename>
2720 static false_type __test(...);
2721 };
2722
2723 struct __do_is_nothrow_swappable_with_impl
2724 {
2725 template<typename _Tp, typename _Up>
2726 static __bool_constant<
2727 noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
2728 &&
2729 noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()))
2730 > __test(int);
2731
2732 template<typename, typename>
2733 static false_type __test(...);
2734 };
2735
2736 } // namespace __swappable_with_details
2737
2738 template<typename _Tp, typename _Up>
2739 struct __is_swappable_with_impl
2740 : public __swappable_with_details::__do_is_swappable_with_impl
2741 {
2742 typedef decltype(__test<_Tp, _Up>(0)) type;
2743 };
2744
2745 // Optimization for the homogenous lvalue case, not required:
2746 template<typename _Tp>
2747 struct __is_swappable_with_impl<_Tp&, _Tp&>
2748 : public __swappable_details::__do_is_swappable_impl
2749 {
2750 typedef decltype(__test<_Tp&>(0)) type;
2751 };
2752
2753 template<typename _Tp, typename _Up>
2754 struct __is_nothrow_swappable_with_impl
2755 : public __swappable_with_details::__do_is_nothrow_swappable_with_impl
2756 {
2757 typedef decltype(__test<_Tp, _Up>(0)) type;
2758 };
2759
2760 // Optimization for the homogenous lvalue case, not required:
2761 template<typename _Tp>
2762 struct __is_nothrow_swappable_with_impl<_Tp&, _Tp&>
2763 : public __swappable_details::__do_is_nothrow_swappable_impl
2764 {
2765 typedef decltype(__test<_Tp&>(0)) type;
2766 };
2767
2768 /// is_swappable_with
2769 template<typename _Tp, typename _Up>
2770 struct is_swappable_with
2771 : public __is_swappable_with_impl<_Tp, _Up>::type
2772 { };
2773
2774 /// is_nothrow_swappable_with
2775 template<typename _Tp, typename _Up>
2776 struct is_nothrow_swappable_with
2777 : public __is_nothrow_swappable_with_impl<_Tp, _Up>::type
2778 { };
2779
2780#if __cplusplus >= 201402L
2781 /// is_swappable_with_v
2782 template<typename _Tp, typename _Up>
288695f7
DK
2783 _GLIBCXX17_INLINE constexpr bool is_swappable_with_v =
2784 is_swappable_with<_Tp, _Up>::value;
6b9539e2
DK
2785
2786 /// is_nothrow_swappable_with_v
2787 template<typename _Tp, typename _Up>
288695f7 2788 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_with_v =
6b9539e2
DK
2789 is_nothrow_swappable_with<_Tp, _Up>::value;
2790#endif // __cplusplus >= 201402L
137422c8 2791
42183d03
JW
2792#endif// c++1z or gnu++11
2793
7dcc645c 2794 // __is_invocable (std::is_invocable for C++11)
42183d03 2795
d91f618d
JW
2796 // The primary template is used for invalid INVOKE expressions.
2797 template<typename _Result, typename _Ret,
2798 bool = is_void<_Ret>::value, typename = void>
7dcc645c 2799 struct __is_invocable_impl : false_type { };
42183d03 2800
d91f618d 2801 // Used for valid INVOKE and INVOKE<void> expressions.
42183d03 2802 template<typename _Result, typename _Ret>
d91f618d
JW
2803 struct __is_invocable_impl<_Result, _Ret,
2804 /* is_void<_Ret> = */ true,
2805 __void_t<typename _Result::type>>
2806 : true_type
42183d03
JW
2807 { };
2808
d91f618d
JW
2809#pragma GCC diagnostic push
2810#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
2811 // Used for INVOKE<R> expressions to check the implicit conversion to R.
2812 template<typename _Result, typename _Ret>
2813 struct __is_invocable_impl<_Result, _Ret,
2814 /* is_void<_Ret> = */ false,
2815 __void_t<typename _Result::type>>
2816 {
2817 private:
2818 // The type of the INVOKE expression.
2819 // Unlike declval, this doesn't add_rvalue_reference.
2820 static typename _Result::type _S_get();
2821
2822 template<typename _Tp>
2823 static void _S_conv(_Tp);
2824
2825 // This overload is viable if INVOKE(f, args...) can convert to _Tp.
2826 template<typename _Tp, typename = decltype(_S_conv<_Tp>(_S_get()))>
2827 static true_type
2828 _S_test(int);
2829
2830 template<typename _Tp>
2831 static false_type
2832 _S_test(...);
2833
2834 public:
2835 using type = decltype(_S_test<_Ret>(1));
2836 };
2837#pragma GCC diagnostic pop
2838
7dcc645c
JW
2839 template<typename _Fn, typename... _ArgTypes>
2840 struct __is_invocable
2841 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
42183d03
JW
2842 { };
2843
42183d03
JW
2844 template<typename _Fn, typename _Tp, typename... _Args>
2845 constexpr bool __call_is_nt(__invoke_memfun_ref)
2846 {
2847 using _Up = typename __inv_unwrap<_Tp>::type;
2848 return noexcept((std::declval<_Up>().*std::declval<_Fn>())(
2849 std::declval<_Args>()...));
2850 }
2851
2852 template<typename _Fn, typename _Tp, typename... _Args>
2853 constexpr bool __call_is_nt(__invoke_memfun_deref)
2854 {
2855 return noexcept(((*std::declval<_Tp>()).*std::declval<_Fn>())(
2856 std::declval<_Args>()...));
2857 }
2858
2859 template<typename _Fn, typename _Tp>
2860 constexpr bool __call_is_nt(__invoke_memobj_ref)
2861 {
2862 using _Up = typename __inv_unwrap<_Tp>::type;
2863 return noexcept(std::declval<_Up>().*std::declval<_Fn>());
2864 }
2865
2866 template<typename _Fn, typename _Tp>
2867 constexpr bool __call_is_nt(__invoke_memobj_deref)
2868 {
2869 return noexcept((*std::declval<_Tp>()).*std::declval<_Fn>());
2870 }
2871
2872 template<typename _Fn, typename... _Args>
2873 constexpr bool __call_is_nt(__invoke_other)
2874 {
2875 return noexcept(std::declval<_Fn>()(std::declval<_Args>()...));
2876 }
2877
7dcc645c 2878 template<typename _Result, typename _Fn, typename... _Args>
42183d03
JW
2879 struct __call_is_nothrow
2880 : __bool_constant<
7dcc645c
JW
2881 std::__call_is_nt<_Fn, _Args...>(typename _Result::__invoke_type{})
2882 >
42183d03
JW
2883 { };
2884
7dcc645c
JW
2885 template<typename _Fn, typename... _Args>
2886 using __call_is_nothrow_
2887 = __call_is_nothrow<__invoke_result<_Fn, _Args...>, _Fn, _Args...>;
42183d03 2888
7dcc645c
JW
2889 // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
2890 template<typename _Fn, typename... _Args>
2891 struct __is_nothrow_invocable
2892 : __and_<__is_invocable<_Fn, _Args...>,
2893 __call_is_nothrow_<_Fn, _Args...>>::type
42183d03
JW
2894 { };
2895
cc28d234
JW
2896#pragma GCC diagnostic push
2897#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
a73d2fa8
NDR
2898 struct __nonesuchbase {};
2899 struct __nonesuch : private __nonesuchbase {
f524d5b3
VV
2900 ~__nonesuch() = delete;
2901 __nonesuch(__nonesuch const&) = delete;
2902 void operator=(__nonesuch const&) = delete;
2903 };
cc28d234 2904#pragma GCC diagnostic pop
f524d5b3 2905
e641ee43 2906#if __cplusplus >= 201703L
7dcc645c
JW
2907# define __cpp_lib_is_invocable 201703
2908
2909 /// std::invoke_result
2910 template<typename _Functor, typename... _ArgTypes>
2911 struct invoke_result
2912 : public __invoke_result<_Functor, _ArgTypes...>
2913 { };
2914
2915 /// std::invoke_result_t
2916 template<typename _Fn, typename... _Args>
2917 using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
42183d03 2918
7dcc645c
JW
2919 /// std::is_invocable
2920 template<typename _Fn, typename... _ArgTypes>
2921 struct is_invocable
2922 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
608a080c
AP
2923 {
2924 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
2925 "_Fn must be a complete class or an unbounded array");
2926 };
42183d03 2927
7dcc645c
JW
2928 /// std::is_invocable_r
2929 template<typename _Ret, typename _Fn, typename... _ArgTypes>
2930 struct is_invocable_r
2931 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>::type
608a080c
AP
2932 {
2933 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
2934 "_Fn must be a complete class or an unbounded array");
2935 };
42183d03 2936
7dcc645c
JW
2937 /// std::is_nothrow_invocable
2938 template<typename _Fn, typename... _ArgTypes>
2939 struct is_nothrow_invocable
2940 : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>,
608a080c
AP
2941 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
2942 {
2943 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
2944 "_Fn must be a complete class or an unbounded array");
2945 };
42183d03 2946
c4b06e7f
JW
2947 template<typename _Result, typename _Ret, typename = void>
2948 struct __is_nt_invocable_impl : false_type { };
2949
2950 template<typename _Result, typename _Ret>
2951 struct __is_nt_invocable_impl<_Result, _Ret,
2952 __void_t<typename _Result::type>>
91d01b33 2953 : __or_<is_void<_Ret>,
ce9f305e 2954 __is_nothrow_convertible<typename _Result::type, _Ret>>
c4b06e7f
JW
2955 { };
2956
7dcc645c
JW
2957 /// std::is_nothrow_invocable_r
2958 template<typename _Ret, typename _Fn, typename... _ArgTypes>
2959 struct is_nothrow_invocable_r
c4b06e7f 2960 : __and_<__is_nt_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>,
7dcc645c 2961 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
42183d03
JW
2962 { };
2963
7dcc645c
JW
2964 /// std::is_invocable_v
2965 template<typename _Fn, typename... _Args>
2966 inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
42183d03 2967
7dcc645c
JW
2968 /// std::is_nothrow_invocable_v
2969 template<typename _Fn, typename... _Args>
2970 inline constexpr bool is_nothrow_invocable_v
2971 = is_nothrow_invocable<_Fn, _Args...>::value;
42183d03 2972
7dcc645c 2973 /// std::is_invocable_r_v
ce9f305e 2974 template<typename _Ret, typename _Fn, typename... _Args>
7dcc645c 2975 inline constexpr bool is_invocable_r_v
ce9f305e 2976 = is_invocable_r<_Ret, _Fn, _Args...>::value;
7dcc645c
JW
2977
2978 /// std::is_nothrow_invocable_r_v
ce9f305e 2979 template<typename _Ret, typename _Fn, typename... _Args>
7dcc645c 2980 inline constexpr bool is_nothrow_invocable_r_v
ce9f305e 2981 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
7dcc645c 2982#endif // C++17
42183d03 2983
e641ee43 2984#if __cplusplus >= 201703L
068c8ac1 2985# define __cpp_lib_type_trait_variable_templates 201510L
137422c8 2986template <typename _Tp>
288695f7 2987 inline constexpr bool is_void_v = is_void<_Tp>::value;
137422c8 2988template <typename _Tp>
288695f7 2989 inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
137422c8 2990template <typename _Tp>
288695f7 2991 inline constexpr bool is_integral_v = is_integral<_Tp>::value;
137422c8 2992template <typename _Tp>
288695f7 2993 inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
137422c8 2994template <typename _Tp>
288695f7 2995 inline constexpr bool is_array_v = is_array<_Tp>::value;
137422c8 2996template <typename _Tp>
288695f7 2997 inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
137422c8 2998template <typename _Tp>
288695f7
DK
2999 inline constexpr bool is_lvalue_reference_v =
3000 is_lvalue_reference<_Tp>::value;
137422c8 3001template <typename _Tp>
288695f7
DK
3002 inline constexpr bool is_rvalue_reference_v =
3003 is_rvalue_reference<_Tp>::value;
137422c8 3004template <typename _Tp>
288695f7 3005 inline constexpr bool is_member_object_pointer_v =
137422c8
VV
3006 is_member_object_pointer<_Tp>::value;
3007template <typename _Tp>
288695f7 3008 inline constexpr bool is_member_function_pointer_v =
137422c8
VV
3009 is_member_function_pointer<_Tp>::value;
3010template <typename _Tp>
288695f7 3011 inline constexpr bool is_enum_v = is_enum<_Tp>::value;
137422c8 3012template <typename _Tp>
288695f7 3013 inline constexpr bool is_union_v = is_union<_Tp>::value;
137422c8 3014template <typename _Tp>
288695f7 3015 inline constexpr bool is_class_v = is_class<_Tp>::value;
137422c8 3016template <typename _Tp>
288695f7 3017 inline constexpr bool is_function_v = is_function<_Tp>::value;
137422c8 3018template <typename _Tp>
288695f7 3019 inline constexpr bool is_reference_v = is_reference<_Tp>::value;
137422c8 3020template <typename _Tp>
288695f7 3021 inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
137422c8 3022template <typename _Tp>
288695f7 3023 inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
137422c8 3024template <typename _Tp>
288695f7 3025 inline constexpr bool is_object_v = is_object<_Tp>::value;
137422c8 3026template <typename _Tp>
288695f7 3027 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
137422c8 3028template <typename _Tp>
288695f7 3029 inline constexpr bool is_compound_v = is_compound<_Tp>::value;
137422c8 3030template <typename _Tp>
288695f7 3031 inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
137422c8 3032template <typename _Tp>
288695f7 3033 inline constexpr bool is_const_v = is_const<_Tp>::value;
137422c8 3034template <typename _Tp>
288695f7 3035 inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
137422c8 3036template <typename _Tp>
288695f7 3037 inline constexpr bool is_trivial_v = is_trivial<_Tp>::value;
137422c8 3038template <typename _Tp>
288695f7
DK
3039 inline constexpr bool is_trivially_copyable_v =
3040 is_trivially_copyable<_Tp>::value;
137422c8 3041template <typename _Tp>
288695f7 3042 inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
137422c8 3043template <typename _Tp>
288695f7 3044 inline constexpr bool is_pod_v = is_pod<_Tp>::value;
137422c8 3045template <typename _Tp>
288695f7 3046 inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
137422c8 3047template <typename _Tp>
288695f7 3048 inline constexpr bool is_empty_v = is_empty<_Tp>::value;
137422c8 3049template <typename _Tp>
288695f7 3050 inline constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value;
137422c8 3051template <typename _Tp>
288695f7 3052 inline constexpr bool is_abstract_v = is_abstract<_Tp>::value;
137422c8 3053template <typename _Tp>
288695f7 3054 inline constexpr bool is_final_v = is_final<_Tp>::value;
137422c8 3055template <typename _Tp>
288695f7 3056 inline constexpr bool is_signed_v = is_signed<_Tp>::value;
137422c8 3057template <typename _Tp>
288695f7 3058 inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
137422c8 3059template <typename _Tp, typename... _Args>
288695f7
DK
3060 inline constexpr bool is_constructible_v =
3061 is_constructible<_Tp, _Args...>::value;
137422c8 3062template <typename _Tp>
288695f7 3063 inline constexpr bool is_default_constructible_v =
137422c8
VV
3064 is_default_constructible<_Tp>::value;
3065template <typename _Tp>
288695f7
DK
3066 inline constexpr bool is_copy_constructible_v =
3067 is_copy_constructible<_Tp>::value;
137422c8 3068template <typename _Tp>
288695f7
DK
3069 inline constexpr bool is_move_constructible_v =
3070 is_move_constructible<_Tp>::value;
137422c8 3071template <typename _Tp, typename _Up>
288695f7 3072 inline constexpr bool is_assignable_v = is_assignable<_Tp, _Up>::value;
137422c8 3073template <typename _Tp>
288695f7 3074 inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
137422c8 3075template <typename _Tp>
288695f7 3076 inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
137422c8 3077template <typename _Tp>
288695f7 3078 inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
137422c8 3079template <typename _Tp, typename... _Args>
288695f7 3080 inline constexpr bool is_trivially_constructible_v =
137422c8
VV
3081 is_trivially_constructible<_Tp, _Args...>::value;
3082template <typename _Tp>
288695f7 3083 inline constexpr bool is_trivially_default_constructible_v =
137422c8
VV
3084 is_trivially_default_constructible<_Tp>::value;
3085template <typename _Tp>
288695f7 3086 inline constexpr bool is_trivially_copy_constructible_v =
137422c8
VV
3087 is_trivially_copy_constructible<_Tp>::value;
3088template <typename _Tp>
288695f7 3089 inline constexpr bool is_trivially_move_constructible_v =
137422c8
VV
3090 is_trivially_move_constructible<_Tp>::value;
3091template <typename _Tp, typename _Up>
288695f7 3092 inline constexpr bool is_trivially_assignable_v =
137422c8
VV
3093 is_trivially_assignable<_Tp, _Up>::value;
3094template <typename _Tp>
288695f7 3095 inline constexpr bool is_trivially_copy_assignable_v =
137422c8
VV
3096 is_trivially_copy_assignable<_Tp>::value;
3097template <typename _Tp>
288695f7 3098 inline constexpr bool is_trivially_move_assignable_v =
137422c8
VV
3099 is_trivially_move_assignable<_Tp>::value;
3100template <typename _Tp>
288695f7 3101 inline constexpr bool is_trivially_destructible_v =
137422c8
VV
3102 is_trivially_destructible<_Tp>::value;
3103template <typename _Tp, typename... _Args>
288695f7 3104 inline constexpr bool is_nothrow_constructible_v =
137422c8
VV
3105 is_nothrow_constructible<_Tp, _Args...>::value;
3106template <typename _Tp>
288695f7 3107 inline constexpr bool is_nothrow_default_constructible_v =
137422c8
VV
3108 is_nothrow_default_constructible<_Tp>::value;
3109template <typename _Tp>
288695f7 3110 inline constexpr bool is_nothrow_copy_constructible_v =
137422c8
VV
3111 is_nothrow_copy_constructible<_Tp>::value;
3112template <typename _Tp>
288695f7 3113 inline constexpr bool is_nothrow_move_constructible_v =
137422c8
VV
3114 is_nothrow_move_constructible<_Tp>::value;
3115template <typename _Tp, typename _Up>
288695f7 3116 inline constexpr bool is_nothrow_assignable_v =
137422c8
VV
3117 is_nothrow_assignable<_Tp, _Up>::value;
3118template <typename _Tp>
288695f7 3119 inline constexpr bool is_nothrow_copy_assignable_v =
137422c8
VV
3120 is_nothrow_copy_assignable<_Tp>::value;
3121template <typename _Tp>
288695f7 3122 inline constexpr bool is_nothrow_move_assignable_v =
137422c8
VV
3123 is_nothrow_move_assignable<_Tp>::value;
3124template <typename _Tp>
288695f7 3125 inline constexpr bool is_nothrow_destructible_v =
137422c8
VV
3126 is_nothrow_destructible<_Tp>::value;
3127template <typename _Tp>
288695f7 3128 inline constexpr bool has_virtual_destructor_v =
137422c8
VV
3129 has_virtual_destructor<_Tp>::value;
3130template <typename _Tp>
288695f7 3131 inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
137422c8 3132template <typename _Tp>
288695f7 3133 inline constexpr size_t rank_v = rank<_Tp>::value;
137422c8 3134template <typename _Tp, unsigned _Idx = 0>
288695f7 3135 inline constexpr size_t extent_v = extent<_Tp, _Idx>::value;
137422c8 3136template <typename _Tp, typename _Up>
288695f7 3137 inline constexpr bool is_same_v = is_same<_Tp, _Up>::value;
137422c8 3138template <typename _Base, typename _Derived>
288695f7 3139 inline constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value;
137422c8 3140template <typename _From, typename _To>
288695f7 3141 inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
873c7d5a 3142
2d763763 3143#ifdef _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
873c7d5a
JW
3144# define __cpp_lib_has_unique_object_representations 201606
3145 /// has_unique_object_representations
3146 template<typename _Tp>
3147 struct has_unique_object_representations
3148 : bool_constant<__has_unique_object_representations(
3149 remove_cv_t<remove_all_extents_t<_Tp>>
3150 )>
608a080c
AP
3151 {
3152 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3153 "template argument must be a complete class or an unbounded array");
3154 };
b0e63d94
JW
3155
3156 template<typename _Tp>
3157 inline constexpr bool has_unique_object_representations_v
3158 = has_unique_object_representations<_Tp>::value;
1f5700e9 3159#endif
e2ac6765 3160
afa56c17 3161#ifdef _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
ff273400 3162# define __cpp_lib_is_aggregate 201703
e2ac6765
VV
3163 /// is_aggregate
3164 template<typename _Tp>
3165 struct is_aggregate
608a080c 3166 : bool_constant<__is_aggregate(remove_cv_t<_Tp>)>
209ee624 3167 { };
e2ac6765
VV
3168
3169 /// is_aggregate_v
3170 template<typename _Tp>
3171 inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
3172#endif
137422c8 3173#endif // C++17
6b9539e2 3174
e641ee43 3175#if __cplusplus > 201703L
6791489e
JW
3176 /// Remove references and cv-qualifiers.
3177 template<typename _Tp>
3178 struct remove_cvref
3179 {
3180 using type = __remove_cvref_t<_Tp>;
3181 };
3182
3183 template<typename _Tp>
3184 using remove_cvref_t = __remove_cvref_t<_Tp>;
3185
ee896276
JW
3186 /// Identity metafunction.
3187 template<typename _Tp>
3188 struct type_identity { using type = _Tp; };
3189
3190 template<typename _Tp>
3191 using type_identity_t = typename type_identity<_Tp>::type;
3192
3d18dc9d
JW
3193 /// Unwrap a reference_wrapper
3194 template<typename _Tp>
3195 struct unwrap_reference { using type = _Tp; };
3196
3197 template<typename _Tp>
3198 struct unwrap_reference<reference_wrapper<_Tp>> { using type = _Tp&; };
3199
82e8c3da
JW
3200 template<typename _Tp>
3201 using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3202
3d18dc9d
JW
3203 /// Decay type and if it's a reference_wrapper, unwrap it
3204 template<typename _Tp>
82e8c3da 3205 struct unwrap_ref_decay { using type = unwrap_reference_t<decay_t<_Tp>>; };
3d18dc9d
JW
3206
3207 template<typename _Tp>
3208 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3209
46610940
JW
3210#define __cpp_lib_bounded_array_traits 201902L
3211
28d85efb
JW
3212 /// True for a type that is an array of known bound.
3213 template<typename _Tp>
3214 struct is_bounded_array
3215 : public __is_array_known_bounds<_Tp>
3216 { };
3217
3218 /// True for a type that is an array of unknown bound.
3219 template<typename _Tp>
3220 struct is_unbounded_array
3221 : public __is_array_unknown_bounds<_Tp>
3222 { };
3223
3224 template<typename _Tp>
3225 inline constexpr bool is_bounded_array_v
3226 = is_bounded_array<_Tp>::value;
3227
3228 template<typename _Tp>
3229 inline constexpr bool is_unbounded_array_v
3230 = is_unbounded_array<_Tp>::value;
3231
0d7924f2 3232#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
134a6f7b 3233
8aa1550e 3234#define __cpp_lib_is_constant_evaluated 201811L
134a6f7b 3235
0d7924f2
JJ
3236 constexpr inline bool
3237 is_constant_evaluated() noexcept
3238 { return __builtin_is_constant_evaluated(); }
3239#endif
3240
e641ee43
JW
3241#endif // C++2a
3242
12ffa228 3243_GLIBCXX_END_NAMESPACE_VERSION
c0ffa2ba 3244} // namespace std
7b50cdef 3245
734f5023 3246#endif // C++11
57317d2a 3247
7274deff 3248#endif // _GLIBCXX_TYPE_TRAITS