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