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>
65namespace 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 __bool_constant<!is_fundamental<_Tp>::value> { };
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#if __cpp_variable_templates && __cpp_concepts
1310 template<typename _Tp>
1311 constexpr bool __is_implicitly_default_constructible_v
1312 = requires (void(&__f)(_Tp)) { __f({}); };
1314 template<typename _Tp>
1315 struct __is_implicitly_default_constructible
1316 : __bool_constant<__is_implicitly_default_constructible_v<_Tp>>
1319 struct __do_is_implicitly_default_constructible_impl
1321 template <typename _Tp>
1322 static void __helper(const _Tp&);
1324 template <typename _Tp>
1325 static true_type __test(const _Tp&,
1326 decltype(__helper<const _Tp&>({}))* = 0);
1328 static false_type __test(...);
1331 template<typename _Tp>
1332 struct __is_implicitly_default_constructible_impl
1333 : public __do_is_implicitly_default_constructible_impl
1335 using type = decltype(__test(declval<_Tp>()));
1338 template<typename _Tp>
1339 struct __is_implicitly_default_constructible_safe
1340 : public __is_implicitly_default_constructible_impl<_Tp>::type
1343 template <typename _Tp>
1344 struct __is_implicitly_default_constructible
1345 : public __and_<__is_constructible_impl<_Tp>,
1346 __is_implicitly_default_constructible_safe<_Tp>>::type
1350 /// is_trivially_copy_constructible
1351 template<typename _Tp>
1352 struct is_trivially_copy_constructible
1353 : public __is_trivially_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1355 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1356 "template argument must be a complete class or an unbounded array");
1359 /// is_trivially_move_constructible
1360 template<typename _Tp>
1361 struct is_trivially_move_constructible
1362 : public __is_trivially_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1364 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1365 "template argument must be a complete class or an unbounded array");
1368 /// @cond undocumented
1369 template<typename _Tp, typename _Up>
1370 using __is_trivially_assignable_impl
1371 = __bool_constant<__is_trivially_assignable(_Tp, _Up)>;
1374 /// is_trivially_assignable
1375 template<typename _Tp, typename _Up>
1376 struct is_trivially_assignable
1377 : public __is_trivially_assignable_impl<_Tp, _Up>
1379 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1380 "template argument must be a complete class or an unbounded array");
1383 /// is_trivially_copy_assignable
1384 template<typename _Tp>
1385 struct is_trivially_copy_assignable
1386 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1387 __add_lval_ref_t<const _Tp>>
1389 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1390 "template argument must be a complete class or an unbounded array");
1393 /// is_trivially_move_assignable
1394 template<typename _Tp>
1395 struct is_trivially_move_assignable
1396 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1397 __add_rval_ref_t<_Tp>>
1399 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1400 "template argument must be a complete class or an unbounded array");
1403 /// is_trivially_destructible
1404 template<typename _Tp>
1405 struct is_trivially_destructible
1406 : public __and_<__is_destructible_safe<_Tp>,
1407 __bool_constant<__has_trivial_destructor(_Tp)>>::type
1409 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1410 "template argument must be a complete class or an unbounded array");
1414 /// has_virtual_destructor
1415 template<typename _Tp>
1416 struct has_virtual_destructor
1417 : public __bool_constant<__has_virtual_destructor(_Tp)>
1419 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1420 "template argument must be a complete class or an unbounded array");
1424 // type property queries.
1427 template<typename _Tp>
1429 : public integral_constant<std::size_t, alignof(_Tp)>
1431 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1432 "template argument must be a complete class or an unbounded array");
1438 : public integral_constant<std::size_t, 0> { };
1440 template<typename _Tp, std::size_t _Size>
1441 struct rank<_Tp[_Size]>
1442 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1444 template<typename _Tp>
1446 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1449 template<typename, unsigned _Uint = 0>
1451 : public integral_constant<size_t, 0> { };
1453 template<typename _Tp, size_t _Size>
1454 struct extent<_Tp[_Size], 0>
1455 : public integral_constant<size_t, _Size> { };
1457 template<typename _Tp, unsigned _Uint, size_t _Size>
1458 struct extent<_Tp[_Size], _Uint>
1459 : public extent<_Tp, _Uint - 1>::type { };
1461 template<typename _Tp>
1462 struct extent<_Tp[], 0>
1463 : public integral_constant<size_t, 0> { };
1465 template<typename _Tp, unsigned _Uint>
1466 struct extent<_Tp[], _Uint>
1467 : public extent<_Tp, _Uint - 1>::type { };
1473#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
1474 template<typename _Tp, typename _Up>
1476 : public __bool_constant<__is_same(_Tp, _Up)>
1479 template<typename _Tp, typename _Up>
1484 template<typename _Tp>
1485 struct is_same<_Tp, _Tp>
1491 template<typename _Base, typename _Derived>
1493 : public __bool_constant<__is_base_of(_Base, _Derived)>
1496#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
1497 template<typename _From, typename _To>
1498 struct is_convertible
1499 : public __bool_constant<__is_convertible(_From, _To)>
1502 template<typename _From, typename _To,
1503 bool = __or_<is_void<_From>, is_function<_To>,
1504 is_array<_To>>::value>
1505 struct __is_convertible_helper
1507 using type = typename is_void<_To>::type;
1510#pragma GCC diagnostic push
1511#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1512 template<typename _From, typename _To>
1513 class __is_convertible_helper<_From, _To, false>
1515 template<typename _To1>
1516 static void __test_aux(_To1) noexcept;
1518 template<typename _From1, typename _To1,
1519 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1523 template<typename, typename>
1528 using type = decltype(__test<_From, _To>(0));
1530#pragma GCC diagnostic pop
1533 template<typename _From, typename _To>
1534 struct is_convertible
1535 : public __is_convertible_helper<_From, _To>::type
1539 // helper trait for unique_ptr<T[]>, shared_ptr<T[]>, and span<T, N>
1540 template<typename _ToElementType, typename _FromElementType>
1541 using __is_array_convertible
1542 = is_convertible<_FromElementType(*)[], _ToElementType(*)[]>;
1544#ifdef __cpp_lib_is_nothrow_convertible // C++ >= 20
1546#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_convertible)
1547 /// is_nothrow_convertible_v
1548 template<typename _From, typename _To>
1549 inline constexpr bool is_nothrow_convertible_v
1550 = __is_nothrow_convertible(_From, _To);
1552 /// is_nothrow_convertible
1553 template<typename _From, typename _To>
1554 struct is_nothrow_convertible
1555 : public bool_constant<is_nothrow_convertible_v<_From, _To>>
1558 template<typename _From, typename _To,
1559 bool = __or_<is_void<_From>, is_function<_To>,
1560 is_array<_To>>::value>
1561 struct __is_nt_convertible_helper
1565#pragma GCC diagnostic push
1566#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1567 template<typename _From, typename _To>
1568 class __is_nt_convertible_helper<_From, _To, false>
1570 template<typename _To1>
1571 static void __test_aux(_To1) noexcept;
1573 template<typename _From1, typename _To1>
1575 __bool_constant<noexcept(__test_aux<_To1>(std::declval<_From1>()))>
1578 template<typename, typename>
1583 using type = decltype(__test<_From, _To>(0));
1585#pragma GCC diagnostic pop
1587 /// is_nothrow_convertible
1588 template<typename _From, typename _To>
1589 struct is_nothrow_convertible
1590 : public __is_nt_convertible_helper<_From, _To>::type
1593 /// is_nothrow_convertible_v
1594 template<typename _From, typename _To>
1595 inline constexpr bool is_nothrow_convertible_v
1596 = is_nothrow_convertible<_From, _To>::value;
1598#endif // __cpp_lib_is_nothrow_convertible
1600 // Const-volatile modifications.
1603 template<typename _Tp>
1605 { using type = _Tp; };
1607 template<typename _Tp>
1608 struct remove_const<_Tp const>
1609 { using type = _Tp; };
1612 template<typename _Tp>
1613 struct remove_volatile
1614 { using type = _Tp; };
1616 template<typename _Tp>
1617 struct remove_volatile<_Tp volatile>
1618 { using type = _Tp; };
1621#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cv)
1622 template<typename _Tp>
1624 { using type = __remove_cv(_Tp); };
1626 template<typename _Tp>
1628 { using type = _Tp; };
1630 template<typename _Tp>
1631 struct remove_cv<const _Tp>
1632 { using type = _Tp; };
1634 template<typename _Tp>
1635 struct remove_cv<volatile _Tp>
1636 { using type = _Tp; };
1638 template<typename _Tp>
1639 struct remove_cv<const volatile _Tp>
1640 { using type = _Tp; };
1644 template<typename _Tp>
1646 { using type = _Tp const; };
1649 template<typename _Tp>
1651 { using type = _Tp volatile; };
1654 template<typename _Tp>
1656 { using type = _Tp const volatile; };
1658#ifdef __cpp_lib_transformation_trait_aliases // C++ >= 14
1659 /// Alias template for remove_const
1660 template<typename _Tp>
1661 using remove_const_t = typename remove_const<_Tp>::type;
1663 /// Alias template for remove_volatile
1664 template<typename _Tp>
1665 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1667 /// Alias template for remove_cv
1668 template<typename _Tp>
1669 using remove_cv_t = typename remove_cv<_Tp>::type;
1671 /// Alias template for add_const
1672 template<typename _Tp>
1673 using add_const_t = typename add_const<_Tp>::type;
1675 /// Alias template for add_volatile
1676 template<typename _Tp>
1677 using add_volatile_t = typename add_volatile<_Tp>::type;
1679 /// Alias template for add_cv
1680 template<typename _Tp>
1681 using add_cv_t = typename add_cv<_Tp>::type;
1684 // Reference transformations.
1686 /// remove_reference
1687#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_reference)
1688 template<typename _Tp>
1689 struct remove_reference
1690 { using type = __remove_reference(_Tp); };
1692 template<typename _Tp>
1693 struct remove_reference
1694 { using type = _Tp; };
1696 template<typename _Tp>
1697 struct remove_reference<_Tp&>
1698 { using type = _Tp; };
1700 template<typename _Tp>
1701 struct remove_reference<_Tp&&>
1702 { using type = _Tp; };
1705 /// add_lvalue_reference
1706 template<typename _Tp>
1707 struct add_lvalue_reference
1708 { using type = __add_lval_ref_t<_Tp>; };
1710 /// add_rvalue_reference
1711 template<typename _Tp>
1712 struct add_rvalue_reference
1713 { using type = __add_rval_ref_t<_Tp>; };
1715#if __cplusplus > 201103L
1716 /// Alias template for remove_reference
1717 template<typename _Tp>
1718 using remove_reference_t = typename remove_reference<_Tp>::type;
1720 /// Alias template for add_lvalue_reference
1721 template<typename _Tp>
1722 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1724 /// Alias template for add_rvalue_reference
1725 template<typename _Tp>
1726 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1729 // Sign modifications.
1731 /// @cond undocumented
1733 // Utility for constructing identically cv-qualified types.
1734 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1735 struct __cv_selector;
1737 template<typename _Unqualified>
1738 struct __cv_selector<_Unqualified, false, false>
1739 { using __type = _Unqualified; };
1741 template<typename _Unqualified>
1742 struct __cv_selector<_Unqualified, false, true>
1743 { using __type = volatile _Unqualified; };
1745 template<typename _Unqualified>
1746 struct __cv_selector<_Unqualified, true, false>
1747 { using __type = const _Unqualified; };
1749 template<typename _Unqualified>
1750 struct __cv_selector<_Unqualified, true, true>
1751 { using __type = const volatile _Unqualified; };
1753 template<typename _Qualified, typename _Unqualified,
1754 bool _IsConst = is_const<_Qualified>::value,
1755 bool _IsVol = is_volatile<_Qualified>::value>
1756 class __match_cv_qualifiers
1758 using __match = __cv_selector<_Unqualified, _IsConst, _IsVol>;
1761 using __type = typename __match::__type;
1764 // Utility for finding the unsigned versions of signed integral types.
1765 template<typename _Tp>
1766 struct __make_unsigned
1767 { using __type = _Tp; };
1770 struct __make_unsigned<char>
1771 { using __type = unsigned char; };
1774 struct __make_unsigned<signed char>
1775 { using __type = unsigned char; };
1778 struct __make_unsigned<short>
1779 { using __type = unsigned short; };
1782 struct __make_unsigned<int>
1783 { using __type = unsigned int; };
1786 struct __make_unsigned<long>
1787 { using __type = unsigned long; };
1790 struct __make_unsigned<long long>
1791 { using __type = unsigned long long; };
1793#if defined(__GLIBCXX_TYPE_INT_N_0)
1796 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1797 { using __type = unsigned __GLIBCXX_TYPE_INT_N_0; };
1799#if defined(__GLIBCXX_TYPE_INT_N_1)
1802 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1803 { using __type = unsigned __GLIBCXX_TYPE_INT_N_1; };
1805#if defined(__GLIBCXX_TYPE_INT_N_2)
1808 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1809 { using __type = unsigned __GLIBCXX_TYPE_INT_N_2; };
1811#if defined(__GLIBCXX_TYPE_INT_N_3)
1814 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1815 { using __type = unsigned __GLIBCXX_TYPE_INT_N_3; };
1818 // Select between integral and enum: not possible to be both.
1819 template<typename _Tp,
1820 bool _IsInt = is_integral<_Tp>::value,
1821 bool _IsEnum = __is_enum(_Tp)>
1822 class __make_unsigned_selector;
1824 template<typename _Tp>
1825 class __make_unsigned_selector<_Tp, true, false>
1827 using __unsigned_type
1828 = typename __make_unsigned<__remove_cv_t<_Tp>>::__type;
1832 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1835 class __make_unsigned_selector_base
1838 template<typename...> struct _List { };
1840 template<typename _Tp, typename... _Up>
1841 struct _List<_Tp, _Up...> : _List<_Up...>
1842 { static constexpr size_t __size = sizeof(_Tp); };
1844 template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
1847 template<size_t _Sz, typename _Uint, typename... _UInts>
1848 struct __select<_Sz, _List<_Uint, _UInts...>, true>
1849 { using __type = _Uint; };
1851 template<size_t _Sz, typename _Uint, typename... _UInts>
1852 struct __select<_Sz, _List<_Uint, _UInts...>, false>
1853 : __select<_Sz, _List<_UInts...>>
1857 // Choose unsigned integer type with the smallest rank and same size as _Tp
1858 template<typename _Tp>
1859 class __make_unsigned_selector<_Tp, false, true>
1860 : __make_unsigned_selector_base
1862 // With -fshort-enums, an enum may be as small as a char.
1863 using _UInts = _List<unsigned char, unsigned short, unsigned int,
1864 unsigned long, unsigned long long>;
1866 using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
1870 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1873 // wchar_t, char8_t, char16_t and char32_t are integral types but are
1874 // neither signed integer types nor unsigned integer types, so must be
1875 // transformed to the unsigned integer type with the smallest rank.
1876 // Use the partial specialization for enumeration types to do that.
1878 struct __make_unsigned<wchar_t>
1881 = typename __make_unsigned_selector<wchar_t, false, true>::__type;
1884#ifdef _GLIBCXX_USE_CHAR8_T
1886 struct __make_unsigned<char8_t>
1889 = typename __make_unsigned_selector<char8_t, false, true>::__type;
1894 struct __make_unsigned<char16_t>
1897 = typename __make_unsigned_selector<char16_t, false, true>::__type;
1901 struct __make_unsigned<char32_t>
1904 = typename __make_unsigned_selector<char32_t, false, true>::__type;
1908 // Given an integral/enum type, return the corresponding unsigned
1910 // Primary template.
1912 template<typename _Tp>
1913 struct make_unsigned
1914 { using type = typename __make_unsigned_selector<_Tp>::__type; };
1916 // Integral, but don't define.
1917 template<> struct make_unsigned<bool>;
1918 template<> struct make_unsigned<bool const>;
1919 template<> struct make_unsigned<bool volatile>;
1920 template<> struct make_unsigned<bool const volatile>;
1922 /// @cond undocumented
1924 // Utility for finding the signed versions of unsigned integral types.
1925 template<typename _Tp>
1926 struct __make_signed
1927 { using __type = _Tp; };
1930 struct __make_signed<char>
1931 { using __type = signed char; };
1934 struct __make_signed<unsigned char>
1935 { using __type = signed char; };
1938 struct __make_signed<unsigned short>
1939 { using __type = signed short; };
1942 struct __make_signed<unsigned int>
1943 { using __type = signed int; };
1946 struct __make_signed<unsigned long>
1947 { using __type = signed long; };
1950 struct __make_signed<unsigned long long>
1951 { using __type = signed long long; };
1953#if defined(__GLIBCXX_TYPE_INT_N_0)
1956 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
1957 { using __type = __GLIBCXX_TYPE_INT_N_0; };
1959#if defined(__GLIBCXX_TYPE_INT_N_1)
1962 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
1963 { using __type = __GLIBCXX_TYPE_INT_N_1; };
1965#if defined(__GLIBCXX_TYPE_INT_N_2)
1968 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
1969 { using __type = __GLIBCXX_TYPE_INT_N_2; };
1971#if defined(__GLIBCXX_TYPE_INT_N_3)
1974 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
1975 { using __type = __GLIBCXX_TYPE_INT_N_3; };
1978 // Select between integral and enum: not possible to be both.
1979 template<typename _Tp,
1980 bool _IsInt = is_integral<_Tp>::value,
1981 bool _IsEnum = __is_enum(_Tp)>
1982 class __make_signed_selector;
1984 template<typename _Tp>
1985 class __make_signed_selector<_Tp, true, false>
1988 = typename __make_signed<__remove_cv_t<_Tp>>::__type;
1992 = typename __match_cv_qualifiers<_Tp, __signed_type>::__type;
1995 // Choose signed integer type with the smallest rank and same size as _Tp
1996 template<typename _Tp>
1997 class __make_signed_selector<_Tp, false, true>
1999 using __unsigned_type = typename __make_unsigned_selector<_Tp>::__type;
2002 using __type = typename __make_signed_selector<__unsigned_type>::__type;
2005 // wchar_t, char16_t and char32_t are integral types but are neither
2006 // signed integer types nor unsigned integer types, so must be
2007 // transformed to the signed integer type with the smallest rank.
2008 // Use the partial specialization for enumeration types to do that.
2010 struct __make_signed<wchar_t>
2013 = typename __make_signed_selector<wchar_t, false, true>::__type;
2016#if defined(_GLIBCXX_USE_CHAR8_T)
2018 struct __make_signed<char8_t>
2021 = typename __make_signed_selector<char8_t, false, true>::__type;
2026 struct __make_signed<char16_t>
2029 = typename __make_signed_selector<char16_t, false, true>::__type;
2033 struct __make_signed<char32_t>
2036 = typename __make_signed_selector<char32_t, false, true>::__type;
2040 // Given an integral/enum type, return the corresponding signed
2042 // Primary template.
2044 template<typename _Tp>
2046 { using type = typename __make_signed_selector<_Tp>::__type; };
2048 // Integral, but don't define.
2049 template<> struct make_signed<bool>;
2050 template<> struct make_signed<bool const>;
2051 template<> struct make_signed<bool volatile>;
2052 template<> struct make_signed<bool const volatile>;
2054#if __cplusplus > 201103L
2055 /// Alias template for make_signed
2056 template<typename _Tp>
2057 using make_signed_t = typename make_signed<_Tp>::type;
2059 /// Alias template for make_unsigned
2060 template<typename _Tp>
2061 using make_unsigned_t = typename make_unsigned<_Tp>::type;
2064 // Array modifications.
2067 template<typename _Tp>
2068 struct remove_extent
2069 { using type = _Tp; };
2071 template<typename _Tp, std::size_t _Size>
2072 struct remove_extent<_Tp[_Size]>
2073 { using type = _Tp; };
2075 template<typename _Tp>
2076 struct remove_extent<_Tp[]>
2077 { using type = _Tp; };
2079 /// remove_all_extents
2080 template<typename _Tp>
2081 struct remove_all_extents
2082 { using type = _Tp; };
2084 template<typename _Tp, std::size_t _Size>
2085 struct remove_all_extents<_Tp[_Size]>
2086 { using type = typename remove_all_extents<_Tp>::type; };
2088 template<typename _Tp>
2089 struct remove_all_extents<_Tp[]>
2090 { using type = typename remove_all_extents<_Tp>::type; };
2092#if __cplusplus > 201103L
2093 /// Alias template for remove_extent
2094 template<typename _Tp>
2095 using remove_extent_t = typename remove_extent<_Tp>::type;
2097 /// Alias template for remove_all_extents
2098 template<typename _Tp>
2099 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
2102 // Pointer modifications.
2105#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer)
2106 template<typename _Tp>
2107 struct remove_pointer
2108 { using type = __remove_pointer(_Tp); };
2110 template<typename _Tp, typename>
2111 struct __remove_pointer_helper
2112 { using type = _Tp; };
2114 template<typename _Tp, typename _Up>
2115 struct __remove_pointer_helper<_Tp, _Up*>
2116 { using type = _Up; };
2118 template<typename _Tp>
2119 struct remove_pointer
2120 : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>>
2124 template<typename _Tp, typename = void>
2125 struct __add_pointer_helper
2126 { using type = _Tp; };
2128 template<typename _Tp>
2129 struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
2130 { using type = _Tp*; };
2133 template<typename _Tp>
2135 : public __add_pointer_helper<_Tp>
2138 template<typename _Tp>
2139 struct add_pointer<_Tp&>
2140 { using type = _Tp*; };
2142 template<typename _Tp>
2143 struct add_pointer<_Tp&&>
2144 { using type = _Tp*; };
2146#if __cplusplus > 201103L
2147 /// Alias template for remove_pointer
2148 template<typename _Tp>
2149 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2151 /// Alias template for add_pointer
2152 template<typename _Tp>
2153 using add_pointer_t = typename add_pointer<_Tp>::type;
2156 template<std::size_t _Len>
2157 struct __aligned_storage_msa
2161 unsigned char __data[_Len];
2162 struct __attribute__((__aligned__)) { } __align;
2167 * @brief Alignment type.
2169 * The value of _Align is a default-alignment which shall be the
2170 * most stringent alignment requirement for any C++ object type
2171 * whose size is no greater than _Len (3.9). The member typedef
2172 * type shall be a POD type suitable for use as uninitialized
2173 * storage for any object whose size is at most _Len and whose
2174 * alignment is a divisor of _Align.
2176 * @deprecated Deprecated in C++23. Uses can be replaced by an
2177 * array std::byte[_Len] declared with alignas(_Align).
2179 template<std::size_t _Len, std::size_t _Align =
2180 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2182 _GLIBCXX23_DEPRECATED
2187 unsigned char __data[_Len];
2188 struct __attribute__((__aligned__((_Align)))) { } __align;
2192 template <typename... _Types>
2193 struct __strictest_alignment
2195 static const size_t _S_alignment = 0;
2196 static const size_t _S_size = 0;
2199 template <typename _Tp, typename... _Types>
2200 struct __strictest_alignment<_Tp, _Types...>
2202 static const size_t _S_alignment =
2203 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2204 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2205 static const size_t _S_size =
2206 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2207 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2210#pragma GCC diagnostic push
2211#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2214 * @brief Provide aligned storage for types.
2216 * [meta.trans.other]
2218 * Provides aligned storage for any of the provided types of at
2221 * @see aligned_storage
2223 * @deprecated Deprecated in C++23.
2225 template <size_t _Len, typename... _Types>
2227 _GLIBCXX23_DEPRECATED
2231 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2233 using __strictest = __strictest_alignment<_Types...>;
2234 static const size_t _S_len = _Len > __strictest::_S_size
2235 ? _Len : __strictest::_S_size;
2237 /// The value of the strictest alignment of _Types.
2238 static const size_t alignment_value = __strictest::_S_alignment;
2240 using type = typename aligned_storage<_S_len, alignment_value>::type;
2243 template <size_t _Len, typename... _Types>
2244 const size_t aligned_union<_Len, _Types...>::alignment_value;
2245#pragma GCC diagnostic pop
2247 /// @cond undocumented
2249 // Decay trait for arrays and functions, used for perfect forwarding
2250 // in make_pair, make_tuple, etc.
2251 template<typename _Up>
2252 struct __decay_selector
2253 : __conditional_t<is_const<const _Up>::value, // false for functions
2254 remove_cv<_Up>, // N.B. DR 705.
2255 add_pointer<_Up>> // function decays to pointer
2258 template<typename _Up, size_t _Nm>
2259 struct __decay_selector<_Up[_Nm]>
2260 { using type = _Up*; };
2262 template<typename _Up>
2263 struct __decay_selector<_Up[]>
2264 { using type = _Up*; };
2269 template<typename _Tp>
2271 { using type = typename __decay_selector<_Tp>::type; };
2273 template<typename _Tp>
2275 { using type = typename __decay_selector<_Tp>::type; };
2277 template<typename _Tp>
2279 { using type = typename __decay_selector<_Tp>::type; };
2281 /// @cond undocumented
2283 // Helper which adds a reference to a type when given a reference_wrapper
2284 template<typename _Tp>
2285 struct __strip_reference_wrapper
2290 template<typename _Tp>
2291 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2293 using __type = _Tp&;
2296 // __decay_t (std::decay_t for C++11).
2297 template<typename _Tp>
2298 using __decay_t = typename decay<_Tp>::type;
2300 template<typename _Tp>
2301 using __decay_and_strip = __strip_reference_wrapper<__decay_t<_Tp>>;
2304 /// @cond undocumented
2306 // Helper for SFINAE constraints
2307 template<typename... _Cond>
2308 using _Require = __enable_if_t<__and_<_Cond...>::value>;
2310 // __remove_cvref_t (std::remove_cvref_t for C++11).
2311 template<typename _Tp>
2312 using __remove_cvref_t
2313 = typename remove_cv<typename remove_reference<_Tp>::type>::type;
2316 // Primary template.
2317 /// Define a member typedef @c type to one of two argument types.
2318 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2320 { using type = _Iftrue; };
2322 // Partial specialization for false.
2323 template<typename _Iftrue, typename _Iffalse>
2324 struct conditional<false, _Iftrue, _Iffalse>
2325 { using type = _Iffalse; };
2328 template<typename... _Tp>
2331 // Sfinae-friendly common_type implementation:
2333 /// @cond undocumented
2335 // For several sfinae-friendly trait implementations we transport both the
2336 // result information (as the member type) and the failure information (no
2337 // member type). This is very similar to std::enable_if, but we cannot use
2338 // that, because we need to derive from them as an implementation detail.
2340 template<typename _Tp>
2341 struct __success_type
2342 { using type = _Tp; };
2344 struct __failure_type
2347 struct __do_common_type_impl
2349 template<typename _Tp, typename _Up>
2351 = decltype(true ? std::declval<_Tp>() : std::declval<_Up>());
2353 // if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2354 // denotes a valid type, let C denote that type.
2355 template<typename _Tp, typename _Up>
2356 static __success_type<__decay_t<__cond_t<_Tp, _Up>>>
2359#if __cplusplus > 201703L
2360 // Otherwise, if COND-RES(CREF(D1), CREF(D2)) denotes a type,
2361 // let C denote the type decay_t<COND-RES(CREF(D1), CREF(D2))>.
2362 template<typename _Tp, typename _Up>
2363 static __success_type<__remove_cvref_t<__cond_t<const _Tp&, const _Up&>>>
2367 template<typename, typename>
2368 static __failure_type
2371 template<typename _Tp, typename _Up>
2372 static decltype(_S_test_2<_Tp, _Up>(0))
2376 // If sizeof...(T) is zero, there shall be no member type.
2378 struct common_type<>
2381 // If sizeof...(T) is one, the same type, if any, as common_type_t<T0, T0>.
2382 template<typename _Tp0>
2383 struct common_type<_Tp0>
2384 : public common_type<_Tp0, _Tp0>
2387 // If sizeof...(T) is two, ...
2388 template<typename _Tp1, typename _Tp2,
2389 typename _Dp1 = __decay_t<_Tp1>, typename _Dp2 = __decay_t<_Tp2>>
2390 struct __common_type_impl
2392 // If is_same_v<T1, D1> is false or is_same_v<T2, D2> is false,
2393 // let C denote the same type, if any, as common_type_t<D1, D2>.
2394 using type = common_type<_Dp1, _Dp2>;
2397 template<typename _Tp1, typename _Tp2>
2398 struct __common_type_impl<_Tp1, _Tp2, _Tp1, _Tp2>
2399 : private __do_common_type_impl
2401 // Otherwise, if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2402 // denotes a valid type, let C denote that type.
2403 using type = decltype(_S_test<_Tp1, _Tp2>(0));
2406 // If sizeof...(T) is two, ...
2407 template<typename _Tp1, typename _Tp2>
2408 struct common_type<_Tp1, _Tp2>
2409 : public __common_type_impl<_Tp1, _Tp2>::type
2412 template<typename...>
2413 struct __common_type_pack
2416 template<typename, typename, typename = void>
2417 struct __common_type_fold;
2419 // If sizeof...(T) is greater than two, ...
2420 template<typename _Tp1, typename _Tp2, typename... _Rp>
2421 struct common_type<_Tp1, _Tp2, _Rp...>
2422 : public __common_type_fold<common_type<_Tp1, _Tp2>,
2423 __common_type_pack<_Rp...>>
2426 // Let C denote the same type, if any, as common_type_t<T1, T2>.
2427 // If there is such a type C, type shall denote the same type, if any,
2428 // as common_type_t<C, R...>.
2429 template<typename _CTp, typename... _Rp>
2430 struct __common_type_fold<_CTp, __common_type_pack<_Rp...>,
2431 __void_t<typename _CTp::type>>
2432 : public common_type<typename _CTp::type, _Rp...>
2435 // Otherwise, there shall be no member type.
2436 template<typename _CTp, typename _Rp>
2437 struct __common_type_fold<_CTp, _Rp, void>
2440 template<typename _Tp, bool = __is_enum(_Tp)>
2441 struct __underlying_type_impl
2443 using type = __underlying_type(_Tp);
2446 template<typename _Tp>
2447 struct __underlying_type_impl<_Tp, false>
2451 /// The underlying type of an enum.
2452 template<typename _Tp>
2453 struct underlying_type
2454 : public __underlying_type_impl<_Tp>
2457 /// @cond undocumented
2458 template<typename _Tp>
2459 struct __declval_protector
2461 static const bool __stop = false;
2465 /** Utility to simplify expressions used in unevaluated operands
2467 * @ingroup utilities
2469 template<typename _Tp>
2470 auto declval() noexcept -> decltype(__declval<_Tp>(0))
2472 static_assert(__declval_protector<_Tp>::__stop,
2473 "declval() must not be used!");
2474 return __declval<_Tp>(0);
2478 template<typename _Signature>
2481 // Sfinae-friendly result_of implementation:
2483 /// @cond undocumented
2484 struct __invoke_memfun_ref { };
2485 struct __invoke_memfun_deref { };
2486 struct __invoke_memobj_ref { };
2487 struct __invoke_memobj_deref { };
2488 struct __invoke_other { };
2490 // Associate a tag type with a specialization of __success_type.
2491 template<typename _Tp, typename _Tag>
2492 struct __result_of_success : __success_type<_Tp>
2493 { using __invoke_type = _Tag; };
2495 // [func.require] paragraph 1 bullet 1:
2496 struct __result_of_memfun_ref_impl
2498 template<typename _Fp, typename _Tp1, typename... _Args>
2499 static __result_of_success<decltype(
2500 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2501 ), __invoke_memfun_ref> _S_test(int);
2503 template<typename...>
2504 static __failure_type _S_test(...);
2507 template<typename _MemPtr, typename _Arg, typename... _Args>
2508 struct __result_of_memfun_ref
2509 : private __result_of_memfun_ref_impl
2511 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2514 // [func.require] paragraph 1 bullet 2:
2515 struct __result_of_memfun_deref_impl
2517 template<typename _Fp, typename _Tp1, typename... _Args>
2518 static __result_of_success<decltype(
2519 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2520 ), __invoke_memfun_deref> _S_test(int);
2522 template<typename...>
2523 static __failure_type _S_test(...);
2526 template<typename _MemPtr, typename _Arg, typename... _Args>
2527 struct __result_of_memfun_deref
2528 : private __result_of_memfun_deref_impl
2530 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2533 // [func.require] paragraph 1 bullet 3:
2534 struct __result_of_memobj_ref_impl
2536 template<typename _Fp, typename _Tp1>
2537 static __result_of_success<decltype(
2538 std::declval<_Tp1>().*std::declval<_Fp>()
2539 ), __invoke_memobj_ref> _S_test(int);
2541 template<typename, typename>
2542 static __failure_type _S_test(...);
2545 template<typename _MemPtr, typename _Arg>
2546 struct __result_of_memobj_ref
2547 : private __result_of_memobj_ref_impl
2549 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2552 // [func.require] paragraph 1 bullet 4:
2553 struct __result_of_memobj_deref_impl
2555 template<typename _Fp, typename _Tp1>
2556 static __result_of_success<decltype(
2557 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2558 ), __invoke_memobj_deref> _S_test(int);
2560 template<typename, typename>
2561 static __failure_type _S_test(...);
2564 template<typename _MemPtr, typename _Arg>
2565 struct __result_of_memobj_deref
2566 : private __result_of_memobj_deref_impl
2568 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2571 template<typename _MemPtr, typename _Arg>
2572 struct __result_of_memobj;
2574 template<typename _Res, typename _Class, typename _Arg>
2575 struct __result_of_memobj<_Res _Class::*, _Arg>
2577 using _Argval = __remove_cvref_t<_Arg>;
2578 using _MemPtr = _Res _Class::*;
2579 using type = typename __conditional_t<__or_<is_same<_Argval, _Class>,
2580 is_base_of<_Class, _Argval>>::value,
2581 __result_of_memobj_ref<_MemPtr, _Arg>,
2582 __result_of_memobj_deref<_MemPtr, _Arg>
2586 template<typename _MemPtr, typename _Arg, typename... _Args>
2587 struct __result_of_memfun;
2589 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2590 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2592 using _Argval = typename remove_reference<_Arg>::type;
2593 using _MemPtr = _Res _Class::*;
2594 using type = typename __conditional_t<is_base_of<_Class, _Argval>::value,
2595 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2596 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2600 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2601 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2602 // as the object expression
2604 // Used by result_of, invoke etc. to unwrap a reference_wrapper.
2605 template<typename _Tp, typename _Up = __remove_cvref_t<_Tp>>
2611 template<typename _Tp, typename _Up>
2612 struct __inv_unwrap<_Tp, reference_wrapper<_Up>>
2617 template<bool, bool, typename _Functor, typename... _ArgTypes>
2618 struct __result_of_impl
2620 using type = __failure_type;
2623 template<typename _MemPtr, typename _Arg>
2624 struct __result_of_impl<true, false, _MemPtr, _Arg>
2625 : public __result_of_memobj<__decay_t<_MemPtr>,
2626 typename __inv_unwrap<_Arg>::type>
2629 template<typename _MemPtr, typename _Arg, typename... _Args>
2630 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2631 : public __result_of_memfun<__decay_t<_MemPtr>,
2632 typename __inv_unwrap<_Arg>::type, _Args...>
2635 // [func.require] paragraph 1 bullet 5:
2636 struct __result_of_other_impl
2638 template<typename _Fn, typename... _Args>
2639 static __result_of_success<decltype(
2640 std::declval<_Fn>()(std::declval<_Args>()...)
2641 ), __invoke_other> _S_test(int);
2643 template<typename...>
2644 static __failure_type _S_test(...);
2647 template<typename _Functor, typename... _ArgTypes>
2648 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2649 : private __result_of_other_impl
2651 using type = decltype(_S_test<_Functor, _ArgTypes...>(0));
2654 // __invoke_result (std::invoke_result for C++11)
2655 template<typename _Functor, typename... _ArgTypes>
2656 struct __invoke_result
2657 : public __result_of_impl<
2658 is_member_object_pointer<
2659 typename remove_reference<_Functor>::type
2661 is_member_function_pointer<
2662 typename remove_reference<_Functor>::type
2664 _Functor, _ArgTypes...
2668 // __invoke_result_t (std::invoke_result_t for C++11)
2669 template<typename _Fn, typename... _Args>
2670 using __invoke_result_t = typename __invoke_result<_Fn, _Args...>::type;
2673 template<typename _Functor, typename... _ArgTypes>
2674 struct result_of<_Functor(_ArgTypes...)>
2675 : public __invoke_result<_Functor, _ArgTypes...>
2676 { } _GLIBCXX17_DEPRECATED_SUGGEST("std::invoke_result");
2678#if __cplusplus >= 201402L
2679#pragma GCC diagnostic push
2680#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2681 /// Alias template for aligned_storage
2682 template<size_t _Len, size_t _Align =
2683 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2684 using aligned_storage_t _GLIBCXX23_DEPRECATED = typename aligned_storage<_Len, _Align>::type;
2686 template <size_t _Len, typename... _Types>
2687 using aligned_union_t _GLIBCXX23_DEPRECATED = typename aligned_union<_Len, _Types...>::type;
2688#pragma GCC diagnostic pop
2690 /// Alias template for decay
2691 template<typename _Tp>
2692 using decay_t = typename decay<_Tp>::type;
2694 /// Alias template for enable_if
2695 template<bool _Cond, typename _Tp = void>
2696 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2698 /// Alias template for conditional
2699 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2700 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2702 /// Alias template for common_type
2703 template<typename... _Tp>
2704 using common_type_t = typename common_type<_Tp...>::type;
2706 /// Alias template for underlying_type
2707 template<typename _Tp>
2708 using underlying_type_t = typename underlying_type<_Tp>::type;
2710 /// Alias template for result_of
2711 template<typename _Tp>
2712 using result_of_t = typename result_of<_Tp>::type;
2715#ifdef __cpp_lib_void_t // C++ >= 17 || GNU++ >= 11
2716 /// A metafunction that always yields void, used for detecting valid types.
2717 template<typename...> using void_t = void;
2720 /// @cond undocumented
2723 // Detect whether _Op<_Args...> is a valid type, use default _Def if not.
2726 // Implementation of the detection idiom (negative case).
2727 template<typename _Def, template<typename...> class _Op, typename... _Args>
2728 struct __detected_or
2731 using __is_detected = false_type;
2734 // Implementation of the detection idiom (positive case).
2735 template<typename _Def, template<typename...> class _Op, typename... _Args>
2736 requires requires { typename _Op<_Args...>; }
2737 struct __detected_or<_Def, _Op, _Args...>
2739 using type = _Op<_Args...>;
2740 using __is_detected = true_type;
2743 /// Implementation of the detection idiom (negative case).
2744 template<typename _Default, typename _AlwaysVoid,
2745 template<typename...> class _Op, typename... _Args>
2748 using type = _Default;
2749 using __is_detected = false_type;
2752 /// Implementation of the detection idiom (positive case).
2753 template<typename _Default, template<typename...> class _Op,
2755 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2757 using type = _Op<_Args...>;
2758 using __is_detected = true_type;
2761 template<typename _Default, template<typename...> class _Op,
2763 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2764#endif // __cpp_concepts
2766 // _Op<_Args...> if that is a valid type, otherwise _Default.
2767 template<typename _Default, template<typename...> class _Op,
2769 using __detected_or_t
2770 = typename __detected_or<_Default, _Op, _Args...>::type;
2773 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2774 * member type _NTYPE.
2776#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2777 template<typename _Tp, typename = __void_t<>> \
2778 struct __has_##_NTYPE \
2781 template<typename _Tp> \
2782 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2786 template <typename _Tp>
2787 struct __is_swappable;
2789 template <typename _Tp>
2790 struct __is_nothrow_swappable;
2793 struct __is_tuple_like_impl : false_type
2796 // Internal type trait that allows us to sfinae-protect tuple_cat.
2797 template<typename _Tp>
2798 struct __is_tuple_like
2799 : public __is_tuple_like_impl<__remove_cvref_t<_Tp>>::type
2803 template<typename _Tp>
2804 _GLIBCXX20_CONSTEXPR
2806 _Require<__not_<__is_tuple_like<_Tp>>,
2807 is_move_constructible<_Tp>,
2808 is_move_assignable<_Tp>>
2810 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
2811 is_nothrow_move_assignable<_Tp>>::value);
2813 template<typename _Tp, size_t _Nm>
2814 _GLIBCXX20_CONSTEXPR
2816 __enable_if_t<__is_swappable<_Tp>::value>
2817 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
2818 noexcept(__is_nothrow_swappable<_Tp>::value);
2820 /// @cond undocumented
2821 namespace __swappable_details {
2824 struct __do_is_swappable_impl
2826 template<typename _Tp, typename
2827 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
2828 static true_type __test(int);
2831 static false_type __test(...);
2834 struct __do_is_nothrow_swappable_impl
2836 template<typename _Tp>
2837 static __bool_constant<
2838 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
2842 static false_type __test(...);
2845 } // namespace __swappable_details
2847 template<typename _Tp>
2848 struct __is_swappable_impl
2849 : public __swappable_details::__do_is_swappable_impl
2851 using type = decltype(__test<_Tp>(0));
2854 template<typename _Tp>
2855 struct __is_nothrow_swappable_impl
2856 : public __swappable_details::__do_is_nothrow_swappable_impl
2858 using type = decltype(__test<_Tp>(0));
2861 template<typename _Tp>
2862 struct __is_swappable
2863 : public __is_swappable_impl<_Tp>::type
2866 template<typename _Tp>
2867 struct __is_nothrow_swappable
2868 : public __is_nothrow_swappable_impl<_Tp>::type
2872#ifdef __cpp_lib_is_swappable // C++ >= 17 || GNU++ >= 11
2873 /// Metafunctions used for detecting swappable types: p0185r1
2876 template<typename _Tp>
2878 : public __is_swappable_impl<_Tp>::type
2880 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2881 "template argument must be a complete class or an unbounded array");
2884 /// is_nothrow_swappable
2885 template<typename _Tp>
2886 struct is_nothrow_swappable
2887 : public __is_nothrow_swappable_impl<_Tp>::type
2889 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2890 "template argument must be a complete class or an unbounded array");
2893#if __cplusplus >= 201402L
2895 template<typename _Tp>
2896 _GLIBCXX17_INLINE constexpr bool is_swappable_v =
2897 is_swappable<_Tp>::value;
2899 /// is_nothrow_swappable_v
2900 template<typename _Tp>
2901 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_v =
2902 is_nothrow_swappable<_Tp>::value;
2903#endif // __cplusplus >= 201402L
2905 /// @cond undocumented
2906 namespace __swappable_with_details {
2909 struct __do_is_swappable_with_impl
2911 template<typename _Tp, typename _Up, typename
2912 = decltype(swap(std::declval<_Tp>(), std::declval<_Up>())),
2914 = decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))>
2915 static true_type __test(int);
2917 template<typename, typename>
2918 static false_type __test(...);
2921 struct __do_is_nothrow_swappable_with_impl
2923 template<typename _Tp, typename _Up>
2924 static __bool_constant<
2925 noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
2927 noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()))
2930 template<typename, typename>
2931 static false_type __test(...);
2934 } // namespace __swappable_with_details
2936 template<typename _Tp, typename _Up>
2937 struct __is_swappable_with_impl
2938 : public __swappable_with_details::__do_is_swappable_with_impl
2940 using type = decltype(__test<_Tp, _Up>(0));
2943 // Optimization for the homogenous lvalue case, not required:
2944 template<typename _Tp>
2945 struct __is_swappable_with_impl<_Tp&, _Tp&>
2946 : public __swappable_details::__do_is_swappable_impl
2948 using type = decltype(__test<_Tp&>(0));
2951 template<typename _Tp, typename _Up>
2952 struct __is_nothrow_swappable_with_impl
2953 : public __swappable_with_details::__do_is_nothrow_swappable_with_impl
2955 using type = decltype(__test<_Tp, _Up>(0));
2958 // Optimization for the homogenous lvalue case, not required:
2959 template<typename _Tp>
2960 struct __is_nothrow_swappable_with_impl<_Tp&, _Tp&>
2961 : public __swappable_details::__do_is_nothrow_swappable_impl
2963 using type = decltype(__test<_Tp&>(0));
2967 /// is_swappable_with
2968 template<typename _Tp, typename _Up>
2969 struct is_swappable_with
2970 : public __is_swappable_with_impl<_Tp, _Up>::type
2972 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2973 "first template argument must be a complete class or an unbounded array");
2974 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
2975 "second template argument must be a complete class or an unbounded array");
2978 /// is_nothrow_swappable_with
2979 template<typename _Tp, typename _Up>
2980 struct is_nothrow_swappable_with
2981 : public __is_nothrow_swappable_with_impl<_Tp, _Up>::type
2983 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
2984 "first template argument must be a complete class or an unbounded array");
2985 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
2986 "second template argument must be a complete class or an unbounded array");
2989#if __cplusplus >= 201402L
2990 /// is_swappable_with_v
2991 template<typename _Tp, typename _Up>
2992 _GLIBCXX17_INLINE constexpr bool is_swappable_with_v =
2993 is_swappable_with<_Tp, _Up>::value;
2995 /// is_nothrow_swappable_with_v
2996 template<typename _Tp, typename _Up>
2997 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_with_v =
2998 is_nothrow_swappable_with<_Tp, _Up>::value;
2999#endif // __cplusplus >= 201402L
3001#endif // __cpp_lib_is_swappable
3003 /// @cond undocumented
3005 // __is_invocable (std::is_invocable for C++11)
3007 // The primary template is used for invalid INVOKE expressions.
3008 template<typename _Result, typename _Ret,
3009 bool = is_void<_Ret>::value, typename = void>
3010 struct __is_invocable_impl
3013 using __nothrow_conv = false_type; // For is_nothrow_invocable_r
3016 // Used for valid INVOKE and INVOKE<void> expressions.
3017 template<typename _Result, typename _Ret>
3018 struct __is_invocable_impl<_Result, _Ret,
3019 /* is_void<_Ret> = */ true,
3020 __void_t<typename _Result::type>>
3023 using __nothrow_conv = true_type; // For is_nothrow_invocable_r
3026#pragma GCC diagnostic push
3027#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3028 // Used for INVOKE<R> expressions to check the implicit conversion to R.
3029 template<typename _Result, typename _Ret>
3030 struct __is_invocable_impl<_Result, _Ret,
3031 /* is_void<_Ret> = */ false,
3032 __void_t<typename _Result::type>>
3035 // The type of the INVOKE expression.
3036 using _Res_t = typename _Result::type;
3038 // Unlike declval, this doesn't add_rvalue_reference, so it respects
3039 // guaranteed copy elision.
3040 static _Res_t _S_get() noexcept;
3042 // Used to check if _Res_t can implicitly convert to _Tp.
3043 template<typename _Tp>
3044 static void _S_conv(__type_identity_t<_Tp>) noexcept;
3046 // This overload is viable if INVOKE(f, args...) can convert to _Tp.
3047 template<typename _Tp,
3048 bool _Nothrow = noexcept(_S_conv<_Tp>(_S_get())),
3049 typename = decltype(_S_conv<_Tp>(_S_get())),
3050#if __has_builtin(__reference_converts_from_temporary)
3051 bool _Dangle = __reference_converts_from_temporary(_Tp, _Res_t)
3053 bool _Dangle = false
3056 static __bool_constant<_Nothrow && !_Dangle>
3059 template<typename _Tp, bool = false>
3064 // For is_invocable_r
3065 using type = decltype(_S_test<_Ret, /* Nothrow = */ true>(1));
3067 // For is_nothrow_invocable_r
3068 using __nothrow_conv = decltype(_S_test<_Ret>(1));
3070#pragma GCC diagnostic pop
3072 template<typename _Fn, typename... _ArgTypes>
3073 struct __is_invocable
3074 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3077 template<typename _Fn, typename _Tp, typename... _Args>
3078 constexpr bool __call_is_nt(__invoke_memfun_ref)
3080 using _Up = typename __inv_unwrap<_Tp>::type;
3081 return noexcept((std::declval<_Up>().*std::declval<_Fn>())(
3082 std::declval<_Args>()...));
3085 template<typename _Fn, typename _Tp, typename... _Args>
3086 constexpr bool __call_is_nt(__invoke_memfun_deref)
3088 return noexcept(((*std::declval<_Tp>()).*std::declval<_Fn>())(
3089 std::declval<_Args>()...));
3092 template<typename _Fn, typename _Tp>
3093 constexpr bool __call_is_nt(__invoke_memobj_ref)
3095 using _Up = typename __inv_unwrap<_Tp>::type;
3096 return noexcept(std::declval<_Up>().*std::declval<_Fn>());
3099 template<typename _Fn, typename _Tp>
3100 constexpr bool __call_is_nt(__invoke_memobj_deref)
3102 return noexcept((*std::declval<_Tp>()).*std::declval<_Fn>());
3105 template<typename _Fn, typename... _Args>
3106 constexpr bool __call_is_nt(__invoke_other)
3108 return noexcept(std::declval<_Fn>()(std::declval<_Args>()...));
3111 template<typename _Result, typename _Fn, typename... _Args>
3112 struct __call_is_nothrow
3114 std::__call_is_nt<_Fn, _Args...>(typename _Result::__invoke_type{})
3118 template<typename _Fn, typename... _Args>
3119 using __call_is_nothrow_
3120 = __call_is_nothrow<__invoke_result<_Fn, _Args...>, _Fn, _Args...>;
3122 // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
3123 template<typename _Fn, typename... _Args>
3124 struct __is_nothrow_invocable
3125 : __and_<__is_invocable<_Fn, _Args...>,
3126 __call_is_nothrow_<_Fn, _Args...>>::type
3129#pragma GCC diagnostic push
3130#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3131 struct __nonesuchbase {};
3132 struct __nonesuch : private __nonesuchbase {
3133 ~__nonesuch() = delete;
3134 __nonesuch(__nonesuch const&) = delete;
3135 void operator=(__nonesuch const&) = delete;
3137#pragma GCC diagnostic pop
3140#ifdef __cpp_lib_is_invocable // C++ >= 17
3141 /// std::invoke_result
3142 template<typename _Functor, typename... _ArgTypes>
3143 struct invoke_result
3144 : public __invoke_result<_Functor, _ArgTypes...>
3146 static_assert(std::__is_complete_or_unbounded(__type_identity<_Functor>{}),
3147 "_Functor 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::invoke_result_t
3154 template<typename _Fn, typename... _Args>
3155 using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3157 /// std::is_invocable
3158 template<typename _Fn, typename... _ArgTypes>
3160 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3162 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3163 "_Fn must be a complete class or an unbounded array");
3164 static_assert((std::__is_complete_or_unbounded(
3165 __type_identity<_ArgTypes>{}) && ...),
3166 "each argument type must be a complete class or an unbounded array");
3169 /// std::is_invocable_r
3170 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3171 struct is_invocable_r
3172 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>::type
3174 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3175 "_Fn must be a complete class or an unbounded array");
3176 static_assert((std::__is_complete_or_unbounded(
3177 __type_identity<_ArgTypes>{}) && ...),
3178 "each argument type must be a complete class or an unbounded array");
3179 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3180 "_Ret must be a complete class or an unbounded array");
3183 /// std::is_nothrow_invocable
3184 template<typename _Fn, typename... _ArgTypes>
3185 struct is_nothrow_invocable
3186 : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>,
3187 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3189 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3190 "_Fn must be a complete class or an unbounded array");
3191 static_assert((std::__is_complete_or_unbounded(
3192 __type_identity<_ArgTypes>{}) && ...),
3193 "each argument type must be a complete class or an unbounded array");
3196 /// @cond undocumented
3197 // This checks that the INVOKE<R> expression is well-formed and that the
3198 // conversion to R does not throw. It does *not* check whether the INVOKE
3199 // expression itself can throw. That is done by __call_is_nothrow_ instead.
3200 template<typename _Result, typename _Ret>
3201 using __is_nt_invocable_impl
3202 = typename __is_invocable_impl<_Result, _Ret>::__nothrow_conv;
3205 /// std::is_nothrow_invocable_r
3206 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3207 struct is_nothrow_invocable_r
3208 : __and_<__is_nt_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>,
3209 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3211 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3212 "_Fn must be a complete class or an unbounded array");
3213 static_assert((std::__is_complete_or_unbounded(
3214 __type_identity<_ArgTypes>{}) && ...),
3215 "each argument type must be a complete class or an unbounded array");
3216 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3217 "_Ret must be a complete class or an unbounded array");
3219#endif // __cpp_lib_is_invocable
3221#if __cpp_lib_type_trait_variable_templates // C++ >= 17
3223 * @defgroup variable_templates Variable templates for type traits
3224 * @ingroup metaprogramming
3226 * Each variable `is_xxx_v<T>` is a boolean constant with the same value
3227 * as the `value` member of the corresponding type trait `is_xxx<T>`.
3229 * @since C++17 unless noted otherwise.
3234 * @ingroup variable_templates
3236template <typename _Tp>
3237 inline constexpr bool is_void_v = is_void<_Tp>::value;
3238template <typename _Tp>
3239 inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
3240template <typename _Tp>
3241 inline constexpr bool is_integral_v = is_integral<_Tp>::value;
3242template <typename _Tp>
3243 inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
3245#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
3246template <typename _Tp>
3247 inline constexpr bool is_array_v = __is_array(_Tp);
3249template <typename _Tp>
3250 inline constexpr bool is_array_v = false;
3251template <typename _Tp>
3252 inline constexpr bool is_array_v<_Tp[]> = true;
3253template <typename _Tp, size_t _Num>
3254 inline constexpr bool is_array_v<_Tp[_Num]> = true;
3257template <typename _Tp>
3258 inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
3259template <typename _Tp>
3260 inline constexpr bool is_lvalue_reference_v = false;
3261template <typename _Tp>
3262 inline constexpr bool is_lvalue_reference_v<_Tp&> = true;
3263template <typename _Tp>
3264 inline constexpr bool is_rvalue_reference_v = false;
3265template <typename _Tp>
3266 inline constexpr bool is_rvalue_reference_v<_Tp&&> = true;
3268#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
3269template <typename _Tp>
3270 inline constexpr bool is_member_object_pointer_v =
3271 __is_member_object_pointer(_Tp);
3273template <typename _Tp>
3274 inline constexpr bool is_member_object_pointer_v =
3275 is_member_object_pointer<_Tp>::value;
3278#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
3279template <typename _Tp>
3280 inline constexpr bool is_member_function_pointer_v =
3281 __is_member_function_pointer(_Tp);
3283template <typename _Tp>
3284 inline constexpr bool is_member_function_pointer_v =
3285 is_member_function_pointer<_Tp>::value;
3288template <typename _Tp>
3289 inline constexpr bool is_enum_v = __is_enum(_Tp);
3290template <typename _Tp>
3291 inline constexpr bool is_union_v = __is_union(_Tp);
3292template <typename _Tp>
3293 inline constexpr bool is_class_v = __is_class(_Tp);
3294// is_function_v is defined below, after is_const_v.
3296#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
3297template <typename _Tp>
3298 inline constexpr bool is_reference_v = __is_reference(_Tp);
3300template <typename _Tp>
3301 inline constexpr bool is_reference_v = false;
3302template <typename _Tp>
3303 inline constexpr bool is_reference_v<_Tp&> = true;
3304template <typename _Tp>
3305 inline constexpr bool is_reference_v<_Tp&&> = true;
3308template <typename _Tp>
3309 inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
3310template <typename _Tp>
3311 inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
3313#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
3314template <typename _Tp>
3315 inline constexpr bool is_object_v = __is_object(_Tp);
3317template <typename _Tp>
3318 inline constexpr bool is_object_v = is_object<_Tp>::value;
3321template <typename _Tp>
3322 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
3323template <typename _Tp>
3324 inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;
3326#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
3327template <typename _Tp>
3328 inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
3330template <typename _Tp>
3331 inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
3334template <typename _Tp>
3335 inline constexpr bool is_const_v = false;
3336template <typename _Tp>
3337 inline constexpr bool is_const_v<const _Tp> = true;
3339#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
3340template <typename _Tp>
3341 inline constexpr bool is_function_v = __is_function(_Tp);
3343template <typename _Tp>
3344 inline constexpr bool is_function_v = !is_const_v<const _Tp>;
3345template <typename _Tp>
3346 inline constexpr bool is_function_v<_Tp&> = false;
3347template <typename _Tp>
3348 inline constexpr bool is_function_v<_Tp&&> = false;
3351template <typename _Tp>
3352 inline constexpr bool is_volatile_v = false;
3353template <typename _Tp>
3354 inline constexpr bool is_volatile_v<volatile _Tp> = true;
3356template <typename _Tp>
3357 inline constexpr bool is_trivial_v = __is_trivial(_Tp);
3358template <typename _Tp>
3359 inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
3360template <typename _Tp>
3361 inline constexpr bool is_standard_layout_v = __is_standard_layout(_Tp);
3362template <typename _Tp>
3363 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout_v && is_trivial_v")
3364 inline constexpr bool is_pod_v = __is_pod(_Tp);
3365template <typename _Tp>
3366 _GLIBCXX17_DEPRECATED
3367 inline constexpr bool is_literal_type_v = __is_literal_type(_Tp);
3368template <typename _Tp>
3369 inline constexpr bool is_empty_v = __is_empty(_Tp);
3370template <typename _Tp>
3371 inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
3372template <typename _Tp>
3373 inline constexpr bool is_abstract_v = __is_abstract(_Tp);
3374template <typename _Tp>
3375 inline constexpr bool is_final_v = __is_final(_Tp);
3377template <typename _Tp>
3378 inline constexpr bool is_signed_v = is_signed<_Tp>::value;
3379template <typename _Tp>
3380 inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
3382template <typename _Tp, typename... _Args>
3383 inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
3384template <typename _Tp>
3385 inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
3386template <typename _Tp>
3387 inline constexpr bool is_copy_constructible_v
3388 = __is_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3389template <typename _Tp>
3390 inline constexpr bool is_move_constructible_v
3391 = __is_constructible(_Tp, __add_rval_ref_t<_Tp>);
3393template <typename _Tp, typename _Up>
3394 inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Up);
3395template <typename _Tp>
3396 inline constexpr bool is_copy_assignable_v
3397 = __is_assignable(__add_lval_ref_t<_Tp>, __add_lval_ref_t<const _Tp>);
3398template <typename _Tp>
3399 inline constexpr bool is_move_assignable_v
3400 = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3402template <typename _Tp>
3403 inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
3405template <typename _Tp, typename... _Args>
3406 inline constexpr bool is_trivially_constructible_v
3407 = __is_trivially_constructible(_Tp, _Args...);
3408template <typename _Tp>
3409 inline constexpr bool is_trivially_default_constructible_v
3410 = __is_trivially_constructible(_Tp);
3411template <typename _Tp>
3412 inline constexpr bool is_trivially_copy_constructible_v
3413 = __is_trivially_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3414template <typename _Tp>
3415 inline constexpr bool is_trivially_move_constructible_v
3416 = __is_trivially_constructible(_Tp, __add_rval_ref_t<_Tp>);
3418template <typename _Tp, typename _Up>
3419 inline constexpr bool is_trivially_assignable_v
3420 = __is_trivially_assignable(_Tp, _Up);
3421template <typename _Tp>
3422 inline constexpr bool is_trivially_copy_assignable_v
3423 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3424 __add_lval_ref_t<const _Tp>);
3425template <typename _Tp>
3426 inline constexpr bool is_trivially_move_assignable_v
3427 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3428 __add_rval_ref_t<_Tp>);
3431template <typename _Tp>
3432 inline constexpr bool is_trivially_destructible_v = false;
3434template <typename _Tp>
3435 requires (!is_reference_v<_Tp>) && requires (_Tp& __t) { __t.~_Tp(); }
3436 inline constexpr bool is_trivially_destructible_v<_Tp>
3437 = __has_trivial_destructor(_Tp);
3438template <typename _Tp>
3439 inline constexpr bool is_trivially_destructible_v<_Tp&> = true;
3440template <typename _Tp>
3441 inline constexpr bool is_trivially_destructible_v<_Tp&&> = true;
3442template <typename _Tp, size_t _Nm>
3443 inline constexpr bool is_trivially_destructible_v<_Tp[_Nm]>
3444 = is_trivially_destructible_v<_Tp>;
3446template <typename _Tp>
3447 inline constexpr bool is_trivially_destructible_v =
3448 is_trivially_destructible<_Tp>::value;
3451template <typename _Tp, typename... _Args>
3452 inline constexpr bool is_nothrow_constructible_v
3453 = __is_nothrow_constructible(_Tp, _Args...);
3454template <typename _Tp>
3455 inline constexpr bool is_nothrow_default_constructible_v
3456 = __is_nothrow_constructible(_Tp);
3457template <typename _Tp>
3458 inline constexpr bool is_nothrow_copy_constructible_v
3459 = __is_nothrow_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3460template <typename _Tp>
3461 inline constexpr bool is_nothrow_move_constructible_v
3462 = __is_nothrow_constructible(_Tp, __add_rval_ref_t<_Tp>);
3464template <typename _Tp, typename _Up>
3465 inline constexpr bool is_nothrow_assignable_v
3466 = __is_nothrow_assignable(_Tp, _Up);
3467template <typename _Tp>
3468 inline constexpr bool is_nothrow_copy_assignable_v
3469 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>,
3470 __add_lval_ref_t<const _Tp>);
3471template <typename _Tp>
3472 inline constexpr bool is_nothrow_move_assignable_v
3473 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3475template <typename _Tp>
3476 inline constexpr bool is_nothrow_destructible_v =
3477 is_nothrow_destructible<_Tp>::value;
3479template <typename _Tp>
3480 inline constexpr bool has_virtual_destructor_v
3481 = __has_virtual_destructor(_Tp);
3483template <typename _Tp>
3484 inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
3486template <typename _Tp>
3487 inline constexpr size_t rank_v = 0;
3488template <typename _Tp, size_t _Size>
3489 inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
3490template <typename _Tp>
3491 inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
3493template <typename _Tp, unsigned _Idx = 0>
3494 inline constexpr size_t extent_v = 0;
3495template <typename _Tp, size_t _Size>
3496 inline constexpr size_t extent_v<_Tp[_Size], 0> = _Size;
3497template <typename _Tp, unsigned _Idx, size_t _Size>
3498 inline constexpr size_t extent_v<_Tp[_Size], _Idx> = extent_v<_Tp, _Idx - 1>;
3499template <typename _Tp>
3500 inline constexpr size_t extent_v<_Tp[], 0> = 0;
3501template <typename _Tp, unsigned _Idx>
3502 inline constexpr size_t extent_v<_Tp[], _Idx> = extent_v<_Tp, _Idx - 1>;
3504#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
3505template <typename _Tp, typename _Up>
3506 inline constexpr bool is_same_v = __is_same(_Tp, _Up);
3508template <typename _Tp, typename _Up>
3509 inline constexpr bool is_same_v = false;
3510template <typename _Tp>
3511 inline constexpr bool is_same_v<_Tp, _Tp> = true;
3513template <typename _Base, typename _Derived>
3514 inline constexpr bool is_base_of_v = __is_base_of(_Base, _Derived);
3515#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
3516template <typename _From, typename _To>
3517 inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
3519template <typename _From, typename _To>
3520 inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
3522template<typename _Fn, typename... _Args>
3523 inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
3524template<typename _Fn, typename... _Args>
3525 inline constexpr bool is_nothrow_invocable_v
3526 = is_nothrow_invocable<_Fn, _Args...>::value;
3527template<typename _Ret, typename _Fn, typename... _Args>
3528 inline constexpr bool is_invocable_r_v
3529 = is_invocable_r<_Ret, _Fn, _Args...>::value;
3530template<typename _Ret, typename _Fn, typename... _Args>
3531 inline constexpr bool is_nothrow_invocable_r_v
3532 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3534#endif // __cpp_lib_type_trait_variable_templates
3536#ifdef __cpp_lib_has_unique_object_representations // C++ >= 17 && HAS_UNIQ_OBJ_REP
3537 /// has_unique_object_representations
3539 template<typename _Tp>
3540 struct has_unique_object_representations
3541 : bool_constant<__has_unique_object_representations(
3542 remove_cv_t<remove_all_extents_t<_Tp>>
3545 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3546 "template argument must be a complete class or an unbounded array");
3549# if __cpp_lib_type_trait_variable_templates // C++ >= 17
3550 /// @ingroup variable_templates
3551 template<typename _Tp>
3552 inline constexpr bool has_unique_object_representations_v
3553 = has_unique_object_representations<_Tp>::value;
3557#ifdef __cpp_lib_is_aggregate // C++ >= 17 && builtin_is_aggregate
3558 /// is_aggregate - true if the type is an aggregate.
3560 template<typename _Tp>
3562 : bool_constant<__is_aggregate(remove_cv_t<_Tp>)>
3565# if __cpp_lib_type_trait_variable_templates // C++ >= 17
3566 /** is_aggregate_v - true if the type is an aggregate.
3567 * @ingroup variable_templates
3570 template<typename _Tp>
3571 inline constexpr bool is_aggregate_v = __is_aggregate(remove_cv_t<_Tp>);
3575 /** * Remove references and cv-qualifiers.
3579#ifdef __cpp_lib_remove_cvref // C++ >= 20
3580# if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cvref)
3581 template<typename _Tp>
3583 { using type = __remove_cvref(_Tp); };
3585 template<typename _Tp>
3587 { using type = typename remove_cv<_Tp>::type; };
3589 template<typename _Tp>
3590 struct remove_cvref<_Tp&>
3591 { using type = typename remove_cv<_Tp>::type; };
3593 template<typename _Tp>
3594 struct remove_cvref<_Tp&&>
3595 { using type = typename remove_cv<_Tp>::type; };
3598 template<typename _Tp>
3599 using remove_cvref_t = typename remove_cvref<_Tp>::type;
3601#endif // __cpp_lib_remove_cvref
3603#ifdef __cpp_lib_type_identity // C++ >= 20
3604 /** * Identity metafunction.
3608 template<typename _Tp>
3609 struct type_identity { using type = _Tp; };
3611 template<typename _Tp>
3612 using type_identity_t = typename type_identity<_Tp>::type;
3616#ifdef __cpp_lib_unwrap_ref // C++ >= 20
3617 /** Unwrap a reference_wrapper
3621 template<typename _Tp>
3622 struct unwrap_reference { using type = _Tp; };
3624 template<typename _Tp>
3625 struct unwrap_reference<reference_wrapper<_Tp>> { using type = _Tp&; };
3627 template<typename _Tp>
3628 using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3631 /** Decay type and if it's a reference_wrapper, unwrap it
3635 template<typename _Tp>
3636 struct unwrap_ref_decay { using type = unwrap_reference_t<decay_t<_Tp>>; };
3638 template<typename _Tp>
3639 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3641#endif // __cpp_lib_unwrap_ref
3643#ifdef __cpp_lib_bounded_array_traits // C++ >= 20
3644 /// True for a type that is an array of known bound.
3645 /// @ingroup variable_templates
3647# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array)
3648 template<typename _Tp>
3649 inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp);
3651 template<typename _Tp>
3652 inline constexpr bool is_bounded_array_v = false;
3654 template<typename _Tp, size_t _Size>
3655 inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true;
3658 /// True for a type that is an array of unknown bound.
3659 /// @ingroup variable_templates
3661 template<typename _Tp>
3662 inline constexpr bool is_unbounded_array_v = false;
3664 template<typename _Tp>
3665 inline constexpr bool is_unbounded_array_v<_Tp[]> = true;
3667 /// True for a type that is an array of known bound.
3669 template<typename _Tp>
3670 struct is_bounded_array
3671 : public bool_constant<is_bounded_array_v<_Tp>>
3674 /// True for a type that is an array of unknown bound.
3676 template<typename _Tp>
3677 struct is_unbounded_array
3678 : public bool_constant<is_unbounded_array_v<_Tp>>
3680#endif // __cpp_lib_bounded_array_traits
3682#if __has_builtin(__is_layout_compatible) && __cplusplus >= 202002L
3685 template<typename _Tp, typename _Up>
3686 struct is_layout_compatible
3687 : bool_constant<__is_layout_compatible(_Tp, _Up)>
3690 /// @ingroup variable_templates
3692 template<typename _Tp, typename _Up>
3693 constexpr bool is_layout_compatible_v
3694 = __is_layout_compatible(_Tp, _Up);
3696#if __has_builtin(__builtin_is_corresponding_member)
3697# ifndef __cpp_lib_is_layout_compatible
3698# error "libstdc++ bug: is_corresponding_member and is_layout_compatible are provided but their FTM is not set"
3702 template<typename _S1, typename _S2, typename _M1, typename _M2>
3704 is_corresponding_member(_M1 _S1::*__m1, _M2 _S2::*__m2) noexcept
3705 { return __builtin_is_corresponding_member(__m1, __m2); }
3709#if __has_builtin(__is_pointer_interconvertible_base_of) \
3710 && __cplusplus >= 202002L
3711 /// True if `_Derived` is standard-layout and has a base class of type `_Base`
3713 template<typename _Base, typename _Derived>
3714 struct is_pointer_interconvertible_base_of
3715 : bool_constant<__is_pointer_interconvertible_base_of(_Base, _Derived)>
3718 /// @ingroup variable_templates
3720 template<typename _Base, typename _Derived>
3721 constexpr bool is_pointer_interconvertible_base_of_v
3722 = __is_pointer_interconvertible_base_of(_Base, _Derived);
3724#if __has_builtin(__builtin_is_pointer_interconvertible_with_class)
3725# ifndef __cpp_lib_is_pointer_interconvertible
3726# error "libstdc++ bug: is_pointer_interconvertible available but FTM is not set"
3729 /// True if `__mp` points to the first member of a standard-layout type
3730 /// @returns true if `s.*__mp` is pointer-interconvertible with `s`
3732 template<typename _Tp, typename _Mem>
3734 is_pointer_interconvertible_with_class(_Mem _Tp::*__mp) noexcept
3735 { return __builtin_is_pointer_interconvertible_with_class(__mp); }
3739#ifdef __cpp_lib_is_scoped_enum // C++ >= 23
3740 /// True if the type is a scoped enumeration type.
3743# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
3744 template<typename _Tp>
3745 struct is_scoped_enum
3746 : bool_constant<__is_scoped_enum(_Tp)>
3749 template<typename _Tp>
3750 struct is_scoped_enum
3754 template<typename _Tp>
3755 requires __is_enum(_Tp)
3756 && requires(remove_cv_t<_Tp> __t) { __t = __t; } // fails if incomplete
3757 struct is_scoped_enum<_Tp>
3758 : bool_constant<!requires(_Tp __t, void(*__f)(int)) { __f(__t); }>
3762 /// @ingroup variable_templates
3764# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
3765 template<typename _Tp>
3766 inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
3768 template<typename _Tp>
3769 inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
3773#ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp
3774 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
3775 /// direct-initialization, and a temporary object would be bound to
3776 /// the reference, false otherwise.
3778 template<typename _Tp, typename _Up>
3779 struct reference_constructs_from_temporary
3780 : public bool_constant<__reference_constructs_from_temporary(_Tp, _Up)>
3782 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
3783 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3784 "template argument must be a complete class or an unbounded array");
3787 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
3788 /// copy-initialization, and a temporary object would be bound to
3789 /// the reference, false otherwise.
3791 template<typename _Tp, typename _Up>
3792 struct reference_converts_from_temporary
3793 : public bool_constant<__reference_converts_from_temporary(_Tp, _Up)>
3795 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
3796 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3797 "template argument must be a complete class or an unbounded array");
3800 /// @ingroup variable_templates
3802 template<typename _Tp, typename _Up>
3803 inline constexpr bool reference_constructs_from_temporary_v
3804 = reference_constructs_from_temporary<_Tp, _Up>::value;
3806 /// @ingroup variable_templates
3808 template<typename _Tp, typename _Up>
3809 inline constexpr bool reference_converts_from_temporary_v
3810 = reference_converts_from_temporary<_Tp, _Up>::value;
3811#endif // __cpp_lib_reference_from_temporary
3813#ifdef __cpp_lib_is_constant_evaluated // C++ >= 20 && HAVE_IS_CONST_EVAL
3814 /// Returns true only when called during constant evaluation.
3816 constexpr inline bool
3817 is_constant_evaluated() noexcept
3819#if __cpp_if_consteval >= 202106L
3820 if consteval { return true; } else { return false; }
3822 return __builtin_is_constant_evaluated();
3827#if __cplusplus >= 202002L
3828 /// @cond undocumented
3829 template<typename _From, typename _To>
3830 using __copy_cv = typename __match_cv_qualifiers<_From, _To>::__type;
3832 template<typename _Xp, typename _Yp>
3834 = decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
3836 template<typename _Ap, typename _Bp, typename = void>
3837 struct __common_ref_impl
3840 // [meta.trans.other], COMMON-REF(A, B)
3841 template<typename _Ap, typename _Bp>
3842 using __common_ref = typename __common_ref_impl<_Ap, _Bp>::type;
3844 // COND-RES(COPYCV(X, Y) &, COPYCV(Y, X) &)
3845 template<typename _Xp, typename _Yp>
3846 using __condres_cvref
3847 = __cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>;
3849 // If A and B are both lvalue reference types, ...
3850 template<typename _Xp, typename _Yp>
3851 struct __common_ref_impl<_Xp&, _Yp&, __void_t<__condres_cvref<_Xp, _Yp>>>
3852 : enable_if<is_reference_v<__condres_cvref<_Xp, _Yp>>,
3853 __condres_cvref<_Xp, _Yp>>
3856 // let C be remove_reference_t<COMMON-REF(X&, Y&)>&&
3857 template<typename _Xp, typename _Yp>
3858 using __common_ref_C = remove_reference_t<__common_ref<_Xp&, _Yp&>>&&;
3860 // If A and B are both rvalue reference types, ...
3861 template<typename _Xp, typename _Yp>
3862 struct __common_ref_impl<_Xp&&, _Yp&&,
3863 _Require<is_convertible<_Xp&&, __common_ref_C<_Xp, _Yp>>,
3864 is_convertible<_Yp&&, __common_ref_C<_Xp, _Yp>>>>
3865 { using type = __common_ref_C<_Xp, _Yp>; };
3867 // let D be COMMON-REF(const X&, Y&)
3868 template<typename _Xp, typename _Yp>
3869 using __common_ref_D = __common_ref<const _Xp&, _Yp&>;
3871 // If A is an rvalue reference and B is an lvalue reference, ...
3872 template<typename _Xp, typename _Yp>
3873 struct __common_ref_impl<_Xp&&, _Yp&,
3874 _Require<is_convertible<_Xp&&, __common_ref_D<_Xp, _Yp>>>>
3875 { using type = __common_ref_D<_Xp, _Yp>; };
3877 // If A is an lvalue reference and B is an rvalue reference, ...
3878 template<typename _Xp, typename _Yp>
3879 struct __common_ref_impl<_Xp&, _Yp&&>
3880 : __common_ref_impl<_Yp&&, _Xp&>
3884 template<typename _Tp, typename _Up,
3885 template<typename> class _TQual, template<typename> class _UQual>
3886 struct basic_common_reference
3889 /// @cond undocumented
3890 template<typename _Tp>
3892 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>; };
3894 template<typename _Tp>
3896 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&; };
3898 template<typename _Tp>
3899 struct __xref<_Tp&&>
3900 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&&; };
3902 template<typename _Tp1, typename _Tp2>
3903 using __basic_common_ref
3904 = typename basic_common_reference<remove_cvref_t<_Tp1>,
3905 remove_cvref_t<_Tp2>,
3906 __xref<_Tp1>::template __type,
3907 __xref<_Tp2>::template __type>::type;
3910 template<typename... _Tp>
3911 struct common_reference;
3913 template<typename... _Tp>
3914 using common_reference_t = typename common_reference<_Tp...>::type;
3916 // If sizeof...(T) is zero, there shall be no member type.
3918 struct common_reference<>
3921 // If sizeof...(T) is one ...
3922 template<typename _Tp0>
3923 struct common_reference<_Tp0>
3924 { using type = _Tp0; };
3926 /// @cond undocumented
3927 template<typename _Tp1, typename _Tp2, int _Bullet = 1, typename = void>
3928 struct __common_reference_impl
3929 : __common_reference_impl<_Tp1, _Tp2, _Bullet + 1>
3932 // If sizeof...(T) is two ...
3933 template<typename _Tp1, typename _Tp2>
3934 struct common_reference<_Tp1, _Tp2>
3935 : __common_reference_impl<_Tp1, _Tp2>
3938 // If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, ...
3939 template<typename _Tp1, typename _Tp2>
3940 struct __common_reference_impl<_Tp1&, _Tp2&, 1,
3941 void_t<__common_ref<_Tp1&, _Tp2&>>>
3942 { using type = __common_ref<_Tp1&, _Tp2&>; };
3944 template<typename _Tp1, typename _Tp2>
3945 struct __common_reference_impl<_Tp1&&, _Tp2&&, 1,
3946 void_t<__common_ref<_Tp1&&, _Tp2&&>>>
3947 { using type = __common_ref<_Tp1&&, _Tp2&&>; };
3949 template<typename _Tp1, typename _Tp2>
3950 struct __common_reference_impl<_Tp1&, _Tp2&&, 1,
3951 void_t<__common_ref<_Tp1&, _Tp2&&>>>
3952 { using type = __common_ref<_Tp1&, _Tp2&&>; };
3954 template<typename _Tp1, typename _Tp2>
3955 struct __common_reference_impl<_Tp1&&, _Tp2&, 1,
3956 void_t<__common_ref<_Tp1&&, _Tp2&>>>
3957 { using type = __common_ref<_Tp1&&, _Tp2&>; };
3959 // Otherwise, if basic_common_reference<...>::type is well-formed, ...
3960 template<typename _Tp1, typename _Tp2>
3961 struct __common_reference_impl<_Tp1, _Tp2, 2,
3962 void_t<__basic_common_ref<_Tp1, _Tp2>>>
3963 { using type = __basic_common_ref<_Tp1, _Tp2>; };
3965 // Otherwise, if COND-RES(T1, T2) is well-formed, ...
3966 template<typename _Tp1, typename _Tp2>
3967 struct __common_reference_impl<_Tp1, _Tp2, 3,
3968 void_t<__cond_res<_Tp1, _Tp2>>>
3969 { using type = __cond_res<_Tp1, _Tp2>; };
3971 // Otherwise, if common_type_t<T1, T2> is well-formed, ...
3972 template<typename _Tp1, typename _Tp2>
3973 struct __common_reference_impl<_Tp1, _Tp2, 4,
3974 void_t<common_type_t<_Tp1, _Tp2>>>
3975 { using type = common_type_t<_Tp1, _Tp2>; };
3977 // Otherwise, there shall be no member type.
3978 template<typename _Tp1, typename _Tp2>
3979 struct __common_reference_impl<_Tp1, _Tp2, 5, void>
3982 // Otherwise, if sizeof...(T) is greater than two, ...
3983 template<typename _Tp1, typename _Tp2, typename... _Rest>
3984 struct common_reference<_Tp1, _Tp2, _Rest...>
3985 : __common_type_fold<common_reference<_Tp1, _Tp2>,
3986 __common_type_pack<_Rest...>>
3989 // Reuse __common_type_fold for common_reference<T1, T2, Rest...>
3990 template<typename _Tp1, typename _Tp2, typename... _Rest>
3991 struct __common_type_fold<common_reference<_Tp1, _Tp2>,
3992 __common_type_pack<_Rest...>,
3993 void_t<common_reference_t<_Tp1, _Tp2>>>
3994 : public common_reference<common_reference_t<_Tp1, _Tp2>, _Rest...>
4000 /// @} group metaprogramming
4002_GLIBCXX_END_NAMESPACE_VERSION
4007#endif // _GLIBCXX_TYPE_TRAITS