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