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