1// C++11 <type_traits> -*- C++ -*-
3// Copyright (C) 2007-2025 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
33#pragma GCC system_header
36#if __cplusplus < 201103L
37# include <bits/c++0x_warning.h>
40#include <bits/c++config.h>
42#define __glibcxx_want_bool_constant
43#define __glibcxx_want_bounded_array_traits
44#define __glibcxx_want_has_unique_object_representations
45#define __glibcxx_want_integral_constant_callable
46#define __glibcxx_want_is_aggregate
47#define __glibcxx_want_is_constant_evaluated
48#define __glibcxx_want_is_final
49#define __glibcxx_want_is_invocable
50#define __glibcxx_want_is_layout_compatible
51#define __glibcxx_want_is_nothrow_convertible
52#define __glibcxx_want_is_null_pointer
53#define __glibcxx_want_is_pointer_interconvertible
54#define __glibcxx_want_is_scoped_enum
55#define __glibcxx_want_is_swappable
56#define __glibcxx_want_is_virtual_base_of
57#define __glibcxx_want_logical_traits
58#define __glibcxx_want_reference_from_temporary
59#define __glibcxx_want_remove_cvref
60#define __glibcxx_want_result_of_sfinae
61#define __glibcxx_want_transformation_trait_aliases
62#define __glibcxx_want_type_identity
63#define __glibcxx_want_type_trait_variable_templates
64#define __glibcxx_want_unwrap_ref
65#define __glibcxx_want_void_t
66#include <bits/version.h>
70namespace std _GLIBCXX_VISIBILITY(default)
72_GLIBCXX_BEGIN_NAMESPACE_VERSION
74 template<typename _Tp>
75 class reference_wrapper;
78 * @defgroup metaprogramming Metaprogramming
81 * Template utilities for compile-time introspection and modification,
82 * including type classification traits, type property inspection traits
83 * and type transformation traits.
91 template<typename _Tp, _Tp __v>
92 struct integral_constant
94 static constexpr _Tp value = __v;
95 using value_type = _Tp;
96 using type = integral_constant<_Tp, __v>;
97 constexpr operator value_type() const noexcept { return value; }
99#ifdef __cpp_lib_integral_constant_callable // C++ >= 14
100 constexpr value_type operator()() const noexcept { return value; }
104#if ! __cpp_inline_variables
105 template<typename _Tp, _Tp __v>
106 constexpr _Tp integral_constant<_Tp, __v>::value;
109 /// @cond undocumented
110 /// bool_constant for C++11
112 using __bool_constant = integral_constant<bool, __v>;
115 /// The type used as a compile-time boolean with true value.
116 using true_type = __bool_constant<true>;
118 /// The type used as a compile-time boolean with false value.
119 using false_type = __bool_constant<false>;
121#ifdef __cpp_lib_bool_constant // C++ >= 17
122 /// Alias template for compile-time boolean constant types.
125 using bool_constant = __bool_constant<__v>;
128 // Metaprogramming helper types.
131 /// Define a member typedef `type` only if a boolean constant is true.
132 template<bool, typename _Tp = void>
136 // Partial specialization for true.
137 template<typename _Tp>
138 struct enable_if<true, _Tp>
139 { using type = _Tp; };
141 // __enable_if_t (std::enable_if_t for C++11)
142 template<bool _Cond, typename _Tp = void>
143 using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
148 template<typename _Tp, typename>
153 struct __conditional<false>
155 template<typename, typename _Up>
159 // More efficient version of std::conditional_t for internal use (and C++11)
160 template<bool _Cond, typename _If, typename _Else>
161 using __conditional_t
162 = typename __conditional<_Cond>::template type<_If, _Else>;
164 /// @cond undocumented
165 template <typename _Type>
166 struct __type_identity
167 { using type = _Type; };
169 template<typename _Tp>
170 using __type_identity_t = typename __type_identity<_Tp>::type;
174 // A variadic alias template that resolves to its first argument.
175 template<typename _Tp, typename...>
176 using __first_t = _Tp;
178 // These are deliberately not defined.
179 template<typename... _Bn>
180 auto __or_fn(int) -> __first_t<false_type,
181 __enable_if_t<!bool(_Bn::value)>...>;
183 template<typename... _Bn>
184 auto __or_fn(...) -> true_type;
186 template<typename... _Bn>
187 auto __and_fn(int) -> __first_t<true_type,
188 __enable_if_t<bool(_Bn::value)>...>;
190 template<typename... _Bn>
191 auto __and_fn(...) -> false_type;
192 } // namespace detail
194 // Like C++17 std::dis/conjunction, but usable in C++11 and resolves
195 // to either true_type or false_type which allows for a more efficient
196 // implementation that avoids recursive class template instantiation.
197 template<typename... _Bn>
199 : decltype(__detail::__or_fn<_Bn...>(0))
202 template<typename... _Bn>
204 : decltype(__detail::__and_fn<_Bn...>(0))
207 template<typename _Pp>
209 : __bool_constant<!bool(_Pp::value)>
213#ifdef __cpp_lib_logical_traits // C++ >= 17
215 /// @cond undocumented
216 template<typename... _Bn>
217 inline constexpr bool __or_v = __or_<_Bn...>::value;
218 template<typename... _Bn>
219 inline constexpr bool __and_v = __and_<_Bn...>::value;
223 template<typename /* = void */, typename _B1, typename... _Bn>
224 struct __disjunction_impl
225 { using type = _B1; };
227 template<typename _B1, typename _B2, typename... _Bn>
228 struct __disjunction_impl<__enable_if_t<!bool(_B1::value)>, _B1, _B2, _Bn...>
229 { using type = typename __disjunction_impl<void, _B2, _Bn...>::type; };
231 template<typename /* = void */, typename _B1, typename... _Bn>
232 struct __conjunction_impl
233 { using type = _B1; };
235 template<typename _B1, typename _B2, typename... _Bn>
236 struct __conjunction_impl<__enable_if_t<bool(_B1::value)>, _B1, _B2, _Bn...>
237 { using type = typename __conjunction_impl<void, _B2, _Bn...>::type; };
238 } // namespace __detail
241 template<typename... _Bn>
243 : __detail::__conjunction_impl<void, _Bn...>::type
251 template<typename... _Bn>
253 : __detail::__disjunction_impl<void, _Bn...>::type
261 template<typename _Pp>
266 /** @ingroup variable_templates
269 template<typename... _Bn>
270 inline constexpr bool conjunction_v = conjunction<_Bn...>::value;
272 template<typename... _Bn>
273 inline constexpr bool disjunction_v = disjunction<_Bn...>::value;
275 template<typename _Pp>
276 inline constexpr bool negation_v = negation<_Pp>::value;
279#endif // __cpp_lib_logical_traits
281 // Forward declarations
289 /// @cond undocumented
291 struct __is_array_unknown_bounds;
293 // An object type which is not an unbounded array.
294 // It might still be an incomplete type, but if this is false_type
295 // then we can be certain it's not a complete object type.
296 template<typename _Tp>
297 using __maybe_complete_object_type
298 = __and_<is_object<_Tp>, __not_<__is_array_unknown_bounds<_Tp>>>;
300 // Helper functions that return false_type for incomplete classes,
301 // incomplete unions and arrays of known bound from those.
303 // More specialized overload for complete object types (returning true_type).
304 template<typename _Tp,
305 typename = __enable_if_t<__maybe_complete_object_type<_Tp>::value>,
306 size_t = sizeof(_Tp)>
308 __is_complete_or_unbounded(__type_identity<_Tp>)
311 // Less specialized overload for reference and unknown-bound array types
312 // (returning true_type), and incomplete types (returning false_type).
313 template<typename _TypeIdentity,
314 typename _NestedType = typename _TypeIdentity::type>
315 constexpr typename __not_<__maybe_complete_object_type<_NestedType>>::type
316 __is_complete_or_unbounded(_TypeIdentity)
319 // __remove_cv_t (std::remove_cv_t for C++11).
320 template<typename _Tp>
321 using __remove_cv_t = typename remove_cv<_Tp>::type;
324 // Primary type categories.
327 template<typename _Tp>
329 : public false_type { };
333 : public true_type { };
336 struct is_void<const void>
337 : public true_type { };
340 struct is_void<volatile void>
341 : public true_type { };
344 struct is_void<const volatile void>
345 : public true_type { };
347 /// @cond undocumented
349 struct __is_integral_helper
350 : public false_type { };
353 struct __is_integral_helper<bool>
354 : public true_type { };
357 struct __is_integral_helper<char>
358 : public true_type { };
361 struct __is_integral_helper<signed char>
362 : public true_type { };
365 struct __is_integral_helper<unsigned char>
366 : public true_type { };
368 // We want is_integral<wchar_t> to be true (and make_signed/unsigned to work)
369 // even when libc doesn't provide working <wchar.h> and related functions,
370 // so don't check _GLIBCXX_USE_WCHAR_T here.
372 struct __is_integral_helper<wchar_t>
373 : public true_type { };
375#ifdef _GLIBCXX_USE_CHAR8_T
377 struct __is_integral_helper<char8_t>
378 : public true_type { };
382 struct __is_integral_helper<char16_t>
383 : public true_type { };
386 struct __is_integral_helper<char32_t>
387 : public true_type { };
390 struct __is_integral_helper<short>
391 : public true_type { };
394 struct __is_integral_helper<unsigned short>
395 : public true_type { };
398 struct __is_integral_helper<int>
399 : public true_type { };
402 struct __is_integral_helper<unsigned int>
403 : public true_type { };
406 struct __is_integral_helper<long>
407 : public true_type { };
410 struct __is_integral_helper<unsigned long>
411 : public true_type { };
414 struct __is_integral_helper<long long>
415 : public true_type { };
418 struct __is_integral_helper<unsigned long long>
419 : public true_type { };
421 // Conditionalizing on __STRICT_ANSI__ here will break any port that
422 // uses one of these types for size_t.
423#if defined(__GLIBCXX_TYPE_INT_N_0)
426 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
427 : public true_type { };
431 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
432 : public true_type { };
434#if defined(__GLIBCXX_TYPE_INT_N_1)
437 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
438 : public true_type { };
442 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
443 : public true_type { };
445#if defined(__GLIBCXX_TYPE_INT_N_2)
448 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
449 : public true_type { };
453 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
454 : public true_type { };
456#if defined(__GLIBCXX_TYPE_INT_N_3)
459 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
460 : public true_type { };
464 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
465 : public true_type { };
468#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
471 struct __is_integral_helper<__int128>
472 : public true_type { };
476 struct __is_integral_helper<unsigned __int128>
477 : public true_type { };
483 template<typename _Tp>
485 : public __is_integral_helper<__remove_cv_t<_Tp>>::type
488 /// @cond undocumented
490 struct __is_floating_point_helper
491 : public false_type { };
494 struct __is_floating_point_helper<float>
495 : public true_type { };
498 struct __is_floating_point_helper<double>
499 : public true_type { };
502 struct __is_floating_point_helper<long double>
503 : public true_type { };
505#ifdef __STDCPP_FLOAT16_T__
507 struct __is_floating_point_helper<_Float16>
508 : public true_type { };
511#ifdef __STDCPP_FLOAT32_T__
513 struct __is_floating_point_helper<_Float32>
514 : public true_type { };
517#ifdef __STDCPP_FLOAT64_T__
519 struct __is_floating_point_helper<_Float64>
520 : public true_type { };
523#ifdef __STDCPP_FLOAT128_T__
525 struct __is_floating_point_helper<_Float128>
526 : public true_type { };
529#ifdef __STDCPP_BFLOAT16_T__
531 struct __is_floating_point_helper<__gnu_cxx::__bfloat16_t>
532 : public true_type { };
535#ifdef _GLIBCXX_USE_FLOAT128
537 struct __is_floating_point_helper<__float128>
538 : public true_type { };
542 /// is_floating_point
543 template<typename _Tp>
544 struct is_floating_point
545 : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type
549#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
550 template<typename _Tp>
552 : public __bool_constant<__is_array(_Tp)>
557 : public false_type { };
559 template<typename _Tp, std::size_t _Size>
560 struct is_array<_Tp[_Size]>
561 : public true_type { };
563 template<typename _Tp>
564 struct is_array<_Tp[]>
565 : public true_type { };
569#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
570 template<typename _Tp>
572 : public __bool_constant<__is_pointer(_Tp)>
575 template<typename _Tp>
577 : public false_type { };
579 template<typename _Tp>
580 struct is_pointer<_Tp*>
581 : public true_type { };
583 template<typename _Tp>
584 struct is_pointer<_Tp* const>
585 : public true_type { };
587 template<typename _Tp>
588 struct is_pointer<_Tp* volatile>
589 : public true_type { };
591 template<typename _Tp>
592 struct is_pointer<_Tp* const volatile>
593 : public true_type { };
596 /// is_lvalue_reference
598 struct is_lvalue_reference
599 : public false_type { };
601 template<typename _Tp>
602 struct is_lvalue_reference<_Tp&>
603 : public true_type { };
605 /// is_rvalue_reference
607 struct is_rvalue_reference
608 : public false_type { };
610 template<typename _Tp>
611 struct is_rvalue_reference<_Tp&&>
612 : public true_type { };
614 /// is_member_object_pointer
615#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
616 template<typename _Tp>
617 struct is_member_object_pointer
618 : public __bool_constant<__is_member_object_pointer(_Tp)>
622 struct __is_member_object_pointer_helper
623 : public false_type { };
625 template<typename _Tp, typename _Cp>
626 struct __is_member_object_pointer_helper<_Tp _Cp::*>
627 : public __not_<is_function<_Tp>>::type { };
630 template<typename _Tp>
631 struct is_member_object_pointer
632 : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type
636#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
637 /// is_member_function_pointer
638 template<typename _Tp>
639 struct is_member_function_pointer
640 : public __bool_constant<__is_member_function_pointer(_Tp)>
644 struct __is_member_function_pointer_helper
645 : public false_type { };
647 template<typename _Tp, typename _Cp>
648 struct __is_member_function_pointer_helper<_Tp _Cp::*>
649 : public is_function<_Tp>::type { };
651 /// is_member_function_pointer
652 template<typename _Tp>
653 struct is_member_function_pointer
654 : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type
659 template<typename _Tp>
661 : public __bool_constant<__is_enum(_Tp)>
665 template<typename _Tp>
667 : public __bool_constant<__is_union(_Tp)>
671 template<typename _Tp>
673 : public __bool_constant<__is_class(_Tp)>
677#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
678 template<typename _Tp>
680 : public __bool_constant<__is_function(_Tp)>
683 template<typename _Tp>
685 : public __bool_constant<!is_const<const _Tp>::value> { };
687 template<typename _Tp>
688 struct is_function<_Tp&>
689 : public false_type { };
691 template<typename _Tp>
692 struct is_function<_Tp&&>
693 : public false_type { };
696#ifdef __cpp_lib_is_null_pointer // C++ >= 11
697 /// is_null_pointer (LWG 2247).
698 template<typename _Tp>
699 struct is_null_pointer
700 : public false_type { };
703 struct is_null_pointer<std::nullptr_t>
704 : public true_type { };
707 struct is_null_pointer<const std::nullptr_t>
708 : public true_type { };
711 struct is_null_pointer<volatile std::nullptr_t>
712 : public true_type { };
715 struct is_null_pointer<const volatile std::nullptr_t>
716 : public true_type { };
718 /// __is_nullptr_t (deprecated extension).
719 /// @deprecated Non-standard. Use `is_null_pointer` instead.
720 template<typename _Tp>
721 struct __is_nullptr_t
722 : public is_null_pointer<_Tp>
723 { } _GLIBCXX_DEPRECATED_SUGGEST("std::is_null_pointer");
724#endif // __cpp_lib_is_null_pointer
726 // Composite type categories.
729#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
730 template<typename _Tp>
732 : public __bool_constant<__is_reference(_Tp)>
735 template<typename _Tp>
740 template<typename _Tp>
741 struct is_reference<_Tp&>
745 template<typename _Tp>
746 struct is_reference<_Tp&&>
752 template<typename _Tp>
754 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
758 template<typename _Tp>
759 struct is_fundamental
760 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
761 is_null_pointer<_Tp>>::type
765#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
766 template<typename _Tp>
768 : public __bool_constant<__is_object(_Tp)>
771 template<typename _Tp>
773 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
779 struct is_member_pointer;
782 template<typename _Tp>
784 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
785 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
789 template<typename _Tp>
791 : public __bool_constant<!is_fundamental<_Tp>::value> { };
793 /// is_member_pointer
794#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
795 template<typename _Tp>
796 struct is_member_pointer
797 : public __bool_constant<__is_member_pointer(_Tp)>
800 /// @cond undocumented
801 template<typename _Tp>
802 struct __is_member_pointer_helper
803 : public false_type { };
805 template<typename _Tp, typename _Cp>
806 struct __is_member_pointer_helper<_Tp _Cp::*>
807 : public true_type { };
810 template<typename _Tp>
811 struct is_member_pointer
812 : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type
816 template<typename, typename>
819 /// @cond undocumented
820 template<typename _Tp, typename... _Types>
821 using __is_one_of = __or_<is_same<_Tp, _Types>...>;
823 // Check if a type is one of the signed integer types.
825 template<typename _Tp>
826 using __is_signed_integer = __is_one_of<__remove_cv_t<_Tp>,
827 signed char, signed short, signed int, signed long,
829#if defined(__GLIBCXX_TYPE_INT_N_0)
830 , signed __GLIBCXX_TYPE_INT_N_0
832#if defined(__GLIBCXX_TYPE_INT_N_1)
833 , signed __GLIBCXX_TYPE_INT_N_1
835#if defined(__GLIBCXX_TYPE_INT_N_2)
836 , signed __GLIBCXX_TYPE_INT_N_2
838#if defined(__GLIBCXX_TYPE_INT_N_3)
839 , signed __GLIBCXX_TYPE_INT_N_3
843 // Check if a type is one of the unsigned integer types.
845 template<typename _Tp>
846 using __is_unsigned_integer = __is_one_of<__remove_cv_t<_Tp>,
847 unsigned char, unsigned short, unsigned int, unsigned long,
849#if defined(__GLIBCXX_TYPE_INT_N_0)
850 , unsigned __GLIBCXX_TYPE_INT_N_0
852#if defined(__GLIBCXX_TYPE_INT_N_1)
853 , unsigned __GLIBCXX_TYPE_INT_N_1
855#if defined(__GLIBCXX_TYPE_INT_N_2)
856 , unsigned __GLIBCXX_TYPE_INT_N_2
858#if defined(__GLIBCXX_TYPE_INT_N_3)
859 , unsigned __GLIBCXX_TYPE_INT_N_3
863 // Check if a type is one of the signed or unsigned integer types.
864 template<typename _Tp>
865 using __is_standard_integer
866 = __or_<__is_signed_integer<_Tp>, __is_unsigned_integer<_Tp>>;
868 // __void_t (std::void_t for C++11)
869 template<typename...> using __void_t = void;
875#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const)
876 template<typename _Tp>
878 : public __bool_constant<__is_const(_Tp)>
883 : public false_type { };
885 template<typename _Tp>
886 struct is_const<_Tp const>
887 : public true_type { };
891#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile)
892 template<typename _Tp>
894 : public __bool_constant<__is_volatile(_Tp)>
899 : public false_type { };
901 template<typename _Tp>
902 struct is_volatile<_Tp volatile>
903 : public true_type { };
907 * @deprecated Deprecated in C++26.
908 * Use a combination of one or more more specialized type traits instead,
909 * such as `is_trivially_default_constructible`,
910 * `is_trivially_copy_constructible`, `is_trivially_copy_assignable`,
911 * etc., depending on the exact check(s) needed.
913 template<typename _Tp>
915 _GLIBCXX26_DEPRECATED_SUGGEST("is_trivially_default_constructible && is_trivially_copyable")
917 : public __bool_constant<__is_trivial(_Tp)>
919 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
920 "template argument must be a complete class or an unbounded array");
923 /// is_trivially_copyable
924 template<typename _Tp>
925 struct is_trivially_copyable
926 : public __bool_constant<__is_trivially_copyable(_Tp)>
928 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
929 "template argument must be a complete class or an unbounded array");
932 /// is_standard_layout
933 template<typename _Tp>
934 struct is_standard_layout
935 : public __bool_constant<__is_standard_layout(_Tp)>
937 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
938 "template argument must be a complete class or an unbounded array");
942 * @deprecated Deprecated in C++20.
943 * Use `is_standard_layout && is_trivial` instead.
945 // Could use is_standard_layout && is_trivial instead of the builtin.
946 template<typename _Tp>
948 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout && is_trivial")
950 : public __bool_constant<__is_pod(_Tp)>
952 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
953 "template argument must be a complete class or an unbounded array");
957 * @deprecated Deprecated in C++17, removed in C++20.
958 * The idea of a literal type isn't useful.
960 template<typename _Tp>
962 _GLIBCXX17_DEPRECATED
964 : public __bool_constant<__is_literal_type(_Tp)>
966 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
967 "template argument must be a complete class or an unbounded array");
971 template<typename _Tp>
973 : public __bool_constant<__is_empty(_Tp)>
977 template<typename _Tp>
978 struct is_polymorphic
979 : public __bool_constant<__is_polymorphic(_Tp)>
982#ifdef __cpp_lib_is_final // C++ >= 14
985 template<typename _Tp>
987 : public __bool_constant<__is_final(_Tp)>
992 template<typename _Tp>
994 : public __bool_constant<__is_abstract(_Tp)>
997 /// @cond undocumented
998 template<typename _Tp,
999 bool = is_arithmetic<_Tp>::value>
1000 struct __is_signed_helper
1001 : public false_type { };
1003 template<typename _Tp>
1004 struct __is_signed_helper<_Tp, true>
1005 : public __bool_constant<_Tp(-1) < _Tp(0)>
1010 template<typename _Tp>
1012 : public __is_signed_helper<_Tp>::type
1016 template<typename _Tp>
1018 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
1021 /// @cond undocumented
1022 template<typename _Tp, typename _Up = _Tp&&>
1026 template<typename _Tp>
1031 template<typename _Tp>
1032 auto declval() noexcept -> decltype(__declval<_Tp>(0));
1035 struct remove_all_extents;
1037 /// @cond undocumented
1038 template<typename _Tp>
1039 struct __is_array_known_bounds
1043 template<typename _Tp, size_t _Size>
1044 struct __is_array_known_bounds<_Tp[_Size]>
1048 template<typename _Tp>
1049 struct __is_array_unknown_bounds
1053 template<typename _Tp>
1054 struct __is_array_unknown_bounds<_Tp[]>
1059 // Destructible and constructible type properties.
1061#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_destructible)
1063 template<typename _Tp>
1064 struct is_destructible
1065 : public __bool_constant<__is_destructible(_Tp)>
1068 /// @cond undocumented
1070 // In N3290 is_destructible does not say anything about function
1071 // types and abstract types, see LWG 2049. This implementation
1072 // describes function types as non-destructible and all complete
1073 // object types as destructible, iff the explicit destructor
1074 // call expression is wellformed.
1075 struct __do_is_destructible_impl
1077 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
1078 static true_type __test(int);
1081 static false_type __test(...);
1084 template<typename _Tp>
1085 struct __is_destructible_impl
1086 : public __do_is_destructible_impl
1088 using type = decltype(__test<_Tp>(0));
1091 template<typename _Tp,
1092 bool = __or_<is_void<_Tp>,
1093 __is_array_unknown_bounds<_Tp>,
1094 is_function<_Tp>>::value,
1095 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1096 struct __is_destructible_safe;
1098 template<typename _Tp>
1099 struct __is_destructible_safe<_Tp, false, false>
1100 : public __is_destructible_impl<typename
1101 remove_all_extents<_Tp>::type>::type
1104 template<typename _Tp>
1105 struct __is_destructible_safe<_Tp, true, false>
1106 : public false_type { };
1108 template<typename _Tp>
1109 struct __is_destructible_safe<_Tp, false, true>
1110 : public true_type { };
1114 template<typename _Tp>
1115 struct is_destructible
1116 : public __is_destructible_safe<_Tp>::type
1118 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1119 "template argument must be a complete class or an unbounded array");
1123#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_destructible)
1124 /// is_nothrow_destructible
1125 template<typename _Tp>
1126 struct is_nothrow_destructible
1127 : public __bool_constant<__is_nothrow_destructible(_Tp)>
1130 /// @cond undocumented
1132 // is_nothrow_destructible requires that is_destructible is
1133 // satisfied as well. We realize that by mimicing the
1134 // implementation of is_destructible but refer to noexcept(expr)
1135 // instead of decltype(expr).
1136 struct __do_is_nt_destructible_impl
1138 template<typename _Tp>
1139 static __bool_constant<noexcept(declval<_Tp&>().~_Tp())>
1143 static false_type __test(...);
1146 template<typename _Tp>
1147 struct __is_nt_destructible_impl
1148 : public __do_is_nt_destructible_impl
1150 using type = decltype(__test<_Tp>(0));
1153 template<typename _Tp,
1154 bool = __or_<is_void<_Tp>,
1155 __is_array_unknown_bounds<_Tp>,
1156 is_function<_Tp>>::value,
1157 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1158 struct __is_nt_destructible_safe;
1160 template<typename _Tp>
1161 struct __is_nt_destructible_safe<_Tp, false, false>
1162 : public __is_nt_destructible_impl<typename
1163 remove_all_extents<_Tp>::type>::type
1166 template<typename _Tp>
1167 struct __is_nt_destructible_safe<_Tp, true, false>
1168 : public false_type { };
1170 template<typename _Tp>
1171 struct __is_nt_destructible_safe<_Tp, false, true>
1172 : public true_type { };
1175 /// is_nothrow_destructible
1176 template<typename _Tp>
1177 struct is_nothrow_destructible
1178 : public __is_nt_destructible_safe<_Tp>::type
1180 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1181 "template argument must be a complete class or an unbounded array");
1185 /// @cond undocumented
1186 template<typename _Tp, typename... _Args>
1187 using __is_constructible_impl
1188 = __bool_constant<__is_constructible(_Tp, _Args...)>;
1191 /// is_constructible
1192 template<typename _Tp, typename... _Args>
1193 struct is_constructible
1194 : public __is_constructible_impl<_Tp, _Args...>
1196 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1197 "template argument must be a complete class or an unbounded array");
1200 /// is_default_constructible
1201 template<typename _Tp>
1202 struct is_default_constructible
1203 : public __is_constructible_impl<_Tp>
1205 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1206 "template argument must be a complete class or an unbounded array");
1209 /// @cond undocumented
1210#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_lvalue_reference)
1211 template<typename _Tp>
1212 using __add_lval_ref_t = __add_lvalue_reference(_Tp);
1214 template<typename _Tp, typename = void>
1215 struct __add_lvalue_reference_helper
1216 { using type = _Tp; };
1218 template<typename _Tp>
1219 struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>>
1220 { using type = _Tp&; };
1222 template<typename _Tp>
1223 using __add_lval_ref_t = typename __add_lvalue_reference_helper<_Tp>::type;
1227 /// is_copy_constructible
1228 template<typename _Tp>
1229 struct is_copy_constructible
1230 : public __is_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1232 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1233 "template argument must be a complete class or an unbounded array");
1236 /// @cond undocumented
1237#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_rvalue_reference)
1238 template<typename _Tp>
1239 using __add_rval_ref_t = __add_rvalue_reference(_Tp);
1241 template<typename _Tp, typename = void>
1242 struct __add_rvalue_reference_helper
1243 { using type = _Tp; };
1245 template<typename _Tp>
1246 struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>>
1247 { using type = _Tp&&; };
1249 template<typename _Tp>
1250 using __add_rval_ref_t = typename __add_rvalue_reference_helper<_Tp>::type;
1254 /// is_move_constructible
1255 template<typename _Tp>
1256 struct is_move_constructible
1257 : public __is_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1259 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1260 "template argument must be a complete class or an unbounded array");
1263 /// @cond undocumented
1264 template<typename _Tp, typename... _Args>
1265 using __is_nothrow_constructible_impl
1266 = __bool_constant<__is_nothrow_constructible(_Tp, _Args...)>;
1269 /// is_nothrow_constructible
1270 template<typename _Tp, typename... _Args>
1271 struct is_nothrow_constructible
1272 : public __is_nothrow_constructible_impl<_Tp, _Args...>
1274 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1275 "template argument must be a complete class or an unbounded array");
1278 /// is_nothrow_default_constructible
1279 template<typename _Tp>
1280 struct is_nothrow_default_constructible
1281 : public __is_nothrow_constructible_impl<_Tp>
1283 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1284 "template argument must be a complete class or an unbounded array");
1287 /// is_nothrow_copy_constructible
1288 template<typename _Tp>
1289 struct is_nothrow_copy_constructible
1290 : public __is_nothrow_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1292 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1293 "template argument must be a complete class or an unbounded array");
1296 /// is_nothrow_move_constructible
1297 template<typename _Tp>
1298 struct is_nothrow_move_constructible
1299 : public __is_nothrow_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1301 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1302 "template argument must be a complete class or an unbounded array");
1305 /// @cond undocumented
1306 template<typename _Tp, typename _Up>
1307 using __is_assignable_impl = __bool_constant<__is_assignable(_Tp, _Up)>;
1311 template<typename _Tp, typename _Up>
1312 struct is_assignable
1313 : public __is_assignable_impl<_Tp, _Up>
1315 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1316 "template argument must be a complete class or an unbounded array");
1319 /// is_copy_assignable
1320 template<typename _Tp>
1321 struct is_copy_assignable
1322 : public __is_assignable_impl<__add_lval_ref_t<_Tp>,
1323 __add_lval_ref_t<const _Tp>>
1325 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1326 "template argument must be a complete class or an unbounded array");
1329 /// is_move_assignable
1330 template<typename _Tp>
1331 struct is_move_assignable
1332 : public __is_assignable_impl<__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>>
1334 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1335 "template argument must be a complete class or an unbounded array");
1338 /// @cond undocumented
1339 template<typename _Tp, typename _Up>
1340 using __is_nothrow_assignable_impl
1341 = __bool_constant<__is_nothrow_assignable(_Tp, _Up)>;
1344 /// is_nothrow_assignable
1345 template<typename _Tp, typename _Up>
1346 struct is_nothrow_assignable
1347 : public __is_nothrow_assignable_impl<_Tp, _Up>
1349 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1350 "template argument must be a complete class or an unbounded array");
1353 /// is_nothrow_copy_assignable
1354 template<typename _Tp>
1355 struct is_nothrow_copy_assignable
1356 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1357 __add_lval_ref_t<const _Tp>>
1359 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1360 "template argument must be a complete class or an unbounded array");
1363 /// is_nothrow_move_assignable
1364 template<typename _Tp>
1365 struct is_nothrow_move_assignable
1366 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1367 __add_rval_ref_t<_Tp>>
1369 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1370 "template argument must be a complete class or an unbounded array");
1373 /// @cond undocumented
1374 template<typename _Tp, typename... _Args>
1375 using __is_trivially_constructible_impl
1376 = __bool_constant<__is_trivially_constructible(_Tp, _Args...)>;
1379 /// is_trivially_constructible
1380 template<typename _Tp, typename... _Args>
1381 struct is_trivially_constructible
1382 : public __is_trivially_constructible_impl<_Tp, _Args...>
1384 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1385 "template argument must be a complete class or an unbounded array");
1388 /// is_trivially_default_constructible
1389 template<typename _Tp>
1390 struct is_trivially_default_constructible
1391 : public __is_trivially_constructible_impl<_Tp>
1393 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1394 "template argument must be a complete class or an unbounded array");
1397#if __cpp_variable_templates && __cpp_concepts
1398 template<typename _Tp>
1399 constexpr bool __is_implicitly_default_constructible_v
1400 = requires (void(&__f)(_Tp)) { __f({}); };
1402 template<typename _Tp>
1403 struct __is_implicitly_default_constructible
1404 : __bool_constant<__is_implicitly_default_constructible_v<_Tp>>
1407 struct __do_is_implicitly_default_constructible_impl
1409 template <typename _Tp>
1410 static void __helper(const _Tp&);
1412 template <typename _Tp>
1413 static true_type __test(const _Tp&,
1414 decltype(__helper<const _Tp&>({}))* = 0);
1416 static false_type __test(...);
1419 template<typename _Tp>
1420 struct __is_implicitly_default_constructible_impl
1421 : public __do_is_implicitly_default_constructible_impl
1423 using type = decltype(__test(declval<_Tp>()));
1426 template<typename _Tp>
1427 struct __is_implicitly_default_constructible_safe
1428 : public __is_implicitly_default_constructible_impl<_Tp>::type
1431 template <typename _Tp>
1432 struct __is_implicitly_default_constructible
1433 : public __and_<__is_constructible_impl<_Tp>,
1434 __is_implicitly_default_constructible_safe<_Tp>>::type
1438 /// is_trivially_copy_constructible
1439 template<typename _Tp>
1440 struct is_trivially_copy_constructible
1441 : public __is_trivially_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1443 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1444 "template argument must be a complete class or an unbounded array");
1447 /// is_trivially_move_constructible
1448 template<typename _Tp>
1449 struct is_trivially_move_constructible
1450 : public __is_trivially_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1452 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1453 "template argument must be a complete class or an unbounded array");
1456 /// @cond undocumented
1457 template<typename _Tp, typename _Up>
1458 using __is_trivially_assignable_impl
1459 = __bool_constant<__is_trivially_assignable(_Tp, _Up)>;
1462 /// is_trivially_assignable
1463 template<typename _Tp, typename _Up>
1464 struct is_trivially_assignable
1465 : public __is_trivially_assignable_impl<_Tp, _Up>
1467 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1468 "template argument must be a complete class or an unbounded array");
1471 /// is_trivially_copy_assignable
1472 template<typename _Tp>
1473 struct is_trivially_copy_assignable
1474 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1475 __add_lval_ref_t<const _Tp>>
1477 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1478 "template argument must be a complete class or an unbounded array");
1481 /// is_trivially_move_assignable
1482 template<typename _Tp>
1483 struct is_trivially_move_assignable
1484 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1485 __add_rval_ref_t<_Tp>>
1487 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1488 "template argument must be a complete class or an unbounded array");
1491#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_trivially_destructible)
1492 /// is_trivially_destructible
1493 template<typename _Tp>
1494 struct is_trivially_destructible
1495 : public __bool_constant<__is_trivially_destructible(_Tp)>
1498 /// is_trivially_destructible
1499 template<typename _Tp>
1500 struct is_trivially_destructible
1501 : public __and_<__is_destructible_safe<_Tp>,
1502 __bool_constant<__has_trivial_destructor(_Tp)>>::type
1504 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1505 "template argument must be a complete class or an unbounded array");
1509 /// has_virtual_destructor
1510 template<typename _Tp>
1511 struct has_virtual_destructor
1512 : public __bool_constant<__has_virtual_destructor(_Tp)>
1514 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1515 "template argument must be a complete class or an unbounded array");
1519 // type property queries.
1522 template<typename _Tp>
1524 : public integral_constant<std::size_t, alignof(_Tp)>
1526 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1527 "template argument must be a complete class or an unbounded array");
1531#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) \
1532 && (!defined(__clang__) || __clang_major__ >= 20) // PR118559
1533 template<typename _Tp>
1535 : public integral_constant<std::size_t, __array_rank(_Tp)> { };
1539 : public integral_constant<std::size_t, 0> { };
1541 template<typename _Tp, std::size_t _Size>
1542 struct rank<_Tp[_Size]>
1543 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1545 template<typename _Tp>
1547 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1551 template<typename, unsigned _Uint = 0>
1553 : public integral_constant<size_t, 0> { };
1555 template<typename _Tp, size_t _Size>
1556 struct extent<_Tp[_Size], 0>
1557 : public integral_constant<size_t, _Size> { };
1559 template<typename _Tp, unsigned _Uint, size_t _Size>
1560 struct extent<_Tp[_Size], _Uint>
1561 : public extent<_Tp, _Uint - 1>::type { };
1563 template<typename _Tp>
1564 struct extent<_Tp[], 0>
1565 : public integral_constant<size_t, 0> { };
1567 template<typename _Tp, unsigned _Uint>
1568 struct extent<_Tp[], _Uint>
1569 : public extent<_Tp, _Uint - 1>::type { };
1575#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
1576 template<typename _Tp, typename _Up>
1578 : public __bool_constant<__is_same(_Tp, _Up)>
1581 template<typename _Tp, typename _Up>
1586 template<typename _Tp>
1587 struct is_same<_Tp, _Tp>
1593 template<typename _Base, typename _Derived>
1595 : public __bool_constant<__is_base_of(_Base, _Derived)>
1598#ifdef __cpp_lib_is_virtual_base_of // C++ >= 26
1599 /// is_virtual_base_of
1601 template<typename _Base, typename _Derived>
1602 struct is_virtual_base_of
1603 : public bool_constant<__builtin_is_virtual_base_of(_Base, _Derived)>
1607#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
1608 template<typename _From, typename _To>
1609 struct is_convertible
1610 : public __bool_constant<__is_convertible(_From, _To)>
1613 template<typename _From, typename _To,
1614 bool = __or_<is_void<_From>, is_function<_To>,
1615 is_array<_To>>::value>
1616 struct __is_convertible_helper
1618 using type = typename is_void<_To>::type;
1621#pragma GCC diagnostic push
1622#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1623 template<typename _From, typename _To>
1624 class __is_convertible_helper<_From, _To, false>
1626 template<typename _To1>
1627 static void __test_aux(_To1) noexcept;
1629 template<typename _From1, typename _To1,
1630 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1634 template<typename, typename>
1639 using type = decltype(__test<_From, _To>(0));
1641#pragma GCC diagnostic pop
1644 template<typename _From, typename _To>
1645 struct is_convertible
1646 : public __is_convertible_helper<_From, _To>::type
1650 // helper trait for unique_ptr<T[]>, shared_ptr<T[]>, and span<T, N>
1651 template<typename _ToElementType, typename _FromElementType>
1652 using __is_array_convertible
1653 = is_convertible<_FromElementType(*)[], _ToElementType(*)[]>;
1655#ifdef __cpp_lib_is_nothrow_convertible // C++ >= 20
1657#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_convertible)
1658 /// is_nothrow_convertible_v
1659 template<typename _From, typename _To>
1660 inline constexpr bool is_nothrow_convertible_v
1661 = __is_nothrow_convertible(_From, _To);
1663 /// is_nothrow_convertible
1664 template<typename _From, typename _To>
1665 struct is_nothrow_convertible
1666 : public bool_constant<is_nothrow_convertible_v<_From, _To>>
1669 template<typename _From, typename _To,
1670 bool = __or_<is_void<_From>, is_function<_To>,
1671 is_array<_To>>::value>
1672 struct __is_nt_convertible_helper
1676#pragma GCC diagnostic push
1677#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1678 template<typename _From, typename _To>
1679 class __is_nt_convertible_helper<_From, _To, false>
1681 template<typename _To1>
1682 static void __test_aux(_To1) noexcept;
1684 template<typename _From1, typename _To1>
1686 __bool_constant<noexcept(__test_aux<_To1>(std::declval<_From1>()))>
1689 template<typename, typename>
1694 using type = decltype(__test<_From, _To>(0));
1696#pragma GCC diagnostic pop
1698 /// is_nothrow_convertible
1699 template<typename _From, typename _To>
1700 struct is_nothrow_convertible
1701 : public __is_nt_convertible_helper<_From, _To>::type
1704 /// is_nothrow_convertible_v
1705 template<typename _From, typename _To>
1706 inline constexpr bool is_nothrow_convertible_v
1707 = is_nothrow_convertible<_From, _To>::value;
1709#endif // __cpp_lib_is_nothrow_convertible
1711#pragma GCC diagnostic push
1712#pragma GCC diagnostic ignored "-Wc++14-extensions" // for variable templates
1713 template<typename _Tp, typename... _Args>
1714 struct __is_nothrow_new_constructible_impl
1716 noexcept(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))
1720 template<typename _Tp, typename... _Args>
1721 _GLIBCXX17_INLINE constexpr bool __is_nothrow_new_constructible
1722 = __and_<is_constructible<_Tp, _Args...>,
1723 __is_nothrow_new_constructible_impl<_Tp, _Args...>>::value;
1724#pragma GCC diagnostic pop
1726 // Const-volatile modifications.
1729 template<typename _Tp>
1731 { using type = _Tp; };
1733 template<typename _Tp>
1734 struct remove_const<_Tp const>
1735 { using type = _Tp; };
1738 template<typename _Tp>
1739 struct remove_volatile
1740 { using type = _Tp; };
1742 template<typename _Tp>
1743 struct remove_volatile<_Tp volatile>
1744 { using type = _Tp; };
1747#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cv)
1748 template<typename _Tp>
1750 { using type = __remove_cv(_Tp); };
1752 template<typename _Tp>
1754 { using type = _Tp; };
1756 template<typename _Tp>
1757 struct remove_cv<const _Tp>
1758 { using type = _Tp; };
1760 template<typename _Tp>
1761 struct remove_cv<volatile _Tp>
1762 { using type = _Tp; };
1764 template<typename _Tp>
1765 struct remove_cv<const volatile _Tp>
1766 { using type = _Tp; };
1770 template<typename _Tp>
1772 { using type = _Tp const; };
1775 template<typename _Tp>
1777 { using type = _Tp volatile; };
1780 template<typename _Tp>
1782 { using type = _Tp const volatile; };
1784#ifdef __cpp_lib_transformation_trait_aliases // C++ >= 14
1785 /// Alias template for remove_const
1786 template<typename _Tp>
1787 using remove_const_t = typename remove_const<_Tp>::type;
1789 /// Alias template for remove_volatile
1790 template<typename _Tp>
1791 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1793 /// Alias template for remove_cv
1794 template<typename _Tp>
1795 using remove_cv_t = typename remove_cv<_Tp>::type;
1797 /// Alias template for add_const
1798 template<typename _Tp>
1799 using add_const_t = typename add_const<_Tp>::type;
1801 /// Alias template for add_volatile
1802 template<typename _Tp>
1803 using add_volatile_t = typename add_volatile<_Tp>::type;
1805 /// Alias template for add_cv
1806 template<typename _Tp>
1807 using add_cv_t = typename add_cv<_Tp>::type;
1810 // Reference transformations.
1812 /// remove_reference
1813#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_reference)
1814 template<typename _Tp>
1815 struct remove_reference
1816 { using type = __remove_reference(_Tp); };
1818 template<typename _Tp>
1819 struct remove_reference
1820 { using type = _Tp; };
1822 template<typename _Tp>
1823 struct remove_reference<_Tp&>
1824 { using type = _Tp; };
1826 template<typename _Tp>
1827 struct remove_reference<_Tp&&>
1828 { using type = _Tp; };
1831 /// add_lvalue_reference
1832 template<typename _Tp>
1833 struct add_lvalue_reference
1834 { using type = __add_lval_ref_t<_Tp>; };
1836 /// add_rvalue_reference
1837 template<typename _Tp>
1838 struct add_rvalue_reference
1839 { using type = __add_rval_ref_t<_Tp>; };
1841#if __cplusplus > 201103L
1842 /// Alias template for remove_reference
1843 template<typename _Tp>
1844 using remove_reference_t = typename remove_reference<_Tp>::type;
1846 /// Alias template for add_lvalue_reference
1847 template<typename _Tp>
1848 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1850 /// Alias template for add_rvalue_reference
1851 template<typename _Tp>
1852 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1855 // Sign modifications.
1857 /// @cond undocumented
1859 // Utility for constructing identically cv-qualified types.
1860 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1861 struct __cv_selector;
1863 template<typename _Unqualified>
1864 struct __cv_selector<_Unqualified, false, false>
1865 { using __type = _Unqualified; };
1867 template<typename _Unqualified>
1868 struct __cv_selector<_Unqualified, false, true>
1869 { using __type = volatile _Unqualified; };
1871 template<typename _Unqualified>
1872 struct __cv_selector<_Unqualified, true, false>
1873 { using __type = const _Unqualified; };
1875 template<typename _Unqualified>
1876 struct __cv_selector<_Unqualified, true, true>
1877 { using __type = const volatile _Unqualified; };
1879 template<typename _Qualified, typename _Unqualified,
1880 bool _IsConst = is_const<_Qualified>::value,
1881 bool _IsVol = is_volatile<_Qualified>::value>
1882 class __match_cv_qualifiers
1884 using __match = __cv_selector<_Unqualified, _IsConst, _IsVol>;
1887 using __type = typename __match::__type;
1890 // Utility for finding the unsigned versions of signed integral types.
1891 template<typename _Tp>
1892 struct __make_unsigned
1893 { using __type = _Tp; };
1896 struct __make_unsigned<char>
1897 { using __type = unsigned char; };
1900 struct __make_unsigned<signed char>
1901 { using __type = unsigned char; };
1904 struct __make_unsigned<short>
1905 { using __type = unsigned short; };
1908 struct __make_unsigned<int>
1909 { using __type = unsigned int; };
1912 struct __make_unsigned<long>
1913 { using __type = unsigned long; };
1916 struct __make_unsigned<long long>
1917 { using __type = unsigned long long; };
1919#if defined(__GLIBCXX_TYPE_INT_N_0)
1922 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1923 { using __type = unsigned __GLIBCXX_TYPE_INT_N_0; };
1925#if defined(__GLIBCXX_TYPE_INT_N_1)
1928 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1929 { using __type = unsigned __GLIBCXX_TYPE_INT_N_1; };
1931#if defined(__GLIBCXX_TYPE_INT_N_2)
1934 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1935 { using __type = unsigned __GLIBCXX_TYPE_INT_N_2; };
1937#if defined(__GLIBCXX_TYPE_INT_N_3)
1940 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1941 { using __type = unsigned __GLIBCXX_TYPE_INT_N_3; };
1943#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
1946 struct __make_unsigned<__int128>
1947 { using __type = unsigned __int128; };
1950 // Select between integral and enum: not possible to be both.
1951 template<typename _Tp,
1952 bool _IsInt = is_integral<_Tp>::value,
1953 bool _IsEnum = __is_enum(_Tp)>
1954 class __make_unsigned_selector;
1956 template<typename _Tp>
1957 class __make_unsigned_selector<_Tp, true, false>
1959 using __unsigned_type
1960 = typename __make_unsigned<__remove_cv_t<_Tp>>::__type;
1964 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1967 class __make_unsigned_selector_base
1970 template<typename...> struct _List { };
1972 template<typename _Tp, typename... _Up>
1973 struct _List<_Tp, _Up...> : _List<_Up...>
1974 { static constexpr size_t __size = sizeof(_Tp); };
1976 template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
1979 template<size_t _Sz, typename _Uint, typename... _UInts>
1980 struct __select<_Sz, _List<_Uint, _UInts...>, true>
1981 { using __type = _Uint; };
1983 template<size_t _Sz, typename _Uint, typename... _UInts>
1984 struct __select<_Sz, _List<_Uint, _UInts...>, false>
1985 : __select<_Sz, _List<_UInts...>>
1989 // Choose unsigned integer type with the smallest rank and same size as _Tp
1990 template<typename _Tp>
1991 class __make_unsigned_selector<_Tp, false, true>
1992 : __make_unsigned_selector_base
1994 // With -fshort-enums, an enum may be as small as a char.
1996 using _UInts = _List<unsigned char, unsigned short, unsigned int,
1997 unsigned long, unsigned long long
1998#ifdef __SIZEOF_INT128__
2003 using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
2007 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
2010 // wchar_t, char8_t, char16_t and char32_t are integral types but are
2011 // neither signed integer types nor unsigned integer types, so must be
2012 // transformed to the unsigned integer type with the smallest rank.
2013 // Use the partial specialization for enumeration types to do that.
2015 struct __make_unsigned<wchar_t>
2018 = typename __make_unsigned_selector<wchar_t, false, true>::__type;
2021#ifdef _GLIBCXX_USE_CHAR8_T
2023 struct __make_unsigned<char8_t>
2026 = typename __make_unsigned_selector<char8_t, false, true>::__type;
2031 struct __make_unsigned<char16_t>
2034 = typename __make_unsigned_selector<char16_t, false, true>::__type;
2038 struct __make_unsigned<char32_t>
2041 = typename __make_unsigned_selector<char32_t, false, true>::__type;
2045 // Given an integral/enum type, return the corresponding unsigned
2047 // Primary template.
2049 template<typename _Tp>
2050 struct make_unsigned
2051 { using type = typename __make_unsigned_selector<_Tp>::__type; };
2053 // Integral, but don't define.
2054 template<> struct make_unsigned<bool>;
2055 template<> struct make_unsigned<bool const>;
2056 template<> struct make_unsigned<bool volatile>;
2057 template<> struct make_unsigned<bool const volatile>;
2059 /// @cond undocumented
2061 // Utility for finding the signed versions of unsigned integral types.
2062 template<typename _Tp>
2063 struct __make_signed
2064 { using __type = _Tp; };
2067 struct __make_signed<char>
2068 { using __type = signed char; };
2071 struct __make_signed<unsigned char>
2072 { using __type = signed char; };
2075 struct __make_signed<unsigned short>
2076 { using __type = signed short; };
2079 struct __make_signed<unsigned int>
2080 { using __type = signed int; };
2083 struct __make_signed<unsigned long>
2084 { using __type = signed long; };
2087 struct __make_signed<unsigned long long>
2088 { using __type = signed long long; };
2090#if defined(__GLIBCXX_TYPE_INT_N_0)
2093 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
2094 { using __type = __GLIBCXX_TYPE_INT_N_0; };
2096#if defined(__GLIBCXX_TYPE_INT_N_1)
2099 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
2100 { using __type = __GLIBCXX_TYPE_INT_N_1; };
2102#if defined(__GLIBCXX_TYPE_INT_N_2)
2105 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
2106 { using __type = __GLIBCXX_TYPE_INT_N_2; };
2108#if defined(__GLIBCXX_TYPE_INT_N_3)
2111 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
2112 { using __type = __GLIBCXX_TYPE_INT_N_3; };
2114#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
2117 struct __make_signed<unsigned __int128>
2118 { using __type = __int128; };
2121 // Select between integral and enum: not possible to be both.
2122 template<typename _Tp,
2123 bool _IsInt = is_integral<_Tp>::value,
2124 bool _IsEnum = __is_enum(_Tp)>
2125 class __make_signed_selector;
2127 template<typename _Tp>
2128 class __make_signed_selector<_Tp, true, false>
2131 = typename __make_signed<__remove_cv_t<_Tp>>::__type;
2135 = typename __match_cv_qualifiers<_Tp, __signed_type>::__type;
2138 // Choose signed integer type with the smallest rank and same size as _Tp
2139 template<typename _Tp>
2140 class __make_signed_selector<_Tp, false, true>
2142 using __unsigned_type = typename __make_unsigned_selector<_Tp>::__type;
2145 using __type = typename __make_signed_selector<__unsigned_type>::__type;
2148 // wchar_t, char16_t and char32_t are integral types but are neither
2149 // signed integer types nor unsigned integer types, so must be
2150 // transformed to the signed integer type with the smallest rank.
2151 // Use the partial specialization for enumeration types to do that.
2153 struct __make_signed<wchar_t>
2156 = typename __make_signed_selector<wchar_t, false, true>::__type;
2159#if defined(_GLIBCXX_USE_CHAR8_T)
2161 struct __make_signed<char8_t>
2164 = typename __make_signed_selector<char8_t, false, true>::__type;
2169 struct __make_signed<char16_t>
2172 = typename __make_signed_selector<char16_t, false, true>::__type;
2176 struct __make_signed<char32_t>
2179 = typename __make_signed_selector<char32_t, false, true>::__type;
2183 // Given an integral/enum type, return the corresponding signed
2185 // Primary template.
2187 template<typename _Tp>
2189 { using type = typename __make_signed_selector<_Tp>::__type; };
2191 // Integral, but don't define.
2192 template<> struct make_signed<bool>;
2193 template<> struct make_signed<bool const>;
2194 template<> struct make_signed<bool volatile>;
2195 template<> struct make_signed<bool const volatile>;
2197#if __cplusplus > 201103L
2198 /// Alias template for make_signed
2199 template<typename _Tp>
2200 using make_signed_t = typename make_signed<_Tp>::type;
2202 /// Alias template for make_unsigned
2203 template<typename _Tp>
2204 using make_unsigned_t = typename make_unsigned<_Tp>::type;
2207 // Array modifications.
2210#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_extent)
2211 template<typename _Tp>
2212 struct remove_extent
2213 { using type = __remove_extent(_Tp); };
2215 template<typename _Tp>
2216 struct remove_extent
2217 { using type = _Tp; };
2219 template<typename _Tp, std::size_t _Size>
2220 struct remove_extent<_Tp[_Size]>
2221 { using type = _Tp; };
2223 template<typename _Tp>
2224 struct remove_extent<_Tp[]>
2225 { using type = _Tp; };
2228 /// remove_all_extents
2229#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_all_extents)
2230 template<typename _Tp>
2231 struct remove_all_extents
2232 { using type = __remove_all_extents(_Tp); };
2234 template<typename _Tp>
2235 struct remove_all_extents
2236 { using type = _Tp; };
2238 template<typename _Tp, std::size_t _Size>
2239 struct remove_all_extents<_Tp[_Size]>
2240 { using type = typename remove_all_extents<_Tp>::type; };
2242 template<typename _Tp>
2243 struct remove_all_extents<_Tp[]>
2244 { using type = typename remove_all_extents<_Tp>::type; };
2247#if __cplusplus > 201103L
2248 /// Alias template for remove_extent
2249 template<typename _Tp>
2250 using remove_extent_t = typename remove_extent<_Tp>::type;
2252 /// Alias template for remove_all_extents
2253 template<typename _Tp>
2254 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
2257 // Pointer modifications.
2260#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer)
2261 template<typename _Tp>
2262 struct remove_pointer
2263 { using type = __remove_pointer(_Tp); };
2265 template<typename _Tp, typename>
2266 struct __remove_pointer_helper
2267 { using type = _Tp; };
2269 template<typename _Tp, typename _Up>
2270 struct __remove_pointer_helper<_Tp, _Up*>
2271 { using type = _Up; };
2273 template<typename _Tp>
2274 struct remove_pointer
2275 : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>>
2280#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer)
2281 template<typename _Tp>
2283 { using type = __add_pointer(_Tp); };
2285 template<typename _Tp, typename = void>
2286 struct __add_pointer_helper
2287 { using type = _Tp; };
2289 template<typename _Tp>
2290 struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
2291 { using type = _Tp*; };
2293 template<typename _Tp>
2295 : public __add_pointer_helper<_Tp>
2298 template<typename _Tp>
2299 struct add_pointer<_Tp&>
2300 { using type = _Tp*; };
2302 template<typename _Tp>
2303 struct add_pointer<_Tp&&>
2304 { using type = _Tp*; };
2307#if __cplusplus > 201103L
2308 /// Alias template for remove_pointer
2309 template<typename _Tp>
2310 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2312 /// Alias template for add_pointer
2313 template<typename _Tp>
2314 using add_pointer_t = typename add_pointer<_Tp>::type;
2317 /// @cond undocumented
2319 // Aligned to maximum fundamental alignment
2320 struct __attribute__((__aligned__)) __aligned_storage_max_align_t
2324 __aligned_storage_default_alignment([[__maybe_unused__]] size_t __len)
2326#if _GLIBCXX_INLINE_VERSION
2328 = integral_constant<size_t, alignof(__aligned_storage_max_align_t)>;
2330 return __len > (_Max_align::value / 2)
2332# if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_clzg)
2333 : 1 << (__SIZE_WIDTH__ - __builtin_clzg(__len - 1u));
2335 : 1 << (__LLONG_WIDTH__ - __builtin_clzll(__len - 1ull));
2338 // Returning a fixed value is incorrect, but kept for ABI compatibility.
2339 // XXX GLIBCXX_ABI Deprecated
2340 return alignof(__aligned_storage_max_align_t);
2346 * @brief Aligned storage
2348 * The member typedef `type` is be a POD type suitable for use as
2349 * uninitialized storage for any object whose size is at most `_Len`
2350 * and whose alignment is a divisor of `_Align`.
2352 * It is important to use the nested `type` as uninitialized storage,
2353 * not the `std::aligned_storage` type itself which is an empty class
2354 * with 1-byte alignment. So this is correct:
2356 * `typename std::aligned_storage<sizeof(X), alignof(X)>::type m_xobj;`
2360 * `std::aligned_storage<sizeof(X), alignof(X)> m_xobj;`
2362 * In C++14 and later `std::aligned_storage_t<sizeof(X), alignof(X)>`
2363 * can be used to refer to the `type` member typedef.
2365 * The default value of _Align is supposed to be the most stringent
2366 * fundamental alignment requirement for any C++ object type whose size
2367 * is no greater than `_Len` (see [basic.align] in the C++ standard).
2369 * @bug In this implementation the default value for _Align is always the
2370 * maximum fundamental alignment, i.e. `alignof(max_align_t)`, which is
2371 * incorrect. It should be an alignment value no greater than `_Len`.
2373 * @deprecated Deprecated in C++23. Uses can be replaced by an
2374 * array `std::byte[_Len]` declared with `alignas(_Align)`.
2376 template<size_t _Len,
2377 size_t _Align = __aligned_storage_default_alignment(_Len)>
2379 _GLIBCXX23_DEPRECATED
2384 alignas(_Align) unsigned char __data[_Len];
2388 template <typename... _Types>
2389 struct __strictest_alignment
2391 static const size_t _S_alignment = 0;
2392 static const size_t _S_size = 0;
2395 template <typename _Tp, typename... _Types>
2396 struct __strictest_alignment<_Tp, _Types...>
2398 static const size_t _S_alignment =
2399 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2400 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2401 static const size_t _S_size =
2402 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2403 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2406#pragma GCC diagnostic push
2407#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2410 * @brief Provide aligned storage for types.
2412 * [meta.trans.other]
2414 * Provides aligned storage for any of the provided types of at
2417 * @see aligned_storage
2419 * @deprecated Deprecated in C++23.
2421 template <size_t _Len, typename... _Types>
2423 _GLIBCXX23_DEPRECATED
2427 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2429 using __strictest = __strictest_alignment<_Types...>;
2430 static const size_t _S_len = _Len > __strictest::_S_size
2431 ? _Len : __strictest::_S_size;
2433 /// The value of the strictest alignment of _Types.
2434 static const size_t alignment_value = __strictest::_S_alignment;
2436 using type = typename aligned_storage<_S_len, alignment_value>::type;
2439 template <size_t _Len, typename... _Types>
2440 const size_t aligned_union<_Len, _Types...>::alignment_value;
2441#pragma GCC diagnostic pop
2443 /// @cond undocumented
2445#if _GLIBCXX_USE_BUILTIN_TRAIT(__decay)
2446 template<typename _Tp>
2448 { using type = __decay(_Tp); };
2450 // Decay trait for arrays and functions, used for perfect forwarding
2451 // in make_pair, make_tuple, etc.
2452 template<typename _Up>
2453 struct __decay_selector
2454 : __conditional_t<is_const<const _Up>::value, // false for functions
2455 remove_cv<_Up>, // N.B. DR 705.
2456 add_pointer<_Up>> // function decays to pointer
2459 template<typename _Up, size_t _Nm>
2460 struct __decay_selector<_Up[_Nm]>
2461 { using type = _Up*; };
2463 template<typename _Up>
2464 struct __decay_selector<_Up[]>
2465 { using type = _Up*; };
2470 template<typename _Tp>
2472 { using type = typename __decay_selector<_Tp>::type; };
2474 template<typename _Tp>
2476 { using type = typename __decay_selector<_Tp>::type; };
2478 template<typename _Tp>
2480 { using type = typename __decay_selector<_Tp>::type; };
2483 /// @cond undocumented
2485 // Helper which adds a reference to a type when given a reference_wrapper
2486 template<typename _Tp>
2487 struct __strip_reference_wrapper
2492 template<typename _Tp>
2493 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2495 using __type = _Tp&;
2498 // __decay_t (std::decay_t for C++11).
2499 template<typename _Tp>
2500 using __decay_t = typename decay<_Tp>::type;
2502 template<typename _Tp>
2503 using __decay_and_strip = __strip_reference_wrapper<__decay_t<_Tp>>;
2506 /// @cond undocumented
2508 // Helper for SFINAE constraints
2509 template<typename... _Cond>
2510 using _Require = __enable_if_t<__and_<_Cond...>::value>;
2512 // __remove_cvref_t (std::remove_cvref_t for C++11).
2513 template<typename _Tp>
2514 using __remove_cvref_t
2515 = typename remove_cv<typename remove_reference<_Tp>::type>::type;
2518 // Primary template.
2519 /// Define a member typedef @c type to one of two argument types.
2520 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2522 { using type = _Iftrue; };
2524 // Partial specialization for false.
2525 template<typename _Iftrue, typename _Iffalse>
2526 struct conditional<false, _Iftrue, _Iffalse>
2527 { using type = _Iffalse; };
2530 template<typename... _Tp>
2533 // Sfinae-friendly common_type implementation:
2535 /// @cond undocumented
2537 // For several sfinae-friendly trait implementations we transport both the
2538 // result information (as the member type) and the failure information (no
2539 // member type). This is very similar to std::enable_if, but we cannot use
2540 // that, because we need to derive from them as an implementation detail.
2542 template<typename _Tp>
2543 struct __success_type
2544 { using type = _Tp; };
2546 struct __failure_type
2549 struct __do_common_type_impl
2551 template<typename _Tp, typename _Up>
2553 = decltype(true ? std::declval<_Tp>() : std::declval<_Up>());
2555 // if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2556 // denotes a valid type, let C denote that type.
2557 template<typename _Tp, typename _Up>
2558 static __success_type<__decay_t<__cond_t<_Tp, _Up>>>
2561#if __cplusplus > 201703L
2562 // Otherwise, if COND-RES(CREF(D1), CREF(D2)) denotes a type,
2563 // let C denote the type decay_t<COND-RES(CREF(D1), CREF(D2))>.
2564 template<typename _Tp, typename _Up>
2565 static __success_type<__remove_cvref_t<__cond_t<const _Tp&, const _Up&>>>
2569 template<typename, typename>
2570 static __failure_type
2573 template<typename _Tp, typename _Up>
2574 static decltype(_S_test_2<_Tp, _Up>(0))
2578 // If sizeof...(T) is zero, there shall be no member type.
2580 struct common_type<>
2583 // If sizeof...(T) is one, the same type, if any, as common_type_t<T0, T0>.
2584 template<typename _Tp0>
2585 struct common_type<_Tp0>
2586 : public common_type<_Tp0, _Tp0>
2589 // If sizeof...(T) is two, ...
2590 template<typename _Tp1, typename _Tp2,
2591 typename _Dp1 = __decay_t<_Tp1>, typename _Dp2 = __decay_t<_Tp2>>
2592 struct __common_type_impl
2594 // If is_same_v<T1, D1> is false or is_same_v<T2, D2> is false,
2595 // let C denote the same type, if any, as common_type_t<D1, D2>.
2596 using type = common_type<_Dp1, _Dp2>;
2599 template<typename _Tp1, typename _Tp2>
2600 struct __common_type_impl<_Tp1, _Tp2, _Tp1, _Tp2>
2601 : private __do_common_type_impl
2603 // Otherwise, if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2604 // denotes a valid type, let C denote that type.
2605 using type = decltype(_S_test<_Tp1, _Tp2>(0));
2608 // If sizeof...(T) is two, ...
2609 template<typename _Tp1, typename _Tp2>
2610 struct common_type<_Tp1, _Tp2>
2611 : public __common_type_impl<_Tp1, _Tp2>::type
2614 template<typename...>
2615 struct __common_type_pack
2618 template<typename, typename, typename = void>
2619 struct __common_type_fold;
2621 // If sizeof...(T) is greater than two, ...
2622 template<typename _Tp1, typename _Tp2, typename... _Rp>
2623 struct common_type<_Tp1, _Tp2, _Rp...>
2624 : public __common_type_fold<common_type<_Tp1, _Tp2>,
2625 __common_type_pack<_Rp...>>
2628 // Let C denote the same type, if any, as common_type_t<T1, T2>.
2629 // If there is such a type C, type shall denote the same type, if any,
2630 // as common_type_t<C, R...>.
2631 template<typename _CTp, typename... _Rp>
2632 struct __common_type_fold<_CTp, __common_type_pack<_Rp...>,
2633 __void_t<typename _CTp::type>>
2634 : public common_type<typename _CTp::type, _Rp...>
2637 // Otherwise, there shall be no member type.
2638 template<typename _CTp, typename _Rp>
2639 struct __common_type_fold<_CTp, _Rp, void>
2642 template<typename _Tp, bool = __is_enum(_Tp)>
2643 struct __underlying_type_impl
2645 using type = __underlying_type(_Tp);
2648 template<typename _Tp>
2649 struct __underlying_type_impl<_Tp, false>
2653 /// The underlying type of an enum.
2654 template<typename _Tp>
2655 struct underlying_type
2656 : public __underlying_type_impl<_Tp>
2659 /// @cond undocumented
2660 template<typename _Tp>
2661 struct __declval_protector
2663 static const bool __stop = false;
2667 /** Utility to simplify expressions used in unevaluated operands
2669 * @ingroup utilities
2671 template<typename _Tp>
2672 auto declval() noexcept -> decltype(__declval<_Tp>(0))
2674 static_assert(__declval_protector<_Tp>::__stop,
2675 "declval() must not be used!");
2676 return __declval<_Tp>(0);
2680 template<typename _Signature>
2683 // Sfinae-friendly result_of implementation:
2685 /// @cond undocumented
2686 struct __invoke_memfun_ref { };
2687 struct __invoke_memfun_deref { };
2688 struct __invoke_memobj_ref { };
2689 struct __invoke_memobj_deref { };
2690 struct __invoke_other { };
2692 // Associate a tag type with a specialization of __success_type.
2693 template<typename _Tp, typename _Tag>
2694 struct __result_of_success : __success_type<_Tp>
2695 { using __invoke_type = _Tag; };
2697 // [func.require] paragraph 1 bullet 1:
2698 struct __result_of_memfun_ref_impl
2700 template<typename _Fp, typename _Tp1, typename... _Args>
2701 static __result_of_success<decltype(
2702 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2703 ), __invoke_memfun_ref> _S_test(int);
2705 template<typename...>
2706 static __failure_type _S_test(...);
2709 template<typename _MemPtr, typename _Arg, typename... _Args>
2710 struct __result_of_memfun_ref
2711 : private __result_of_memfun_ref_impl
2713 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2716 // [func.require] paragraph 1 bullet 2:
2717 struct __result_of_memfun_deref_impl
2719 template<typename _Fp, typename _Tp1, typename... _Args>
2720 static __result_of_success<decltype(
2721 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2722 ), __invoke_memfun_deref> _S_test(int);
2724 template<typename...>
2725 static __failure_type _S_test(...);
2728 template<typename _MemPtr, typename _Arg, typename... _Args>
2729 struct __result_of_memfun_deref
2730 : private __result_of_memfun_deref_impl
2732 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2735 // [func.require] paragraph 1 bullet 3:
2736 struct __result_of_memobj_ref_impl
2738 template<typename _Fp, typename _Tp1>
2739 static __result_of_success<decltype(
2740 std::declval<_Tp1>().*std::declval<_Fp>()
2741 ), __invoke_memobj_ref> _S_test(int);
2743 template<typename, typename>
2744 static __failure_type _S_test(...);
2747 template<typename _MemPtr, typename _Arg>
2748 struct __result_of_memobj_ref
2749 : private __result_of_memobj_ref_impl
2751 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2754 // [func.require] paragraph 1 bullet 4:
2755 struct __result_of_memobj_deref_impl
2757 template<typename _Fp, typename _Tp1>
2758 static __result_of_success<decltype(
2759 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2760 ), __invoke_memobj_deref> _S_test(int);
2762 template<typename, typename>
2763 static __failure_type _S_test(...);
2766 template<typename _MemPtr, typename _Arg>
2767 struct __result_of_memobj_deref
2768 : private __result_of_memobj_deref_impl
2770 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2773 template<typename _MemPtr, typename _Arg>
2774 struct __result_of_memobj;
2776 template<typename _Res, typename _Class, typename _Arg>
2777 struct __result_of_memobj<_Res _Class::*, _Arg>
2779 using _Argval = __remove_cvref_t<_Arg>;
2780 using _MemPtr = _Res _Class::*;
2781 using type = typename __conditional_t<__or_<is_same<_Argval, _Class>,
2782 is_base_of<_Class, _Argval>>::value,
2783 __result_of_memobj_ref<_MemPtr, _Arg>,
2784 __result_of_memobj_deref<_MemPtr, _Arg>
2788 template<typename _MemPtr, typename _Arg, typename... _Args>
2789 struct __result_of_memfun;
2791 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2792 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2794 using _Argval = typename remove_reference<_Arg>::type;
2795 using _MemPtr = _Res _Class::*;
2796 using type = typename __conditional_t<is_base_of<_Class, _Argval>::value,
2797 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2798 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2802 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2803 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2804 // as the object expression
2806 // Used by result_of, invoke etc. to unwrap a reference_wrapper.
2807 template<typename _Tp, typename _Up = __remove_cvref_t<_Tp>>
2813 template<typename _Tp, typename _Up>
2814 struct __inv_unwrap<_Tp, reference_wrapper<_Up>>
2819 template<bool, bool, typename _Functor, typename... _ArgTypes>
2820 struct __result_of_impl
2822 using type = __failure_type;
2825 template<typename _MemPtr, typename _Arg>
2826 struct __result_of_impl<true, false, _MemPtr, _Arg>
2827 : public __result_of_memobj<__decay_t<_MemPtr>,
2828 typename __inv_unwrap<_Arg>::type>
2831 template<typename _MemPtr, typename _Arg, typename... _Args>
2832 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2833 : public __result_of_memfun<__decay_t<_MemPtr>,
2834 typename __inv_unwrap<_Arg>::type, _Args...>
2837 // [func.require] paragraph 1 bullet 5:
2838 struct __result_of_other_impl
2840 template<typename _Fn, typename... _Args>
2841 static __result_of_success<decltype(
2842 std::declval<_Fn>()(std::declval<_Args>()...)
2843 ), __invoke_other> _S_test(int);
2845 template<typename...>
2846 static __failure_type _S_test(...);
2849 template<typename _Functor, typename... _ArgTypes>
2850 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2851 : private __result_of_other_impl
2853 using type = decltype(_S_test<_Functor, _ArgTypes...>(0));
2856 // __invoke_result (std::invoke_result for C++11)
2857 template<typename _Functor, typename... _ArgTypes>
2858 struct __invoke_result
2859 : public __result_of_impl<
2860 is_member_object_pointer<
2861 typename remove_reference<_Functor>::type
2863 is_member_function_pointer<
2864 typename remove_reference<_Functor>::type
2866 _Functor, _ArgTypes...
2870 // __invoke_result_t (std::invoke_result_t for C++11)
2871 template<typename _Fn, typename... _Args>
2872 using __invoke_result_t = typename __invoke_result<_Fn, _Args...>::type;
2875 template<typename _Functor, typename... _ArgTypes>
2876 struct result_of<_Functor(_ArgTypes...)>
2877 : public __invoke_result<_Functor, _ArgTypes...>
2878 { } _GLIBCXX17_DEPRECATED_SUGGEST("std::invoke_result");
2880#if __cplusplus >= 201402L
2881#pragma GCC diagnostic push
2882#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2883 /// Alias template for aligned_storage
2884 template<size_t _Len,
2885 size_t _Align = __aligned_storage_default_alignment(_Len)>
2886 using aligned_storage_t _GLIBCXX23_DEPRECATED = typename aligned_storage<_Len, _Align>::type;
2888 template <size_t _Len, typename... _Types>
2889 using aligned_union_t _GLIBCXX23_DEPRECATED = typename aligned_union<_Len, _Types...>::type;
2890#pragma GCC diagnostic pop
2892 /// Alias template for decay
2893 template<typename _Tp>
2894 using decay_t = typename decay<_Tp>::type;
2896 /// Alias template for enable_if
2897 template<bool _Cond, typename _Tp = void>
2898 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2900 /// Alias template for conditional
2901 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2902 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2904 /// Alias template for common_type
2905 template<typename... _Tp>
2906 using common_type_t = typename common_type<_Tp...>::type;
2908 /// Alias template for underlying_type
2909 template<typename _Tp>
2910 using underlying_type_t = typename underlying_type<_Tp>::type;
2912 /// Alias template for result_of
2913 template<typename _Tp>
2914 using result_of_t = typename result_of<_Tp>::type;
2917#ifdef __cpp_lib_void_t // C++ >= 17 || GNU++ >= 11
2918 /// A metafunction that always yields void, used for detecting valid types.
2919 template<typename...> using void_t = void;
2922 /// @cond undocumented
2925 // Detect whether _Op<_Args...> is a valid type, use default _Def if not.
2928 // Implementation of the detection idiom (negative case).
2929 template<typename _Def, template<typename...> class _Op, typename... _Args>
2930 struct __detected_or
2933 using __is_detected = false_type;
2936 // Implementation of the detection idiom (positive case).
2937 template<typename _Def, template<typename...> class _Op, typename... _Args>
2938 requires requires { typename _Op<_Args...>; }
2939 struct __detected_or<_Def, _Op, _Args...>
2941 using type = _Op<_Args...>;
2942 using __is_detected = true_type;
2945 /// Implementation of the detection idiom (negative case).
2946 template<typename _Default, typename _AlwaysVoid,
2947 template<typename...> class _Op, typename... _Args>
2950 using type = _Default;
2951 using __is_detected = false_type;
2954 /// Implementation of the detection idiom (positive case).
2955 template<typename _Default, template<typename...> class _Op,
2957 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2959 using type = _Op<_Args...>;
2960 using __is_detected = true_type;
2963 template<typename _Default, template<typename...> class _Op,
2965 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2966#endif // __cpp_concepts
2968 // _Op<_Args...> if that is a valid type, otherwise _Default.
2969 template<typename _Default, template<typename...> class _Op,
2971 using __detected_or_t
2972 = typename __detected_or<_Default, _Op, _Args...>::type;
2975 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2976 * member type _NTYPE.
2978#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2979 template<typename _Tp, typename = __void_t<>> \
2980 struct __has_##_NTYPE \
2983 template<typename _Tp> \
2984 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2988 template <typename _Tp>
2989 struct __is_swappable;
2991 template <typename _Tp>
2992 struct __is_nothrow_swappable;
2995 struct __is_tuple_like_impl : false_type
2998 // Internal type trait that allows us to sfinae-protect tuple_cat.
2999 template<typename _Tp>
3000 struct __is_tuple_like
3001 : public __is_tuple_like_impl<__remove_cvref_t<_Tp>>::type
3005 template<typename _Tp>
3006 _GLIBCXX20_CONSTEXPR
3008 _Require<__not_<__is_tuple_like<_Tp>>,
3009 is_move_constructible<_Tp>,
3010 is_move_assignable<_Tp>>
3012 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
3013 is_nothrow_move_assignable<_Tp>>::value);
3015 template<typename _Tp, size_t _Nm>
3016 _GLIBCXX20_CONSTEXPR
3018 __enable_if_t<__is_swappable<_Tp>::value>
3019 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
3020 noexcept(__is_nothrow_swappable<_Tp>::value);
3022 /// @cond undocumented
3023 namespace __swappable_details {
3026 struct __do_is_swappable_impl
3028 template<typename _Tp, typename
3029 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
3030 static true_type __test(int);
3033 static false_type __test(...);
3036 struct __do_is_nothrow_swappable_impl
3038 template<typename _Tp>
3039 static __bool_constant<
3040 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
3044 static false_type __test(...);
3047 } // namespace __swappable_details
3049 template<typename _Tp>
3050 struct __is_swappable_impl
3051 : public __swappable_details::__do_is_swappable_impl
3053 using type = decltype(__test<_Tp>(0));
3056 template<typename _Tp>
3057 struct __is_nothrow_swappable_impl
3058 : public __swappable_details::__do_is_nothrow_swappable_impl
3060 using type = decltype(__test<_Tp>(0));
3063 template<typename _Tp>
3064 struct __is_swappable
3065 : public __is_swappable_impl<_Tp>::type
3068 template<typename _Tp>
3069 struct __is_nothrow_swappable
3070 : public __is_nothrow_swappable_impl<_Tp>::type
3074#ifdef __cpp_lib_is_swappable // C++ >= 17 || GNU++ >= 11
3075 /// Metafunctions used for detecting swappable types: p0185r1
3078 template<typename _Tp>
3080 : public __is_swappable_impl<_Tp>::type
3082 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3083 "template argument must be a complete class or an unbounded array");
3086 /// is_nothrow_swappable
3087 template<typename _Tp>
3088 struct is_nothrow_swappable
3089 : public __is_nothrow_swappable_impl<_Tp>::type
3091 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3092 "template argument must be a complete class or an unbounded array");
3095#if __cplusplus >= 201402L
3097 template<typename _Tp>
3098 _GLIBCXX17_INLINE constexpr bool is_swappable_v =
3099 is_swappable<_Tp>::value;
3101 /// is_nothrow_swappable_v
3102 template<typename _Tp>
3103 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_v =
3104 is_nothrow_swappable<_Tp>::value;
3105#endif // __cplusplus >= 201402L
3107 /// @cond undocumented
3108 namespace __swappable_with_details {
3111 struct __do_is_swappable_with_impl
3113 template<typename _Tp, typename _Up, typename
3114 = decltype(swap(std::declval<_Tp>(), std::declval<_Up>())),
3116 = decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))>
3117 static true_type __test(int);
3119 template<typename, typename>
3120 static false_type __test(...);
3123 struct __do_is_nothrow_swappable_with_impl
3125 template<typename _Tp, typename _Up>
3126 static __bool_constant<
3127 noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
3129 noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()))
3132 template<typename, typename>
3133 static false_type __test(...);
3136 } // namespace __swappable_with_details
3138 template<typename _Tp, typename _Up>
3139 struct __is_swappable_with_impl
3140 : public __swappable_with_details::__do_is_swappable_with_impl
3142 using type = decltype(__test<_Tp, _Up>(0));
3145 // Optimization for the homogenous lvalue case, not required:
3146 template<typename _Tp>
3147 struct __is_swappable_with_impl<_Tp&, _Tp&>
3148 : public __swappable_details::__do_is_swappable_impl
3150 using type = decltype(__test<_Tp&>(0));
3153 template<typename _Tp, typename _Up>
3154 struct __is_nothrow_swappable_with_impl
3155 : public __swappable_with_details::__do_is_nothrow_swappable_with_impl
3157 using type = decltype(__test<_Tp, _Up>(0));
3160 // Optimization for the homogenous lvalue case, not required:
3161 template<typename _Tp>
3162 struct __is_nothrow_swappable_with_impl<_Tp&, _Tp&>
3163 : public __swappable_details::__do_is_nothrow_swappable_impl
3165 using type = decltype(__test<_Tp&>(0));
3169 /// is_swappable_with
3170 template<typename _Tp, typename _Up>
3171 struct is_swappable_with
3172 : public __is_swappable_with_impl<_Tp, _Up>::type
3174 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3175 "first template argument must be a complete class or an unbounded array");
3176 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3177 "second template argument must be a complete class or an unbounded array");
3180 /// is_nothrow_swappable_with
3181 template<typename _Tp, typename _Up>
3182 struct is_nothrow_swappable_with
3183 : public __is_nothrow_swappable_with_impl<_Tp, _Up>::type
3185 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3186 "first template argument must be a complete class or an unbounded array");
3187 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3188 "second template argument must be a complete class or an unbounded array");
3191#if __cplusplus >= 201402L
3192 /// is_swappable_with_v
3193 template<typename _Tp, typename _Up>
3194 _GLIBCXX17_INLINE constexpr bool is_swappable_with_v =
3195 is_swappable_with<_Tp, _Up>::value;
3197 /// is_nothrow_swappable_with_v
3198 template<typename _Tp, typename _Up>
3199 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_with_v =
3200 is_nothrow_swappable_with<_Tp, _Up>::value;
3201#endif // __cplusplus >= 201402L
3203#endif // __cpp_lib_is_swappable
3205 /// @cond undocumented
3207 // __is_invocable (std::is_invocable for C++11)
3209 // The primary template is used for invalid INVOKE expressions.
3210 template<typename _Result, typename _Ret,
3211 bool = is_void<_Ret>::value, typename = void>
3212 struct __is_invocable_impl
3215 using __nothrow_conv = false_type; // For is_nothrow_invocable_r
3218 // Used for valid INVOKE and INVOKE<void> expressions.
3219 template<typename _Result, typename _Ret>
3220 struct __is_invocable_impl<_Result, _Ret,
3221 /* is_void<_Ret> = */ true,
3222 __void_t<typename _Result::type>>
3225 using __nothrow_conv = true_type; // For is_nothrow_invocable_r
3228#pragma GCC diagnostic push
3229#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3230 // Used for INVOKE<R> expressions to check the implicit conversion to R.
3231 template<typename _Result, typename _Ret>
3232 struct __is_invocable_impl<_Result, _Ret,
3233 /* is_void<_Ret> = */ false,
3234 __void_t<typename _Result::type>>
3237 // The type of the INVOKE expression.
3238 using _Res_t = typename _Result::type;
3240 // Unlike declval, this doesn't add_rvalue_reference, so it respects
3241 // guaranteed copy elision.
3242 static _Res_t _S_get() noexcept;
3244 // Used to check if _Res_t can implicitly convert to _Tp.
3245 template<typename _Tp>
3246 static void _S_conv(__type_identity_t<_Tp>) noexcept;
3248 // This overload is viable if INVOKE(f, args...) can convert to _Tp.
3249 template<typename _Tp,
3250 bool _Nothrow = noexcept(_S_conv<_Tp>(_S_get())),
3251 typename = decltype(_S_conv<_Tp>(_S_get())),
3252#if __has_builtin(__reference_converts_from_temporary)
3253 bool _Dangle = __reference_converts_from_temporary(_Tp, _Res_t)
3255 bool _Dangle = false
3258 static __bool_constant<_Nothrow && !_Dangle>
3261 template<typename _Tp, bool = false>
3266 // For is_invocable_r
3267 using type = decltype(_S_test<_Ret, /* Nothrow = */ true>(1));
3269 // For is_nothrow_invocable_r
3270 using __nothrow_conv = decltype(_S_test<_Ret>(1));
3272#pragma GCC diagnostic pop
3274 template<typename _Fn, typename... _ArgTypes>
3275 struct __is_invocable
3276#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3277 : __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
3279 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3283 template<typename _Fn, typename _Tp, typename... _Args>
3284 constexpr bool __call_is_nt(__invoke_memfun_ref)
3286 using _Up = typename __inv_unwrap<_Tp>::type;
3287 return noexcept((std::declval<_Up>().*std::declval<_Fn>())(
3288 std::declval<_Args>()...));
3291 template<typename _Fn, typename _Tp, typename... _Args>
3292 constexpr bool __call_is_nt(__invoke_memfun_deref)
3294 return noexcept(((*std::declval<_Tp>()).*std::declval<_Fn>())(
3295 std::declval<_Args>()...));
3298 template<typename _Fn, typename _Tp>
3299 constexpr bool __call_is_nt(__invoke_memobj_ref)
3301 using _Up = typename __inv_unwrap<_Tp>::type;
3302 return noexcept(std::declval<_Up>().*std::declval<_Fn>());
3305 template<typename _Fn, typename _Tp>
3306 constexpr bool __call_is_nt(__invoke_memobj_deref)
3308 return noexcept((*std::declval<_Tp>()).*std::declval<_Fn>());
3311 template<typename _Fn, typename... _Args>
3312 constexpr bool __call_is_nt(__invoke_other)
3314 return noexcept(std::declval<_Fn>()(std::declval<_Args>()...));
3317 template<typename _Result, typename _Fn, typename... _Args>
3318 struct __call_is_nothrow
3320 std::__call_is_nt<_Fn, _Args...>(typename _Result::__invoke_type{})
3324 template<typename _Fn, typename... _Args>
3325 using __call_is_nothrow_
3326 = __call_is_nothrow<__invoke_result<_Fn, _Args...>, _Fn, _Args...>;
3328 // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
3329 template<typename _Fn, typename... _Args>
3330 struct __is_nothrow_invocable
3331#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3332 : __bool_constant<__is_nothrow_invocable(_Fn, _Args...)>
3334 : __and_<__is_invocable<_Fn, _Args...>,
3335 __call_is_nothrow_<_Fn, _Args...>>::type
3339#pragma GCC diagnostic push
3340#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3341 struct __nonesuchbase {};
3342 struct __nonesuch : private __nonesuchbase {
3343 ~__nonesuch() = delete;
3344 __nonesuch(__nonesuch const&) = delete;
3345 void operator=(__nonesuch const&) = delete;
3347#pragma GCC diagnostic pop
3350#ifdef __cpp_lib_is_invocable // C++ >= 17
3351 /// std::invoke_result
3352 template<typename _Functor, typename... _ArgTypes>
3353 struct invoke_result
3354 : public __invoke_result<_Functor, _ArgTypes...>
3356 static_assert(std::__is_complete_or_unbounded(__type_identity<_Functor>{}),
3357 "_Functor must be a complete class or an unbounded array");
3358 static_assert((std::__is_complete_or_unbounded(
3359 __type_identity<_ArgTypes>{}) && ...),
3360 "each argument type must be a complete class or an unbounded array");
3363 /// std::invoke_result_t
3364 template<typename _Fn, typename... _Args>
3365 using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3367 /// std::is_invocable
3368 template<typename _Fn, typename... _ArgTypes>
3370#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3371 : public __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
3373 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3376 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3377 "_Fn must be a complete class or an unbounded array");
3378 static_assert((std::__is_complete_or_unbounded(
3379 __type_identity<_ArgTypes>{}) && ...),
3380 "each argument type must be a complete class or an unbounded array");
3383 /// std::is_invocable_r
3384 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3385 struct is_invocable_r
3386 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>::type
3388 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3389 "_Fn must be a complete class or an unbounded array");
3390 static_assert((std::__is_complete_or_unbounded(
3391 __type_identity<_ArgTypes>{}) && ...),
3392 "each argument type must be a complete class or an unbounded array");
3393 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3394 "_Ret must be a complete class or an unbounded array");
3397 /// std::is_nothrow_invocable
3398 template<typename _Fn, typename... _ArgTypes>
3399 struct is_nothrow_invocable
3400#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3401 : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)>
3403 : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>,
3404 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3407 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3408 "_Fn must be a complete class or an unbounded array");
3409 static_assert((std::__is_complete_or_unbounded(
3410 __type_identity<_ArgTypes>{}) && ...),
3411 "each argument type must be a complete class or an unbounded array");
3414 /// @cond undocumented
3415 // This checks that the INVOKE<R> expression is well-formed and that the
3416 // conversion to R does not throw. It does *not* check whether the INVOKE
3417 // expression itself can throw. That is done by __call_is_nothrow_ instead.
3418 template<typename _Result, typename _Ret>
3419 using __is_nt_invocable_impl
3420 = typename __is_invocable_impl<_Result, _Ret>::__nothrow_conv;
3423 /// std::is_nothrow_invocable_r
3424 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3425 struct is_nothrow_invocable_r
3426 : __and_<__is_nt_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>,
3427 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3429 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3430 "_Fn must be a complete class or an unbounded array");
3431 static_assert((std::__is_complete_or_unbounded(
3432 __type_identity<_ArgTypes>{}) && ...),
3433 "each argument type must be a complete class or an unbounded array");
3434 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3435 "_Ret must be a complete class or an unbounded array");
3437#endif // __cpp_lib_is_invocable
3439#if __cpp_lib_type_trait_variable_templates // C++ >= 17
3441 * @defgroup variable_templates Variable templates for type traits
3442 * @ingroup metaprogramming
3444 * Each variable `is_xxx_v<T>` is a boolean constant with the same value
3445 * as the `value` member of the corresponding type trait `is_xxx<T>`.
3447 * @since C++17 unless noted otherwise.
3452 * @ingroup variable_templates
3454template <typename _Tp>
3455 inline constexpr bool is_void_v = is_void<_Tp>::value;
3456template <typename _Tp>
3457 inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
3458template <typename _Tp>
3459 inline constexpr bool is_integral_v = is_integral<_Tp>::value;
3460template <typename _Tp>
3461 inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
3463#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
3464template <typename _Tp>
3465 inline constexpr bool is_array_v = __is_array(_Tp);
3467template <typename _Tp>
3468 inline constexpr bool is_array_v = false;
3469template <typename _Tp>
3470 inline constexpr bool is_array_v<_Tp[]> = true;
3471template <typename _Tp, size_t _Num>
3472 inline constexpr bool is_array_v<_Tp[_Num]> = true;
3475#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
3476template <typename _Tp>
3477 inline constexpr bool is_pointer_v = __is_pointer(_Tp);
3479template <typename _Tp>
3480 inline constexpr bool is_pointer_v = false;
3481template <typename _Tp>
3482 inline constexpr bool is_pointer_v<_Tp*> = true;
3483template <typename _Tp>
3484 inline constexpr bool is_pointer_v<_Tp* const> = true;
3485template <typename _Tp>
3486 inline constexpr bool is_pointer_v<_Tp* volatile> = true;
3487template <typename _Tp>
3488 inline constexpr bool is_pointer_v<_Tp* const volatile> = true;
3491template <typename _Tp>
3492 inline constexpr bool is_lvalue_reference_v = false;
3493template <typename _Tp>
3494 inline constexpr bool is_lvalue_reference_v<_Tp&> = true;
3495template <typename _Tp>
3496 inline constexpr bool is_rvalue_reference_v = false;
3497template <typename _Tp>
3498 inline constexpr bool is_rvalue_reference_v<_Tp&&> = true;
3500#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
3501template <typename _Tp>
3502 inline constexpr bool is_member_object_pointer_v =
3503 __is_member_object_pointer(_Tp);
3505template <typename _Tp>
3506 inline constexpr bool is_member_object_pointer_v =
3507 is_member_object_pointer<_Tp>::value;
3510#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
3511template <typename _Tp>
3512 inline constexpr bool is_member_function_pointer_v =
3513 __is_member_function_pointer(_Tp);
3515template <typename _Tp>
3516 inline constexpr bool is_member_function_pointer_v =
3517 is_member_function_pointer<_Tp>::value;
3520template <typename _Tp>
3521 inline constexpr bool is_enum_v = __is_enum(_Tp);
3522template <typename _Tp>
3523 inline constexpr bool is_union_v = __is_union(_Tp);
3524template <typename _Tp>
3525 inline constexpr bool is_class_v = __is_class(_Tp);
3526// is_function_v is defined below, after is_const_v.
3528#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
3529template <typename _Tp>
3530 inline constexpr bool is_reference_v = __is_reference(_Tp);
3532template <typename _Tp>
3533 inline constexpr bool is_reference_v = false;
3534template <typename _Tp>
3535 inline constexpr bool is_reference_v<_Tp&> = true;
3536template <typename _Tp>
3537 inline constexpr bool is_reference_v<_Tp&&> = true;
3540template <typename _Tp>
3541 inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
3542template <typename _Tp>
3543 inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
3545#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
3546template <typename _Tp>
3547 inline constexpr bool is_object_v = __is_object(_Tp);
3549template <typename _Tp>
3550 inline constexpr bool is_object_v = is_object<_Tp>::value;
3553template <typename _Tp>
3554 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
3555template <typename _Tp>
3556 inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;
3558#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
3559template <typename _Tp>
3560 inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
3562template <typename _Tp>
3563 inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
3566#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const)
3567template <typename _Tp>
3568 inline constexpr bool is_const_v = __is_const(_Tp);
3570template <typename _Tp>
3571 inline constexpr bool is_const_v = false;
3572template <typename _Tp>
3573 inline constexpr bool is_const_v<const _Tp> = true;
3576#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
3577template <typename _Tp>
3578 inline constexpr bool is_function_v = __is_function(_Tp);
3580template <typename _Tp>
3581 inline constexpr bool is_function_v = !is_const_v<const _Tp>;
3582template <typename _Tp>
3583 inline constexpr bool is_function_v<_Tp&> = false;
3584template <typename _Tp>
3585 inline constexpr bool is_function_v<_Tp&&> = false;
3588#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile)
3589template <typename _Tp>
3590 inline constexpr bool is_volatile_v = __is_volatile(_Tp);
3592template <typename _Tp>
3593 inline constexpr bool is_volatile_v = false;
3594template <typename _Tp>
3595 inline constexpr bool is_volatile_v<volatile _Tp> = true;
3598template <typename _Tp>
3599 _GLIBCXX26_DEPRECATED_SUGGEST("is_trivially_default_constructible_v && is_trivially_copyable_v")
3600 inline constexpr bool is_trivial_v = __is_trivial(_Tp);
3601template <typename _Tp>
3602 inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
3603template <typename _Tp>
3604 inline constexpr bool is_standard_layout_v = __is_standard_layout(_Tp);
3605template <typename _Tp>
3606 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout_v && is_trivial_v")
3607 inline constexpr bool is_pod_v = __is_pod(_Tp);
3608template <typename _Tp>
3609 _GLIBCXX17_DEPRECATED
3610 inline constexpr bool is_literal_type_v = __is_literal_type(_Tp);
3611template <typename _Tp>
3612 inline constexpr bool is_empty_v = __is_empty(_Tp);
3613template <typename _Tp>
3614 inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
3615template <typename _Tp>
3616 inline constexpr bool is_abstract_v = __is_abstract(_Tp);
3617template <typename _Tp>
3618 inline constexpr bool is_final_v = __is_final(_Tp);
3620template <typename _Tp>
3621 inline constexpr bool is_signed_v = is_signed<_Tp>::value;
3622template <typename _Tp>
3623 inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
3625template <typename _Tp, typename... _Args>
3626 inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
3627template <typename _Tp>
3628 inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
3629template <typename _Tp>
3630 inline constexpr bool is_copy_constructible_v
3631 = __is_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3632template <typename _Tp>
3633 inline constexpr bool is_move_constructible_v
3634 = __is_constructible(_Tp, __add_rval_ref_t<_Tp>);
3636template <typename _Tp, typename _Up>
3637 inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Up);
3638template <typename _Tp>
3639 inline constexpr bool is_copy_assignable_v
3640 = __is_assignable(__add_lval_ref_t<_Tp>, __add_lval_ref_t<const _Tp>);
3641template <typename _Tp>
3642 inline constexpr bool is_move_assignable_v
3643 = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3645#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_destructible)
3646template <typename _Tp>
3647 inline constexpr bool is_destructible_v = __is_destructible(_Tp);
3649template <typename _Tp>
3650 inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
3653template <typename _Tp, typename... _Args>
3654 inline constexpr bool is_trivially_constructible_v
3655 = __is_trivially_constructible(_Tp, _Args...);
3656template <typename _Tp>
3657 inline constexpr bool is_trivially_default_constructible_v
3658 = __is_trivially_constructible(_Tp);
3659template <typename _Tp>
3660 inline constexpr bool is_trivially_copy_constructible_v
3661 = __is_trivially_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3662template <typename _Tp>
3663 inline constexpr bool is_trivially_move_constructible_v
3664 = __is_trivially_constructible(_Tp, __add_rval_ref_t<_Tp>);
3666template <typename _Tp, typename _Up>
3667 inline constexpr bool is_trivially_assignable_v
3668 = __is_trivially_assignable(_Tp, _Up);
3669template <typename _Tp>
3670 inline constexpr bool is_trivially_copy_assignable_v
3671 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3672 __add_lval_ref_t<const _Tp>);
3673template <typename _Tp>
3674 inline constexpr bool is_trivially_move_assignable_v
3675 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3676 __add_rval_ref_t<_Tp>);
3678#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_trivially_destructible)
3679template <typename _Tp>
3680 inline constexpr bool is_trivially_destructible_v
3681 = __is_trivially_destructible(_Tp);
3683template <typename _Tp>
3684 inline constexpr bool is_trivially_destructible_v = false;
3686template <typename _Tp>
3687 requires (!is_reference_v<_Tp>) && requires (_Tp& __t) { __t.~_Tp(); }
3688 inline constexpr bool is_trivially_destructible_v<_Tp>
3689 = __has_trivial_destructor(_Tp);
3690template <typename _Tp>
3691 inline constexpr bool is_trivially_destructible_v<_Tp&> = true;
3692template <typename _Tp>
3693 inline constexpr bool is_trivially_destructible_v<_Tp&&> = true;
3694template <typename _Tp, size_t _Nm>
3695 inline constexpr bool is_trivially_destructible_v<_Tp[_Nm]>
3696 = is_trivially_destructible_v<_Tp>;
3698template <typename _Tp>
3699 inline constexpr bool is_trivially_destructible_v =
3700 is_trivially_destructible<_Tp>::value;
3703template <typename _Tp, typename... _Args>
3704 inline constexpr bool is_nothrow_constructible_v
3705 = __is_nothrow_constructible(_Tp, _Args...);
3706template <typename _Tp>
3707 inline constexpr bool is_nothrow_default_constructible_v
3708 = __is_nothrow_constructible(_Tp);
3709template <typename _Tp>
3710 inline constexpr bool is_nothrow_copy_constructible_v
3711 = __is_nothrow_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3712template <typename _Tp>
3713 inline constexpr bool is_nothrow_move_constructible_v
3714 = __is_nothrow_constructible(_Tp, __add_rval_ref_t<_Tp>);
3716template <typename _Tp, typename _Up>
3717 inline constexpr bool is_nothrow_assignable_v
3718 = __is_nothrow_assignable(_Tp, _Up);
3719template <typename _Tp>
3720 inline constexpr bool is_nothrow_copy_assignable_v
3721 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>,
3722 __add_lval_ref_t<const _Tp>);
3723template <typename _Tp>
3724 inline constexpr bool is_nothrow_move_assignable_v
3725 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3727#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_destructible)
3728template <typename _Tp>
3729 inline constexpr bool is_nothrow_destructible_v
3730 = __is_nothrow_destructible(_Tp);
3732template <typename _Tp>
3733 inline constexpr bool is_nothrow_destructible_v =
3734 is_nothrow_destructible<_Tp>::value;
3737template <typename _Tp>
3738 inline constexpr bool has_virtual_destructor_v
3739 = __has_virtual_destructor(_Tp);
3741template <typename _Tp>
3742 inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
3744#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) \
3745 && (!defined(__clang__) || __clang_major__ >= 20) // PR118559
3746template <typename _Tp>
3747 inline constexpr size_t rank_v = __array_rank(_Tp);
3749template <typename _Tp>
3750 inline constexpr size_t rank_v = 0;
3751template <typename _Tp, size_t _Size>
3752 inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
3753template <typename _Tp>
3754 inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
3757template <typename _Tp, unsigned _Idx = 0>
3758 inline constexpr size_t extent_v = 0;
3759template <typename _Tp, size_t _Size>
3760 inline constexpr size_t extent_v<_Tp[_Size], 0> = _Size;
3761template <typename _Tp, unsigned _Idx, size_t _Size>
3762 inline constexpr size_t extent_v<_Tp[_Size], _Idx> = extent_v<_Tp, _Idx - 1>;
3763template <typename _Tp>
3764 inline constexpr size_t extent_v<_Tp[], 0> = 0;
3765template <typename _Tp, unsigned _Idx>
3766 inline constexpr size_t extent_v<_Tp[], _Idx> = extent_v<_Tp, _Idx - 1>;
3768#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
3769template <typename _Tp, typename _Up>
3770 inline constexpr bool is_same_v = __is_same(_Tp, _Up);
3772template <typename _Tp, typename _Up>
3773 inline constexpr bool is_same_v = false;
3774template <typename _Tp>
3775 inline constexpr bool is_same_v<_Tp, _Tp> = true;
3777template <typename _Base, typename _Derived>
3778 inline constexpr bool is_base_of_v = __is_base_of(_Base, _Derived);
3779#ifdef __cpp_lib_is_virtual_base_of // C++ >= 26
3780template <typename _Base, typename _Derived>
3781 inline constexpr bool is_virtual_base_of_v = __builtin_is_virtual_base_of(_Base, _Derived);
3783#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
3784template <typename _From, typename _To>
3785 inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
3787template <typename _From, typename _To>
3788 inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
3790template<typename _Fn, typename... _Args>
3791 inline constexpr bool is_invocable_v
3792#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3793 = __is_invocable(_Fn, _Args...);
3795 = is_invocable<_Fn, _Args...>::value;
3797template<typename _Fn, typename... _Args>
3798 inline constexpr bool is_nothrow_invocable_v
3799#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3800 = __is_nothrow_invocable(_Fn, _Args...);
3802 = is_nothrow_invocable<_Fn, _Args...>::value;
3804template<typename _Ret, typename _Fn, typename... _Args>
3805 inline constexpr bool is_invocable_r_v
3806 = is_invocable_r<_Ret, _Fn, _Args...>::value;
3807template<typename _Ret, typename _Fn, typename... _Args>
3808 inline constexpr bool is_nothrow_invocable_r_v
3809 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3811#endif // __cpp_lib_type_trait_variable_templates
3813#ifdef __cpp_lib_has_unique_object_representations // C++ >= 17 && HAS_UNIQ_OBJ_REP
3814 /// has_unique_object_representations
3816 template<typename _Tp>
3817 struct has_unique_object_representations
3818 : bool_constant<__has_unique_object_representations(
3819 remove_cv_t<remove_all_extents_t<_Tp>>
3822 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3823 "template argument must be a complete class or an unbounded array");
3826# if __cpp_lib_type_trait_variable_templates // C++ >= 17
3827 /// @ingroup variable_templates
3828 template<typename _Tp>
3829 inline constexpr bool has_unique_object_representations_v
3830 = has_unique_object_representations<_Tp>::value;
3834#ifdef __cpp_lib_is_aggregate // C++ >= 17 && builtin_is_aggregate
3835 /// is_aggregate - true if the type is an aggregate.
3837 template<typename _Tp>
3839 : bool_constant<__is_aggregate(remove_cv_t<_Tp>)>
3842# if __cpp_lib_type_trait_variable_templates // C++ >= 17
3843 /** is_aggregate_v - true if the type is an aggregate.
3844 * @ingroup variable_templates
3847 template<typename _Tp>
3848 inline constexpr bool is_aggregate_v = __is_aggregate(remove_cv_t<_Tp>);
3852 /** * Remove references and cv-qualifiers.
3856#ifdef __cpp_lib_remove_cvref // C++ >= 20
3857# if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cvref)
3858 template<typename _Tp>
3860 { using type = __remove_cvref(_Tp); };
3862 template<typename _Tp>
3864 { using type = typename remove_cv<_Tp>::type; };
3866 template<typename _Tp>
3867 struct remove_cvref<_Tp&>
3868 { using type = typename remove_cv<_Tp>::type; };
3870 template<typename _Tp>
3871 struct remove_cvref<_Tp&&>
3872 { using type = typename remove_cv<_Tp>::type; };
3875 template<typename _Tp>
3876 using remove_cvref_t = typename remove_cvref<_Tp>::type;
3878#endif // __cpp_lib_remove_cvref
3880#ifdef __cpp_lib_type_identity // C++ >= 20
3881 /** * Identity metafunction.
3885 template<typename _Tp>
3886 struct type_identity { using type = _Tp; };
3888 template<typename _Tp>
3889 using type_identity_t = typename type_identity<_Tp>::type;
3893#ifdef __cpp_lib_unwrap_ref // C++ >= 20
3894 /** Unwrap a reference_wrapper
3898 template<typename _Tp>
3899 struct unwrap_reference { using type = _Tp; };
3901 template<typename _Tp>
3902 struct unwrap_reference<reference_wrapper<_Tp>> { using type = _Tp&; };
3904 template<typename _Tp>
3905 using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3908 /** Decay type and if it's a reference_wrapper, unwrap it
3912 template<typename _Tp>
3913 struct unwrap_ref_decay { using type = unwrap_reference_t<decay_t<_Tp>>; };
3915 template<typename _Tp>
3916 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3918#endif // __cpp_lib_unwrap_ref
3920#ifdef __cpp_lib_bounded_array_traits // C++ >= 20
3921 /// True for a type that is an array of known bound.
3922 /// @ingroup variable_templates
3924# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array)
3925 template<typename _Tp>
3926 inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp);
3928 template<typename _Tp>
3929 inline constexpr bool is_bounded_array_v = false;
3931 template<typename _Tp, size_t _Size>
3932 inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true;
3935 /// True for a type that is an array of unknown bound.
3936 /// @ingroup variable_templates
3938# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array)
3939 template<typename _Tp>
3940 inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp);
3942 template<typename _Tp>
3943 inline constexpr bool is_unbounded_array_v = false;
3945 template<typename _Tp>
3946 inline constexpr bool is_unbounded_array_v<_Tp[]> = true;
3949 /// True for a type that is an array of known bound.
3951 template<typename _Tp>
3952 struct is_bounded_array
3953 : public bool_constant<is_bounded_array_v<_Tp>>
3956 /// True for a type that is an array of unknown bound.
3958 template<typename _Tp>
3959 struct is_unbounded_array
3960 : public bool_constant<is_unbounded_array_v<_Tp>>
3962#endif // __cpp_lib_bounded_array_traits
3964#if __has_builtin(__is_layout_compatible) && __cplusplus >= 202002L
3967 template<typename _Tp, typename _Up>
3968 struct is_layout_compatible
3969 : bool_constant<__is_layout_compatible(_Tp, _Up)>
3972 /// @ingroup variable_templates
3974 template<typename _Tp, typename _Up>
3975 constexpr bool is_layout_compatible_v
3976 = __is_layout_compatible(_Tp, _Up);
3978#if __has_builtin(__builtin_is_corresponding_member)
3979# ifndef __cpp_lib_is_layout_compatible
3980# error "libstdc++ bug: is_corresponding_member and is_layout_compatible are provided but their FTM is not set"
3984 template<typename _S1, typename _S2, typename _M1, typename _M2>
3986 is_corresponding_member(_M1 _S1::*__m1, _M2 _S2::*__m2) noexcept
3987 { return __builtin_is_corresponding_member(__m1, __m2); }
3991#if __has_builtin(__is_pointer_interconvertible_base_of) \
3992 && __cplusplus >= 202002L
3993 /// True if `_Derived` is standard-layout and has a base class of type `_Base`
3995 template<typename _Base, typename _Derived>
3996 struct is_pointer_interconvertible_base_of
3997 : bool_constant<__is_pointer_interconvertible_base_of(_Base, _Derived)>
4000 /// @ingroup variable_templates
4002 template<typename _Base, typename _Derived>
4003 constexpr bool is_pointer_interconvertible_base_of_v
4004 = __is_pointer_interconvertible_base_of(_Base, _Derived);
4006#if __has_builtin(__builtin_is_pointer_interconvertible_with_class)
4007# ifndef __cpp_lib_is_pointer_interconvertible
4008# error "libstdc++ bug: is_pointer_interconvertible available but FTM is not set"
4011 /// True if `__mp` points to the first member of a standard-layout type
4012 /// @returns true if `s.*__mp` is pointer-interconvertible with `s`
4014 template<typename _Tp, typename _Mem>
4016 is_pointer_interconvertible_with_class(_Mem _Tp::*__mp) noexcept
4017 { return __builtin_is_pointer_interconvertible_with_class(__mp); }
4021#ifdef __cpp_lib_is_scoped_enum // C++ >= 23
4022 /// True if the type is a scoped enumeration type.
4025# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
4026 template<typename _Tp>
4027 struct is_scoped_enum
4028 : bool_constant<__is_scoped_enum(_Tp)>
4031 template<typename _Tp>
4032 struct is_scoped_enum
4036 template<typename _Tp>
4037 requires __is_enum(_Tp)
4038 && requires(remove_cv_t<_Tp> __t) { __t = __t; } // fails if incomplete
4039 struct is_scoped_enum<_Tp>
4040 : bool_constant<!requires(_Tp __t, void(*__f)(int)) { __f(__t); }>
4044 /// @ingroup variable_templates
4046# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
4047 template<typename _Tp>
4048 inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
4050 template<typename _Tp>
4051 inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
4055#ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp
4056 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
4057 /// direct-initialization, and a temporary object would be bound to
4058 /// the reference, false otherwise.
4060 template<typename _Tp, typename _Up>
4061 struct reference_constructs_from_temporary
4062 : public bool_constant<__reference_constructs_from_temporary(_Tp, _Up)>
4064 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
4065 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
4066 "template argument must be a complete class or an unbounded array");
4069 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
4070 /// copy-initialization, and a temporary object would be bound to
4071 /// the reference, false otherwise.
4073 template<typename _Tp, typename _Up>
4074 struct reference_converts_from_temporary
4075 : public bool_constant<__reference_converts_from_temporary(_Tp, _Up)>
4077 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
4078 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
4079 "template argument must be a complete class or an unbounded array");
4082 /// @ingroup variable_templates
4084 template<typename _Tp, typename _Up>
4085 inline constexpr bool reference_constructs_from_temporary_v
4086 = reference_constructs_from_temporary<_Tp, _Up>::value;
4088 /// @ingroup variable_templates
4090 template<typename _Tp, typename _Up>
4091 inline constexpr bool reference_converts_from_temporary_v
4092 = reference_converts_from_temporary<_Tp, _Up>::value;
4093#endif // __cpp_lib_reference_from_temporary
4095#ifdef __cpp_lib_is_constant_evaluated // C++ >= 20 && HAVE_IS_CONST_EVAL
4096 /// Returns true only when called during constant evaluation.
4098 [[__gnu__::__always_inline__]]
4100 is_constant_evaluated() noexcept
4102#if __cpp_if_consteval >= 202106L
4103 if consteval { return true; } else { return false; }
4105 return __builtin_is_constant_evaluated();
4110#if __cplusplus >= 202002L
4111 /// @cond undocumented
4112 template<typename _From, typename _To>
4113 using __copy_cv = typename __match_cv_qualifiers<_From, _To>::__type;
4115 template<typename _Xp, typename _Yp>
4117 = decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
4119 template<typename _Ap, typename _Bp, typename = void>
4120 struct __common_ref_impl
4123 // [meta.trans.other], COMMON-REF(A, B)
4124 template<typename _Ap, typename _Bp>
4125 using __common_ref = typename __common_ref_impl<_Ap, _Bp>::type;
4127 // COND-RES(COPYCV(X, Y) &, COPYCV(Y, X) &)
4128 template<typename _Xp, typename _Yp>
4129 using __condres_cvref
4130 = __cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>;
4132 // If A and B are both lvalue reference types, ...
4133 template<typename _Xp, typename _Yp>
4134 struct __common_ref_impl<_Xp&, _Yp&, __void_t<__condres_cvref<_Xp, _Yp>>>
4135 : enable_if<is_reference_v<__condres_cvref<_Xp, _Yp>>,
4136 __condres_cvref<_Xp, _Yp>>
4139 // let C be remove_reference_t<COMMON-REF(X&, Y&)>&&
4140 template<typename _Xp, typename _Yp>
4141 using __common_ref_C = remove_reference_t<__common_ref<_Xp&, _Yp&>>&&;
4143 // If A and B are both rvalue reference types, ...
4144 template<typename _Xp, typename _Yp>
4145 struct __common_ref_impl<_Xp&&, _Yp&&,
4146 _Require<is_convertible<_Xp&&, __common_ref_C<_Xp, _Yp>>,
4147 is_convertible<_Yp&&, __common_ref_C<_Xp, _Yp>>>>
4148 { using type = __common_ref_C<_Xp, _Yp>; };
4150 // let D be COMMON-REF(const X&, Y&)
4151 template<typename _Xp, typename _Yp>
4152 using __common_ref_D = __common_ref<const _Xp&, _Yp&>;
4154 // If A is an rvalue reference and B is an lvalue reference, ...
4155 template<typename _Xp, typename _Yp>
4156 struct __common_ref_impl<_Xp&&, _Yp&,
4157 _Require<is_convertible<_Xp&&, __common_ref_D<_Xp, _Yp>>>>
4158 { using type = __common_ref_D<_Xp, _Yp>; };
4160 // If A is an lvalue reference and B is an rvalue reference, ...
4161 template<typename _Xp, typename _Yp>
4162 struct __common_ref_impl<_Xp&, _Yp&&>
4163 : __common_ref_impl<_Yp&&, _Xp&>
4167 template<typename _Tp, typename _Up,
4168 template<typename> class _TQual, template<typename> class _UQual>
4169 struct basic_common_reference
4172 /// @cond undocumented
4173 template<typename _Tp>
4175 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>; };
4177 template<typename _Tp>
4179 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&; };
4181 template<typename _Tp>
4182 struct __xref<_Tp&&>
4183 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&&; };
4185 template<typename _Tp1, typename _Tp2>
4186 using __basic_common_ref
4187 = typename basic_common_reference<remove_cvref_t<_Tp1>,
4188 remove_cvref_t<_Tp2>,
4189 __xref<_Tp1>::template __type,
4190 __xref<_Tp2>::template __type>::type;
4193 template<typename... _Tp>
4194 struct common_reference;
4196 template<typename... _Tp>
4197 using common_reference_t = typename common_reference<_Tp...>::type;
4199 // If sizeof...(T) is zero, there shall be no member type.
4201 struct common_reference<>
4204 // If sizeof...(T) is one ...
4205 template<typename _Tp0>
4206 struct common_reference<_Tp0>
4207 { using type = _Tp0; };
4209 /// @cond undocumented
4210 template<typename _Tp1, typename _Tp2, int _Bullet = 1, typename = void>
4211 struct __common_reference_impl
4212 : __common_reference_impl<_Tp1, _Tp2, _Bullet + 1>
4215 // If sizeof...(T) is two ...
4216 template<typename _Tp1, typename _Tp2>
4217 struct common_reference<_Tp1, _Tp2>
4218 : __common_reference_impl<_Tp1, _Tp2>
4221 // If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, ...
4222 template<typename _Tp1, typename _Tp2>
4223 struct __common_reference_impl<_Tp1&, _Tp2&, 1,
4224 void_t<__common_ref<_Tp1&, _Tp2&>>>
4225 { using type = __common_ref<_Tp1&, _Tp2&>; };
4227 template<typename _Tp1, typename _Tp2>
4228 struct __common_reference_impl<_Tp1&&, _Tp2&&, 1,
4229 void_t<__common_ref<_Tp1&&, _Tp2&&>>>
4230 { using type = __common_ref<_Tp1&&, _Tp2&&>; };
4232 template<typename _Tp1, typename _Tp2>
4233 struct __common_reference_impl<_Tp1&, _Tp2&&, 1,
4234 void_t<__common_ref<_Tp1&, _Tp2&&>>>
4235 { using type = __common_ref<_Tp1&, _Tp2&&>; };
4237 template<typename _Tp1, typename _Tp2>
4238 struct __common_reference_impl<_Tp1&&, _Tp2&, 1,
4239 void_t<__common_ref<_Tp1&&, _Tp2&>>>
4240 { using type = __common_ref<_Tp1&&, _Tp2&>; };
4242 // Otherwise, if basic_common_reference<...>::type is well-formed, ...
4243 template<typename _Tp1, typename _Tp2>
4244 struct __common_reference_impl<_Tp1, _Tp2, 2,
4245 void_t<__basic_common_ref<_Tp1, _Tp2>>>
4246 { using type = __basic_common_ref<_Tp1, _Tp2>; };
4248 // Otherwise, if COND-RES(T1, T2) is well-formed, ...
4249 template<typename _Tp1, typename _Tp2>
4250 struct __common_reference_impl<_Tp1, _Tp2, 3,
4251 void_t<__cond_res<_Tp1, _Tp2>>>
4252 { using type = __cond_res<_Tp1, _Tp2>; };
4254 // Otherwise, if common_type_t<T1, T2> is well-formed, ...
4255 template<typename _Tp1, typename _Tp2>
4256 struct __common_reference_impl<_Tp1, _Tp2, 4,
4257 void_t<common_type_t<_Tp1, _Tp2>>>
4258 { using type = common_type_t<_Tp1, _Tp2>; };
4260 // Otherwise, there shall be no member type.
4261 template<typename _Tp1, typename _Tp2>
4262 struct __common_reference_impl<_Tp1, _Tp2, 5, void>
4265 // Otherwise, if sizeof...(T) is greater than two, ...
4266 template<typename _Tp1, typename _Tp2, typename... _Rest>
4267 struct common_reference<_Tp1, _Tp2, _Rest...>
4268 : __common_type_fold<common_reference<_Tp1, _Tp2>,
4269 __common_type_pack<_Rest...>>
4272 // Reuse __common_type_fold for common_reference<T1, T2, Rest...>
4273 template<typename _Tp1, typename _Tp2, typename... _Rest>
4274 struct __common_type_fold<common_reference<_Tp1, _Tp2>,
4275 __common_type_pack<_Rest...>,
4276 void_t<common_reference_t<_Tp1, _Tp2>>>
4277 : public common_reference<common_reference_t<_Tp1, _Tp2>, _Rest...>
4283#if __cplusplus >= 201103L
4284 // Stores a tuple of indices. Used by tuple and pair, and by bind() to
4285 // extract the elements in a tuple.
4286 template<size_t... _Indexes> struct _Index_tuple { };
4288 // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
4289 template<size_t _Num>
4290 struct _Build_index_tuple
4292#if __has_builtin(__make_integer_seq)
4293 template<typename, size_t... _Indices>
4294 using _IdxTuple = _Index_tuple<_Indices...>;
4296 // Clang defines __make_integer_seq for this purpose.
4297 using __type = __make_integer_seq<_IdxTuple, size_t, _Num>;
4299 // For GCC and other compilers, use __integer_pack instead.
4300 using __type = _Index_tuple<__integer_pack(_Num)...>;
4305 /// @} group metaprogramming
4307_GLIBCXX_END_NAMESPACE_VERSION
4313#endif // _GLIBCXX_TYPE_TRAITS