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