1 // C++11 <type_traits> -*- C++ -*-
3 // Copyright (C) 2007-2024 Free Software Foundation, Inc.
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)
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.
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.
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/>.
25 /** @file include/type_traits
26 * This is a Standard C++ Library header.
29 #ifndef _GLIBCXX_TYPE_TRAITS
30 #define _GLIBCXX_TYPE_TRAITS 1
32 #pragma GCC system_header
34 #if __cplusplus < 201103L
35 # include <bits/c++0x_warning.h>
38 #include <bits/c++config.h>
40 #define __glibcxx_want_bool_constant
41 #define __glibcxx_want_bounded_array_traits
42 #define __glibcxx_want_has_unique_object_representations
43 #define __glibcxx_want_integral_constant_callable
44 #define __glibcxx_want_is_aggregate
45 #define __glibcxx_want_is_constant_evaluated
46 #define __glibcxx_want_is_final
47 #define __glibcxx_want_is_invocable
48 #define __glibcxx_want_is_layout_compatible
49 #define __glibcxx_want_is_nothrow_convertible
50 #define __glibcxx_want_is_null_pointer
51 #define __glibcxx_want_is_pointer_interconvertible
52 #define __glibcxx_want_is_scoped_enum
53 #define __glibcxx_want_is_swappable
54 #define __glibcxx_want_logical_traits
55 #define __glibcxx_want_reference_from_temporary
56 #define __glibcxx_want_remove_cvref
57 #define __glibcxx_want_result_of_sfinae
58 #define __glibcxx_want_transformation_trait_aliases
59 #define __glibcxx_want_type_identity
60 #define __glibcxx_want_type_trait_variable_templates
61 #define __glibcxx_want_unwrap_ref
62 #define __glibcxx_want_void_t
63 #include <bits/version.h>
65 namespace std _GLIBCXX_VISIBILITY(default)
67 _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 template<typename _Tp>
70 class reference_wrapper;
73 * @defgroup metaprogramming Metaprogramming
76 * Template utilities for compile-time introspection and modification,
77 * including type classification traits, type property inspection traits
78 * and type transformation traits.
86 template<typename _Tp, _Tp __v>
87 struct integral_constant
89 static constexpr _Tp value = __v;
90 using value_type = _Tp;
91 using type = integral_constant<_Tp, __v>;
92 constexpr operator value_type() const noexcept { return value; }
94 #ifdef __cpp_lib_integral_constant_callable // C++ >= 14
95 constexpr value_type operator()() const noexcept { return value; }
99 #if ! __cpp_inline_variables
100 template<typename _Tp, _Tp __v>
101 constexpr _Tp integral_constant<_Tp, __v>::value;
104 /// @cond undocumented
105 /// bool_constant for C++11
107 using __bool_constant = integral_constant<bool, __v>;
110 /// The type used as a compile-time boolean with true value.
111 using true_type = __bool_constant<true>;
113 /// The type used as a compile-time boolean with false value.
114 using false_type = __bool_constant<false>;
116 #ifdef __cpp_lib_bool_constant // C++ >= 17
117 /// Alias template for compile-time boolean constant types.
120 using bool_constant = __bool_constant<__v>;
123 // Metaprogramming helper types.
126 /// Define a member typedef `type` only if a boolean constant is true.
127 template<bool, typename _Tp = void>
131 // Partial specialization for true.
132 template<typename _Tp>
133 struct enable_if<true, _Tp>
134 { using type = _Tp; };
136 // __enable_if_t (std::enable_if_t for C++11)
137 template<bool _Cond, typename _Tp = void>
138 using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
143 template<typename _Tp, typename>
148 struct __conditional<false>
150 template<typename, typename _Up>
154 // More efficient version of std::conditional_t for internal use (and C++11)
155 template<bool _Cond, typename _If, typename _Else>
156 using __conditional_t
157 = typename __conditional<_Cond>::template type<_If, _Else>;
159 /// @cond undocumented
160 template <typename _Type>
161 struct __type_identity
162 { using type = _Type; };
164 template<typename _Tp>
165 using __type_identity_t = typename __type_identity<_Tp>::type;
169 // A variadic alias template that resolves to its first argument.
170 template<typename _Tp, typename...>
171 using __first_t = _Tp;
173 // These are deliberately not defined.
174 template<typename... _Bn>
175 auto __or_fn(int) -> __first_t<false_type,
176 __enable_if_t<!bool(_Bn::value)>...>;
178 template<typename... _Bn>
179 auto __or_fn(...) -> true_type;
181 template<typename... _Bn>
182 auto __and_fn(int) -> __first_t<true_type,
183 __enable_if_t<bool(_Bn::value)>...>;
185 template<typename... _Bn>
186 auto __and_fn(...) -> false_type;
187 } // namespace detail
189 // Like C++17 std::dis/conjunction, but usable in C++11 and resolves
190 // to either true_type or false_type which allows for a more efficient
191 // implementation that avoids recursive class template instantiation.
192 template<typename... _Bn>
194 : decltype(__detail::__or_fn<_Bn...>(0))
197 template<typename... _Bn>
199 : decltype(__detail::__and_fn<_Bn...>(0))
202 template<typename _Pp>
204 : __bool_constant<!bool(_Pp::value)>
208 #ifdef __cpp_lib_logical_traits // C++ >= 17
210 /// @cond undocumented
211 template<typename... _Bn>
212 inline constexpr bool __or_v = __or_<_Bn...>::value;
213 template<typename... _Bn>
214 inline constexpr bool __and_v = __and_<_Bn...>::value;
218 template<typename /* = void */, typename _B1, typename... _Bn>
219 struct __disjunction_impl
220 { using type = _B1; };
222 template<typename _B1, typename _B2, typename... _Bn>
223 struct __disjunction_impl<__enable_if_t<!bool(_B1::value)>, _B1, _B2, _Bn...>
224 { using type = typename __disjunction_impl<void, _B2, _Bn...>::type; };
226 template<typename /* = void */, typename _B1, typename... _Bn>
227 struct __conjunction_impl
228 { using type = _B1; };
230 template<typename _B1, typename _B2, typename... _Bn>
231 struct __conjunction_impl<__enable_if_t<bool(_B1::value)>, _B1, _B2, _Bn...>
232 { using type = typename __conjunction_impl<void, _B2, _Bn...>::type; };
233 } // namespace __detail
236 template<typename... _Bn>
238 : __detail::__conjunction_impl<void, _Bn...>::type
246 template<typename... _Bn>
248 : __detail::__disjunction_impl<void, _Bn...>::type
256 template<typename _Pp>
261 /** @ingroup variable_templates
264 template<typename... _Bn>
265 inline constexpr bool conjunction_v = conjunction<_Bn...>::value;
267 template<typename... _Bn>
268 inline constexpr bool disjunction_v = disjunction<_Bn...>::value;
270 template<typename _Pp>
271 inline constexpr bool negation_v = negation<_Pp>::value;
274 #endif // __cpp_lib_logical_traits
276 // Forward declarations
288 /// @cond undocumented
290 struct __is_array_unknown_bounds;
292 // Helper functions that return false_type for incomplete classes,
293 // incomplete unions and arrays of known bound from those.
295 template <typename _Tp, size_t = sizeof(_Tp)>
296 constexpr true_type __is_complete_or_unbounded(__type_identity<_Tp>)
299 template <typename _TypeIdentity,
300 typename _NestedType = typename _TypeIdentity::type>
301 constexpr typename __or_<
302 is_reference<_NestedType>,
303 is_function<_NestedType>,
304 is_void<_NestedType>,
305 __is_array_unknown_bounds<_NestedType>
306 >::type __is_complete_or_unbounded(_TypeIdentity)
309 // __remove_cv_t (std::remove_cv_t for C++11).
310 template<typename _Tp>
311 using __remove_cv_t = typename remove_cv<_Tp>::type;
314 // Primary type categories.
317 template<typename _Tp>
319 : public false_type { };
323 : public true_type { };
326 struct is_void<const void>
327 : public true_type { };
330 struct is_void<volatile void>
331 : public true_type { };
334 struct is_void<const volatile void>
335 : public true_type { };
337 /// @cond undocumented
339 struct __is_integral_helper
340 : public false_type { };
343 struct __is_integral_helper<bool>
344 : public true_type { };
347 struct __is_integral_helper<char>
348 : public true_type { };
351 struct __is_integral_helper<signed char>
352 : public true_type { };
355 struct __is_integral_helper<unsigned char>
356 : public true_type { };
358 // We want is_integral<wchar_t> to be true (and make_signed/unsigned to work)
359 // even when libc doesn't provide working <wchar.h> and related functions,
360 // so don't check _GLIBCXX_USE_WCHAR_T here.
362 struct __is_integral_helper<wchar_t>
363 : public true_type { };
365 #ifdef _GLIBCXX_USE_CHAR8_T
367 struct __is_integral_helper<char8_t>
368 : public true_type { };
372 struct __is_integral_helper<char16_t>
373 : public true_type { };
376 struct __is_integral_helper<char32_t>
377 : public true_type { };
380 struct __is_integral_helper<short>
381 : public true_type { };
384 struct __is_integral_helper<unsigned short>
385 : public true_type { };
388 struct __is_integral_helper<int>
389 : public true_type { };
392 struct __is_integral_helper<unsigned int>
393 : public true_type { };
396 struct __is_integral_helper<long>
397 : public true_type { };
400 struct __is_integral_helper<unsigned long>
401 : public true_type { };
404 struct __is_integral_helper<long long>
405 : public true_type { };
408 struct __is_integral_helper<unsigned long long>
409 : public true_type { };
411 // Conditionalizing on __STRICT_ANSI__ here will break any port that
412 // uses one of these types for size_t.
413 #if defined(__GLIBCXX_TYPE_INT_N_0)
416 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
417 : public true_type { };
421 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
422 : public true_type { };
424 #if defined(__GLIBCXX_TYPE_INT_N_1)
427 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
428 : public true_type { };
432 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
433 : public true_type { };
435 #if defined(__GLIBCXX_TYPE_INT_N_2)
438 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
439 : public true_type { };
443 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
444 : public true_type { };
446 #if defined(__GLIBCXX_TYPE_INT_N_3)
449 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
450 : public true_type { };
454 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
455 : public true_type { };
460 template<typename _Tp>
462 : public __is_integral_helper<__remove_cv_t<_Tp>>::type
465 /// @cond undocumented
467 struct __is_floating_point_helper
468 : public false_type { };
471 struct __is_floating_point_helper<float>
472 : public true_type { };
475 struct __is_floating_point_helper<double>
476 : public true_type { };
479 struct __is_floating_point_helper<long double>
480 : public true_type { };
482 #ifdef __STDCPP_FLOAT16_T__
484 struct __is_floating_point_helper<_Float16>
485 : public true_type { };
488 #ifdef __STDCPP_FLOAT32_T__
490 struct __is_floating_point_helper<_Float32>
491 : public true_type { };
494 #ifdef __STDCPP_FLOAT64_T__
496 struct __is_floating_point_helper<_Float64>
497 : public true_type { };
500 #ifdef __STDCPP_FLOAT128_T__
502 struct __is_floating_point_helper<_Float128>
503 : public true_type { };
506 #ifdef __STDCPP_BFLOAT16_T__
508 struct __is_floating_point_helper<__gnu_cxx::__bfloat16_t>
509 : public true_type { };
512 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
514 struct __is_floating_point_helper<__float128>
515 : public true_type { };
519 /// is_floating_point
520 template<typename _Tp>
521 struct is_floating_point
522 : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type
526 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
527 template<typename _Tp>
529 : public __bool_constant<__is_array(_Tp)>
534 : public false_type { };
536 template<typename _Tp, std::size_t _Size>
537 struct is_array<_Tp[_Size]>
538 : public true_type { };
540 template<typename _Tp>
541 struct is_array<_Tp[]>
542 : public true_type { };
546 struct __is_pointer_helper
547 : public false_type { };
549 template<typename _Tp>
550 struct __is_pointer_helper<_Tp*>
551 : public true_type { };
554 template<typename _Tp>
556 : public __is_pointer_helper<__remove_cv_t<_Tp>>::type
559 /// is_lvalue_reference
561 struct is_lvalue_reference
562 : public false_type { };
564 template<typename _Tp>
565 struct is_lvalue_reference<_Tp&>
566 : public true_type { };
568 /// is_rvalue_reference
570 struct is_rvalue_reference
571 : public false_type { };
573 template<typename _Tp>
574 struct is_rvalue_reference<_Tp&&>
575 : public true_type { };
577 /// is_member_object_pointer
578 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
579 template<typename _Tp>
580 struct is_member_object_pointer
581 : public __bool_constant<__is_member_object_pointer(_Tp)>
585 struct __is_member_object_pointer_helper
586 : public false_type { };
588 template<typename _Tp, typename _Cp>
589 struct __is_member_object_pointer_helper<_Tp _Cp::*>
590 : public __not_<is_function<_Tp>>::type { };
593 template<typename _Tp>
594 struct is_member_object_pointer
595 : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type
599 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
600 /// is_member_function_pointer
601 template<typename _Tp>
602 struct is_member_function_pointer
603 : public __bool_constant<__is_member_function_pointer(_Tp)>
607 struct __is_member_function_pointer_helper
608 : public false_type { };
610 template<typename _Tp, typename _Cp>
611 struct __is_member_function_pointer_helper<_Tp _Cp::*>
612 : public is_function<_Tp>::type { };
614 /// is_member_function_pointer
615 template<typename _Tp>
616 struct is_member_function_pointer
617 : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type
622 template<typename _Tp>
624 : public __bool_constant<__is_enum(_Tp)>
628 template<typename _Tp>
630 : public __bool_constant<__is_union(_Tp)>
634 template<typename _Tp>
636 : public __bool_constant<__is_class(_Tp)>
640 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
641 template<typename _Tp>
643 : public __bool_constant<__is_function(_Tp)>
646 template<typename _Tp>
648 : public __bool_constant<!is_const<const _Tp>::value> { };
650 template<typename _Tp>
651 struct is_function<_Tp&>
652 : public false_type { };
654 template<typename _Tp>
655 struct is_function<_Tp&&>
656 : public false_type { };
659 #ifdef __cpp_lib_is_null_pointer // C++ >= 11
660 /// is_null_pointer (LWG 2247).
661 template<typename _Tp>
662 struct is_null_pointer
663 : public false_type { };
666 struct is_null_pointer<std::nullptr_t>
667 : public true_type { };
670 struct is_null_pointer<const std::nullptr_t>
671 : public true_type { };
674 struct is_null_pointer<volatile std::nullptr_t>
675 : public true_type { };
678 struct is_null_pointer<const volatile std::nullptr_t>
679 : public true_type { };
681 /// __is_nullptr_t (deprecated extension).
682 /// @deprecated Non-standard. Use `is_null_pointer` instead.
683 template<typename _Tp>
684 struct __is_nullptr_t
685 : public is_null_pointer<_Tp>
686 { } _GLIBCXX_DEPRECATED_SUGGEST("std::is_null_pointer");
687 #endif // __cpp_lib_is_null_pointer
689 // Composite type categories.
692 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
693 template<typename _Tp>
695 : public __bool_constant<__is_reference(_Tp)>
698 template<typename _Tp>
703 template<typename _Tp>
704 struct is_reference<_Tp&>
708 template<typename _Tp>
709 struct is_reference<_Tp&&>
715 template<typename _Tp>
717 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
721 template<typename _Tp>
722 struct is_fundamental
723 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
724 is_null_pointer<_Tp>>::type
728 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
729 template<typename _Tp>
731 : public __bool_constant<__is_object(_Tp)>
734 template<typename _Tp>
736 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
742 struct is_member_pointer;
745 template<typename _Tp>
747 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
748 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
752 template<typename _Tp>
754 : public __not_<is_fundamental<_Tp>>::type { };
756 /// is_member_pointer
757 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
758 template<typename _Tp>
759 struct is_member_pointer
760 : public __bool_constant<__is_member_pointer(_Tp)>
763 /// @cond undocumented
764 template<typename _Tp>
765 struct __is_member_pointer_helper
766 : public false_type { };
768 template<typename _Tp, typename _Cp>
769 struct __is_member_pointer_helper<_Tp _Cp::*>
770 : public true_type { };
773 template<typename _Tp>
774 struct is_member_pointer
775 : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type
779 template<typename, typename>
782 /// @cond undocumented
783 template<typename _Tp, typename... _Types>
784 using __is_one_of = __or_<is_same<_Tp, _Types>...>;
786 // Check if a type is one of the signed integer types.
788 template<typename _Tp>
789 using __is_signed_integer = __is_one_of<__remove_cv_t<_Tp>,
790 signed char, signed short, signed int, signed long,
792 #if defined(__GLIBCXX_TYPE_INT_N_0)
793 , signed __GLIBCXX_TYPE_INT_N_0
795 #if defined(__GLIBCXX_TYPE_INT_N_1)
796 , signed __GLIBCXX_TYPE_INT_N_1
798 #if defined(__GLIBCXX_TYPE_INT_N_2)
799 , signed __GLIBCXX_TYPE_INT_N_2
801 #if defined(__GLIBCXX_TYPE_INT_N_3)
802 , signed __GLIBCXX_TYPE_INT_N_3
806 // Check if a type is one of the unsigned integer types.
808 template<typename _Tp>
809 using __is_unsigned_integer = __is_one_of<__remove_cv_t<_Tp>,
810 unsigned char, unsigned short, unsigned int, unsigned long,
812 #if defined(__GLIBCXX_TYPE_INT_N_0)
813 , unsigned __GLIBCXX_TYPE_INT_N_0
815 #if defined(__GLIBCXX_TYPE_INT_N_1)
816 , unsigned __GLIBCXX_TYPE_INT_N_1
818 #if defined(__GLIBCXX_TYPE_INT_N_2)
819 , unsigned __GLIBCXX_TYPE_INT_N_2
821 #if defined(__GLIBCXX_TYPE_INT_N_3)
822 , unsigned __GLIBCXX_TYPE_INT_N_3
826 // Check if a type is one of the signed or unsigned integer types.
827 template<typename _Tp>
828 using __is_standard_integer
829 = __or_<__is_signed_integer<_Tp>, __is_unsigned_integer<_Tp>>;
831 // __void_t (std::void_t for C++11)
832 template<typename...> using __void_t = void;
840 : public false_type { };
842 template<typename _Tp>
843 struct is_const<_Tp const>
844 : public true_type { };
849 : public false_type { };
851 template<typename _Tp>
852 struct is_volatile<_Tp volatile>
853 : public true_type { };
856 template<typename _Tp>
858 : public __bool_constant<__is_trivial(_Tp)>
860 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
861 "template argument must be a complete class or an unbounded array");
864 /// is_trivially_copyable
865 template<typename _Tp>
866 struct is_trivially_copyable
867 : public __bool_constant<__is_trivially_copyable(_Tp)>
869 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
870 "template argument must be a complete class or an unbounded array");
873 /// is_standard_layout
874 template<typename _Tp>
875 struct is_standard_layout
876 : public __bool_constant<__is_standard_layout(_Tp)>
878 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
879 "template argument must be a complete class or an unbounded array");
883 * @deprecated Deprecated in C++20.
884 * Use `is_standard_layout && is_trivial` instead.
886 // Could use is_standard_layout && is_trivial instead of the builtin.
887 template<typename _Tp>
889 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout && is_trivial")
891 : public __bool_constant<__is_pod(_Tp)>
893 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
894 "template argument must be a complete class or an unbounded array");
898 * @deprecated Deprecated in C++17, removed in C++20.
899 * The idea of a literal type isn't useful.
901 template<typename _Tp>
903 _GLIBCXX17_DEPRECATED
905 : public __bool_constant<__is_literal_type(_Tp)>
907 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
908 "template argument must be a complete class or an unbounded array");
912 template<typename _Tp>
914 : public __bool_constant<__is_empty(_Tp)>
918 template<typename _Tp>
919 struct is_polymorphic
920 : public __bool_constant<__is_polymorphic(_Tp)>
923 #ifdef __cpp_lib_is_final // C++ >= 14
926 template<typename _Tp>
928 : public __bool_constant<__is_final(_Tp)>
933 template<typename _Tp>
935 : public __bool_constant<__is_abstract(_Tp)>
938 /// @cond undocumented
939 template<typename _Tp,
940 bool = is_arithmetic<_Tp>::value>
941 struct __is_signed_helper
942 : public false_type { };
944 template<typename _Tp>
945 struct __is_signed_helper<_Tp, true>
946 : public __bool_constant<_Tp(-1) < _Tp(0)>
951 template<typename _Tp>
953 : public __is_signed_helper<_Tp>::type
957 template<typename _Tp>
959 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
962 /// @cond undocumented
963 template<typename _Tp, typename _Up = _Tp&&>
967 template<typename _Tp>
972 template<typename _Tp>
973 auto declval() noexcept -> decltype(__declval<_Tp>(0));
976 struct remove_all_extents;
978 /// @cond undocumented
979 template<typename _Tp>
980 struct __is_array_known_bounds
984 template<typename _Tp, size_t _Size>
985 struct __is_array_known_bounds<_Tp[_Size]>
989 template<typename _Tp>
990 struct __is_array_unknown_bounds
994 template<typename _Tp>
995 struct __is_array_unknown_bounds<_Tp[]>
999 // Destructible and constructible type properties.
1001 // In N3290 is_destructible does not say anything about function
1002 // types and abstract types, see LWG 2049. This implementation
1003 // describes function types as non-destructible and all complete
1004 // object types as destructible, iff the explicit destructor
1005 // call expression is wellformed.
1006 struct __do_is_destructible_impl
1008 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
1009 static true_type __test(int);
1012 static false_type __test(...);
1015 template<typename _Tp>
1016 struct __is_destructible_impl
1017 : public __do_is_destructible_impl
1019 using type = decltype(__test<_Tp>(0));
1022 template<typename _Tp,
1023 bool = __or_<is_void<_Tp>,
1024 __is_array_unknown_bounds<_Tp>,
1025 is_function<_Tp>>::value,
1026 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1027 struct __is_destructible_safe;
1029 template<typename _Tp>
1030 struct __is_destructible_safe<_Tp, false, false>
1031 : public __is_destructible_impl<typename
1032 remove_all_extents<_Tp>::type>::type
1035 template<typename _Tp>
1036 struct __is_destructible_safe<_Tp, true, false>
1037 : public false_type { };
1039 template<typename _Tp>
1040 struct __is_destructible_safe<_Tp, false, true>
1041 : public true_type { };
1045 template<typename _Tp>
1046 struct is_destructible
1047 : public __is_destructible_safe<_Tp>::type
1049 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1050 "template argument must be a complete class or an unbounded array");
1053 /// @cond undocumented
1055 // is_nothrow_destructible requires that is_destructible is
1056 // satisfied as well. We realize that by mimicing the
1057 // implementation of is_destructible but refer to noexcept(expr)
1058 // instead of decltype(expr).
1059 struct __do_is_nt_destructible_impl
1061 template<typename _Tp>
1062 static __bool_constant<noexcept(declval<_Tp&>().~_Tp())>
1066 static false_type __test(...);
1069 template<typename _Tp>
1070 struct __is_nt_destructible_impl
1071 : public __do_is_nt_destructible_impl
1073 using type = decltype(__test<_Tp>(0));
1076 template<typename _Tp,
1077 bool = __or_<is_void<_Tp>,
1078 __is_array_unknown_bounds<_Tp>,
1079 is_function<_Tp>>::value,
1080 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1081 struct __is_nt_destructible_safe;
1083 template<typename _Tp>
1084 struct __is_nt_destructible_safe<_Tp, false, false>
1085 : public __is_nt_destructible_impl<typename
1086 remove_all_extents<_Tp>::type>::type
1089 template<typename _Tp>
1090 struct __is_nt_destructible_safe<_Tp, true, false>
1091 : public false_type { };
1093 template<typename _Tp>
1094 struct __is_nt_destructible_safe<_Tp, false, true>
1095 : public true_type { };
1098 /// is_nothrow_destructible
1099 template<typename _Tp>
1100 struct is_nothrow_destructible
1101 : public __is_nt_destructible_safe<_Tp>::type
1103 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1104 "template argument must be a complete class or an unbounded array");
1107 /// @cond undocumented
1108 template<typename _Tp, typename... _Args>
1109 using __is_constructible_impl
1110 = __bool_constant<__is_constructible(_Tp, _Args...)>;
1113 /// is_constructible
1114 template<typename _Tp, typename... _Args>
1115 struct is_constructible
1116 : public __is_constructible_impl<_Tp, _Args...>
1118 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1119 "template argument must be a complete class or an unbounded array");
1122 /// is_default_constructible
1123 template<typename _Tp>
1124 struct is_default_constructible
1125 : public __is_constructible_impl<_Tp>
1127 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1128 "template argument must be a complete class or an unbounded array");
1131 /// @cond undocumented
1132 template<typename _Tp, typename = void>
1133 struct __add_lvalue_reference_helper
1134 { using type = _Tp; };
1136 template<typename _Tp>
1137 struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>>
1138 { using type = _Tp&; };
1140 template<typename _Tp>
1141 using __add_lval_ref_t = typename __add_lvalue_reference_helper<_Tp>::type;
1144 /// is_copy_constructible
1145 template<typename _Tp>
1146 struct is_copy_constructible
1147 : public __is_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1149 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1150 "template argument must be a complete class or an unbounded array");
1153 /// @cond undocumented
1154 template<typename _Tp, typename = void>
1155 struct __add_rvalue_reference_helper
1156 { using type = _Tp; };
1158 template<typename _Tp>
1159 struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>>
1160 { using type = _Tp&&; };
1162 template<typename _Tp>
1163 using __add_rval_ref_t = typename __add_rvalue_reference_helper<_Tp>::type;
1166 /// is_move_constructible
1167 template<typename _Tp>
1168 struct is_move_constructible
1169 : public __is_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1171 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1172 "template argument must be a complete class or an unbounded array");
1175 /// @cond undocumented
1176 template<typename _Tp, typename... _Args>
1177 using __is_nothrow_constructible_impl
1178 = __bool_constant<__is_nothrow_constructible(_Tp, _Args...)>;
1181 /// is_nothrow_constructible
1182 template<typename _Tp, typename... _Args>
1183 struct is_nothrow_constructible
1184 : public __is_nothrow_constructible_impl<_Tp, _Args...>
1186 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1187 "template argument must be a complete class or an unbounded array");
1190 /// is_nothrow_default_constructible
1191 template<typename _Tp>
1192 struct is_nothrow_default_constructible
1193 : public __is_nothrow_constructible_impl<_Tp>
1195 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1196 "template argument must be a complete class or an unbounded array");
1199 /// is_nothrow_copy_constructible
1200 template<typename _Tp>
1201 struct is_nothrow_copy_constructible
1202 : public __is_nothrow_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1204 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1205 "template argument must be a complete class or an unbounded array");
1208 /// is_nothrow_move_constructible
1209 template<typename _Tp>
1210 struct is_nothrow_move_constructible
1211 : public __is_nothrow_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1213 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1214 "template argument must be a complete class or an unbounded array");
1217 /// @cond undocumented
1218 template<typename _Tp, typename _Up>
1219 using __is_assignable_impl = __bool_constant<__is_assignable(_Tp, _Up)>;
1223 template<typename _Tp, typename _Up>
1224 struct is_assignable
1225 : public __is_assignable_impl<_Tp, _Up>
1227 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1228 "template argument must be a complete class or an unbounded array");
1231 /// is_copy_assignable
1232 template<typename _Tp>
1233 struct is_copy_assignable
1234 : public __is_assignable_impl<__add_lval_ref_t<_Tp>,
1235 __add_lval_ref_t<const _Tp>>
1237 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1238 "template argument must be a complete class or an unbounded array");
1241 /// is_move_assignable
1242 template<typename _Tp>
1243 struct is_move_assignable
1244 : public __is_assignable_impl<__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>>
1246 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1247 "template argument must be a complete class or an unbounded array");
1250 /// @cond undocumented
1251 template<typename _Tp, typename _Up>
1252 using __is_nothrow_assignable_impl
1253 = __bool_constant<__is_nothrow_assignable(_Tp, _Up)>;
1256 /// is_nothrow_assignable
1257 template<typename _Tp, typename _Up>
1258 struct is_nothrow_assignable
1259 : public __is_nothrow_assignable_impl<_Tp, _Up>
1261 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1262 "template argument must be a complete class or an unbounded array");
1265 /// is_nothrow_copy_assignable
1266 template<typename _Tp>
1267 struct is_nothrow_copy_assignable
1268 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1269 __add_lval_ref_t<const _Tp>>
1271 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1272 "template argument must be a complete class or an unbounded array");
1275 /// is_nothrow_move_assignable
1276 template<typename _Tp>
1277 struct is_nothrow_move_assignable
1278 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1279 __add_rval_ref_t<_Tp>>
1281 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1282 "template argument must be a complete class or an unbounded array");
1285 /// @cond undocumented
1286 template<typename _Tp, typename... _Args>
1287 using __is_trivially_constructible_impl
1288 = __bool_constant<__is_trivially_constructible(_Tp, _Args...)>;
1291 /// is_trivially_constructible
1292 template<typename _Tp, typename... _Args>
1293 struct is_trivially_constructible
1294 : public __is_trivially_constructible_impl<_Tp, _Args...>
1296 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1297 "template argument must be a complete class or an unbounded array");
1300 /// is_trivially_default_constructible
1301 template<typename _Tp>
1302 struct is_trivially_default_constructible
1303 : public __is_trivially_constructible_impl<_Tp>
1305 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1306 "template argument must be a complete class or an unbounded array");
1309 struct __do_is_implicitly_default_constructible_impl
1311 template <typename _Tp>
1312 static void __helper(const _Tp&);
1314 template <typename _Tp>
1315 static true_type __test(const _Tp&,
1316 decltype(__helper<const _Tp&>({}))* = 0);
1318 static false_type __test(...);
1321 template<typename _Tp>
1322 struct __is_implicitly_default_constructible_impl
1323 : public __do_is_implicitly_default_constructible_impl
1325 using type = decltype(__test(declval<_Tp>()));
1328 template<typename _Tp>
1329 struct __is_implicitly_default_constructible_safe
1330 : public __is_implicitly_default_constructible_impl<_Tp>::type
1333 template <typename _Tp>
1334 struct __is_implicitly_default_constructible
1335 : public __and_<__is_constructible_impl<_Tp>,
1336 __is_implicitly_default_constructible_safe<_Tp>>::type
1339 /// is_trivially_copy_constructible
1340 template<typename _Tp>
1341 struct is_trivially_copy_constructible
1342 : public __is_trivially_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1344 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1345 "template argument must be a complete class or an unbounded array");
1348 /// is_trivially_move_constructible
1349 template<typename _Tp>
1350 struct is_trivially_move_constructible
1351 : public __is_trivially_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1353 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1354 "template argument must be a complete class or an unbounded array");
1357 /// @cond undocumented
1358 template<typename _Tp, typename _Up>
1359 using __is_trivially_assignable_impl
1360 = __bool_constant<__is_trivially_assignable(_Tp, _Up)>;
1363 /// is_trivially_assignable
1364 template<typename _Tp, typename _Up>
1365 struct is_trivially_assignable
1366 : public __is_trivially_assignable_impl<_Tp, _Up>
1368 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1369 "template argument must be a complete class or an unbounded array");
1372 /// is_trivially_copy_assignable
1373 template<typename _Tp>
1374 struct is_trivially_copy_assignable
1375 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1376 __add_lval_ref_t<const _Tp>>
1378 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1379 "template argument must be a complete class or an unbounded array");
1382 /// is_trivially_move_assignable
1383 template<typename _Tp>
1384 struct is_trivially_move_assignable
1385 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1386 __add_rval_ref_t<_Tp>>
1388 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1389 "template argument must be a complete class or an unbounded array");
1392 /// is_trivially_destructible
1393 template<typename _Tp>
1394 struct is_trivially_destructible
1395 : public __and_<__is_destructible_safe<_Tp>,
1396 __bool_constant<__has_trivial_destructor(_Tp)>>::type
1398 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1399 "template argument must be a complete class or an unbounded array");
1403 /// has_virtual_destructor
1404 template<typename _Tp>
1405 struct has_virtual_destructor
1406 : public __bool_constant<__has_virtual_destructor(_Tp)>
1408 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1409 "template argument must be a complete class or an unbounded array");
1413 // type property queries.
1416 template<typename _Tp>
1418 : public integral_constant<std::size_t, alignof(_Tp)>
1420 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1421 "template argument must be a complete class or an unbounded array");
1427 : public integral_constant<std::size_t, 0> { };
1429 template<typename _Tp, std::size_t _Size>
1430 struct rank<_Tp[_Size]>
1431 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1433 template<typename _Tp>
1435 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1438 template<typename, unsigned _Uint = 0>
1440 : public integral_constant<size_t, 0> { };
1442 template<typename _Tp, size_t _Size>
1443 struct extent<_Tp[_Size], 0>
1444 : public integral_constant<size_t, _Size> { };
1446 template<typename _Tp, unsigned _Uint, size_t _Size>
1447 struct extent<_Tp[_Size], _Uint>
1448 : public extent<_Tp, _Uint - 1>::type { };
1450 template<typename _Tp>
1451 struct extent<_Tp[], 0>
1452 : public integral_constant<size_t, 0> { };
1454 template<typename _Tp, unsigned _Uint>
1455 struct extent<_Tp[], _Uint>
1456 : public extent<_Tp, _Uint - 1>::type { };
1462 template<typename _Tp, typename _Up>
1464 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_SAME
1465 : public __bool_constant<__is_same(_Tp, _Up)>
1471 #ifndef _GLIBCXX_HAVE_BUILTIN_IS_SAME
1472 template<typename _Tp>
1473 struct is_same<_Tp, _Tp>
1479 template<typename _Base, typename _Derived>
1481 : public __bool_constant<__is_base_of(_Base, _Derived)>
1484 #if __has_builtin(__is_convertible)
1485 template<typename _From, typename _To>
1486 struct is_convertible
1487 : public __bool_constant<__is_convertible(_From, _To)>
1490 template<typename _From, typename _To,
1491 bool = __or_<is_void<_From>, is_function<_To>,
1492 is_array<_To>>::value>
1493 struct __is_convertible_helper
1495 using type = typename is_void<_To>::type;
1498 #pragma GCC diagnostic push
1499 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1500 template<typename _From, typename _To>
1501 class __is_convertible_helper<_From, _To, false>
1503 template<typename _To1>
1504 static void __test_aux(_To1) noexcept;
1506 template<typename _From1, typename _To1,
1507 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1511 template<typename, typename>
1516 using type = decltype(__test<_From, _To>(0));
1518 #pragma GCC diagnostic pop
1521 template<typename _From, typename _To>
1522 struct is_convertible
1523 : public __is_convertible_helper<_From, _To>::type
1527 // helper trait for unique_ptr<T[]>, shared_ptr<T[]>, and span<T, N>
1528 template<typename _ToElementType, typename _FromElementType>
1529 using __is_array_convertible
1530 = is_convertible<_FromElementType(*)[], _ToElementType(*)[]>;
1532 #ifdef __cpp_lib_is_nothrow_convertible // C++ >= 20
1534 #if __has_builtin(__is_nothrow_convertible)
1535 /// is_nothrow_convertible_v
1536 template<typename _From, typename _To>
1537 inline constexpr bool is_nothrow_convertible_v
1538 = __is_nothrow_convertible(_From, _To);
1540 /// is_nothrow_convertible
1541 template<typename _From, typename _To>
1542 struct is_nothrow_convertible
1543 : public bool_constant<is_nothrow_convertible_v<_From, _To>>
1546 template<typename _From, typename _To,
1547 bool = __or_<is_void<_From>, is_function<_To>,
1548 is_array<_To>>::value>
1549 struct __is_nt_convertible_helper
1553 #pragma GCC diagnostic push
1554 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1555 template<typename _From, typename _To>
1556 class __is_nt_convertible_helper<_From, _To, false>
1558 template<typename _To1>
1559 static void __test_aux(_To1) noexcept;
1561 template<typename _From1, typename _To1>
1563 __bool_constant<noexcept(__test_aux<_To1>(std::declval<_From1>()))>
1566 template<typename, typename>
1571 using type = decltype(__test<_From, _To>(0));
1573 #pragma GCC diagnostic pop
1575 /// is_nothrow_convertible
1576 template<typename _From, typename _To>
1577 struct is_nothrow_convertible
1578 : public __is_nt_convertible_helper<_From, _To>::type
1581 /// is_nothrow_convertible_v
1582 template<typename _From, typename _To>
1583 inline constexpr bool is_nothrow_convertible_v
1584 = is_nothrow_convertible<_From, _To>::value;
1586 #endif // __cpp_lib_is_nothrow_convertible
1588 // Const-volatile modifications.
1591 template<typename _Tp>
1593 { using type = _Tp; };
1595 template<typename _Tp>
1596 struct remove_const<_Tp const>
1597 { using type = _Tp; };
1600 template<typename _Tp>
1601 struct remove_volatile
1602 { using type = _Tp; };
1604 template<typename _Tp>
1605 struct remove_volatile<_Tp volatile>
1606 { using type = _Tp; };
1609 #if __has_builtin(__remove_cv)
1610 template<typename _Tp>
1612 { using type = __remove_cv(_Tp); };
1614 template<typename _Tp>
1616 { using type = _Tp; };
1618 template<typename _Tp>
1619 struct remove_cv<const _Tp>
1620 { using type = _Tp; };
1622 template<typename _Tp>
1623 struct remove_cv<volatile _Tp>
1624 { using type = _Tp; };
1626 template<typename _Tp>
1627 struct remove_cv<const volatile _Tp>
1628 { using type = _Tp; };
1632 template<typename _Tp>
1634 { using type = _Tp const; };
1637 template<typename _Tp>
1639 { using type = _Tp volatile; };
1642 template<typename _Tp>
1644 { using type = _Tp const volatile; };
1646 #ifdef __cpp_lib_transformation_trait_aliases // C++ >= 14
1647 /// Alias template for remove_const
1648 template<typename _Tp>
1649 using remove_const_t = typename remove_const<_Tp>::type;
1651 /// Alias template for remove_volatile
1652 template<typename _Tp>
1653 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1655 /// Alias template for remove_cv
1656 template<typename _Tp>
1657 using remove_cv_t = typename remove_cv<_Tp>::type;
1659 /// Alias template for add_const
1660 template<typename _Tp>
1661 using add_const_t = typename add_const<_Tp>::type;
1663 /// Alias template for add_volatile
1664 template<typename _Tp>
1665 using add_volatile_t = typename add_volatile<_Tp>::type;
1667 /// Alias template for add_cv
1668 template<typename _Tp>
1669 using add_cv_t = typename add_cv<_Tp>::type;
1672 // Reference transformations.
1674 /// remove_reference
1675 #if __has_builtin(__remove_reference)
1676 template<typename _Tp>
1677 struct remove_reference
1678 { using type = __remove_reference(_Tp); };
1680 template<typename _Tp>
1681 struct remove_reference
1682 { using type = _Tp; };
1684 template<typename _Tp>
1685 struct remove_reference<_Tp&>
1686 { using type = _Tp; };
1688 template<typename _Tp>
1689 struct remove_reference<_Tp&&>
1690 { using type = _Tp; };
1693 /// add_lvalue_reference
1694 template<typename _Tp>
1695 struct add_lvalue_reference
1696 { using type = __add_lval_ref_t<_Tp>; };
1698 /// add_rvalue_reference
1699 template<typename _Tp>
1700 struct add_rvalue_reference
1701 { using type = __add_rval_ref_t<_Tp>; };
1703 #if __cplusplus > 201103L
1704 /// Alias template for remove_reference
1705 template<typename _Tp>
1706 using remove_reference_t = typename remove_reference<_Tp>::type;
1708 /// Alias template for add_lvalue_reference
1709 template<typename _Tp>
1710 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1712 /// Alias template for add_rvalue_reference
1713 template<typename _Tp>
1714 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1717 // Sign modifications.
1719 /// @cond undocumented
1721 // Utility for constructing identically cv-qualified types.
1722 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1723 struct __cv_selector;
1725 template<typename _Unqualified>
1726 struct __cv_selector<_Unqualified, false, false>
1727 { using __type = _Unqualified; };
1729 template<typename _Unqualified>
1730 struct __cv_selector<_Unqualified, false, true>
1731 { using __type = volatile _Unqualified; };
1733 template<typename _Unqualified>
1734 struct __cv_selector<_Unqualified, true, false>
1735 { using __type = const _Unqualified; };
1737 template<typename _Unqualified>
1738 struct __cv_selector<_Unqualified, true, true>
1739 { using __type = const volatile _Unqualified; };
1741 template<typename _Qualified, typename _Unqualified,
1742 bool _IsConst = is_const<_Qualified>::value,
1743 bool _IsVol = is_volatile<_Qualified>::value>
1744 class __match_cv_qualifiers
1746 using __match = __cv_selector<_Unqualified, _IsConst, _IsVol>;
1749 using __type = typename __match::__type;
1752 // Utility for finding the unsigned versions of signed integral types.
1753 template<typename _Tp>
1754 struct __make_unsigned
1755 { using __type = _Tp; };
1758 struct __make_unsigned<char>
1759 { using __type = unsigned char; };
1762 struct __make_unsigned<signed char>
1763 { using __type = unsigned char; };
1766 struct __make_unsigned<short>
1767 { using __type = unsigned short; };
1770 struct __make_unsigned<int>
1771 { using __type = unsigned int; };
1774 struct __make_unsigned<long>
1775 { using __type = unsigned long; };
1778 struct __make_unsigned<long long>
1779 { using __type = unsigned long long; };
1781 #if defined(__GLIBCXX_TYPE_INT_N_0)
1784 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1785 { using __type = unsigned __GLIBCXX_TYPE_INT_N_0; };
1787 #if defined(__GLIBCXX_TYPE_INT_N_1)
1790 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1791 { using __type = unsigned __GLIBCXX_TYPE_INT_N_1; };
1793 #if defined(__GLIBCXX_TYPE_INT_N_2)
1796 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1797 { using __type = unsigned __GLIBCXX_TYPE_INT_N_2; };
1799 #if defined(__GLIBCXX_TYPE_INT_N_3)
1802 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1803 { using __type = unsigned __GLIBCXX_TYPE_INT_N_3; };
1806 // Select between integral and enum: not possible to be both.
1807 template<typename _Tp,
1808 bool _IsInt = is_integral<_Tp>::value,
1809 bool _IsEnum = __is_enum(_Tp)>
1810 class __make_unsigned_selector;
1812 template<typename _Tp>
1813 class __make_unsigned_selector<_Tp, true, false>
1815 using __unsigned_type
1816 = typename __make_unsigned<__remove_cv_t<_Tp>>::__type;
1820 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1823 class __make_unsigned_selector_base
1826 template<typename...> struct _List { };
1828 template<typename _Tp, typename... _Up>
1829 struct _List<_Tp, _Up...> : _List<_Up...>
1830 { static constexpr size_t __size = sizeof(_Tp); };
1832 template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
1835 template<size_t _Sz, typename _Uint, typename... _UInts>
1836 struct __select<_Sz, _List<_Uint, _UInts...>, true>
1837 { using __type = _Uint; };
1839 template<size_t _Sz, typename _Uint, typename... _UInts>
1840 struct __select<_Sz, _List<_Uint, _UInts...>, false>
1841 : __select<_Sz, _List<_UInts...>>
1845 // Choose unsigned integer type with the smallest rank and same size as _Tp
1846 template<typename _Tp>
1847 class __make_unsigned_selector<_Tp, false, true>
1848 : __make_unsigned_selector_base
1850 // With -fshort-enums, an enum may be as small as a char.
1851 using _UInts = _List<unsigned char, unsigned short, unsigned int,
1852 unsigned long, unsigned long long>;
1854 using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
1858 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1861 // wchar_t, char8_t, char16_t and char32_t are integral types but are
1862 // neither signed integer types nor unsigned integer types, so must be
1863 // transformed to the unsigned integer type with the smallest rank.
1864 // Use the partial specialization for enumeration types to do that.
1866 struct __make_unsigned<wchar_t>
1869 = typename __make_unsigned_selector<wchar_t, false, true>::__type;
1872 #ifdef _GLIBCXX_USE_CHAR8_T
1874 struct __make_unsigned<char8_t>
1877 = typename __make_unsigned_selector<char8_t, false, true>::__type;
1882 struct __make_unsigned<char16_t>
1885 = typename __make_unsigned_selector<char16_t, false, true>::__type;
1889 struct __make_unsigned<char32_t>
1892 = typename __make_unsigned_selector<char32_t, false, true>::__type;
1896 // Given an integral/enum type, return the corresponding unsigned
1898 // Primary template.
1900 template<typename _Tp>
1901 struct make_unsigned
1902 { using type = typename __make_unsigned_selector<_Tp>::__type; };
1904 // Integral, but don't define.
1905 template<> struct make_unsigned<bool>;
1906 template<> struct make_unsigned<bool const>;
1907 template<> struct make_unsigned<bool volatile>;
1908 template<> struct make_unsigned<bool const volatile>;
1910 /// @cond undocumented
1912 // Utility for finding the signed versions of unsigned integral types.
1913 template<typename _Tp>
1914 struct __make_signed
1915 { using __type = _Tp; };
1918 struct __make_signed<char>
1919 { using __type = signed char; };
1922 struct __make_signed<unsigned char>
1923 { using __type = signed char; };
1926 struct __make_signed<unsigned short>
1927 { using __type = signed short; };
1930 struct __make_signed<unsigned int>
1931 { using __type = signed int; };
1934 struct __make_signed<unsigned long>
1935 { using __type = signed long; };
1938 struct __make_signed<unsigned long long>
1939 { using __type = signed long long; };
1941 #if defined(__GLIBCXX_TYPE_INT_N_0)
1944 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
1945 { using __type = __GLIBCXX_TYPE_INT_N_0; };
1947 #if defined(__GLIBCXX_TYPE_INT_N_1)
1950 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
1951 { using __type = __GLIBCXX_TYPE_INT_N_1; };
1953 #if defined(__GLIBCXX_TYPE_INT_N_2)
1956 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
1957 { using __type = __GLIBCXX_TYPE_INT_N_2; };
1959 #if defined(__GLIBCXX_TYPE_INT_N_3)
1962 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
1963 { using __type = __GLIBCXX_TYPE_INT_N_3; };
1966 // Select between integral and enum: not possible to be both.
1967 template<typename _Tp,
1968 bool _IsInt = is_integral<_Tp>::value,
1969 bool _IsEnum = __is_enum(_Tp)>
1970 class __make_signed_selector;
1972 template<typename _Tp>
1973 class __make_signed_selector<_Tp, true, false>
1976 = typename __make_signed<__remove_cv_t<_Tp>>::__type;
1980 = typename __match_cv_qualifiers<_Tp, __signed_type>::__type;
1983 // Choose signed integer type with the smallest rank and same size as _Tp
1984 template<typename _Tp>
1985 class __make_signed_selector<_Tp, false, true>
1987 using __unsigned_type = typename __make_unsigned_selector<_Tp>::__type;
1990 using __type = typename __make_signed_selector<__unsigned_type>::__type;
1993 // wchar_t, char16_t and char32_t are integral types but are neither
1994 // signed integer types nor unsigned integer types, so must be
1995 // transformed to the signed integer type with the smallest rank.
1996 // Use the partial specialization for enumeration types to do that.
1998 struct __make_signed<wchar_t>
2001 = typename __make_signed_selector<wchar_t, false, true>::__type;
2004 #if defined(_GLIBCXX_USE_CHAR8_T)
2006 struct __make_signed<char8_t>
2009 = typename __make_signed_selector<char8_t, false, true>::__type;
2014 struct __make_signed<char16_t>
2017 = typename __make_signed_selector<char16_t, false, true>::__type;
2021 struct __make_signed<char32_t>
2024 = typename __make_signed_selector<char32_t, false, true>::__type;
2028 // Given an integral/enum type, return the corresponding signed
2030 // Primary template.
2032 template<typename _Tp>
2034 { using type = typename __make_signed_selector<_Tp>::__type; };
2036 // Integral, but don't define.
2037 template<> struct make_signed<bool>;
2038 template<> struct make_signed<bool const>;
2039 template<> struct make_signed<bool volatile>;
2040 template<> struct make_signed<bool const volatile>;
2042 #if __cplusplus > 201103L
2043 /// Alias template for make_signed
2044 template<typename _Tp>
2045 using make_signed_t = typename make_signed<_Tp>::type;
2047 /// Alias template for make_unsigned
2048 template<typename _Tp>
2049 using make_unsigned_t = typename make_unsigned<_Tp>::type;
2052 // Array modifications.
2055 template<typename _Tp>
2056 struct remove_extent
2057 { using type = _Tp; };
2059 template<typename _Tp, std::size_t _Size>
2060 struct remove_extent<_Tp[_Size]>
2061 { using type = _Tp; };
2063 template<typename _Tp>
2064 struct remove_extent<_Tp[]>
2065 { using type = _Tp; };
2067 /// remove_all_extents
2068 template<typename _Tp>
2069 struct remove_all_extents
2070 { using type = _Tp; };
2072 template<typename _Tp, std::size_t _Size>
2073 struct remove_all_extents<_Tp[_Size]>
2074 { using type = typename remove_all_extents<_Tp>::type; };
2076 template<typename _Tp>
2077 struct remove_all_extents<_Tp[]>
2078 { using type = typename remove_all_extents<_Tp>::type; };
2080 #if __cplusplus > 201103L
2081 /// Alias template for remove_extent
2082 template<typename _Tp>
2083 using remove_extent_t = typename remove_extent<_Tp>::type;
2085 /// Alias template for remove_all_extents
2086 template<typename _Tp>
2087 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
2090 // Pointer modifications.
2093 #if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer)
2094 template<typename _Tp>
2095 struct remove_pointer
2096 { using type = __remove_pointer(_Tp); };
2098 template<typename _Tp, typename>
2099 struct __remove_pointer_helper
2100 { using type = _Tp; };
2102 template<typename _Tp, typename _Up>
2103 struct __remove_pointer_helper<_Tp, _Up*>
2104 { using type = _Up; };
2106 template<typename _Tp>
2107 struct remove_pointer
2108 : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>>
2112 template<typename _Tp, typename = void>
2113 struct __add_pointer_helper
2114 { using type = _Tp; };
2116 template<typename _Tp>
2117 struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
2118 { using type = _Tp*; };
2121 template<typename _Tp>
2123 : public __add_pointer_helper<_Tp>
2126 template<typename _Tp>
2127 struct add_pointer<_Tp&>
2128 { using type = _Tp*; };
2130 template<typename _Tp>
2131 struct add_pointer<_Tp&&>
2132 { using type = _Tp*; };
2134 #if __cplusplus > 201103L
2135 /// Alias template for remove_pointer
2136 template<typename _Tp>
2137 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2139 /// Alias template for add_pointer
2140 template<typename _Tp>
2141 using add_pointer_t = typename add_pointer<_Tp>::type;
2144 template<std::size_t _Len>
2145 struct __aligned_storage_msa
2149 unsigned char __data[_Len];
2150 struct __attribute__((__aligned__)) { } __align;
2155 * @brief Alignment type.
2157 * The value of _Align is a default-alignment which shall be the
2158 * most stringent alignment requirement for any C++ object type
2159 * whose size is no greater than _Len (3.9). The member typedef
2160 * type shall be a POD type suitable for use as uninitialized
2161 * storage for any object whose size is at most _Len and whose
2162 * alignment is a divisor of _Align.
2164 * @deprecated Deprecated in C++23. Uses can be replaced by an
2165 * array std::byte[_Len] declared with alignas(_Align).
2167 template<std::size_t _Len, std::size_t _Align =
2168 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2170 _GLIBCXX23_DEPRECATED
2175 unsigned char __data[_Len];
2176 struct __attribute__((__aligned__((_Align)))) { } __align;
2180 template <typename... _Types>
2181 struct __strictest_alignment
2183 static const size_t _S_alignment = 0;
2184 static const size_t _S_size = 0;
2187 template <typename _Tp, typename... _Types>
2188 struct __strictest_alignment<_Tp, _Types...>
2190 static const size_t _S_alignment =
2191 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2192 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2193 static const size_t _S_size =
2194 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2195 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2198 #pragma GCC diagnostic push
2199 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2202 * @brief Provide aligned storage for types.
2204 * [meta.trans.other]
2206 * Provides aligned storage for any of the provided types of at
2209 * @see aligned_storage
2211 * @deprecated Deprecated in C++23.
2213 template <size_t _Len, typename... _Types>
2215 _GLIBCXX23_DEPRECATED
2219 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2221 using __strictest = __strictest_alignment<_Types...>;
2222 static const size_t _S_len = _Len > __strictest::_S_size
2223 ? _Len : __strictest::_S_size;
2225 /// The value of the strictest alignment of _Types.
2226 static const size_t alignment_value = __strictest::_S_alignment;
2228 using type = typename aligned_storage<_S_len, alignment_value>::type;
2231 template <size_t _Len, typename... _Types>
2232 const size_t aligned_union<_Len, _Types...>::alignment_value;
2233 #pragma GCC diagnostic pop
2235 /// @cond undocumented
2237 // Decay trait for arrays and functions, used for perfect forwarding
2238 // in make_pair, make_tuple, etc.
2239 template<typename _Up>
2240 struct __decay_selector
2241 : __conditional_t<is_const<const _Up>::value, // false for functions
2242 remove_cv<_Up>, // N.B. DR 705.
2243 add_pointer<_Up>> // function decays to pointer
2246 template<typename _Up, size_t _Nm>
2247 struct __decay_selector<_Up[_Nm]>
2248 { using type = _Up*; };
2250 template<typename _Up>
2251 struct __decay_selector<_Up[]>
2252 { using type = _Up*; };
2257 template<typename _Tp>
2259 { using type = typename __decay_selector<_Tp>::type; };
2261 template<typename _Tp>
2263 { using type = typename __decay_selector<_Tp>::type; };
2265 template<typename _Tp>
2267 { using type = typename __decay_selector<_Tp>::type; };
2269 /// @cond undocumented
2271 // Helper which adds a reference to a type when given a reference_wrapper
2272 template<typename _Tp>
2273 struct __strip_reference_wrapper
2278 template<typename _Tp>
2279 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2281 using __type = _Tp&;
2284 // __decay_t (std::decay_t for C++11).
2285 template<typename _Tp>
2286 using __decay_t = typename decay<_Tp>::type;
2288 template<typename _Tp>
2289 using __decay_and_strip = __strip_reference_wrapper<__decay_t<_Tp>>;
2292 /// @cond undocumented
2294 // Helper for SFINAE constraints
2295 template<typename... _Cond>
2296 using _Require = __enable_if_t<__and_<_Cond...>::value>;
2298 // __remove_cvref_t (std::remove_cvref_t for C++11).
2299 template<typename _Tp>
2300 using __remove_cvref_t
2301 = typename remove_cv<typename remove_reference<_Tp>::type>::type;
2304 // Primary template.
2305 /// Define a member typedef @c type to one of two argument types.
2306 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2308 { using type = _Iftrue; };
2310 // Partial specialization for false.
2311 template<typename _Iftrue, typename _Iffalse>
2312 struct conditional<false, _Iftrue, _Iffalse>
2313 { using type = _Iffalse; };
2316 template<typename... _Tp>
2319 // Sfinae-friendly common_type implementation:
2321 /// @cond undocumented
2323 // For several sfinae-friendly trait implementations we transport both the
2324 // result information (as the member type) and the failure information (no
2325 // member type). This is very similar to std::enable_if, but we cannot use
2326 // that, because we need to derive from them as an implementation detail.
2328 template<typename _Tp>
2329 struct __success_type
2330 { using type = _Tp; };
2332 struct __failure_type
2335 struct __do_common_type_impl
2337 template<typename _Tp, typename _Up>
2339 = decltype(true ? std::declval<_Tp>() : std::declval<_Up>());
2341 // if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2342 // denotes a valid type, let C denote that type.
2343 template<typename _Tp, typename _Up>
2344 static __success_type<__decay_t<__cond_t<_Tp, _Up>>>
2347 #if __cplusplus > 201703L
2348 // Otherwise, if COND-RES(CREF(D1), CREF(D2)) denotes a type,
2349 // let C denote the type decay_t<COND-RES(CREF(D1), CREF(D2))>.
2350 template<typename _Tp, typename _Up>
2351 static __success_type<__remove_cvref_t<__cond_t<const _Tp&, const _Up&>>>
2355 template<typename, typename>
2356 static __failure_type
2359 template<typename _Tp, typename _Up>
2360 static decltype(_S_test_2<_Tp, _Up>(0))
2364 // If sizeof...(T) is zero, there shall be no member type.
2366 struct common_type<>
2369 // If sizeof...(T) is one, the same type, if any, as common_type_t<T0, T0>.
2370 template<typename _Tp0>
2371 struct common_type<_Tp0>
2372 : public common_type<_Tp0, _Tp0>
2375 // If sizeof...(T) is two, ...
2376 template<typename _Tp1, typename _Tp2,
2377 typename _Dp1 = __decay_t<_Tp1>, typename _Dp2 = __decay_t<_Tp2>>
2378 struct __common_type_impl
2380 // If is_same_v<T1, D1> is false or is_same_v<T2, D2> is false,
2381 // let C denote the same type, if any, as common_type_t<D1, D2>.
2382 using type = common_type<_Dp1, _Dp2>;
2385 template<typename _Tp1, typename _Tp2>
2386 struct __common_type_impl<_Tp1, _Tp2, _Tp1, _Tp2>
2387 : private __do_common_type_impl
2389 // Otherwise, if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2390 // denotes a valid type, let C denote that type.
2391 using type = decltype(_S_test<_Tp1, _Tp2>(0));
2394 // If sizeof...(T) is two, ...
2395 template<typename _Tp1, typename _Tp2>
2396 struct common_type<_Tp1, _Tp2>
2397 : public __common_type_impl<_Tp1, _Tp2>::type
2400 template<typename...>
2401 struct __common_type_pack
2404 template<typename, typename, typename = void>
2405 struct __common_type_fold;
2407 // If sizeof...(T) is greater than two, ...
2408 template<typename _Tp1, typename _Tp2, typename... _Rp>
2409 struct common_type<_Tp1, _Tp2, _Rp...>
2410 : public __common_type_fold<common_type<_Tp1, _Tp2>,
2411 __common_type_pack<_Rp...>>
2414 // Let C denote the same type, if any, as common_type_t<T1, T2>.
2415 // If there is such a type C, type shall denote the same type, if any,
2416 // as common_type_t<C, R...>.
2417 template<typename _CTp, typename... _Rp>
2418 struct __common_type_fold<_CTp, __common_type_pack<_Rp...>,
2419 __void_t<typename _CTp::type>>
2420 : public common_type<typename _CTp::type, _Rp...>
2423 // Otherwise, there shall be no member type.
2424 template<typename _CTp, typename _Rp>
2425 struct __common_type_fold<_CTp, _Rp, void>
2428 template<typename _Tp, bool = __is_enum(_Tp)>
2429 struct __underlying_type_impl
2431 using type = __underlying_type(_Tp);
2434 template<typename _Tp>
2435 struct __underlying_type_impl<_Tp, false>
2439 /// The underlying type of an enum.
2440 template<typename _Tp>
2441 struct underlying_type
2442 : public __underlying_type_impl<_Tp>
2445 /// @cond undocumented
2446 template<typename _Tp>
2447 struct __declval_protector
2449 static const bool __stop = false;
2453 /** Utility to simplify expressions used in unevaluated operands
2455 * @ingroup utilities
2457 template<typename _Tp>
2458 auto declval() noexcept -> decltype(__declval<_Tp>(0))
2460 static_assert(__declval_protector<_Tp>::__stop,
2461 "declval() must not be used!");
2462 return __declval<_Tp>(0);
2466 template<typename _Signature>
2469 // Sfinae-friendly result_of implementation:
2471 /// @cond undocumented
2472 struct __invoke_memfun_ref { };
2473 struct __invoke_memfun_deref { };
2474 struct __invoke_memobj_ref { };
2475 struct __invoke_memobj_deref { };
2476 struct __invoke_other { };
2478 // Associate a tag type with a specialization of __success_type.
2479 template<typename _Tp, typename _Tag>
2480 struct __result_of_success : __success_type<_Tp>
2481 { using __invoke_type = _Tag; };
2483 // [func.require] paragraph 1 bullet 1:
2484 struct __result_of_memfun_ref_impl
2486 template<typename _Fp, typename _Tp1, typename... _Args>
2487 static __result_of_success<decltype(
2488 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2489 ), __invoke_memfun_ref> _S_test(int);
2491 template<typename...>
2492 static __failure_type _S_test(...);
2495 template<typename _MemPtr, typename _Arg, typename... _Args>
2496 struct __result_of_memfun_ref
2497 : private __result_of_memfun_ref_impl
2499 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2502 // [func.require] paragraph 1 bullet 2:
2503 struct __result_of_memfun_deref_impl
2505 template<typename _Fp, typename _Tp1, typename... _Args>
2506 static __result_of_success<decltype(
2507 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2508 ), __invoke_memfun_deref> _S_test(int);
2510 template<typename...>
2511 static __failure_type _S_test(...);
2514 template<typename _MemPtr, typename _Arg, typename... _Args>
2515 struct __result_of_memfun_deref
2516 : private __result_of_memfun_deref_impl
2518 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2521 // [func.require] paragraph 1 bullet 3:
2522 struct __result_of_memobj_ref_impl
2524 template<typename _Fp, typename _Tp1>
2525 static __result_of_success<decltype(
2526 std::declval<_Tp1>().*std::declval<_Fp>()
2527 ), __invoke_memobj_ref> _S_test(int);
2529 template<typename, typename>
2530 static __failure_type _S_test(...);
2533 template<typename _MemPtr, typename _Arg>
2534 struct __result_of_memobj_ref
2535 : private __result_of_memobj_ref_impl
2537 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2540 // [func.require] paragraph 1 bullet 4:
2541 struct __result_of_memobj_deref_impl
2543 template<typename _Fp, typename _Tp1>
2544 static __result_of_success<decltype(
2545 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2546 ), __invoke_memobj_deref> _S_test(int);
2548 template<typename, typename>
2549 static __failure_type _S_test(...);
2552 template<typename _MemPtr, typename _Arg>
2553 struct __result_of_memobj_deref
2554 : private __result_of_memobj_deref_impl
2556 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2559 template<typename _MemPtr, typename _Arg>
2560 struct __result_of_memobj;
2562 template<typename _Res, typename _Class, typename _Arg>
2563 struct __result_of_memobj<_Res _Class::*, _Arg>
2565 using _Argval = __remove_cvref_t<_Arg>;
2566 using _MemPtr = _Res _Class::*;
2567 using type = typename __conditional_t<__or_<is_same<_Argval, _Class>,
2568 is_base_of<_Class, _Argval>>::value,
2569 __result_of_memobj_ref<_MemPtr, _Arg>,
2570 __result_of_memobj_deref<_MemPtr, _Arg>
2574 template<typename _MemPtr, typename _Arg, typename... _Args>
2575 struct __result_of_memfun;
2577 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2578 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2580 using _Argval = typename remove_reference<_Arg>::type;
2581 using _MemPtr = _Res _Class::*;
2582 using type = typename __conditional_t<is_base_of<_Class, _Argval>::value,
2583 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2584 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2588 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2589 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2590 // as the object expression
2592 // Used by result_of, invoke etc. to unwrap a reference_wrapper.
2593 template<typename _Tp, typename _Up = __remove_cvref_t<_Tp>>
2599 template<typename _Tp, typename _Up>
2600 struct __inv_unwrap<_Tp, reference_wrapper<_Up>>
2605 template<bool, bool, typename _Functor, typename... _ArgTypes>
2606 struct __result_of_impl
2608 using type = __failure_type;
2611 template<typename _MemPtr, typename _Arg>
2612 struct __result_of_impl<true, false, _MemPtr, _Arg>
2613 : public __result_of_memobj<__decay_t<_MemPtr>,
2614 typename __inv_unwrap<_Arg>::type>
2617 template<typename _MemPtr, typename _Arg, typename... _Args>
2618 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2619 : public __result_of_memfun<__decay_t<_MemPtr>,
2620 typename __inv_unwrap<_Arg>::type, _Args...>
2623 // [func.require] paragraph 1 bullet 5:
2624 struct __result_of_other_impl
2626 template<typename _Fn, typename... _Args>
2627 static __result_of_success<decltype(
2628 std::declval<_Fn>()(std::declval<_Args>()...)
2629 ), __invoke_other> _S_test(int);
2631 template<typename...>
2632 static __failure_type _S_test(...);
2635 template<typename _Functor, typename... _ArgTypes>
2636 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2637 : private __result_of_other_impl
2639 using type = decltype(_S_test<_Functor, _ArgTypes...>(0));
2642 // __invoke_result (std::invoke_result for C++11)
2643 template<typename _Functor, typename... _ArgTypes>
2644 struct __invoke_result
2645 : public __result_of_impl<
2646 is_member_object_pointer<
2647 typename remove_reference<_Functor>::type
2649 is_member_function_pointer<
2650 typename remove_reference<_Functor>::type
2652 _Functor, _ArgTypes...
2657 template<typename _Functor, typename... _ArgTypes>
2658 struct result_of<_Functor(_ArgTypes...)>
2659 : public __invoke_result<_Functor, _ArgTypes...>
2660 { } _GLIBCXX17_DEPRECATED_SUGGEST("std::invoke_result");
2662 #if __cplusplus >= 201402L
2663 #pragma GCC diagnostic push
2664 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2665 /// Alias template for aligned_storage
2666 template<size_t _Len, size_t _Align =
2667 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2668 using aligned_storage_t _GLIBCXX23_DEPRECATED = typename aligned_storage<_Len, _Align>::type;
2670 template <size_t _Len, typename... _Types>
2671 using aligned_union_t _GLIBCXX23_DEPRECATED = typename aligned_union<_Len, _Types...>::type;
2672 #pragma GCC diagnostic pop
2674 /// Alias template for decay
2675 template<typename _Tp>
2676 using decay_t = typename decay<_Tp>::type;
2678 /// Alias template for enable_if
2679 template<bool _Cond, typename _Tp = void>
2680 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2682 /// Alias template for conditional
2683 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2684 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2686 /// Alias template for common_type
2687 template<typename... _Tp>
2688 using common_type_t = typename common_type<_Tp...>::type;
2690 /// Alias template for underlying_type
2691 template<typename _Tp>
2692 using underlying_type_t = typename underlying_type<_Tp>::type;
2694 /// Alias template for result_of
2695 template<typename _Tp>
2696 using result_of_t = typename result_of<_Tp>::type;
2699 #ifdef __cpp_lib_void_t // C++ >= 17 || GNU++ >= 11
2700 /// A metafunction that always yields void, used for detecting valid types.
2701 template<typename...> using void_t = void;
2704 /// @cond undocumented
2707 // Detect whether _Op<_Args...> is a valid type, use default _Def if not.
2710 // Implementation of the detection idiom (negative case).
2711 template<typename _Def, template<typename...> class _Op, typename... _Args>
2712 struct __detected_or
2715 using __is_detected = false_type;
2718 // Implementation of the detection idiom (positive case).
2719 template<typename _Def, template<typename...> class _Op, typename... _Args>
2720 requires requires { typename _Op<_Args...>; }
2721 struct __detected_or<_Def, _Op, _Args...>
2723 using type = _Op<_Args...>;
2724 using __is_detected = true_type;
2727 /// Implementation of the detection idiom (negative case).
2728 template<typename _Default, typename _AlwaysVoid,
2729 template<typename...> class _Op, typename... _Args>
2732 using type = _Default;
2733 using __is_detected = false_type;
2736 /// Implementation of the detection idiom (positive case).
2737 template<typename _Default, template<typename...> class _Op,
2739 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2741 using type = _Op<_Args...>;
2742 using __is_detected = true_type;
2745 template<typename _Default, template<typename...> class _Op,
2747 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2748 #endif // __cpp_concepts
2750 // _Op<_Args...> if that is a valid type, otherwise _Default.
2751 template<typename _Default, template<typename...> class _Op,
2753 using __detected_or_t
2754 = typename __detected_or<_Default, _Op, _Args...>::type;
2757 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2758 * member type _NTYPE.
2760 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2761 template<typename _Tp, typename = __void_t<>> \
2762 struct __has_##_NTYPE \
2765 template<typename _Tp> \
2766 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2770 template <typename _Tp>
2771 struct __is_swappable;
2773 template <typename _Tp>
2774 struct __is_nothrow_swappable;
2777 struct __is_tuple_like_impl : false_type
2780 // Internal type trait that allows us to sfinae-protect tuple_cat.
2781 template<typename _Tp>
2782 struct __is_tuple_like
2783 : public __is_tuple_like_impl<__remove_cvref_t<_Tp>>::type
2787 template<typename _Tp>
2788 _GLIBCXX20_CONSTEXPR
2790 _Require<__not_<__is_tuple_like<_Tp>>,
2791 is_move_constructible<_Tp>,
2792 is_move_assignable<_Tp>>
2794 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
2795 is_nothrow_move_assignable<_Tp>>::value);
2797 template<typename _Tp, size_t _Nm>
2798 _GLIBCXX20_CONSTEXPR
2800 __enable_if_t<__is_swappable<_Tp>::value>
2801 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
2802 noexcept(__is_nothrow_swappable<_Tp>::value);
2804 /// @cond undocumented
2805 namespace __swappable_details {
2808 struct __do_is_swappable_impl
2810 template<typename _Tp, typename
2811 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
2812 static true_type __test(int);
2815 static false_type __test(...);
2818 struct __do_is_nothrow_swappable_impl
2820 template<typename _Tp>
2821 static __bool_constant<
2822 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
2826 static false_type __test(...);
2829 } // namespace __swappable_details
2831 template<typename _Tp>
2832 struct __is_swappable_impl
2833 : public __swappable_details::__do_is_swappable_impl
2835 using type = decltype(__test<_Tp>(0));
2838 template<typename _Tp>
2839 struct __is_nothrow_swappable_impl
2840 : public __swappable_details::__do_is_nothrow_swappable_impl
2842 using type = decltype(__test<_Tp>(0));
2845 template<typename _Tp>
2846 struct __is_swappable
2847 : public __is_swappable_impl<_Tp>::type
2850 template<typename _Tp>
2851 struct __is_nothrow_swappable
2852 : public __is_nothrow_swappable_impl<_Tp>::type
2856 #ifdef __cpp_lib_is_swappable // C++ >= 17 || GNU++ >= 11
2857 /// Metafunctions used for detecting swappable types: p0185r1
2860 template<typename _Tp>
2862 : public __is_swappable_impl<_Tp>::type
2864 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2865 "template argument must be a complete class or an unbounded array");
2868 /// is_nothrow_swappable
2869 template<typename _Tp>
2870 struct is_nothrow_swappable
2871 : public __is_nothrow_swappable_impl<_Tp>::type
2873 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2874 "template argument must be a complete class or an unbounded array");
2877 #if __cplusplus >= 201402L
2879 template<typename _Tp>
2880 _GLIBCXX17_INLINE constexpr bool is_swappable_v =
2881 is_swappable<_Tp>::value;
2883 /// is_nothrow_swappable_v
2884 template<typename _Tp>
2885 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_v =
2886 is_nothrow_swappable<_Tp>::value;
2887 #endif // __cplusplus >= 201402L
2889 /// @cond undocumented
2890 namespace __swappable_with_details {
2893 struct __do_is_swappable_with_impl
2895 template<typename _Tp, typename _Up, typename
2896 = decltype(swap(std::declval<_Tp>(), std::declval<_Up>())),
2898 = decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))>
2899 static true_type __test(int);
2901 template<typename, typename>
2902 static false_type __test(...);
2905 struct __do_is_nothrow_swappable_with_impl
2907 template<typename _Tp, typename _Up>
2908 static __bool_constant<
2909 noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
2911 noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()))
2914 template<typename, typename>
2915 static false_type __test(...);
2918 } // namespace __swappable_with_details
2920 template<typename _Tp, typename _Up>
2921 struct __is_swappable_with_impl
2922 : public __swappable_with_details::__do_is_swappable_with_impl
2924 using type = decltype(__test<_Tp, _Up>(0));
2927 // Optimization for the homogenous lvalue case, not required:
2928 template<typename _Tp>
2929 struct __is_swappable_with_impl<_Tp&, _Tp&>
2930 : public __swappable_details::__do_is_swappable_impl
2932 using type = decltype(__test<_Tp&>(0));
2935 template<typename _Tp, typename _Up>
2936 struct __is_nothrow_swappable_with_impl
2937 : public __swappable_with_details::__do_is_nothrow_swappable_with_impl
2939 using type = decltype(__test<_Tp, _Up>(0));
2942 // Optimization for the homogenous lvalue case, not required:
2943 template<typename _Tp>
2944 struct __is_nothrow_swappable_with_impl<_Tp&, _Tp&>
2945 : public __swappable_details::__do_is_nothrow_swappable_impl
2947 using type = decltype(__test<_Tp&>(0));
2951 /// is_swappable_with
2952 template<typename _Tp, typename _Up>
2953 struct is_swappable_with
2954 : public __is_swappable_with_impl<_Tp, _Up>::type
2956 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2957 "first template argument must be a complete class or an unbounded array");
2958 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
2959 "second template argument must be a complete class or an unbounded array");
2962 /// is_nothrow_swappable_with
2963 template<typename _Tp, typename _Up>
2964 struct is_nothrow_swappable_with
2965 : public __is_nothrow_swappable_with_impl<_Tp, _Up>::type
2967 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2968 "first template argument must be a complete class or an unbounded array");
2969 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
2970 "second template argument must be a complete class or an unbounded array");
2973 #if __cplusplus >= 201402L
2974 /// is_swappable_with_v
2975 template<typename _Tp, typename _Up>
2976 _GLIBCXX17_INLINE constexpr bool is_swappable_with_v =
2977 is_swappable_with<_Tp, _Up>::value;
2979 /// is_nothrow_swappable_with_v
2980 template<typename _Tp, typename _Up>
2981 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_with_v =
2982 is_nothrow_swappable_with<_Tp, _Up>::value;
2983 #endif // __cplusplus >= 201402L
2985 #endif // __cpp_lib_is_swappable
2987 /// @cond undocumented
2989 // __is_invocable (std::is_invocable for C++11)
2991 // The primary template is used for invalid INVOKE expressions.
2992 template<typename _Result, typename _Ret,
2993 bool = is_void<_Ret>::value, typename = void>
2994 struct __is_invocable_impl
2997 using __nothrow_conv = false_type; // For is_nothrow_invocable_r
3000 // Used for valid INVOKE and INVOKE<void> expressions.
3001 template<typename _Result, typename _Ret>
3002 struct __is_invocable_impl<_Result, _Ret,
3003 /* is_void<_Ret> = */ true,
3004 __void_t<typename _Result::type>>
3007 using __nothrow_conv = true_type; // For is_nothrow_invocable_r
3010 #pragma GCC diagnostic push
3011 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3012 // Used for INVOKE<R> expressions to check the implicit conversion to R.
3013 template<typename _Result, typename _Ret>
3014 struct __is_invocable_impl<_Result, _Ret,
3015 /* is_void<_Ret> = */ false,
3016 __void_t<typename _Result::type>>
3019 // The type of the INVOKE expression.
3020 using _Res_t = typename _Result::type;
3022 // Unlike declval, this doesn't add_rvalue_reference, so it respects
3023 // guaranteed copy elision.
3024 static _Res_t _S_get() noexcept;
3026 // Used to check if _Res_t can implicitly convert to _Tp.
3027 template<typename _Tp>
3028 static void _S_conv(__type_identity_t<_Tp>) noexcept;
3030 // This overload is viable if INVOKE(f, args...) can convert to _Tp.
3031 template<typename _Tp,
3032 bool _Nothrow = noexcept(_S_conv<_Tp>(_S_get())),
3033 typename = decltype(_S_conv<_Tp>(_S_get())),
3034 #if __has_builtin(__reference_converts_from_temporary)
3035 bool _Dangle = __reference_converts_from_temporary(_Tp, _Res_t)
3037 bool _Dangle = false
3040 static __bool_constant<_Nothrow && !_Dangle>
3043 template<typename _Tp, bool = false>
3048 // For is_invocable_r
3049 using type = decltype(_S_test<_Ret, /* Nothrow = */ true>(1));
3051 // For is_nothrow_invocable_r
3052 using __nothrow_conv = decltype(_S_test<_Ret>(1));
3054 #pragma GCC diagnostic pop
3056 template<typename _Fn, typename... _ArgTypes>
3057 struct __is_invocable
3058 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3061 template<typename _Fn, typename _Tp, typename... _Args>
3062 constexpr bool __call_is_nt(__invoke_memfun_ref)
3064 using _Up = typename __inv_unwrap<_Tp>::type;
3065 return noexcept((std::declval<_Up>().*std::declval<_Fn>())(
3066 std::declval<_Args>()...));
3069 template<typename _Fn, typename _Tp, typename... _Args>
3070 constexpr bool __call_is_nt(__invoke_memfun_deref)
3072 return noexcept(((*std::declval<_Tp>()).*std::declval<_Fn>())(
3073 std::declval<_Args>()...));
3076 template<typename _Fn, typename _Tp>
3077 constexpr bool __call_is_nt(__invoke_memobj_ref)
3079 using _Up = typename __inv_unwrap<_Tp>::type;
3080 return noexcept(std::declval<_Up>().*std::declval<_Fn>());
3083 template<typename _Fn, typename _Tp>
3084 constexpr bool __call_is_nt(__invoke_memobj_deref)
3086 return noexcept((*std::declval<_Tp>()).*std::declval<_Fn>());
3089 template<typename _Fn, typename... _Args>
3090 constexpr bool __call_is_nt(__invoke_other)
3092 return noexcept(std::declval<_Fn>()(std::declval<_Args>()...));
3095 template<typename _Result, typename _Fn, typename... _Args>
3096 struct __call_is_nothrow
3098 std::__call_is_nt<_Fn, _Args...>(typename _Result::__invoke_type{})
3102 template<typename _Fn, typename... _Args>
3103 using __call_is_nothrow_
3104 = __call_is_nothrow<__invoke_result<_Fn, _Args...>, _Fn, _Args...>;
3106 // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
3107 template<typename _Fn, typename... _Args>
3108 struct __is_nothrow_invocable
3109 : __and_<__is_invocable<_Fn, _Args...>,
3110 __call_is_nothrow_<_Fn, _Args...>>::type
3113 #pragma GCC diagnostic push
3114 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3115 struct __nonesuchbase {};
3116 struct __nonesuch : private __nonesuchbase {
3117 ~__nonesuch() = delete;
3118 __nonesuch(__nonesuch const&) = delete;
3119 void operator=(__nonesuch const&) = delete;
3121 #pragma GCC diagnostic pop
3124 #ifdef __cpp_lib_is_invocable // C++ >= 17
3125 /// std::invoke_result
3126 template<typename _Functor, typename... _ArgTypes>
3127 struct invoke_result
3128 : public __invoke_result<_Functor, _ArgTypes...>
3130 static_assert(std::__is_complete_or_unbounded(__type_identity<_Functor>{}),
3131 "_Functor must be a complete class or an unbounded array");
3132 static_assert((std::__is_complete_or_unbounded(
3133 __type_identity<_ArgTypes>{}) && ...),
3134 "each argument type must be a complete class or an unbounded array");
3137 /// std::invoke_result_t
3138 template<typename _Fn, typename... _Args>
3139 using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3141 /// std::is_invocable
3142 template<typename _Fn, typename... _ArgTypes>
3144 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3146 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3147 "_Fn must be a complete class or an unbounded array");
3148 static_assert((std::__is_complete_or_unbounded(
3149 __type_identity<_ArgTypes>{}) && ...),
3150 "each argument type must be a complete class or an unbounded array");
3153 /// std::is_invocable_r
3154 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3155 struct is_invocable_r
3156 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>::type
3158 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3159 "_Fn must be a complete class or an unbounded array");
3160 static_assert((std::__is_complete_or_unbounded(
3161 __type_identity<_ArgTypes>{}) && ...),
3162 "each argument type must be a complete class or an unbounded array");
3163 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3164 "_Ret must be a complete class or an unbounded array");
3167 /// std::is_nothrow_invocable
3168 template<typename _Fn, typename... _ArgTypes>
3169 struct is_nothrow_invocable
3170 : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>,
3171 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3173 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3174 "_Fn must be a complete class or an unbounded array");
3175 static_assert((std::__is_complete_or_unbounded(
3176 __type_identity<_ArgTypes>{}) && ...),
3177 "each argument type must be a complete class or an unbounded array");
3180 /// @cond undocumented
3181 // This checks that the INVOKE<R> expression is well-formed and that the
3182 // conversion to R does not throw. It does *not* check whether the INVOKE
3183 // expression itself can throw. That is done by __call_is_nothrow_ instead.
3184 template<typename _Result, typename _Ret>
3185 using __is_nt_invocable_impl
3186 = typename __is_invocable_impl<_Result, _Ret>::__nothrow_conv;
3189 /// std::is_nothrow_invocable_r
3190 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3191 struct is_nothrow_invocable_r
3192 : __and_<__is_nt_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>,
3193 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3195 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3196 "_Fn must be a complete class or an unbounded array");
3197 static_assert((std::__is_complete_or_unbounded(
3198 __type_identity<_ArgTypes>{}) && ...),
3199 "each argument type must be a complete class or an unbounded array");
3200 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3201 "_Ret must be a complete class or an unbounded array");
3203 #endif // __cpp_lib_is_invocable
3205 #if __cpp_lib_type_trait_variable_templates // C++ >= 17
3207 * @defgroup variable_templates Variable templates for type traits
3208 * @ingroup metaprogramming
3210 * Each variable `is_xxx_v<T>` is a boolean constant with the same value
3211 * as the `value` member of the corresponding type trait `is_xxx<T>`.
3213 * @since C++17 unless noted otherwise.
3218 * @ingroup variable_templates
3220 template <typename _Tp>
3221 inline constexpr bool is_void_v = is_void<_Tp>::value;
3222 template <typename _Tp>
3223 inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
3224 template <typename _Tp>
3225 inline constexpr bool is_integral_v = is_integral<_Tp>::value;
3226 template <typename _Tp>
3227 inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
3229 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
3230 template <typename _Tp>
3231 inline constexpr bool is_array_v = __is_array(_Tp);
3233 template <typename _Tp>
3234 inline constexpr bool is_array_v = false;
3235 template <typename _Tp>
3236 inline constexpr bool is_array_v<_Tp[]> = true;
3237 template <typename _Tp, size_t _Num>
3238 inline constexpr bool is_array_v<_Tp[_Num]> = true;
3241 template <typename _Tp>
3242 inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
3243 template <typename _Tp>
3244 inline constexpr bool is_lvalue_reference_v = false;
3245 template <typename _Tp>
3246 inline constexpr bool is_lvalue_reference_v<_Tp&> = true;
3247 template <typename _Tp>
3248 inline constexpr bool is_rvalue_reference_v = false;
3249 template <typename _Tp>
3250 inline constexpr bool is_rvalue_reference_v<_Tp&&> = true;
3252 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
3253 template <typename _Tp>
3254 inline constexpr bool is_member_object_pointer_v =
3255 __is_member_object_pointer(_Tp);
3257 template <typename _Tp>
3258 inline constexpr bool is_member_object_pointer_v =
3259 is_member_object_pointer<_Tp>::value;
3262 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
3263 template <typename _Tp>
3264 inline constexpr bool is_member_function_pointer_v =
3265 __is_member_function_pointer(_Tp);
3267 template <typename _Tp>
3268 inline constexpr bool is_member_function_pointer_v =
3269 is_member_function_pointer<_Tp>::value;
3272 template <typename _Tp>
3273 inline constexpr bool is_enum_v = __is_enum(_Tp);
3274 template <typename _Tp>
3275 inline constexpr bool is_union_v = __is_union(_Tp);
3276 template <typename _Tp>
3277 inline constexpr bool is_class_v = __is_class(_Tp);
3278 // is_function_v is defined below, after is_const_v.
3280 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
3281 template <typename _Tp>
3282 inline constexpr bool is_reference_v = __is_reference(_Tp);
3284 template <typename _Tp>
3285 inline constexpr bool is_reference_v = false;
3286 template <typename _Tp>
3287 inline constexpr bool is_reference_v<_Tp&> = true;
3288 template <typename _Tp>
3289 inline constexpr bool is_reference_v<_Tp&&> = true;
3292 template <typename _Tp>
3293 inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
3294 template <typename _Tp>
3295 inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
3297 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
3298 template <typename _Tp>
3299 inline constexpr bool is_object_v = __is_object(_Tp);
3301 template <typename _Tp>
3302 inline constexpr bool is_object_v = is_object<_Tp>::value;
3305 template <typename _Tp>
3306 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
3307 template <typename _Tp>
3308 inline constexpr bool is_compound_v = is_compound<_Tp>::value;
3310 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
3311 template <typename _Tp>
3312 inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
3314 template <typename _Tp>
3315 inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
3318 template <typename _Tp>
3319 inline constexpr bool is_const_v = false;
3320 template <typename _Tp>
3321 inline constexpr bool is_const_v<const _Tp> = true;
3323 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
3324 template <typename _Tp>
3325 inline constexpr bool is_function_v = __is_function(_Tp);
3327 template <typename _Tp>
3328 inline constexpr bool is_function_v = !is_const_v<const _Tp>;
3329 template <typename _Tp>
3330 inline constexpr bool is_function_v<_Tp&> = false;
3331 template <typename _Tp>
3332 inline constexpr bool is_function_v<_Tp&&> = false;
3335 template <typename _Tp>
3336 inline constexpr bool is_volatile_v = false;
3337 template <typename _Tp>
3338 inline constexpr bool is_volatile_v<volatile _Tp> = true;
3340 template <typename _Tp>
3341 inline constexpr bool is_trivial_v = __is_trivial(_Tp);
3342 template <typename _Tp>
3343 inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
3344 template <typename _Tp>
3345 inline constexpr bool is_standard_layout_v = __is_standard_layout(_Tp);
3346 template <typename _Tp>
3347 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout_v && is_trivial_v")
3348 inline constexpr bool is_pod_v = __is_pod(_Tp);
3349 template <typename _Tp>
3350 _GLIBCXX17_DEPRECATED
3351 inline constexpr bool is_literal_type_v = __is_literal_type(_Tp);
3352 template <typename _Tp>
3353 inline constexpr bool is_empty_v = __is_empty(_Tp);
3354 template <typename _Tp>
3355 inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
3356 template <typename _Tp>
3357 inline constexpr bool is_abstract_v = __is_abstract(_Tp);
3358 template <typename _Tp>
3359 inline constexpr bool is_final_v = __is_final(_Tp);
3361 template <typename _Tp>
3362 inline constexpr bool is_signed_v = is_signed<_Tp>::value;
3363 template <typename _Tp>
3364 inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
3366 template <typename _Tp, typename... _Args>
3367 inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
3368 template <typename _Tp>
3369 inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
3370 template <typename _Tp>
3371 inline constexpr bool is_copy_constructible_v
3372 = __is_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3373 template <typename _Tp>
3374 inline constexpr bool is_move_constructible_v
3375 = __is_constructible(_Tp, __add_rval_ref_t<_Tp>);
3377 template <typename _Tp, typename _Up>
3378 inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Up);
3379 template <typename _Tp>
3380 inline constexpr bool is_copy_assignable_v
3381 = __is_assignable(__add_lval_ref_t<_Tp>, __add_lval_ref_t<const _Tp>);
3382 template <typename _Tp>
3383 inline constexpr bool is_move_assignable_v
3384 = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3386 template <typename _Tp>
3387 inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
3389 template <typename _Tp, typename... _Args>
3390 inline constexpr bool is_trivially_constructible_v
3391 = __is_trivially_constructible(_Tp, _Args...);
3392 template <typename _Tp>
3393 inline constexpr bool is_trivially_default_constructible_v
3394 = __is_trivially_constructible(_Tp);
3395 template <typename _Tp>
3396 inline constexpr bool is_trivially_copy_constructible_v
3397 = __is_trivially_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3398 template <typename _Tp>
3399 inline constexpr bool is_trivially_move_constructible_v
3400 = __is_trivially_constructible(_Tp, __add_rval_ref_t<_Tp>);
3402 template <typename _Tp, typename _Up>
3403 inline constexpr bool is_trivially_assignable_v
3404 = __is_trivially_assignable(_Tp, _Up);
3405 template <typename _Tp>
3406 inline constexpr bool is_trivially_copy_assignable_v
3407 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3408 __add_lval_ref_t<const _Tp>);
3409 template <typename _Tp>
3410 inline constexpr bool is_trivially_move_assignable_v
3411 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3412 __add_rval_ref_t<_Tp>);
3413 template <typename _Tp>
3414 inline constexpr bool is_trivially_destructible_v =
3415 is_trivially_destructible<_Tp>::value;
3416 template <typename _Tp, typename... _Args>
3417 inline constexpr bool is_nothrow_constructible_v
3418 = __is_nothrow_constructible(_Tp, _Args...);
3419 template <typename _Tp>
3420 inline constexpr bool is_nothrow_default_constructible_v
3421 = __is_nothrow_constructible(_Tp);
3422 template <typename _Tp>
3423 inline constexpr bool is_nothrow_copy_constructible_v
3424 = __is_nothrow_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3425 template <typename _Tp>
3426 inline constexpr bool is_nothrow_move_constructible_v
3427 = __is_nothrow_constructible(_Tp, __add_rval_ref_t<_Tp>);
3429 template <typename _Tp, typename _Up>
3430 inline constexpr bool is_nothrow_assignable_v
3431 = __is_nothrow_assignable(_Tp, _Up);
3432 template <typename _Tp>
3433 inline constexpr bool is_nothrow_copy_assignable_v
3434 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>,
3435 __add_lval_ref_t<const _Tp>);
3436 template <typename _Tp>
3437 inline constexpr bool is_nothrow_move_assignable_v
3438 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3440 template <typename _Tp>
3441 inline constexpr bool is_nothrow_destructible_v =
3442 is_nothrow_destructible<_Tp>::value;
3444 template <typename _Tp>
3445 inline constexpr bool has_virtual_destructor_v
3446 = __has_virtual_destructor(_Tp);
3448 template <typename _Tp>
3449 inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
3451 template <typename _Tp>
3452 inline constexpr size_t rank_v = 0;
3453 template <typename _Tp, size_t _Size>
3454 inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
3455 template <typename _Tp>
3456 inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
3458 template <typename _Tp, unsigned _Idx = 0>
3459 inline constexpr size_t extent_v = 0;
3460 template <typename _Tp, size_t _Size>
3461 inline constexpr size_t extent_v<_Tp[_Size], 0> = _Size;
3462 template <typename _Tp, unsigned _Idx, size_t _Size>
3463 inline constexpr size_t extent_v<_Tp[_Size], _Idx> = extent_v<_Tp, _Idx - 1>;
3464 template <typename _Tp>
3465 inline constexpr size_t extent_v<_Tp[], 0> = 0;
3466 template <typename _Tp, unsigned _Idx>
3467 inline constexpr size_t extent_v<_Tp[], _Idx> = extent_v<_Tp, _Idx - 1>;
3469 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_SAME
3470 template <typename _Tp, typename _Up>
3471 inline constexpr bool is_same_v = __is_same(_Tp, _Up);
3473 template <typename _Tp, typename _Up>
3474 inline constexpr bool is_same_v = false;
3475 template <typename _Tp>
3476 inline constexpr bool is_same_v<_Tp, _Tp> = true;
3478 template <typename _Base, typename _Derived>
3479 inline constexpr bool is_base_of_v = __is_base_of(_Base, _Derived);
3480 template <typename _From, typename _To>
3481 inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
3482 template<typename _Fn, typename... _Args>
3483 inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
3484 template<typename _Fn, typename... _Args>
3485 inline constexpr bool is_nothrow_invocable_v
3486 = is_nothrow_invocable<_Fn, _Args...>::value;
3487 template<typename _Ret, typename _Fn, typename... _Args>
3488 inline constexpr bool is_invocable_r_v
3489 = is_invocable_r<_Ret, _Fn, _Args...>::value;
3490 template<typename _Ret, typename _Fn, typename... _Args>
3491 inline constexpr bool is_nothrow_invocable_r_v
3492 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3494 #endif // __cpp_lib_type_trait_variable_templates
3496 #ifdef __cpp_lib_has_unique_object_representations // C++ >= 17 && HAS_UNIQ_OBJ_REP
3497 /// has_unique_object_representations
3499 template<typename _Tp>
3500 struct has_unique_object_representations
3501 : bool_constant<__has_unique_object_representations(
3502 remove_cv_t<remove_all_extents_t<_Tp>>
3505 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3506 "template argument must be a complete class or an unbounded array");
3509 # if __cpp_lib_type_trait_variable_templates // C++ >= 17
3510 /// @ingroup variable_templates
3511 template<typename _Tp>
3512 inline constexpr bool has_unique_object_representations_v
3513 = has_unique_object_representations<_Tp>::value;
3517 #ifdef __cpp_lib_is_aggregate // C++ >= 17 && builtin_is_aggregate
3518 /// is_aggregate - true if the type is an aggregate.
3520 template<typename _Tp>
3522 : bool_constant<__is_aggregate(remove_cv_t<_Tp>)>
3525 # if __cpp_lib_type_trait_variable_templates // C++ >= 17
3526 /** is_aggregate_v - true if the type is an aggregate.
3527 * @ingroup variable_templates
3530 template<typename _Tp>
3531 inline constexpr bool is_aggregate_v = __is_aggregate(remove_cv_t<_Tp>);
3535 /** * Remove references and cv-qualifiers.
3539 #ifdef __cpp_lib_remove_cvref // C++ >= 20
3540 # if __has_builtin(__remove_cvref)
3541 template<typename _Tp>
3543 { using type = __remove_cvref(_Tp); };
3545 template<typename _Tp>
3547 { using type = typename remove_cv<_Tp>::type; };
3549 template<typename _Tp>
3550 struct remove_cvref<_Tp&>
3551 { using type = typename remove_cv<_Tp>::type; };
3553 template<typename _Tp>
3554 struct remove_cvref<_Tp&&>
3555 { using type = typename remove_cv<_Tp>::type; };
3558 template<typename _Tp>
3559 using remove_cvref_t = typename remove_cvref<_Tp>::type;
3561 #endif // __cpp_lib_remove_cvref
3563 #ifdef __cpp_lib_type_identity // C++ >= 20
3564 /** * Identity metafunction.
3568 template<typename _Tp>
3569 struct type_identity { using type = _Tp; };
3571 template<typename _Tp>
3572 using type_identity_t = typename type_identity<_Tp>::type;
3576 #ifdef __cpp_lib_unwrap_ref // C++ >= 20
3577 /** Unwrap a reference_wrapper
3581 template<typename _Tp>
3582 struct unwrap_reference { using type = _Tp; };
3584 template<typename _Tp>
3585 struct unwrap_reference<reference_wrapper<_Tp>> { using type = _Tp&; };
3587 template<typename _Tp>
3588 using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3591 /** Decay type and if it's a reference_wrapper, unwrap it
3595 template<typename _Tp>
3596 struct unwrap_ref_decay { using type = unwrap_reference_t<decay_t<_Tp>>; };
3598 template<typename _Tp>
3599 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3601 #endif // __cpp_lib_unwrap_ref
3603 #ifdef __cpp_lib_bounded_array_traits // C++ >= 20
3604 /// True for a type that is an array of known bound.
3605 /// @ingroup variable_templates
3607 # if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array)
3608 template<typename _Tp>
3609 inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp);
3611 template<typename _Tp>
3612 inline constexpr bool is_bounded_array_v = false;
3614 template<typename _Tp, size_t _Size>
3615 inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true;
3618 /// True for a type that is an array of unknown bound.
3619 /// @ingroup variable_templates
3621 template<typename _Tp>
3622 inline constexpr bool is_unbounded_array_v = false;
3624 template<typename _Tp>
3625 inline constexpr bool is_unbounded_array_v<_Tp[]> = true;
3627 /// True for a type that is an array of known bound.
3629 template<typename _Tp>
3630 struct is_bounded_array
3631 : public bool_constant<is_bounded_array_v<_Tp>>
3634 /// True for a type that is an array of unknown bound.
3636 template<typename _Tp>
3637 struct is_unbounded_array
3638 : public bool_constant<is_unbounded_array_v<_Tp>>
3640 #endif // __cpp_lib_bounded_array_traits
3642 #if __has_builtin(__is_layout_compatible) && __cplusplus >= 202002L
3645 template<typename _Tp, typename _Up>
3646 struct is_layout_compatible
3647 : bool_constant<__is_layout_compatible(_Tp, _Up)>
3650 /// @ingroup variable_templates
3652 template<typename _Tp, typename _Up>
3653 constexpr bool is_layout_compatible_v
3654 = __is_layout_compatible(_Tp, _Up);
3656 #if __has_builtin(__builtin_is_corresponding_member)
3657 # ifndef __cpp_lib_is_layout_compatible
3658 # error "libstdc++ bug: is_corresponding_member and is_layout_compatible are provided but their FTM is not set"
3662 template<typename _S1, typename _S2, typename _M1, typename _M2>
3664 is_corresponding_member(_M1 _S1::*__m1, _M2 _S2::*__m2) noexcept
3665 { return __builtin_is_corresponding_member(__m1, __m2); }
3669 #if __has_builtin(__is_pointer_interconvertible_base_of) \
3670 && __cplusplus >= 202002L
3671 /// True if `_Derived` is standard-layout and has a base class of type `_Base`
3673 template<typename _Base, typename _Derived>
3674 struct is_pointer_interconvertible_base_of
3675 : bool_constant<__is_pointer_interconvertible_base_of(_Base, _Derived)>
3678 /// @ingroup variable_templates
3680 template<typename _Base, typename _Derived>
3681 constexpr bool is_pointer_interconvertible_base_of_v
3682 = __is_pointer_interconvertible_base_of(_Base, _Derived);
3684 #if __has_builtin(__builtin_is_pointer_interconvertible_with_class)
3685 # ifndef __cpp_lib_is_pointer_interconvertible
3686 # error "libstdc++ bug: is_pointer_interconvertible available but FTM is not set"
3689 /// True if `__mp` points to the first member of a standard-layout type
3690 /// @returns true if `s.*__mp` is pointer-interconvertible with `s`
3692 template<typename _Tp, typename _Mem>
3694 is_pointer_interconvertible_with_class(_Mem _Tp::*__mp) noexcept
3695 { return __builtin_is_pointer_interconvertible_with_class(__mp); }
3699 #ifdef __cpp_lib_is_scoped_enum // C++ >= 23
3700 /// True if the type is a scoped enumeration type.
3703 # if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
3704 template<typename _Tp>
3705 struct is_scoped_enum
3706 : bool_constant<__is_scoped_enum(_Tp)>
3709 template<typename _Tp>
3710 struct is_scoped_enum
3714 template<typename _Tp>
3715 requires __is_enum(_Tp)
3716 && requires(remove_cv_t<_Tp> __t) { __t = __t; } // fails if incomplete
3717 struct is_scoped_enum<_Tp>
3718 : bool_constant<!requires(_Tp __t, void(*__f)(int)) { __f(__t); }>
3722 /// @ingroup variable_templates
3724 # if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
3725 template<typename _Tp>
3726 inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
3728 template<typename _Tp>
3729 inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
3733 #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp
3734 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
3735 /// direct-initialization, and a temporary object would be bound to
3736 /// the reference, false otherwise.
3738 template<typename _Tp, typename _Up>
3739 struct reference_constructs_from_temporary
3740 : public bool_constant<__reference_constructs_from_temporary(_Tp, _Up)>
3742 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
3743 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3744 "template argument must be a complete class or an unbounded array");
3747 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
3748 /// copy-initialization, and a temporary object would be bound to
3749 /// the reference, false otherwise.
3751 template<typename _Tp, typename _Up>
3752 struct reference_converts_from_temporary
3753 : public bool_constant<__reference_converts_from_temporary(_Tp, _Up)>
3755 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
3756 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3757 "template argument must be a complete class or an unbounded array");
3760 /// @ingroup variable_templates
3762 template<typename _Tp, typename _Up>
3763 inline constexpr bool reference_constructs_from_temporary_v
3764 = reference_constructs_from_temporary<_Tp, _Up>::value;
3766 /// @ingroup variable_templates
3768 template<typename _Tp, typename _Up>
3769 inline constexpr bool reference_converts_from_temporary_v
3770 = reference_converts_from_temporary<_Tp, _Up>::value;
3771 #endif // __cpp_lib_reference_from_temporary
3773 #ifdef __cpp_lib_is_constant_evaluated // C++ >= 20 && HAVE_IS_CONST_EVAL
3774 /// Returns true only when called during constant evaluation.
3776 constexpr inline bool
3777 is_constant_evaluated() noexcept
3779 #if __cpp_if_consteval >= 202106L
3780 if consteval { return true; } else { return false; }
3782 return __builtin_is_constant_evaluated();
3787 #if __cplusplus >= 202002L
3788 /// @cond undocumented
3789 template<typename _From, typename _To>
3790 using __copy_cv = typename __match_cv_qualifiers<_From, _To>::__type;
3792 template<typename _Xp, typename _Yp>
3794 = decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
3796 template<typename _Ap, typename _Bp, typename = void>
3797 struct __common_ref_impl
3800 // [meta.trans.other], COMMON-REF(A, B)
3801 template<typename _Ap, typename _Bp>
3802 using __common_ref = typename __common_ref_impl<_Ap, _Bp>::type;
3804 // COND-RES(COPYCV(X, Y) &, COPYCV(Y, X) &)
3805 template<typename _Xp, typename _Yp>
3806 using __condres_cvref
3807 = __cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>;
3809 // If A and B are both lvalue reference types, ...
3810 template<typename _Xp, typename _Yp>
3811 struct __common_ref_impl<_Xp&, _Yp&, __void_t<__condres_cvref<_Xp, _Yp>>>
3812 : enable_if<is_reference_v<__condres_cvref<_Xp, _Yp>>,
3813 __condres_cvref<_Xp, _Yp>>
3816 // let C be remove_reference_t<COMMON-REF(X&, Y&)>&&
3817 template<typename _Xp, typename _Yp>
3818 using __common_ref_C = remove_reference_t<__common_ref<_Xp&, _Yp&>>&&;
3820 // If A and B are both rvalue reference types, ...
3821 template<typename _Xp, typename _Yp>
3822 struct __common_ref_impl<_Xp&&, _Yp&&,
3823 _Require<is_convertible<_Xp&&, __common_ref_C<_Xp, _Yp>>,
3824 is_convertible<_Yp&&, __common_ref_C<_Xp, _Yp>>>>
3825 { using type = __common_ref_C<_Xp, _Yp>; };
3827 // let D be COMMON-REF(const X&, Y&)
3828 template<typename _Xp, typename _Yp>
3829 using __common_ref_D = __common_ref<const _Xp&, _Yp&>;
3831 // If A is an rvalue reference and B is an lvalue reference, ...
3832 template<typename _Xp, typename _Yp>
3833 struct __common_ref_impl<_Xp&&, _Yp&,
3834 _Require<is_convertible<_Xp&&, __common_ref_D<_Xp, _Yp>>>>
3835 { using type = __common_ref_D<_Xp, _Yp>; };
3837 // If A is an lvalue reference and B is an rvalue reference, ...
3838 template<typename _Xp, typename _Yp>
3839 struct __common_ref_impl<_Xp&, _Yp&&>
3840 : __common_ref_impl<_Yp&&, _Xp&>
3844 template<typename _Tp, typename _Up,
3845 template<typename> class _TQual, template<typename> class _UQual>
3846 struct basic_common_reference
3849 /// @cond undocumented
3850 template<typename _Tp>
3852 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>; };
3854 template<typename _Tp>
3856 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&; };
3858 template<typename _Tp>
3859 struct __xref<_Tp&&>
3860 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&&; };
3862 template<typename _Tp1, typename _Tp2>
3863 using __basic_common_ref
3864 = typename basic_common_reference<remove_cvref_t<_Tp1>,
3865 remove_cvref_t<_Tp2>,
3866 __xref<_Tp1>::template __type,
3867 __xref<_Tp2>::template __type>::type;
3870 template<typename... _Tp>
3871 struct common_reference;
3873 template<typename... _Tp>
3874 using common_reference_t = typename common_reference<_Tp...>::type;
3876 // If sizeof...(T) is zero, there shall be no member type.
3878 struct common_reference<>
3881 // If sizeof...(T) is one ...
3882 template<typename _Tp0>
3883 struct common_reference<_Tp0>
3884 { using type = _Tp0; };
3886 /// @cond undocumented
3887 template<typename _Tp1, typename _Tp2, int _Bullet = 1, typename = void>
3888 struct __common_reference_impl
3889 : __common_reference_impl<_Tp1, _Tp2, _Bullet + 1>
3892 // If sizeof...(T) is two ...
3893 template<typename _Tp1, typename _Tp2>
3894 struct common_reference<_Tp1, _Tp2>
3895 : __common_reference_impl<_Tp1, _Tp2>
3898 // If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, ...
3899 template<typename _Tp1, typename _Tp2>
3900 struct __common_reference_impl<_Tp1&, _Tp2&, 1,
3901 void_t<__common_ref<_Tp1&, _Tp2&>>>
3902 { using type = __common_ref<_Tp1&, _Tp2&>; };
3904 template<typename _Tp1, typename _Tp2>
3905 struct __common_reference_impl<_Tp1&&, _Tp2&&, 1,
3906 void_t<__common_ref<_Tp1&&, _Tp2&&>>>
3907 { using type = __common_ref<_Tp1&&, _Tp2&&>; };
3909 template<typename _Tp1, typename _Tp2>
3910 struct __common_reference_impl<_Tp1&, _Tp2&&, 1,
3911 void_t<__common_ref<_Tp1&, _Tp2&&>>>
3912 { using type = __common_ref<_Tp1&, _Tp2&&>; };
3914 template<typename _Tp1, typename _Tp2>
3915 struct __common_reference_impl<_Tp1&&, _Tp2&, 1,
3916 void_t<__common_ref<_Tp1&&, _Tp2&>>>
3917 { using type = __common_ref<_Tp1&&, _Tp2&>; };
3919 // Otherwise, if basic_common_reference<...>::type is well-formed, ...
3920 template<typename _Tp1, typename _Tp2>
3921 struct __common_reference_impl<_Tp1, _Tp2, 2,
3922 void_t<__basic_common_ref<_Tp1, _Tp2>>>
3923 { using type = __basic_common_ref<_Tp1, _Tp2>; };
3925 // Otherwise, if COND-RES(T1, T2) is well-formed, ...
3926 template<typename _Tp1, typename _Tp2>
3927 struct __common_reference_impl<_Tp1, _Tp2, 3,
3928 void_t<__cond_res<_Tp1, _Tp2>>>
3929 { using type = __cond_res<_Tp1, _Tp2>; };
3931 // Otherwise, if common_type_t<T1, T2> is well-formed, ...
3932 template<typename _Tp1, typename _Tp2>
3933 struct __common_reference_impl<_Tp1, _Tp2, 4,
3934 void_t<common_type_t<_Tp1, _Tp2>>>
3935 { using type = common_type_t<_Tp1, _Tp2>; };
3937 // Otherwise, there shall be no member type.
3938 template<typename _Tp1, typename _Tp2>
3939 struct __common_reference_impl<_Tp1, _Tp2, 5, void>
3942 // Otherwise, if sizeof...(T) is greater than two, ...
3943 template<typename _Tp1, typename _Tp2, typename... _Rest>
3944 struct common_reference<_Tp1, _Tp2, _Rest...>
3945 : __common_type_fold<common_reference<_Tp1, _Tp2>,
3946 __common_type_pack<_Rest...>>
3949 // Reuse __common_type_fold for common_reference<T1, T2, Rest...>
3950 template<typename _Tp1, typename _Tp2, typename... _Rest>
3951 struct __common_type_fold<common_reference<_Tp1, _Tp2>,
3952 __common_type_pack<_Rest...>,
3953 void_t<common_reference_t<_Tp1, _Tp2>>>
3954 : public common_reference<common_reference_t<_Tp1, _Tp2>, _Rest...>
3960 /// @} group metaprogramming
3962 _GLIBCXX_END_NAMESPACE_VERSION
3967 #endif // _GLIBCXX_TYPE_TRAITS