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