1 // C++11 <type_traits> -*- C++ -*-
3 // Copyright (C) 2007-2026 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file include/type_traits
26 * This is a Standard C++ Library header.
29 #ifndef _GLIBCXX_TYPE_TRAITS
30 #define _GLIBCXX_TYPE_TRAITS 1
32 #ifdef _GLIBCXX_SYSHDR
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_common_reference
45 #define __glibcxx_want_has_unique_object_representations
46 #define __glibcxx_want_integral_constant_callable
47 #define __glibcxx_want_is_aggregate
48 #define __glibcxx_want_is_constant_evaluated
49 #define __glibcxx_want_is_final
50 #define __glibcxx_want_is_implicit_lifetime
51 #define __glibcxx_want_is_invocable
52 #define __glibcxx_want_is_layout_compatible
53 #define __glibcxx_want_is_nothrow_convertible
54 #define __glibcxx_want_is_null_pointer
55 #define __glibcxx_want_is_pointer_interconvertible
56 #define __glibcxx_want_is_scoped_enum
57 #define __glibcxx_want_is_structural
58 #define __glibcxx_want_is_swappable
59 #define __glibcxx_want_is_virtual_base_of
60 #define __glibcxx_want_logical_traits
61 #define __glibcxx_want_reference_from_temporary
62 #define __glibcxx_want_remove_cvref
63 #define __glibcxx_want_result_of_sfinae
64 #define __glibcxx_want_transformation_trait_aliases
65 #define __glibcxx_want_type_identity
66 #define __glibcxx_want_type_trait_variable_templates
67 #define __glibcxx_want_unwrap_ref
68 #define __glibcxx_want_void_t
69 #include <bits/version.h>
73 namespace std _GLIBCXX_VISIBILITY(default)
75 _GLIBCXX_BEGIN_NAMESPACE_VERSION
77 template<typename _Tp>
78 class reference_wrapper;
81 * @defgroup metaprogramming Metaprogramming
84 * Template utilities for compile-time introspection and modification,
85 * including type classification traits, type property inspection traits
86 * and type transformation traits.
94 template<typename _Tp, _Tp __v>
95 struct integral_constant
97 static constexpr _Tp value = __v;
98 using value_type = _Tp;
99 using type = integral_constant<_Tp, __v>;
100 constexpr operator value_type() const noexcept { return value; }
102 #ifdef __cpp_lib_integral_constant_callable // C++ >= 14
103 constexpr value_type operator()() const noexcept { return value; }
107 #if ! __cpp_inline_variables
108 template<typename _Tp, _Tp __v>
109 constexpr _Tp integral_constant<_Tp, __v>::value;
112 /// @cond undocumented
113 /// bool_constant for C++11
115 using __bool_constant = integral_constant<bool, __v>;
118 /// The type used as a compile-time boolean with true value.
119 using true_type = __bool_constant<true>;
121 /// The type used as a compile-time boolean with false value.
122 using false_type = __bool_constant<false>;
124 #ifdef __cpp_lib_bool_constant // C++ >= 17
125 /// Alias template for compile-time boolean constant types.
128 using bool_constant = __bool_constant<__v>;
131 // Metaprogramming helper types.
134 /// Define a member typedef `type` only if a boolean constant is true.
135 template<bool, typename _Tp = void>
139 // Partial specialization for true.
140 template<typename _Tp>
141 struct enable_if<true, _Tp>
142 { using type = _Tp; };
144 // __enable_if_t (std::enable_if_t for C++11)
145 template<bool _Cond, typename _Tp = void>
146 using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
151 template<typename _Tp, typename>
156 struct __conditional<false>
158 template<typename, typename _Up>
162 // More efficient version of std::conditional_t for internal use (and C++11)
163 template<bool _Cond, typename _If, typename _Else>
164 using __conditional_t
165 = typename __conditional<_Cond>::template type<_If, _Else>;
167 /// @cond undocumented
168 template <typename _Type>
169 struct __type_identity
170 { using type = _Type; };
172 template<typename _Tp>
173 using __type_identity_t = typename __type_identity<_Tp>::type;
177 // A variadic alias template that resolves to its first argument.
178 template<typename _Tp, typename...>
179 using __first_t = _Tp;
181 // These are deliberately not defined.
182 template<typename... _Bn>
183 auto __or_fn(int) -> __first_t<false_type,
184 __enable_if_t<!bool(_Bn::value)>...>;
186 template<typename... _Bn>
187 auto __or_fn(...) -> true_type;
189 template<typename... _Bn>
190 auto __and_fn(int) -> __first_t<true_type,
191 __enable_if_t<bool(_Bn::value)>...>;
193 template<typename... _Bn>
194 auto __and_fn(...) -> false_type;
195 } // namespace detail
197 // Like C++17 std::dis/conjunction, but usable in C++11 and resolves
198 // to either true_type or false_type which allows for a more efficient
199 // implementation that avoids recursive class template instantiation.
200 template<typename... _Bn>
202 : decltype(__detail::__or_fn<_Bn...>(0))
205 template<typename... _Bn>
207 : decltype(__detail::__and_fn<_Bn...>(0))
210 template<typename _Pp>
212 : __bool_constant<!bool(_Pp::value)>
216 #ifdef __cpp_lib_logical_traits // C++ >= 17
218 /// @cond undocumented
219 template<typename... _Bn>
220 inline constexpr bool __or_v = __or_<_Bn...>::value;
221 template<typename... _Bn>
222 inline constexpr bool __and_v = __and_<_Bn...>::value;
226 template<typename /* = void */, typename _B1, typename... _Bn>
227 struct __disjunction_impl
228 { using type = _B1; };
230 template<typename _B1, typename _B2, typename... _Bn>
231 struct __disjunction_impl<__enable_if_t<!bool(_B1::value)>, _B1, _B2, _Bn...>
232 { using type = typename __disjunction_impl<void, _B2, _Bn...>::type; };
234 template<typename /* = void */, typename _B1, typename... _Bn>
235 struct __conjunction_impl
236 { using type = _B1; };
238 template<typename _B1, typename _B2, typename... _Bn>
239 struct __conjunction_impl<__enable_if_t<bool(_B1::value)>, _B1, _B2, _Bn...>
240 { using type = typename __conjunction_impl<void, _B2, _Bn...>::type; };
241 } // namespace __detail
244 template<typename... _Bn>
246 : __detail::__conjunction_impl<void, _Bn...>::type
254 template<typename... _Bn>
256 : __detail::__disjunction_impl<void, _Bn...>::type
264 template<typename _Pp>
269 /** @ingroup variable_templates
272 template<typename... _Bn>
273 inline constexpr bool conjunction_v = conjunction<_Bn...>::value;
275 template<typename... _Bn>
276 inline constexpr bool disjunction_v = disjunction<_Bn...>::value;
278 template<typename _Pp>
279 inline constexpr bool negation_v = negation<_Pp>::value;
282 #endif // __cpp_lib_logical_traits
284 // Forward declarations
292 /// @cond undocumented
294 struct __is_array_unknown_bounds;
296 // An object type which is not an unbounded array.
297 // It might still be an incomplete type, but if this is false_type
298 // then we can be certain it's not a complete object type.
299 template<typename _Tp>
300 using __maybe_complete_object_type
301 = __and_<is_object<_Tp>, __not_<__is_array_unknown_bounds<_Tp>>>;
303 // Helper functions that return false_type for incomplete classes,
304 // incomplete unions and arrays of known bound from those.
306 // More specialized overload for complete object types (returning true_type).
307 template<typename _Tp,
308 typename = __enable_if_t<__maybe_complete_object_type<_Tp>::value>,
309 size_t = sizeof(_Tp)>
311 __is_complete_or_unbounded(__type_identity<_Tp>)
314 // Less specialized overload for reference and unknown-bound array types
315 // (returning true_type), and incomplete types (returning false_type).
316 template<typename _TypeIdentity,
317 typename _NestedType = typename _TypeIdentity::type>
318 constexpr typename __not_<__maybe_complete_object_type<_NestedType>>::type
319 __is_complete_or_unbounded(_TypeIdentity)
322 // __remove_cv_t (std::remove_cv_t for C++11).
323 template<typename _Tp>
324 using __remove_cv_t = typename remove_cv<_Tp>::type;
327 // Primary type categories.
330 template<typename _Tp>
332 : public false_type { };
336 : public true_type { };
339 struct is_void<const void>
340 : public true_type { };
343 struct is_void<volatile void>
344 : public true_type { };
347 struct is_void<const volatile void>
348 : public true_type { };
350 /// @cond undocumented
352 // Every integral type is either one of the character types, one of the
353 // signed integer types, one of the unsigned integer types, or bool,
354 // or a cv-qualified version of one of those types ([basic.fundamental]).
355 // For now we only need to distinguish the signed/unsigned integer types.
356 enum class _Integer_kind { _None, _Signed, _Unsigned };
359 struct __is_integral_helper
361 { static constexpr auto _S_kind = _Integer_kind::_None; };
364 struct __is_integral_helper<bool>
366 { static constexpr auto _S_kind = _Integer_kind::_None; };
369 struct __is_integral_helper<char>
371 { static constexpr auto _S_kind = _Integer_kind::_None; };
374 struct __is_integral_helper<signed char>
376 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
379 struct __is_integral_helper<unsigned char>
381 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
383 // We want is_integral<wchar_t> to be true (and make_signed/unsigned to work)
384 // even when libc doesn't provide working <wchar.h> and related functions,
385 // so don't check _GLIBCXX_USE_WCHAR_T here.
387 struct __is_integral_helper<wchar_t>
389 { static constexpr auto _S_kind = _Integer_kind::_None; };
391 #ifdef _GLIBCXX_USE_CHAR8_T
393 struct __is_integral_helper<char8_t>
395 { static constexpr auto _S_kind = _Integer_kind::_None; };
399 struct __is_integral_helper<char16_t>
401 { static constexpr auto _S_kind = _Integer_kind::_None; };
404 struct __is_integral_helper<char32_t>
406 { static constexpr auto _S_kind = _Integer_kind::_None; };
409 struct __is_integral_helper<short>
411 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
414 struct __is_integral_helper<unsigned short>
416 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
419 struct __is_integral_helper<int>
421 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
424 struct __is_integral_helper<unsigned int>
426 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
429 struct __is_integral_helper<long>
431 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
434 struct __is_integral_helper<unsigned long>
436 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
439 struct __is_integral_helper<long long>
441 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
444 struct __is_integral_helper<unsigned long long>
446 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
448 // Conditionalizing on __STRICT_ANSI__ here will break any port that
449 // uses one of these types for size_t.
450 #if defined(__GLIBCXX_TYPE_INT_N_0)
453 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
455 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
459 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
461 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
463 #if defined(__GLIBCXX_TYPE_INT_N_1)
466 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
468 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
472 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
474 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
476 #if defined(__GLIBCXX_TYPE_INT_N_2)
479 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
481 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
485 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
487 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
489 #if defined(__GLIBCXX_TYPE_INT_N_3)
492 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
494 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
498 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
500 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
503 #if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
506 struct __is_integral_helper<__int128>
508 { static constexpr auto _S_kind = _Integer_kind::_Signed; };
512 struct __is_integral_helper<unsigned __int128>
514 { static constexpr auto _S_kind = _Integer_kind::_Unsigned; };
517 // Check if a type is one of the signed integer types.
518 template<typename _Tp>
519 using __is_signed_integer
520 = __bool_constant<__is_integral_helper<_Tp>::_S_kind
521 == _Integer_kind::_Signed>;
523 // Check if a type is one of the unsigned integer types.
524 template<typename _Tp>
525 using __is_unsigned_integer
526 = __bool_constant<__is_integral_helper<_Tp>::_S_kind
527 == _Integer_kind::_Unsigned>;
529 // Check if a type is one of the signed or unsigned integer types.
530 // i.e. an integral type except bool, char, wchar_t, and charN_t.
531 template<typename _Tp>
532 using __is_signed_or_unsigned_integer
533 = __bool_constant<__is_integral_helper<_Tp>::_S_kind
534 != _Integer_kind::_None>;
539 template<typename _Tp>
541 : public __is_integral_helper<__remove_cv_t<_Tp>>::type
544 /// @cond undocumented
546 struct __is_floating_point_helper
547 : public false_type { };
550 struct __is_floating_point_helper<float>
551 : public true_type { };
554 struct __is_floating_point_helper<double>
555 : public true_type { };
558 struct __is_floating_point_helper<long double>
559 : public true_type { };
561 #ifdef __STDCPP_FLOAT16_T__
563 struct __is_floating_point_helper<_Float16>
564 : public true_type { };
567 #ifdef __STDCPP_FLOAT32_T__
569 struct __is_floating_point_helper<_Float32>
570 : public true_type { };
573 #ifdef __STDCPP_FLOAT64_T__
575 struct __is_floating_point_helper<_Float64>
576 : public true_type { };
579 #ifdef __STDCPP_FLOAT128_T__
581 struct __is_floating_point_helper<_Float128>
582 : public true_type { };
585 #ifdef __STDCPP_BFLOAT16_T__
587 struct __is_floating_point_helper<__gnu_cxx::__bfloat16_t>
588 : public true_type { };
591 #ifdef _GLIBCXX_USE_FLOAT128
593 struct __is_floating_point_helper<__float128>
594 : public true_type { };
598 /// is_floating_point
599 template<typename _Tp>
600 struct is_floating_point
601 : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type
605 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
606 template<typename _Tp>
608 : public __bool_constant<__is_array(_Tp)>
613 : public false_type { };
615 template<typename _Tp, std::size_t _Size>
616 struct is_array<_Tp[_Size]>
617 : public true_type { };
619 template<typename _Tp>
620 struct is_array<_Tp[]>
621 : public true_type { };
625 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
626 template<typename _Tp>
628 : public __bool_constant<__is_pointer(_Tp)>
631 template<typename _Tp>
633 : public false_type { };
635 template<typename _Tp>
636 struct is_pointer<_Tp*>
637 : public true_type { };
639 template<typename _Tp>
640 struct is_pointer<_Tp* const>
641 : public true_type { };
643 template<typename _Tp>
644 struct is_pointer<_Tp* volatile>
645 : public true_type { };
647 template<typename _Tp>
648 struct is_pointer<_Tp* const volatile>
649 : public true_type { };
652 /// is_lvalue_reference
654 struct is_lvalue_reference
655 : public false_type { };
657 template<typename _Tp>
658 struct is_lvalue_reference<_Tp&>
659 : public true_type { };
661 /// is_rvalue_reference
663 struct is_rvalue_reference
664 : public false_type { };
666 template<typename _Tp>
667 struct is_rvalue_reference<_Tp&&>
668 : public true_type { };
670 /// is_member_object_pointer
671 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
672 template<typename _Tp>
673 struct is_member_object_pointer
674 : public __bool_constant<__is_member_object_pointer(_Tp)>
677 template<typename _Tp>
681 struct __is_member_object_pointer_helper
682 : public false_type { };
684 template<typename _Tp, typename _Cp>
685 struct __is_member_object_pointer_helper<_Tp _Cp::*>
686 : public __not_<is_function<_Tp>>::type { };
689 template<typename _Tp>
690 struct is_member_object_pointer
691 : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type
695 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
696 /// is_member_function_pointer
697 template<typename _Tp>
698 struct is_member_function_pointer
699 : public __bool_constant<__is_member_function_pointer(_Tp)>
702 template<typename _Tp>
706 struct __is_member_function_pointer_helper
707 : public false_type { };
709 template<typename _Tp, typename _Cp>
710 struct __is_member_function_pointer_helper<_Tp _Cp::*>
711 : public is_function<_Tp>::type { };
713 /// is_member_function_pointer
714 template<typename _Tp>
715 struct is_member_function_pointer
716 : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type
721 template<typename _Tp>
723 : public __bool_constant<__is_enum(_Tp)>
727 template<typename _Tp>
729 : public __bool_constant<__is_union(_Tp)>
733 template<typename _Tp>
735 : public __bool_constant<__is_class(_Tp)>
739 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
740 template<typename _Tp>
742 : public __bool_constant<__is_function(_Tp)>
745 template<typename _Tp>
747 : public __bool_constant<!is_const<const _Tp>::value> { };
749 template<typename _Tp>
750 struct is_function<_Tp&>
751 : public false_type { };
753 template<typename _Tp>
754 struct is_function<_Tp&&>
755 : public false_type { };
758 #if __cpp_impl_reflection >= 202506L // C++ >= 26
760 template<typename _Tp>
762 : public false_type { };
765 struct is_reflection<decltype(^^int)>
766 : public true_type { };
769 struct is_reflection<const decltype(^^int)>
770 : public true_type { };
773 struct is_reflection<volatile decltype(^^int)>
774 : public true_type { };
777 struct is_reflection<const volatile decltype(^^int)>
778 : public true_type { };
781 #ifdef __cpp_lib_is_null_pointer // C++ >= 11
782 /// is_null_pointer (LWG 2247).
783 template<typename _Tp>
784 struct is_null_pointer
785 : public false_type { };
788 struct is_null_pointer<std::nullptr_t>
789 : public true_type { };
792 struct is_null_pointer<const std::nullptr_t>
793 : public true_type { };
796 struct is_null_pointer<volatile std::nullptr_t>
797 : public true_type { };
800 struct is_null_pointer<const volatile std::nullptr_t>
801 : public true_type { };
803 /// __is_nullptr_t (deprecated extension).
804 /// @deprecated Non-standard. Use `is_null_pointer` instead.
805 template<typename _Tp>
806 struct __is_nullptr_t
807 : public is_null_pointer<_Tp>
808 { } _GLIBCXX_DEPRECATED_SUGGEST("std::is_null_pointer");
809 #endif // __cpp_lib_is_null_pointer
811 // Composite type categories.
814 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
815 template<typename _Tp>
817 : public __bool_constant<__is_reference(_Tp)>
820 template<typename _Tp>
825 template<typename _Tp>
826 struct is_reference<_Tp&>
830 template<typename _Tp>
831 struct is_reference<_Tp&&>
837 template<typename _Tp>
839 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
843 template<typename _Tp>
844 struct is_fundamental
845 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
847 #if __cpp_impl_reflection >= 202506L
854 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
855 template<typename _Tp>
857 : public __bool_constant<__is_object(_Tp)>
860 template<typename _Tp>
862 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
868 struct is_member_pointer;
871 template<typename _Tp>
873 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
874 is_member_pointer<_Tp>, is_null_pointer<_Tp>
875 #if __cpp_impl_reflection >= 202506L
882 template<typename _Tp>
884 : public __bool_constant<!is_fundamental<_Tp>::value> { };
886 /// is_member_pointer
887 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
888 template<typename _Tp>
889 struct is_member_pointer
890 : public __bool_constant<__is_member_pointer(_Tp)>
893 /// @cond undocumented
894 template<typename _Tp>
895 struct __is_member_pointer_helper
896 : public false_type { };
898 template<typename _Tp, typename _Cp>
899 struct __is_member_pointer_helper<_Tp _Cp::*>
900 : public true_type { };
903 template<typename _Tp>
904 struct is_member_pointer
905 : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type
909 template<typename, typename>
912 /// @cond undocumented
913 template<typename _Tp, typename... _Types>
914 using __is_one_of = __or_<is_same<_Tp, _Types>...>;
916 // __void_t (std::void_t for C++11)
917 template<typename...> using __void_t = void;
923 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const)
924 template<typename _Tp>
926 : public __bool_constant<__is_const(_Tp)>
931 : public false_type { };
933 template<typename _Tp>
934 struct is_const<_Tp const>
935 : public true_type { };
939 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile)
940 template<typename _Tp>
942 : public __bool_constant<__is_volatile(_Tp)>
947 : public false_type { };
949 template<typename _Tp>
950 struct is_volatile<_Tp volatile>
951 : public true_type { };
955 * @deprecated Deprecated in C++26.
956 * Use a combination of one or more more specialized type traits instead,
957 * such as `is_trivially_default_constructible`,
958 * `is_trivially_copy_constructible`, `is_trivially_copy_assignable`,
959 * etc., depending on the exact check(s) needed.
961 template<typename _Tp>
963 _GLIBCXX26_DEPRECATED_SUGGEST("is_trivially_default_constructible && is_trivially_copyable")
965 : public __bool_constant<__is_trivial(_Tp)>
967 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
968 "template argument must be a complete class or an unbounded array");
971 /// is_trivially_copyable
972 template<typename _Tp>
973 struct is_trivially_copyable
974 : public __bool_constant<__is_trivially_copyable(_Tp)>
976 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
977 "template argument must be a complete class or an unbounded array");
980 /// is_standard_layout
981 template<typename _Tp>
982 struct is_standard_layout
983 : public __bool_constant<__is_standard_layout(_Tp)>
985 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
986 "template argument must be a complete class or an unbounded array");
990 * @deprecated Deprecated in C++20.
991 * Use `is_standard_layout && is_trivial` instead.
993 // Could use is_standard_layout && is_trivial instead of the builtin.
994 template<typename _Tp>
996 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout && is_trivial")
998 : public __bool_constant<__is_pod(_Tp)>
1000 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1001 "template argument must be a complete class or an unbounded array");
1005 * @deprecated Deprecated in C++17, removed in C++20.
1006 * The idea of a literal type isn't useful.
1008 template<typename _Tp>
1010 _GLIBCXX17_DEPRECATED
1012 : public __bool_constant<__is_literal_type(_Tp)>
1014 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1015 "template argument must be a complete class or an unbounded array");
1019 template<typename _Tp>
1021 : public __bool_constant<__is_empty(_Tp)>
1025 template<typename _Tp>
1026 struct is_polymorphic
1027 : public __bool_constant<__is_polymorphic(_Tp)>
1030 #ifdef __cpp_lib_is_final // C++ >= 14
1033 template<typename _Tp>
1035 : public __bool_constant<__is_final(_Tp)>
1040 template<typename _Tp>
1042 : public __bool_constant<__is_abstract(_Tp)>
1045 /// @cond undocumented
1046 template<typename _Tp,
1047 bool = is_arithmetic<_Tp>::value>
1048 struct __is_signed_helper
1049 : public false_type { };
1051 template<typename _Tp>
1052 struct __is_signed_helper<_Tp, true>
1053 : public __bool_constant<_Tp(-1) < _Tp(0)>
1058 template<typename _Tp>
1060 : public __is_signed_helper<_Tp>::type
1064 template<typename _Tp>
1066 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
1069 /// @cond undocumented
1070 template<typename _Tp, typename _Up = _Tp&&>
1074 template<typename _Tp>
1079 template<typename _Tp>
1080 auto declval() noexcept -> decltype(__declval<_Tp>(0));
1083 struct remove_all_extents;
1085 /// @cond undocumented
1086 template<typename _Tp>
1087 struct __is_array_known_bounds
1091 template<typename _Tp, size_t _Size>
1092 struct __is_array_known_bounds<_Tp[_Size]>
1096 template<typename _Tp>
1097 struct __is_array_unknown_bounds
1101 template<typename _Tp>
1102 struct __is_array_unknown_bounds<_Tp[]>
1107 // Destructible and constructible type properties.
1109 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_destructible)
1111 template<typename _Tp>
1112 struct is_destructible
1113 : public __bool_constant<__is_destructible(_Tp)>
1116 /// @cond undocumented
1118 // In N3290 is_destructible does not say anything about function
1119 // types and abstract types, see LWG 2049. This implementation
1120 // describes function types as non-destructible and all complete
1121 // object types as destructible, iff the explicit destructor
1122 // call expression is wellformed.
1123 struct __do_is_destructible_impl
1125 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
1126 static true_type __test(int);
1129 static false_type __test(...);
1132 template<typename _Tp>
1133 struct __is_destructible_impl
1134 : public __do_is_destructible_impl
1136 using type = decltype(__test<_Tp>(0));
1139 template<typename _Tp,
1140 bool = __or_<is_void<_Tp>,
1141 __is_array_unknown_bounds<_Tp>,
1142 is_function<_Tp>>::value,
1143 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1144 struct __is_destructible_safe;
1146 template<typename _Tp>
1147 struct __is_destructible_safe<_Tp, false, false>
1148 : public __is_destructible_impl<typename
1149 remove_all_extents<_Tp>::type>::type
1152 template<typename _Tp>
1153 struct __is_destructible_safe<_Tp, true, false>
1154 : public false_type { };
1156 template<typename _Tp>
1157 struct __is_destructible_safe<_Tp, false, true>
1158 : public true_type { };
1162 template<typename _Tp>
1163 struct is_destructible
1164 : public __is_destructible_safe<_Tp>::type
1166 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1167 "template argument must be a complete class or an unbounded array");
1171 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_destructible)
1172 /// is_nothrow_destructible
1173 template<typename _Tp>
1174 struct is_nothrow_destructible
1175 : public __bool_constant<__is_nothrow_destructible(_Tp)>
1178 /// @cond undocumented
1180 // is_nothrow_destructible requires that is_destructible is
1181 // satisfied as well. We realize that by mimicing the
1182 // implementation of is_destructible but refer to noexcept(expr)
1183 // instead of decltype(expr).
1184 struct __do_is_nt_destructible_impl
1186 template<typename _Tp>
1187 static __bool_constant<noexcept(declval<_Tp&>().~_Tp())>
1191 static false_type __test(...);
1194 template<typename _Tp>
1195 struct __is_nt_destructible_impl
1196 : public __do_is_nt_destructible_impl
1198 using type = decltype(__test<_Tp>(0));
1201 template<typename _Tp,
1202 bool = __or_<is_void<_Tp>,
1203 __is_array_unknown_bounds<_Tp>,
1204 is_function<_Tp>>::value,
1205 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1206 struct __is_nt_destructible_safe;
1208 template<typename _Tp>
1209 struct __is_nt_destructible_safe<_Tp, false, false>
1210 : public __is_nt_destructible_impl<typename
1211 remove_all_extents<_Tp>::type>::type
1214 template<typename _Tp>
1215 struct __is_nt_destructible_safe<_Tp, true, false>
1216 : public false_type { };
1218 template<typename _Tp>
1219 struct __is_nt_destructible_safe<_Tp, false, true>
1220 : public true_type { };
1223 /// is_nothrow_destructible
1224 template<typename _Tp>
1225 struct is_nothrow_destructible
1226 : public __is_nt_destructible_safe<_Tp>::type
1228 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1229 "template argument must be a complete class or an unbounded array");
1233 /// @cond undocumented
1234 template<typename _Tp, typename... _Args>
1235 using __is_constructible_impl
1236 = __bool_constant<__is_constructible(_Tp, _Args...)>;
1239 /// is_constructible
1240 template<typename _Tp, typename... _Args>
1241 struct is_constructible
1242 : public __is_constructible_impl<_Tp, _Args...>
1244 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1245 "template argument must be a complete class or an unbounded array");
1248 /// is_default_constructible
1249 template<typename _Tp>
1250 struct is_default_constructible
1251 : public __is_constructible_impl<_Tp>
1253 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1254 "template argument must be a complete class or an unbounded array");
1257 /// @cond undocumented
1258 #if _GLIBCXX_USE_BUILTIN_TRAIT(__add_lvalue_reference)
1259 template<typename _Tp>
1260 using __add_lval_ref_t = __add_lvalue_reference(_Tp);
1262 template<typename _Tp, typename = void>
1263 struct __add_lvalue_reference_helper
1264 { using type = _Tp; };
1266 template<typename _Tp>
1267 struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>>
1268 { using type = _Tp&; };
1270 template<typename _Tp>
1271 using __add_lval_ref_t = typename __add_lvalue_reference_helper<_Tp>::type;
1275 /// is_copy_constructible
1276 template<typename _Tp>
1277 struct is_copy_constructible
1278 : public __is_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1280 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1281 "template argument must be a complete class or an unbounded array");
1284 /// @cond undocumented
1285 #if _GLIBCXX_USE_BUILTIN_TRAIT(__add_rvalue_reference)
1286 template<typename _Tp>
1287 using __add_rval_ref_t = __add_rvalue_reference(_Tp);
1289 template<typename _Tp, typename = void>
1290 struct __add_rvalue_reference_helper
1291 { using type = _Tp; };
1293 template<typename _Tp>
1294 struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>>
1295 { using type = _Tp&&; };
1297 template<typename _Tp>
1298 using __add_rval_ref_t = typename __add_rvalue_reference_helper<_Tp>::type;
1302 /// is_move_constructible
1303 template<typename _Tp>
1304 struct is_move_constructible
1305 : public __is_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1307 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1308 "template argument must be a complete class or an unbounded array");
1311 /// @cond undocumented
1312 template<typename _Tp, typename... _Args>
1313 using __is_nothrow_constructible_impl
1314 = __bool_constant<__is_nothrow_constructible(_Tp, _Args...)>;
1317 /// is_nothrow_constructible
1318 template<typename _Tp, typename... _Args>
1319 struct is_nothrow_constructible
1320 : public __is_nothrow_constructible_impl<_Tp, _Args...>
1322 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1323 "template argument must be a complete class or an unbounded array");
1326 /// is_nothrow_default_constructible
1327 template<typename _Tp>
1328 struct is_nothrow_default_constructible
1329 : public __is_nothrow_constructible_impl<_Tp>
1331 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1332 "template argument must be a complete class or an unbounded array");
1335 /// is_nothrow_copy_constructible
1336 template<typename _Tp>
1337 struct is_nothrow_copy_constructible
1338 : public __is_nothrow_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1340 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1341 "template argument must be a complete class or an unbounded array");
1344 /// is_nothrow_move_constructible
1345 template<typename _Tp>
1346 struct is_nothrow_move_constructible
1347 : public __is_nothrow_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1349 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1350 "template argument must be a complete class or an unbounded array");
1353 /// @cond undocumented
1354 template<typename _Tp, typename _Up>
1355 using __is_assignable_impl = __bool_constant<__is_assignable(_Tp, _Up)>;
1359 template<typename _Tp, typename _Up>
1360 struct is_assignable
1361 : public __is_assignable_impl<_Tp, _Up>
1363 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1364 "template argument must be a complete class or an unbounded array");
1367 /// is_copy_assignable
1368 template<typename _Tp>
1369 struct is_copy_assignable
1370 : public __is_assignable_impl<__add_lval_ref_t<_Tp>,
1371 __add_lval_ref_t<const _Tp>>
1373 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1374 "template argument must be a complete class or an unbounded array");
1377 /// is_move_assignable
1378 template<typename _Tp>
1379 struct is_move_assignable
1380 : public __is_assignable_impl<__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>>
1382 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1383 "template argument must be a complete class or an unbounded array");
1386 /// @cond undocumented
1387 template<typename _Tp, typename _Up>
1388 using __is_nothrow_assignable_impl
1389 = __bool_constant<__is_nothrow_assignable(_Tp, _Up)>;
1392 /// is_nothrow_assignable
1393 template<typename _Tp, typename _Up>
1394 struct is_nothrow_assignable
1395 : public __is_nothrow_assignable_impl<_Tp, _Up>
1397 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1398 "template argument must be a complete class or an unbounded array");
1401 /// is_nothrow_copy_assignable
1402 template<typename _Tp>
1403 struct is_nothrow_copy_assignable
1404 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1405 __add_lval_ref_t<const _Tp>>
1407 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1408 "template argument must be a complete class or an unbounded array");
1411 /// is_nothrow_move_assignable
1412 template<typename _Tp>
1413 struct is_nothrow_move_assignable
1414 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1415 __add_rval_ref_t<_Tp>>
1417 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1418 "template argument must be a complete class or an unbounded array");
1421 /// @cond undocumented
1422 template<typename _Tp, typename... _Args>
1423 using __is_trivially_constructible_impl
1424 = __bool_constant<__is_trivially_constructible(_Tp, _Args...)>;
1427 /// is_trivially_constructible
1428 template<typename _Tp, typename... _Args>
1429 struct is_trivially_constructible
1430 : public __is_trivially_constructible_impl<_Tp, _Args...>
1432 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1433 "template argument must be a complete class or an unbounded array");
1436 /// is_trivially_default_constructible
1437 template<typename _Tp>
1438 struct is_trivially_default_constructible
1439 : public __is_trivially_constructible_impl<_Tp>
1441 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1442 "template argument must be a complete class or an unbounded array");
1445 #if __cpp_variable_templates && __cpp_concepts
1446 template<typename _Tp>
1447 constexpr bool __is_implicitly_default_constructible_v
1448 = requires (void(&__f)(_Tp)) { __f({}); };
1450 template<typename _Tp>
1451 struct __is_implicitly_default_constructible
1452 : __bool_constant<__is_implicitly_default_constructible_v<_Tp>>
1455 struct __do_is_implicitly_default_constructible_impl
1457 template <typename _Tp>
1458 static void __helper(const _Tp&);
1460 template <typename _Tp>
1461 static true_type __test(const _Tp&,
1462 decltype(__helper<const _Tp&>({}))* = 0);
1464 static false_type __test(...);
1467 template<typename _Tp>
1468 struct __is_implicitly_default_constructible_impl
1469 : public __do_is_implicitly_default_constructible_impl
1471 using type = decltype(__test(declval<_Tp>()));
1474 template<typename _Tp>
1475 struct __is_implicitly_default_constructible_safe
1476 : public __is_implicitly_default_constructible_impl<_Tp>::type
1479 template <typename _Tp>
1480 struct __is_implicitly_default_constructible
1481 : public __and_<__is_constructible_impl<_Tp>,
1482 __is_implicitly_default_constructible_safe<_Tp>>::type
1486 /// is_trivially_copy_constructible
1487 template<typename _Tp>
1488 struct is_trivially_copy_constructible
1489 : public __is_trivially_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1491 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1492 "template argument must be a complete class or an unbounded array");
1495 /// is_trivially_move_constructible
1496 template<typename _Tp>
1497 struct is_trivially_move_constructible
1498 : public __is_trivially_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1500 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1501 "template argument must be a complete class or an unbounded array");
1504 /// @cond undocumented
1505 template<typename _Tp, typename _Up>
1506 using __is_trivially_assignable_impl
1507 = __bool_constant<__is_trivially_assignable(_Tp, _Up)>;
1510 /// is_trivially_assignable
1511 template<typename _Tp, typename _Up>
1512 struct is_trivially_assignable
1513 : public __is_trivially_assignable_impl<_Tp, _Up>
1515 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1516 "template argument must be a complete class or an unbounded array");
1519 /// is_trivially_copy_assignable
1520 template<typename _Tp>
1521 struct is_trivially_copy_assignable
1522 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1523 __add_lval_ref_t<const _Tp>>
1525 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1526 "template argument must be a complete class or an unbounded array");
1529 /// is_trivially_move_assignable
1530 template<typename _Tp>
1531 struct is_trivially_move_assignable
1532 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1533 __add_rval_ref_t<_Tp>>
1535 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1536 "template argument must be a complete class or an unbounded array");
1539 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_trivially_destructible)
1540 /// is_trivially_destructible
1541 template<typename _Tp>
1542 struct is_trivially_destructible
1543 : public __bool_constant<__is_trivially_destructible(_Tp)>
1546 /// is_trivially_destructible
1547 template<typename _Tp>
1548 struct is_trivially_destructible
1549 : public __and_<__is_destructible_safe<_Tp>,
1550 __bool_constant<__has_trivial_destructor(_Tp)>>::type
1552 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1553 "template argument must be a complete class or an unbounded array");
1557 /// has_virtual_destructor
1558 template<typename _Tp>
1559 struct has_virtual_destructor
1560 : public __bool_constant<__has_virtual_destructor(_Tp)>
1562 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1563 "template argument must be a complete class or an unbounded array");
1567 // type property queries.
1570 template<typename _Tp>
1572 : public integral_constant<std::size_t, alignof(_Tp)>
1574 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1575 "template argument must be a complete class or an unbounded array");
1579 #if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) \
1580 && (!defined(__clang__) || __clang_major__ >= 20) // PR118559
1581 template<typename _Tp>
1583 : public integral_constant<std::size_t, __array_rank(_Tp)> { };
1587 : public integral_constant<std::size_t, 0> { };
1589 template<typename _Tp, std::size_t _Size>
1590 struct rank<_Tp[_Size]>
1591 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1593 template<typename _Tp>
1595 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1599 template<typename, unsigned _Uint = 0>
1601 : public integral_constant<size_t, 0> { };
1603 template<typename _Tp, size_t _Size>
1604 struct extent<_Tp[_Size], 0>
1605 : public integral_constant<size_t, _Size> { };
1607 template<typename _Tp, unsigned _Uint, size_t _Size>
1608 struct extent<_Tp[_Size], _Uint>
1609 : public extent<_Tp, _Uint - 1>::type { };
1611 template<typename _Tp>
1612 struct extent<_Tp[], 0>
1613 : public integral_constant<size_t, 0> { };
1615 template<typename _Tp, unsigned _Uint>
1616 struct extent<_Tp[], _Uint>
1617 : public extent<_Tp, _Uint - 1>::type { };
1623 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
1624 template<typename _Tp, typename _Up>
1626 : public __bool_constant<__is_same(_Tp, _Up)>
1629 template<typename _Tp, typename _Up>
1634 template<typename _Tp>
1635 struct is_same<_Tp, _Tp>
1641 template<typename _Base, typename _Derived>
1643 : public __bool_constant<__is_base_of(_Base, _Derived)>
1646 #ifdef __cpp_lib_is_virtual_base_of // C++ >= 26
1647 /// is_virtual_base_of
1649 template<typename _Base, typename _Derived>
1650 struct is_virtual_base_of
1651 : public bool_constant<__builtin_is_virtual_base_of(_Base, _Derived)>
1655 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
1656 template<typename _From, typename _To>
1657 struct is_convertible
1658 : public __bool_constant<__is_convertible(_From, _To)>
1661 template<typename _From, typename _To,
1662 bool = __or_<is_void<_From>, is_function<_To>,
1663 is_array<_To>>::value>
1664 struct __is_convertible_helper
1666 using type = typename is_void<_To>::type;
1669 #pragma GCC diagnostic push
1670 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1671 template<typename _From, typename _To>
1672 class __is_convertible_helper<_From, _To, false>
1674 template<typename _To1>
1675 static void __test_aux(_To1) noexcept;
1677 template<typename _From1, typename _To1,
1678 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1682 template<typename, typename>
1687 using type = decltype(__test<_From, _To>(0));
1689 #pragma GCC diagnostic pop
1692 template<typename _From, typename _To>
1693 struct is_convertible
1694 : public __is_convertible_helper<_From, _To>::type
1698 // helper trait for unique_ptr<T[]>, shared_ptr<T[]>, and span<T, N>
1699 template<typename _ToElementType, typename _FromElementType>
1700 using __is_array_convertible
1701 = is_convertible<_FromElementType(*)[], _ToElementType(*)[]>;
1703 #ifdef __cpp_lib_is_nothrow_convertible // C++ >= 20
1705 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_convertible)
1706 /// is_nothrow_convertible_v
1707 template<typename _From, typename _To>
1708 inline constexpr bool is_nothrow_convertible_v
1709 = __is_nothrow_convertible(_From, _To);
1711 /// is_nothrow_convertible
1712 template<typename _From, typename _To>
1713 struct is_nothrow_convertible
1714 : public bool_constant<is_nothrow_convertible_v<_From, _To>>
1717 template<typename _From, typename _To,
1718 bool = __or_<is_void<_From>, is_function<_To>,
1719 is_array<_To>>::value>
1720 struct __is_nt_convertible_helper
1724 #pragma GCC diagnostic push
1725 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1726 template<typename _From, typename _To>
1727 class __is_nt_convertible_helper<_From, _To, false>
1729 template<typename _To1>
1730 static void __test_aux(_To1) noexcept;
1732 template<typename _From1, typename _To1>
1734 __bool_constant<noexcept(__test_aux<_To1>(std::declval<_From1>()))>
1737 template<typename, typename>
1742 using type = decltype(__test<_From, _To>(0));
1744 #pragma GCC diagnostic pop
1746 /// is_nothrow_convertible
1747 template<typename _From, typename _To>
1748 struct is_nothrow_convertible
1749 : public __is_nt_convertible_helper<_From, _To>::type
1752 /// is_nothrow_convertible_v
1753 template<typename _From, typename _To>
1754 inline constexpr bool is_nothrow_convertible_v
1755 = is_nothrow_convertible<_From, _To>::value;
1757 #endif // __cpp_lib_is_nothrow_convertible
1759 #pragma GCC diagnostic push
1760 #pragma GCC diagnostic ignored "-Wc++14-extensions" // for variable templates
1761 template<typename _Tp, typename... _Args>
1762 struct __is_nothrow_new_constructible_impl
1764 noexcept(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))
1768 template<typename _Tp, typename... _Args>
1769 _GLIBCXX17_INLINE constexpr bool __is_nothrow_new_constructible
1770 = __and_<is_constructible<_Tp, _Args...>,
1771 __is_nothrow_new_constructible_impl<_Tp, _Args...>>::value;
1772 #pragma GCC diagnostic pop
1774 // Const-volatile modifications.
1777 template<typename _Tp>
1779 { using type = _Tp; };
1781 template<typename _Tp>
1782 struct remove_const<_Tp const>
1783 { using type = _Tp; };
1786 template<typename _Tp>
1787 struct remove_volatile
1788 { using type = _Tp; };
1790 template<typename _Tp>
1791 struct remove_volatile<_Tp volatile>
1792 { using type = _Tp; };
1795 #if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cv)
1796 template<typename _Tp>
1798 { using type = __remove_cv(_Tp); };
1800 template<typename _Tp>
1802 { using type = _Tp; };
1804 template<typename _Tp>
1805 struct remove_cv<const _Tp>
1806 { using type = _Tp; };
1808 template<typename _Tp>
1809 struct remove_cv<volatile _Tp>
1810 { using type = _Tp; };
1812 template<typename _Tp>
1813 struct remove_cv<const volatile _Tp>
1814 { using type = _Tp; };
1818 template<typename _Tp>
1820 { using type = _Tp const; };
1823 template<typename _Tp>
1825 { using type = _Tp volatile; };
1828 template<typename _Tp>
1830 { using type = _Tp const volatile; };
1832 #ifdef __cpp_lib_transformation_trait_aliases // C++ >= 14
1833 /// Alias template for remove_const
1834 template<typename _Tp>
1835 using remove_const_t = typename remove_const<_Tp>::type;
1837 /// Alias template for remove_volatile
1838 template<typename _Tp>
1839 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1841 /// Alias template for remove_cv
1842 template<typename _Tp>
1843 using remove_cv_t = typename remove_cv<_Tp>::type;
1845 /// Alias template for add_const
1846 template<typename _Tp>
1847 using add_const_t = typename add_const<_Tp>::type;
1849 /// Alias template for add_volatile
1850 template<typename _Tp>
1851 using add_volatile_t = typename add_volatile<_Tp>::type;
1853 /// Alias template for add_cv
1854 template<typename _Tp>
1855 using add_cv_t = typename add_cv<_Tp>::type;
1858 // Reference transformations.
1860 /// remove_reference
1861 #if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_reference)
1862 template<typename _Tp>
1863 struct remove_reference
1864 { using type = __remove_reference(_Tp); };
1866 template<typename _Tp>
1867 struct remove_reference
1868 { using type = _Tp; };
1870 template<typename _Tp>
1871 struct remove_reference<_Tp&>
1872 { using type = _Tp; };
1874 template<typename _Tp>
1875 struct remove_reference<_Tp&&>
1876 { using type = _Tp; };
1879 /// add_lvalue_reference
1880 template<typename _Tp>
1881 struct add_lvalue_reference
1882 { using type = __add_lval_ref_t<_Tp>; };
1884 /// add_rvalue_reference
1885 template<typename _Tp>
1886 struct add_rvalue_reference
1887 { using type = __add_rval_ref_t<_Tp>; };
1889 #if __cplusplus > 201103L
1890 /// Alias template for remove_reference
1891 template<typename _Tp>
1892 using remove_reference_t = typename remove_reference<_Tp>::type;
1894 /// Alias template for add_lvalue_reference
1895 template<typename _Tp>
1896 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1898 /// Alias template for add_rvalue_reference
1899 template<typename _Tp>
1900 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1903 // Sign modifications.
1905 /// @cond undocumented
1907 // Utility for constructing identically cv-qualified types.
1908 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1909 struct __cv_selector;
1911 template<typename _Unqualified>
1912 struct __cv_selector<_Unqualified, false, false>
1913 { using __type = _Unqualified; };
1915 template<typename _Unqualified>
1916 struct __cv_selector<_Unqualified, false, true>
1917 { using __type = volatile _Unqualified; };
1919 template<typename _Unqualified>
1920 struct __cv_selector<_Unqualified, true, false>
1921 { using __type = const _Unqualified; };
1923 template<typename _Unqualified>
1924 struct __cv_selector<_Unqualified, true, true>
1925 { using __type = const volatile _Unqualified; };
1927 template<typename _Qualified, typename _Unqualified,
1928 bool _IsConst = is_const<_Qualified>::value,
1929 bool _IsVol = is_volatile<_Qualified>::value>
1930 class __match_cv_qualifiers
1932 using __match = __cv_selector<_Unqualified, _IsConst, _IsVol>;
1935 using __type = typename __match::__type;
1938 // Utility for finding the unsigned versions of signed integral types.
1939 template<typename _Tp>
1940 struct __make_unsigned
1941 { using __type = _Tp; };
1944 struct __make_unsigned<char>
1945 { using __type = unsigned char; };
1948 struct __make_unsigned<signed char>
1949 { using __type = unsigned char; };
1952 struct __make_unsigned<short>
1953 { using __type = unsigned short; };
1956 struct __make_unsigned<int>
1957 { using __type = unsigned int; };
1960 struct __make_unsigned<long>
1961 { using __type = unsigned long; };
1964 struct __make_unsigned<long long>
1965 { using __type = unsigned long long; };
1967 #if defined(__GLIBCXX_TYPE_INT_N_0)
1970 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1971 { using __type = unsigned __GLIBCXX_TYPE_INT_N_0; };
1973 #if defined(__GLIBCXX_TYPE_INT_N_1)
1976 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1977 { using __type = unsigned __GLIBCXX_TYPE_INT_N_1; };
1979 #if defined(__GLIBCXX_TYPE_INT_N_2)
1982 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1983 { using __type = unsigned __GLIBCXX_TYPE_INT_N_2; };
1985 #if defined(__GLIBCXX_TYPE_INT_N_3)
1988 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1989 { using __type = unsigned __GLIBCXX_TYPE_INT_N_3; };
1991 #if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
1994 struct __make_unsigned<__int128>
1995 { using __type = unsigned __int128; };
1998 // Select between integral and enum: not possible to be both.
1999 template<typename _Tp,
2000 bool _IsInt = is_integral<_Tp>::value,
2001 bool _IsEnum = __is_enum(_Tp)>
2002 class __make_unsigned_selector;
2004 template<typename _Tp>
2005 class __make_unsigned_selector<_Tp, true, false>
2007 using __unsigned_type
2008 = typename __make_unsigned<__remove_cv_t<_Tp>>::__type;
2012 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
2015 class __make_unsigned_selector_base
2018 template<typename...> struct _List { };
2020 template<typename _Tp, typename... _Up>
2021 struct _List<_Tp, _Up...> : _List<_Up...>
2022 { static constexpr size_t __size = sizeof(_Tp); };
2024 template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
2027 template<size_t _Sz, typename _Uint, typename... _UInts>
2028 struct __select<_Sz, _List<_Uint, _UInts...>, true>
2029 { using __type = _Uint; };
2031 template<size_t _Sz, typename _Uint, typename... _UInts>
2032 struct __select<_Sz, _List<_Uint, _UInts...>, false>
2033 : __select<_Sz, _List<_UInts...>>
2037 // Choose unsigned integer type with the smallest rank and same size as _Tp
2038 template<typename _Tp>
2039 class __make_unsigned_selector<_Tp, false, true>
2040 : __make_unsigned_selector_base
2042 // With -fshort-enums, an enum may be as small as a char.
2044 using _UInts = _List<unsigned char, unsigned short, unsigned int,
2045 unsigned long, unsigned long long
2046 #ifdef __SIZEOF_INT128__
2051 using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
2055 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
2058 // wchar_t, char8_t, char16_t and char32_t are integral types but are
2059 // neither signed integer types nor unsigned integer types, so must be
2060 // transformed to the unsigned integer type with the smallest rank.
2061 // Use the partial specialization for enumeration types to do that.
2063 struct __make_unsigned<wchar_t>
2066 = typename __make_unsigned_selector<wchar_t, false, true>::__type;
2069 #ifdef _GLIBCXX_USE_CHAR8_T
2071 struct __make_unsigned<char8_t>
2074 = typename __make_unsigned_selector<char8_t, false, true>::__type;
2079 struct __make_unsigned<char16_t>
2082 = typename __make_unsigned_selector<char16_t, false, true>::__type;
2086 struct __make_unsigned<char32_t>
2089 = typename __make_unsigned_selector<char32_t, false, true>::__type;
2093 // Given an integral/enum type, return the corresponding unsigned
2095 // Primary template.
2097 template<typename _Tp>
2098 struct make_unsigned
2099 { using type = typename __make_unsigned_selector<_Tp>::__type; };
2101 // Integral, but don't define.
2102 template<> struct make_unsigned<bool>;
2103 template<> struct make_unsigned<bool const>;
2104 template<> struct make_unsigned<bool volatile>;
2105 template<> struct make_unsigned<bool const volatile>;
2107 /// @cond undocumented
2109 // Utility for finding the signed versions of unsigned integral types.
2110 template<typename _Tp>
2111 struct __make_signed
2112 { using __type = _Tp; };
2115 struct __make_signed<char>
2116 { using __type = signed char; };
2119 struct __make_signed<unsigned char>
2120 { using __type = signed char; };
2123 struct __make_signed<unsigned short>
2124 { using __type = signed short; };
2127 struct __make_signed<unsigned int>
2128 { using __type = signed int; };
2131 struct __make_signed<unsigned long>
2132 { using __type = signed long; };
2135 struct __make_signed<unsigned long long>
2136 { using __type = signed long long; };
2138 #if defined(__GLIBCXX_TYPE_INT_N_0)
2141 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
2142 { using __type = __GLIBCXX_TYPE_INT_N_0; };
2144 #if defined(__GLIBCXX_TYPE_INT_N_1)
2147 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
2148 { using __type = __GLIBCXX_TYPE_INT_N_1; };
2150 #if defined(__GLIBCXX_TYPE_INT_N_2)
2153 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
2154 { using __type = __GLIBCXX_TYPE_INT_N_2; };
2156 #if defined(__GLIBCXX_TYPE_INT_N_3)
2159 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
2160 { using __type = __GLIBCXX_TYPE_INT_N_3; };
2162 #if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
2165 struct __make_signed<unsigned __int128>
2166 { using __type = __int128; };
2169 // Select between integral and enum: not possible to be both.
2170 template<typename _Tp,
2171 bool _IsInt = is_integral<_Tp>::value,
2172 bool _IsEnum = __is_enum(_Tp)>
2173 class __make_signed_selector;
2175 template<typename _Tp>
2176 class __make_signed_selector<_Tp, true, false>
2179 = typename __make_signed<__remove_cv_t<_Tp>>::__type;
2183 = typename __match_cv_qualifiers<_Tp, __signed_type>::__type;
2186 // Choose signed integer type with the smallest rank and same size as _Tp
2187 template<typename _Tp>
2188 class __make_signed_selector<_Tp, false, true>
2190 using __unsigned_type = typename __make_unsigned_selector<_Tp>::__type;
2193 using __type = typename __make_signed_selector<__unsigned_type>::__type;
2196 // wchar_t, char16_t and char32_t are integral types but are neither
2197 // signed integer types nor unsigned integer types, so must be
2198 // transformed to the signed integer type with the smallest rank.
2199 // Use the partial specialization for enumeration types to do that.
2201 struct __make_signed<wchar_t>
2204 = typename __make_signed_selector<wchar_t, false, true>::__type;
2207 #if defined(_GLIBCXX_USE_CHAR8_T)
2209 struct __make_signed<char8_t>
2212 = typename __make_signed_selector<char8_t, false, true>::__type;
2217 struct __make_signed<char16_t>
2220 = typename __make_signed_selector<char16_t, false, true>::__type;
2224 struct __make_signed<char32_t>
2227 = typename __make_signed_selector<char32_t, false, true>::__type;
2231 // Given an integral/enum type, return the corresponding signed
2233 // Primary template.
2235 template<typename _Tp>
2237 { using type = typename __make_signed_selector<_Tp>::__type; };
2239 // Integral, but don't define.
2240 template<> struct make_signed<bool>;
2241 template<> struct make_signed<bool const>;
2242 template<> struct make_signed<bool volatile>;
2243 template<> struct make_signed<bool const volatile>;
2245 #if __cplusplus > 201103L
2246 /// Alias template for make_signed
2247 template<typename _Tp>
2248 using make_signed_t = typename make_signed<_Tp>::type;
2250 /// Alias template for make_unsigned
2251 template<typename _Tp>
2252 using make_unsigned_t = typename make_unsigned<_Tp>::type;
2255 // Array modifications.
2258 #if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_extent)
2259 template<typename _Tp>
2260 struct remove_extent
2261 { using type = __remove_extent(_Tp); };
2263 template<typename _Tp>
2264 struct remove_extent
2265 { using type = _Tp; };
2267 template<typename _Tp, std::size_t _Size>
2268 struct remove_extent<_Tp[_Size]>
2269 { using type = _Tp; };
2271 template<typename _Tp>
2272 struct remove_extent<_Tp[]>
2273 { using type = _Tp; };
2276 /// remove_all_extents
2277 #if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_all_extents)
2278 template<typename _Tp>
2279 struct remove_all_extents
2280 { using type = __remove_all_extents(_Tp); };
2282 template<typename _Tp>
2283 struct remove_all_extents
2284 { using type = _Tp; };
2286 template<typename _Tp, std::size_t _Size>
2287 struct remove_all_extents<_Tp[_Size]>
2288 { using type = typename remove_all_extents<_Tp>::type; };
2290 template<typename _Tp>
2291 struct remove_all_extents<_Tp[]>
2292 { using type = typename remove_all_extents<_Tp>::type; };
2295 #if __cplusplus > 201103L
2296 /// Alias template for remove_extent
2297 template<typename _Tp>
2298 using remove_extent_t = typename remove_extent<_Tp>::type;
2300 /// Alias template for remove_all_extents
2301 template<typename _Tp>
2302 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
2305 // Pointer modifications.
2308 #if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer)
2309 template<typename _Tp>
2310 struct remove_pointer
2311 { using type = __remove_pointer(_Tp); };
2313 template<typename _Tp, typename>
2314 struct __remove_pointer_helper
2315 { using type = _Tp; };
2317 template<typename _Tp, typename _Up>
2318 struct __remove_pointer_helper<_Tp, _Up*>
2319 { using type = _Up; };
2321 template<typename _Tp>
2322 struct remove_pointer
2323 : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>>
2328 #if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer)
2329 template<typename _Tp>
2331 { using type = __add_pointer(_Tp); };
2333 template<typename _Tp, typename = void>
2334 struct __add_pointer_helper
2335 { using type = _Tp; };
2337 template<typename _Tp>
2338 struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
2339 { using type = _Tp*; };
2341 template<typename _Tp>
2343 : public __add_pointer_helper<_Tp>
2346 template<typename _Tp>
2347 struct add_pointer<_Tp&>
2348 { using type = _Tp*; };
2350 template<typename _Tp>
2351 struct add_pointer<_Tp&&>
2352 { using type = _Tp*; };
2355 #if __cplusplus > 201103L
2356 /// Alias template for remove_pointer
2357 template<typename _Tp>
2358 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2360 /// Alias template for add_pointer
2361 template<typename _Tp>
2362 using add_pointer_t = typename add_pointer<_Tp>::type;
2365 /// @cond undocumented
2367 // Aligned to maximum fundamental alignment
2368 struct __attribute__((__aligned__)) __aligned_storage_max_align_t
2372 __aligned_storage_default_alignment([[__maybe_unused__]] size_t __len)
2374 #if _GLIBCXX_INLINE_VERSION
2376 = integral_constant<size_t, alignof(__aligned_storage_max_align_t)>;
2378 return __len > (_Max_align::value / 2)
2380 # if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_clzg)
2381 : 1 << (__SIZE_WIDTH__ - __builtin_clzg(__len - 1u));
2383 : 1 << (__LLONG_WIDTH__ - __builtin_clzll(__len - 1ull));
2386 // Returning a fixed value is incorrect, but kept for ABI compatibility.
2387 // XXX GLIBCXX_ABI Deprecated
2388 return alignof(__aligned_storage_max_align_t);
2394 * @brief Aligned storage
2396 * The member typedef `type` is be a POD type suitable for use as
2397 * uninitialized storage for any object whose size is at most `_Len`
2398 * and whose alignment is a divisor of `_Align`.
2400 * It is important to use the nested `type` as uninitialized storage,
2401 * not the `std::aligned_storage` type itself which is an empty class
2402 * with 1-byte alignment. So this is correct:
2404 * `typename std::aligned_storage<sizeof(X), alignof(X)>::type m_xobj;`
2408 * `std::aligned_storage<sizeof(X), alignof(X)> m_xobj;`
2410 * In C++14 and later `std::aligned_storage_t<sizeof(X), alignof(X)>`
2411 * can be used to refer to the `type` member typedef.
2413 * The default value of _Align is supposed to be the most stringent
2414 * fundamental alignment requirement for any C++ object type whose size
2415 * is no greater than `_Len` (see [basic.align] in the C++ standard).
2417 * @bug In this implementation the default value for _Align is always the
2418 * maximum fundamental alignment, i.e. `alignof(max_align_t)`, which is
2419 * incorrect. It should be an alignment value no greater than `_Len`.
2421 * @deprecated Deprecated in C++23. Uses can be replaced by an
2422 * array `std::byte[_Len]` declared with `alignas(_Align)`.
2424 template<size_t _Len,
2425 size_t _Align = __aligned_storage_default_alignment(_Len)>
2427 _GLIBCXX23_DEPRECATED
2432 alignas(_Align) unsigned char __data[_Len];
2436 template <typename... _Types>
2437 struct __strictest_alignment
2439 static const size_t _S_alignment = 0;
2440 static const size_t _S_size = 0;
2443 template <typename _Tp, typename... _Types>
2444 struct __strictest_alignment<_Tp, _Types...>
2446 static const size_t _S_alignment =
2447 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2448 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2449 static const size_t _S_size =
2450 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2451 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2454 #pragma GCC diagnostic push
2455 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2458 * @brief Provide aligned storage for types.
2460 * [meta.trans.other]
2462 * Provides aligned storage for any of the provided types of at
2465 * @see aligned_storage
2467 * @deprecated Deprecated in C++23.
2469 template <size_t _Len, typename... _Types>
2471 _GLIBCXX23_DEPRECATED
2475 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2477 using __strictest = __strictest_alignment<_Types...>;
2478 static const size_t _S_len = _Len > __strictest::_S_size
2479 ? _Len : __strictest::_S_size;
2481 /// The value of the strictest alignment of _Types.
2482 static const size_t alignment_value = __strictest::_S_alignment;
2484 using type = typename aligned_storage<_S_len, alignment_value>::type;
2487 template <size_t _Len, typename... _Types>
2488 const size_t aligned_union<_Len, _Types...>::alignment_value;
2489 #pragma GCC diagnostic pop
2491 // Decay trait for arrays and functions, used for perfect forwarding
2492 // in make_pair, make_tuple, etc.
2493 #if _GLIBCXX_USE_BUILTIN_TRAIT(__decay)
2494 template<typename _Tp>
2496 { using type = __decay(_Tp); };
2498 /// @cond undocumented
2500 template<typename _Up>
2501 struct __decay_selector
2502 : __conditional_t<is_const<const _Up>::value, // false for functions
2503 remove_cv<_Up>, // N.B. DR 705.
2504 add_pointer<_Up>> // function decays to pointer
2507 template<typename _Up, size_t _Nm>
2508 struct __decay_selector<_Up[_Nm]>
2509 { using type = _Up*; };
2511 template<typename _Up>
2512 struct __decay_selector<_Up[]>
2513 { using type = _Up*; };
2518 template<typename _Tp>
2520 { using type = typename __decay_selector<_Tp>::type; };
2522 template<typename _Tp>
2524 { using type = typename __decay_selector<_Tp>::type; };
2526 template<typename _Tp>
2528 { using type = typename __decay_selector<_Tp>::type; };
2531 /// @cond undocumented
2533 // Helper which adds a reference to a type when given a reference_wrapper
2534 template<typename _Tp>
2535 struct __strip_reference_wrapper
2540 template<typename _Tp>
2541 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2543 using __type = _Tp&;
2546 // __decay_t (std::decay_t for C++11).
2547 template<typename _Tp>
2548 using __decay_t = typename decay<_Tp>::type;
2550 template<typename _Tp>
2551 using __decay_and_strip = __strip_reference_wrapper<__decay_t<_Tp>>;
2554 /// @cond undocumented
2556 // Helper for SFINAE constraints
2557 template<typename... _Cond>
2558 using _Require = __enable_if_t<__and_<_Cond...>::value>;
2560 // __remove_cvref_t (std::remove_cvref_t for C++11).
2561 template<typename _Tp>
2562 using __remove_cvref_t
2563 = typename remove_cv<typename remove_reference<_Tp>::type>::type;
2566 // Primary template.
2567 /// Define a member typedef @c type to one of two argument types.
2568 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2570 { using type = _Iftrue; };
2572 // Partial specialization for false.
2573 template<typename _Iftrue, typename _Iffalse>
2574 struct conditional<false, _Iftrue, _Iffalse>
2575 { using type = _Iffalse; };
2578 template<typename... _Tp>
2581 // Sfinae-friendly common_type implementation:
2583 /// @cond undocumented
2585 // For several sfinae-friendly trait implementations we transport both the
2586 // result information (as the member type) and the failure information (no
2587 // member type). This is very similar to std::enable_if, but we cannot use
2588 // that, because we need to derive from them as an implementation detail.
2590 template<typename _Tp>
2591 struct __success_type
2592 { using type = _Tp; };
2594 struct __failure_type
2597 struct __do_common_type_impl
2599 template<typename _Tp, typename _Up>
2601 = decltype(true ? std::declval<_Tp>() : std::declval<_Up>());
2603 // if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2604 // denotes a valid type, let C denote that type.
2605 template<typename _Tp, typename _Up>
2606 static __success_type<__decay_t<__cond_t<_Tp, _Up>>>
2609 #if __cplusplus > 201703L
2610 // Otherwise, if COND-RES(CREF(D1), CREF(D2)) denotes a type,
2611 // let C denote the type decay_t<COND-RES(CREF(D1), CREF(D2))>.
2612 template<typename _Tp, typename _Up>
2613 static __success_type<__remove_cvref_t<__cond_t<const _Tp&, const _Up&>>>
2617 template<typename, typename>
2618 static __failure_type
2621 template<typename _Tp, typename _Up>
2622 static decltype(_S_test_2<_Tp, _Up>(0))
2626 // If sizeof...(T) is zero, there shall be no member type.
2628 struct common_type<>
2631 // If sizeof...(T) is one, the same type, if any, as common_type_t<T0, T0>.
2632 template<typename _Tp0>
2633 struct common_type<_Tp0>
2634 : public common_type<_Tp0, _Tp0>
2637 // If sizeof...(T) is two, ...
2638 template<typename _Tp1, typename _Tp2,
2639 typename _Dp1 = __decay_t<_Tp1>, typename _Dp2 = __decay_t<_Tp2>>
2640 struct __common_type_impl
2642 // If is_same_v<T1, D1> is false or is_same_v<T2, D2> is false,
2643 // let C denote the same type, if any, as common_type_t<D1, D2>.
2644 using type = common_type<_Dp1, _Dp2>;
2647 template<typename _Tp1, typename _Tp2>
2648 struct __common_type_impl<_Tp1, _Tp2, _Tp1, _Tp2>
2649 : private __do_common_type_impl
2651 // Otherwise, if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2652 // denotes a valid type, let C denote that type.
2653 using type = decltype(_S_test<_Tp1, _Tp2>(0));
2656 // If sizeof...(T) is two, ...
2657 template<typename _Tp1, typename _Tp2>
2658 struct common_type<_Tp1, _Tp2>
2659 : public __common_type_impl<_Tp1, _Tp2>::type
2662 template<typename...>
2663 struct __common_type_pack
2666 template<typename, typename, typename = void>
2667 struct __common_type_fold;
2669 // If sizeof...(T) is greater than two, ...
2670 template<typename _Tp1, typename _Tp2, typename... _Rp>
2671 struct common_type<_Tp1, _Tp2, _Rp...>
2672 : public __common_type_fold<common_type<_Tp1, _Tp2>,
2673 __common_type_pack<_Rp...>>
2676 // Let C denote the same type, if any, as common_type_t<T1, T2>.
2677 // If there is such a type C, type shall denote the same type, if any,
2678 // as common_type_t<C, R...>.
2679 template<typename _CTp, typename... _Rp>
2680 struct __common_type_fold<_CTp, __common_type_pack<_Rp...>,
2681 __void_t<typename _CTp::type>>
2682 : public common_type<typename _CTp::type, _Rp...>
2685 // Otherwise, there shall be no member type.
2686 template<typename _CTp, typename _Rp>
2687 struct __common_type_fold<_CTp, _Rp, void>
2690 template<typename _Tp, bool = __is_enum(_Tp)>
2691 struct __underlying_type_impl
2693 using type = __underlying_type(_Tp);
2696 template<typename _Tp>
2697 struct __underlying_type_impl<_Tp, false>
2701 /// The underlying type of an enum.
2702 template<typename _Tp>
2703 struct underlying_type
2704 : public __underlying_type_impl<_Tp>
2707 /// @cond undocumented
2708 template<typename _Tp>
2709 struct __declval_protector
2711 static const bool __stop = false;
2715 /** Utility to simplify expressions used in unevaluated operands
2717 * @ingroup utilities
2719 template<typename _Tp>
2720 auto declval() noexcept -> decltype(__declval<_Tp>(0))
2722 static_assert(__declval_protector<_Tp>::__stop,
2723 "declval() must not be used!");
2724 return __declval<_Tp>(0);
2728 template<typename _Signature>
2731 // Sfinae-friendly result_of implementation:
2733 /// @cond undocumented
2734 struct __invoke_memfun_ref { };
2735 struct __invoke_memfun_deref { };
2736 struct __invoke_memobj_ref { };
2737 struct __invoke_memobj_deref { };
2738 struct __invoke_other { };
2740 // Associate a tag type with a specialization of __success_type.
2741 template<typename _Tp, typename _Tag>
2742 struct __result_of_success : __success_type<_Tp>
2743 { using __invoke_type = _Tag; };
2745 // [func.require] paragraph 1 bullet 1:
2746 struct __result_of_memfun_ref_impl
2748 template<typename _Fp, typename _Tp1, typename... _Args>
2749 static __result_of_success<decltype(
2750 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2751 ), __invoke_memfun_ref> _S_test(int);
2753 template<typename...>
2754 static __failure_type _S_test(...);
2757 template<typename _MemPtr, typename _Arg, typename... _Args>
2758 struct __result_of_memfun_ref
2759 : private __result_of_memfun_ref_impl
2761 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2764 // [func.require] paragraph 1 bullet 2:
2765 struct __result_of_memfun_deref_impl
2767 template<typename _Fp, typename _Tp1, typename... _Args>
2768 static __result_of_success<decltype(
2769 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2770 ), __invoke_memfun_deref> _S_test(int);
2772 template<typename...>
2773 static __failure_type _S_test(...);
2776 template<typename _MemPtr, typename _Arg, typename... _Args>
2777 struct __result_of_memfun_deref
2778 : private __result_of_memfun_deref_impl
2780 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2783 // [func.require] paragraph 1 bullet 3:
2784 struct __result_of_memobj_ref_impl
2786 template<typename _Fp, typename _Tp1>
2787 static __result_of_success<decltype(
2788 std::declval<_Tp1>().*std::declval<_Fp>()
2789 ), __invoke_memobj_ref> _S_test(int);
2791 template<typename, typename>
2792 static __failure_type _S_test(...);
2795 template<typename _MemPtr, typename _Arg>
2796 struct __result_of_memobj_ref
2797 : private __result_of_memobj_ref_impl
2799 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2802 // [func.require] paragraph 1 bullet 4:
2803 struct __result_of_memobj_deref_impl
2805 template<typename _Fp, typename _Tp1>
2806 static __result_of_success<decltype(
2807 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2808 ), __invoke_memobj_deref> _S_test(int);
2810 template<typename, typename>
2811 static __failure_type _S_test(...);
2814 template<typename _MemPtr, typename _Arg>
2815 struct __result_of_memobj_deref
2816 : private __result_of_memobj_deref_impl
2818 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2821 template<typename _MemPtr, typename _Arg>
2822 struct __result_of_memobj;
2824 template<typename _Res, typename _Class, typename _Arg>
2825 struct __result_of_memobj<_Res _Class::*, _Arg>
2827 using _Argval = __remove_cvref_t<_Arg>;
2828 using _MemPtr = _Res _Class::*;
2829 using type = typename __conditional_t<__or_<is_same<_Argval, _Class>,
2830 is_base_of<_Class, _Argval>>::value,
2831 __result_of_memobj_ref<_MemPtr, _Arg>,
2832 __result_of_memobj_deref<_MemPtr, _Arg>
2836 template<typename _MemPtr, typename _Arg, typename... _Args>
2837 struct __result_of_memfun;
2839 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2840 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2842 using _Argval = typename remove_reference<_Arg>::type;
2843 using _MemPtr = _Res _Class::*;
2844 using type = typename __conditional_t<is_base_of<_Class, _Argval>::value,
2845 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2846 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2850 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2851 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2852 // as the object expression
2854 // Used by result_of, invoke etc. to unwrap a reference_wrapper.
2855 template<typename _Tp, typename _Up = __remove_cvref_t<_Tp>>
2861 template<typename _Tp, typename _Up>
2862 struct __inv_unwrap<_Tp, reference_wrapper<_Up>>
2867 template<bool, bool, typename _Functor, typename... _ArgTypes>
2868 struct __result_of_impl
2870 using type = __failure_type;
2873 template<typename _MemPtr, typename _Arg>
2874 struct __result_of_impl<true, false, _MemPtr, _Arg>
2875 : public __result_of_memobj<__decay_t<_MemPtr>,
2876 typename __inv_unwrap<_Arg>::type>
2879 template<typename _MemPtr, typename _Arg, typename... _Args>
2880 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2881 : public __result_of_memfun<__decay_t<_MemPtr>,
2882 typename __inv_unwrap<_Arg>::type, _Args...>
2885 // [func.require] paragraph 1 bullet 5:
2886 struct __result_of_other_impl
2888 template<typename _Fn, typename... _Args>
2889 static __result_of_success<decltype(
2890 std::declval<_Fn>()(std::declval<_Args>()...)
2891 ), __invoke_other> _S_test(int);
2893 template<typename...>
2894 static __failure_type _S_test(...);
2897 template<typename _Functor, typename... _ArgTypes>
2898 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2899 : private __result_of_other_impl
2901 using type = decltype(_S_test<_Functor, _ArgTypes...>(0));
2904 // __invoke_result (std::invoke_result for C++11)
2905 template<typename _Functor, typename... _ArgTypes>
2906 struct __invoke_result
2907 : public __result_of_impl<
2908 is_member_object_pointer<
2909 typename remove_reference<_Functor>::type
2911 is_member_function_pointer<
2912 typename remove_reference<_Functor>::type
2914 _Functor, _ArgTypes...
2918 // __invoke_result_t (std::invoke_result_t for C++11)
2919 template<typename _Fn, typename... _Args>
2920 using __invoke_result_t = typename __invoke_result<_Fn, _Args...>::type;
2923 template<typename _Functor, typename... _ArgTypes>
2924 struct result_of<_Functor(_ArgTypes...)>
2925 : public __invoke_result<_Functor, _ArgTypes...>
2926 { } _GLIBCXX17_DEPRECATED_SUGGEST("std::invoke_result");
2928 #if __cplusplus >= 201402L
2929 #pragma GCC diagnostic push
2930 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2931 /// Alias template for aligned_storage
2932 template<size_t _Len,
2933 size_t _Align = __aligned_storage_default_alignment(_Len)>
2934 using aligned_storage_t _GLIBCXX23_DEPRECATED = typename aligned_storage<_Len, _Align>::type;
2936 template <size_t _Len, typename... _Types>
2937 using aligned_union_t _GLIBCXX23_DEPRECATED = typename aligned_union<_Len, _Types...>::type;
2938 #pragma GCC diagnostic pop
2940 /// Alias template for decay
2941 template<typename _Tp>
2942 using decay_t = typename decay<_Tp>::type;
2944 /// Alias template for enable_if
2945 template<bool _Cond, typename _Tp = void>
2946 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2948 /// Alias template for conditional
2949 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2950 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2952 /// Alias template for common_type
2953 template<typename... _Tp>
2954 using common_type_t = typename common_type<_Tp...>::type;
2956 /// Alias template for underlying_type
2957 template<typename _Tp>
2958 using underlying_type_t = typename underlying_type<_Tp>::type;
2960 /// Alias template for result_of
2961 template<typename _Tp>
2962 using result_of_t = typename result_of<_Tp>::type;
2965 #ifdef __cpp_lib_void_t // C++ >= 17 || GNU++ >= 11
2966 /// A metafunction that always yields void, used for detecting valid types.
2967 template<typename...> using void_t = void;
2970 /// @cond undocumented
2973 // Detect whether _Op<_Args...> is a valid type, use default _Def if not.
2976 // Implementation of the detection idiom (negative case).
2977 template<typename _Def, template<typename...> class _Op, typename... _Args>
2978 struct __detected_or
2981 using __is_detected = false_type;
2984 // Implementation of the detection idiom (positive case).
2985 template<typename _Def, template<typename...> class _Op, typename... _Args>
2986 requires requires { typename _Op<_Args...>; }
2987 struct __detected_or<_Def, _Op, _Args...>
2989 using type = _Op<_Args...>;
2990 using __is_detected = true_type;
2993 /// Implementation of the detection idiom (negative case).
2994 template<typename _Default, typename _AlwaysVoid,
2995 template<typename...> class _Op, typename... _Args>
2998 using type = _Default;
2999 using __is_detected = false_type;
3002 /// Implementation of the detection idiom (positive case).
3003 template<typename _Default, template<typename...> class _Op,
3005 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
3007 using type = _Op<_Args...>;
3008 using __is_detected = true_type;
3011 template<typename _Default, template<typename...> class _Op,
3013 using __detected_or = __detector<_Default, void, _Op, _Args...>;
3014 #endif // __cpp_concepts
3016 // _Op<_Args...> if that is a valid type, otherwise _Default.
3017 template<typename _Default, template<typename...> class _Op,
3019 using __detected_or_t
3020 = typename __detected_or<_Default, _Op, _Args...>::type;
3023 * Use SFINAE to determine if the type _Tp has a publicly-accessible
3024 * member type _NTYPE.
3026 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
3027 template<typename _Tp, typename = __void_t<>> \
3028 struct __has_##_NTYPE \
3031 template<typename _Tp> \
3032 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
3036 template <typename _Tp>
3037 struct __is_swappable;
3039 template <typename _Tp>
3040 struct __is_nothrow_swappable;
3043 struct __is_tuple_like_impl : false_type
3046 // Internal type trait that allows us to sfinae-protect tuple_cat.
3047 template<typename _Tp>
3048 struct __is_tuple_like
3049 : public __is_tuple_like_impl<__remove_cvref_t<_Tp>>::type
3053 template<typename _Tp>
3054 _GLIBCXX20_CONSTEXPR
3056 _Require<__not_<__is_tuple_like<_Tp>>,
3057 is_move_constructible<_Tp>,
3058 is_move_assignable<_Tp>>
3060 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
3061 is_nothrow_move_assignable<_Tp>>::value);
3063 template<typename _Tp, size_t _Nm>
3064 _GLIBCXX20_CONSTEXPR
3066 __enable_if_t<__is_swappable<_Tp>::value>
3067 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
3068 noexcept(__is_nothrow_swappable<_Tp>::value);
3070 /// @cond undocumented
3071 namespace __swappable_details {
3074 struct __do_is_swappable_impl
3076 template<typename _Tp, typename
3077 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
3078 static true_type __test(int);
3081 static false_type __test(...);
3084 struct __do_is_nothrow_swappable_impl
3086 template<typename _Tp>
3087 static __bool_constant<
3088 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
3092 static false_type __test(...);
3095 } // namespace __swappable_details
3097 template<typename _Tp>
3098 struct __is_swappable_impl
3099 : public __swappable_details::__do_is_swappable_impl
3101 using type = decltype(__test<_Tp>(0));
3104 template<typename _Tp>
3105 struct __is_nothrow_swappable_impl
3106 : public __swappable_details::__do_is_nothrow_swappable_impl
3108 using type = decltype(__test<_Tp>(0));
3111 template<typename _Tp>
3112 struct __is_swappable
3113 : public __is_swappable_impl<_Tp>::type
3116 template<typename _Tp>
3117 struct __is_nothrow_swappable
3118 : public __is_nothrow_swappable_impl<_Tp>::type
3122 #ifdef __cpp_lib_is_swappable // C++ >= 17 || GNU++ >= 11
3123 /// Metafunctions used for detecting swappable types: p0185r1
3126 template<typename _Tp>
3128 : public __is_swappable_impl<_Tp>::type
3130 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3131 "template argument must be a complete class or an unbounded array");
3134 /// is_nothrow_swappable
3135 template<typename _Tp>
3136 struct is_nothrow_swappable
3137 : public __is_nothrow_swappable_impl<_Tp>::type
3139 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3140 "template argument must be a complete class or an unbounded array");
3143 #if __cplusplus >= 201402L
3145 template<typename _Tp>
3146 _GLIBCXX17_INLINE constexpr bool is_swappable_v =
3147 is_swappable<_Tp>::value;
3149 /// is_nothrow_swappable_v
3150 template<typename _Tp>
3151 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_v =
3152 is_nothrow_swappable<_Tp>::value;
3153 #endif // __cplusplus >= 201402L
3155 /// @cond undocumented
3156 namespace __swappable_with_details {
3159 struct __do_is_swappable_with_impl
3161 template<typename _Tp, typename _Up, typename
3162 = decltype(swap(std::declval<_Tp>(), std::declval<_Up>())),
3164 = decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))>
3165 static true_type __test(int);
3167 template<typename, typename>
3168 static false_type __test(...);
3171 struct __do_is_nothrow_swappable_with_impl
3173 template<typename _Tp, typename _Up>
3174 static __bool_constant<
3175 noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
3177 noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()))
3180 template<typename, typename>
3181 static false_type __test(...);
3184 } // namespace __swappable_with_details
3186 template<typename _Tp, typename _Up>
3187 struct __is_swappable_with_impl
3188 : public __swappable_with_details::__do_is_swappable_with_impl
3190 using type = decltype(__test<_Tp, _Up>(0));
3193 // Optimization for the homogenous lvalue case, not required:
3194 template<typename _Tp>
3195 struct __is_swappable_with_impl<_Tp&, _Tp&>
3196 : public __swappable_details::__do_is_swappable_impl
3198 using type = decltype(__test<_Tp&>(0));
3201 template<typename _Tp, typename _Up>
3202 struct __is_nothrow_swappable_with_impl
3203 : public __swappable_with_details::__do_is_nothrow_swappable_with_impl
3205 using type = decltype(__test<_Tp, _Up>(0));
3208 // Optimization for the homogenous lvalue case, not required:
3209 template<typename _Tp>
3210 struct __is_nothrow_swappable_with_impl<_Tp&, _Tp&>
3211 : public __swappable_details::__do_is_nothrow_swappable_impl
3213 using type = decltype(__test<_Tp&>(0));
3217 /// is_swappable_with
3218 template<typename _Tp, typename _Up>
3219 struct is_swappable_with
3220 : public __is_swappable_with_impl<_Tp, _Up>::type
3222 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3223 "first template argument must be a complete class or an unbounded array");
3224 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3225 "second template argument must be a complete class or an unbounded array");
3228 /// is_nothrow_swappable_with
3229 template<typename _Tp, typename _Up>
3230 struct is_nothrow_swappable_with
3231 : public __is_nothrow_swappable_with_impl<_Tp, _Up>::type
3233 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3234 "first template argument must be a complete class or an unbounded array");
3235 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3236 "second template argument must be a complete class or an unbounded array");
3239 #if __cplusplus >= 201402L
3240 /// is_swappable_with_v
3241 template<typename _Tp, typename _Up>
3242 _GLIBCXX17_INLINE constexpr bool is_swappable_with_v =
3243 is_swappable_with<_Tp, _Up>::value;
3245 /// is_nothrow_swappable_with_v
3246 template<typename _Tp, typename _Up>
3247 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_with_v =
3248 is_nothrow_swappable_with<_Tp, _Up>::value;
3249 #endif // __cplusplus >= 201402L
3251 #endif // __cpp_lib_is_swappable
3253 /// @cond undocumented
3255 // __is_invocable (std::is_invocable for C++11)
3257 // The primary template is used for invalid INVOKE expressions.
3258 template<typename _Result, typename _Ret,
3259 bool = is_void<_Ret>::value, typename = void>
3260 struct __is_invocable_impl
3263 using __nothrow_conv = false_type; // For is_nothrow_invocable_r
3266 // Used for valid INVOKE and INVOKE<void> expressions.
3267 template<typename _Result, typename _Ret>
3268 struct __is_invocable_impl<_Result, _Ret,
3269 /* is_void<_Ret> = */ true,
3270 __void_t<typename _Result::type>>
3273 using __nothrow_conv = true_type; // For is_nothrow_invocable_r
3276 #pragma GCC diagnostic push
3277 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3278 // Used for INVOKE<R> expressions to check the implicit conversion to R.
3279 template<typename _Result, typename _Ret>
3280 struct __is_invocable_impl<_Result, _Ret,
3281 /* is_void<_Ret> = */ false,
3282 __void_t<typename _Result::type>>
3285 // The type of the INVOKE expression.
3286 using _Res_t = typename _Result::type;
3288 // Unlike declval, this doesn't add_rvalue_reference, so it respects
3289 // guaranteed copy elision.
3290 static _Res_t _S_get() noexcept;
3292 // Used to check if _Res_t can implicitly convert to _Tp.
3293 template<typename _Tp>
3294 static void _S_conv(__type_identity_t<_Tp>) noexcept;
3296 // This overload is viable if INVOKE(f, args...) can convert to _Tp.
3297 template<typename _Tp,
3298 bool _Nothrow = noexcept(_S_conv<_Tp>(_S_get())),
3299 typename = decltype(_S_conv<_Tp>(_S_get())),
3300 #if __has_builtin(__reference_converts_from_temporary)
3301 bool _Dangle = __reference_converts_from_temporary(_Tp, _Res_t)
3303 bool _Dangle = false
3306 static __bool_constant<_Nothrow && !_Dangle>
3309 template<typename _Tp, bool = false>
3314 // For is_invocable_r
3315 using type = decltype(_S_test<_Ret, /* Nothrow = */ true>(1));
3317 // For is_nothrow_invocable_r
3318 using __nothrow_conv = decltype(_S_test<_Ret>(1));
3320 #pragma GCC diagnostic pop
3322 template<typename _Fn, typename... _ArgTypes>
3323 struct __is_invocable
3324 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3325 : __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
3327 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3331 template<typename _Fn, typename _Tp, typename... _Args>
3332 constexpr bool __call_is_nt(__invoke_memfun_ref)
3334 using _Up = typename __inv_unwrap<_Tp>::type;
3335 return noexcept((std::declval<_Up>().*std::declval<_Fn>())(
3336 std::declval<_Args>()...));
3339 template<typename _Fn, typename _Tp, typename... _Args>
3340 constexpr bool __call_is_nt(__invoke_memfun_deref)
3342 return noexcept(((*std::declval<_Tp>()).*std::declval<_Fn>())(
3343 std::declval<_Args>()...));
3346 template<typename _Fn, typename _Tp>
3347 constexpr bool __call_is_nt(__invoke_memobj_ref)
3349 using _Up = typename __inv_unwrap<_Tp>::type;
3350 return noexcept(std::declval<_Up>().*std::declval<_Fn>());
3353 template<typename _Fn, typename _Tp>
3354 constexpr bool __call_is_nt(__invoke_memobj_deref)
3356 return noexcept((*std::declval<_Tp>()).*std::declval<_Fn>());
3359 template<typename _Fn, typename... _Args>
3360 constexpr bool __call_is_nt(__invoke_other)
3362 return noexcept(std::declval<_Fn>()(std::declval<_Args>()...));
3365 template<typename _Result, typename _Fn, typename... _Args>
3366 struct __call_is_nothrow
3368 std::__call_is_nt<_Fn, _Args...>(typename _Result::__invoke_type{})
3372 template<typename _Fn, typename... _Args>
3373 using __call_is_nothrow_
3374 = __call_is_nothrow<__invoke_result<_Fn, _Args...>, _Fn, _Args...>;
3376 // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
3377 template<typename _Fn, typename... _Args>
3378 struct __is_nothrow_invocable
3379 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3380 : __bool_constant<__is_nothrow_invocable(_Fn, _Args...)>
3382 : __and_<__is_invocable<_Fn, _Args...>,
3383 __call_is_nothrow_<_Fn, _Args...>>::type
3387 #pragma GCC diagnostic push
3388 #pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3389 struct __nonesuchbase {};
3390 struct __nonesuch : private __nonesuchbase {
3391 ~__nonesuch() = delete;
3392 __nonesuch(__nonesuch const&) = delete;
3393 void operator=(__nonesuch const&) = delete;
3395 #pragma GCC diagnostic pop
3398 #ifdef __cpp_lib_is_invocable // C++ >= 17
3399 /// std::invoke_result
3400 template<typename _Functor, typename... _ArgTypes>
3401 struct invoke_result
3402 : public __invoke_result<_Functor, _ArgTypes...>
3404 static_assert(std::__is_complete_or_unbounded(__type_identity<_Functor>{}),
3405 "_Functor must be a complete class or an unbounded array");
3406 static_assert((std::__is_complete_or_unbounded(
3407 __type_identity<_ArgTypes>{}) && ...),
3408 "each argument type must be a complete class or an unbounded array");
3411 /// std::invoke_result_t
3412 template<typename _Fn, typename... _Args>
3413 using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3415 /// std::is_invocable
3416 template<typename _Fn, typename... _ArgTypes>
3418 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3419 : public __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
3421 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3424 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3425 "_Fn must be a complete class or an unbounded array");
3426 static_assert((std::__is_complete_or_unbounded(
3427 __type_identity<_ArgTypes>{}) && ...),
3428 "each argument type must be a complete class or an unbounded array");
3431 /// std::is_invocable_r
3432 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3433 struct is_invocable_r
3434 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>::type
3436 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3437 "_Fn must be a complete class or an unbounded array");
3438 static_assert((std::__is_complete_or_unbounded(
3439 __type_identity<_ArgTypes>{}) && ...),
3440 "each argument type must be a complete class or an unbounded array");
3441 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3442 "_Ret must be a complete class or an unbounded array");
3445 /// std::is_nothrow_invocable
3446 template<typename _Fn, typename... _ArgTypes>
3447 struct is_nothrow_invocable
3448 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3449 : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)>
3451 : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>,
3452 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3455 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3456 "_Fn must be a complete class or an unbounded array");
3457 static_assert((std::__is_complete_or_unbounded(
3458 __type_identity<_ArgTypes>{}) && ...),
3459 "each argument type must be a complete class or an unbounded array");
3462 /// @cond undocumented
3463 // This checks that the INVOKE<R> expression is well-formed and that the
3464 // conversion to R does not throw. It does *not* check whether the INVOKE
3465 // expression itself can throw. That is done by __call_is_nothrow_ instead.
3466 template<typename _Result, typename _Ret>
3467 using __is_nt_invocable_impl
3468 = typename __is_invocable_impl<_Result, _Ret>::__nothrow_conv;
3471 /// std::is_nothrow_invocable_r
3472 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3473 struct is_nothrow_invocable_r
3474 : __and_<__is_nt_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>,
3475 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3477 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3478 "_Fn must be a complete class or an unbounded array");
3479 static_assert((std::__is_complete_or_unbounded(
3480 __type_identity<_ArgTypes>{}) && ...),
3481 "each argument type must be a complete class or an unbounded array");
3482 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3483 "_Ret must be a complete class or an unbounded array");
3485 #endif // __cpp_lib_is_invocable
3487 #if __cpp_lib_type_trait_variable_templates // C++ >= 17
3489 * @defgroup variable_templates Variable templates for type traits
3490 * @ingroup metaprogramming
3492 * Each variable `is_xxx_v<T>` is a boolean constant with the same value
3493 * as the `value` member of the corresponding type trait `is_xxx<T>`.
3495 * @since C++17 unless noted otherwise.
3500 * @ingroup variable_templates
3502 template <typename _Tp>
3503 inline constexpr bool is_void_v = is_void<_Tp>::value;
3504 template <typename _Tp>
3505 inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
3506 template <typename _Tp>
3507 inline constexpr bool is_integral_v = is_integral<_Tp>::value;
3508 template <typename _Tp>
3509 inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
3511 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
3512 template <typename _Tp>
3513 inline constexpr bool is_array_v = __is_array(_Tp);
3515 template <typename _Tp>
3516 inline constexpr bool is_array_v = false;
3517 template <typename _Tp>
3518 inline constexpr bool is_array_v<_Tp[]> = true;
3519 template <typename _Tp, size_t _Num>
3520 inline constexpr bool is_array_v<_Tp[_Num]> = true;
3523 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
3524 template <typename _Tp>
3525 inline constexpr bool is_pointer_v = __is_pointer(_Tp);
3527 template <typename _Tp>
3528 inline constexpr bool is_pointer_v = false;
3529 template <typename _Tp>
3530 inline constexpr bool is_pointer_v<_Tp*> = true;
3531 template <typename _Tp>
3532 inline constexpr bool is_pointer_v<_Tp* const> = true;
3533 template <typename _Tp>
3534 inline constexpr bool is_pointer_v<_Tp* volatile> = true;
3535 template <typename _Tp>
3536 inline constexpr bool is_pointer_v<_Tp* const volatile> = true;
3539 template <typename _Tp>
3540 inline constexpr bool is_lvalue_reference_v = false;
3541 template <typename _Tp>
3542 inline constexpr bool is_lvalue_reference_v<_Tp&> = true;
3543 template <typename _Tp>
3544 inline constexpr bool is_rvalue_reference_v = false;
3545 template <typename _Tp>
3546 inline constexpr bool is_rvalue_reference_v<_Tp&&> = true;
3548 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
3549 template <typename _Tp>
3550 inline constexpr bool is_member_object_pointer_v =
3551 __is_member_object_pointer(_Tp);
3553 template <typename _Tp>
3554 inline constexpr bool is_member_object_pointer_v =
3555 is_member_object_pointer<_Tp>::value;
3558 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
3559 template <typename _Tp>
3560 inline constexpr bool is_member_function_pointer_v =
3561 __is_member_function_pointer(_Tp);
3563 template <typename _Tp>
3564 inline constexpr bool is_member_function_pointer_v =
3565 is_member_function_pointer<_Tp>::value;
3568 #if __cpp_impl_reflection >= 202506L // C++ >= 26
3569 template <typename _Tp>
3570 inline constexpr bool is_reflection_v = false;
3572 inline constexpr bool is_reflection_v<decltype(^^int)> = true;
3574 inline constexpr bool is_reflection_v<const decltype(^^int)> = true;
3576 inline constexpr bool is_reflection_v<volatile decltype(^^int)> = true;
3578 inline constexpr bool is_reflection_v<const volatile decltype(^^int)> = true;
3581 template <typename _Tp>
3582 inline constexpr bool is_enum_v = __is_enum(_Tp);
3583 template <typename _Tp>
3584 inline constexpr bool is_union_v = __is_union(_Tp);
3585 template <typename _Tp>
3586 inline constexpr bool is_class_v = __is_class(_Tp);
3587 // is_function_v is defined below, after is_const_v.
3589 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
3590 template <typename _Tp>
3591 inline constexpr bool is_reference_v = __is_reference(_Tp);
3593 template <typename _Tp>
3594 inline constexpr bool is_reference_v = false;
3595 template <typename _Tp>
3596 inline constexpr bool is_reference_v<_Tp&> = true;
3597 template <typename _Tp>
3598 inline constexpr bool is_reference_v<_Tp&&> = true;
3601 template <typename _Tp>
3602 inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
3603 template <typename _Tp>
3604 inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
3606 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
3607 template <typename _Tp>
3608 inline constexpr bool is_object_v = __is_object(_Tp);
3610 template <typename _Tp>
3611 inline constexpr bool is_object_v = is_object<_Tp>::value;
3614 template <typename _Tp>
3615 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
3616 template <typename _Tp>
3617 inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;
3619 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
3620 template <typename _Tp>
3621 inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
3623 template <typename _Tp>
3624 inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
3627 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const)
3628 template <typename _Tp>
3629 inline constexpr bool is_const_v = __is_const(_Tp);
3631 template <typename _Tp>
3632 inline constexpr bool is_const_v = false;
3633 template <typename _Tp>
3634 inline constexpr bool is_const_v<const _Tp> = true;
3637 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
3638 template <typename _Tp>
3639 inline constexpr bool is_function_v = __is_function(_Tp);
3641 template <typename _Tp>
3642 inline constexpr bool is_function_v = !is_const_v<const _Tp>;
3643 template <typename _Tp>
3644 inline constexpr bool is_function_v<_Tp&> = false;
3645 template <typename _Tp>
3646 inline constexpr bool is_function_v<_Tp&&> = false;
3649 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile)
3650 template <typename _Tp>
3651 inline constexpr bool is_volatile_v = __is_volatile(_Tp);
3653 template <typename _Tp>
3654 inline constexpr bool is_volatile_v = false;
3655 template <typename _Tp>
3656 inline constexpr bool is_volatile_v<volatile _Tp> = true;
3659 template <typename _Tp>
3660 _GLIBCXX26_DEPRECATED_SUGGEST("is_trivially_default_constructible_v && is_trivially_copyable_v")
3661 inline constexpr bool is_trivial_v = __is_trivial(_Tp);
3662 template <typename _Tp>
3663 inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
3664 template <typename _Tp>
3665 inline constexpr bool is_standard_layout_v = __is_standard_layout(_Tp);
3666 template <typename _Tp>
3667 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout_v && is_trivial_v")
3668 inline constexpr bool is_pod_v = __is_pod(_Tp);
3669 template <typename _Tp>
3670 _GLIBCXX17_DEPRECATED
3671 inline constexpr bool is_literal_type_v = __is_literal_type(_Tp);
3672 template <typename _Tp>
3673 inline constexpr bool is_empty_v = __is_empty(_Tp);
3674 template <typename _Tp>
3675 inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
3676 template <typename _Tp>
3677 inline constexpr bool is_abstract_v = __is_abstract(_Tp);
3678 template <typename _Tp>
3679 inline constexpr bool is_final_v = __is_final(_Tp);
3681 template <typename _Tp>
3682 inline constexpr bool is_signed_v = is_signed<_Tp>::value;
3683 template <typename _Tp>
3684 inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
3686 template <typename _Tp, typename... _Args>
3687 inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
3688 template <typename _Tp>
3689 inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
3690 template <typename _Tp>
3691 inline constexpr bool is_copy_constructible_v
3692 = __is_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3693 template <typename _Tp>
3694 inline constexpr bool is_move_constructible_v
3695 = __is_constructible(_Tp, __add_rval_ref_t<_Tp>);
3697 template <typename _Tp, typename _Up>
3698 inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Up);
3699 template <typename _Tp>
3700 inline constexpr bool is_copy_assignable_v
3701 = __is_assignable(__add_lval_ref_t<_Tp>, __add_lval_ref_t<const _Tp>);
3702 template <typename _Tp>
3703 inline constexpr bool is_move_assignable_v
3704 = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3706 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_destructible)
3707 template <typename _Tp>
3708 inline constexpr bool is_destructible_v = __is_destructible(_Tp);
3710 template <typename _Tp>
3711 inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
3714 template <typename _Tp, typename... _Args>
3715 inline constexpr bool is_trivially_constructible_v
3716 = __is_trivially_constructible(_Tp, _Args...);
3717 template <typename _Tp>
3718 inline constexpr bool is_trivially_default_constructible_v
3719 = __is_trivially_constructible(_Tp);
3720 template <typename _Tp>
3721 inline constexpr bool is_trivially_copy_constructible_v
3722 = __is_trivially_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3723 template <typename _Tp>
3724 inline constexpr bool is_trivially_move_constructible_v
3725 = __is_trivially_constructible(_Tp, __add_rval_ref_t<_Tp>);
3727 template <typename _Tp, typename _Up>
3728 inline constexpr bool is_trivially_assignable_v
3729 = __is_trivially_assignable(_Tp, _Up);
3730 template <typename _Tp>
3731 inline constexpr bool is_trivially_copy_assignable_v
3732 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3733 __add_lval_ref_t<const _Tp>);
3734 template <typename _Tp>
3735 inline constexpr bool is_trivially_move_assignable_v
3736 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3737 __add_rval_ref_t<_Tp>);
3739 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_trivially_destructible)
3740 template <typename _Tp>
3741 inline constexpr bool is_trivially_destructible_v
3742 = __is_trivially_destructible(_Tp);
3743 #elif __cpp_concepts
3744 template <typename _Tp>
3745 inline constexpr bool is_trivially_destructible_v = false;
3747 template <typename _Tp>
3748 requires (!is_reference_v<_Tp>) && requires (_Tp& __t) { __t.~_Tp(); }
3749 inline constexpr bool is_trivially_destructible_v<_Tp>
3750 = __has_trivial_destructor(_Tp);
3751 template <typename _Tp>
3752 inline constexpr bool is_trivially_destructible_v<_Tp&> = true;
3753 template <typename _Tp>
3754 inline constexpr bool is_trivially_destructible_v<_Tp&&> = true;
3755 template <typename _Tp, size_t _Nm>
3756 inline constexpr bool is_trivially_destructible_v<_Tp[_Nm]>
3757 = is_trivially_destructible_v<_Tp>;
3759 template <typename _Tp>
3760 inline constexpr bool is_trivially_destructible_v =
3761 is_trivially_destructible<_Tp>::value;
3764 template <typename _Tp, typename... _Args>
3765 inline constexpr bool is_nothrow_constructible_v
3766 = __is_nothrow_constructible(_Tp, _Args...);
3767 template <typename _Tp>
3768 inline constexpr bool is_nothrow_default_constructible_v
3769 = __is_nothrow_constructible(_Tp);
3770 template <typename _Tp>
3771 inline constexpr bool is_nothrow_copy_constructible_v
3772 = __is_nothrow_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3773 template <typename _Tp>
3774 inline constexpr bool is_nothrow_move_constructible_v
3775 = __is_nothrow_constructible(_Tp, __add_rval_ref_t<_Tp>);
3777 template <typename _Tp, typename _Up>
3778 inline constexpr bool is_nothrow_assignable_v
3779 = __is_nothrow_assignable(_Tp, _Up);
3780 template <typename _Tp>
3781 inline constexpr bool is_nothrow_copy_assignable_v
3782 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>,
3783 __add_lval_ref_t<const _Tp>);
3784 template <typename _Tp>
3785 inline constexpr bool is_nothrow_move_assignable_v
3786 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3788 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_destructible)
3789 template <typename _Tp>
3790 inline constexpr bool is_nothrow_destructible_v
3791 = __is_nothrow_destructible(_Tp);
3793 template <typename _Tp>
3794 inline constexpr bool is_nothrow_destructible_v =
3795 is_nothrow_destructible<_Tp>::value;
3798 template <typename _Tp>
3799 inline constexpr bool has_virtual_destructor_v
3800 = __has_virtual_destructor(_Tp);
3802 template <typename _Tp>
3803 inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
3805 #if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) \
3806 && (!defined(__clang__) || __clang_major__ >= 20) // PR118559
3807 template <typename _Tp>
3808 inline constexpr size_t rank_v = __array_rank(_Tp);
3810 template <typename _Tp>
3811 inline constexpr size_t rank_v = 0;
3812 template <typename _Tp, size_t _Size>
3813 inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
3814 template <typename _Tp>
3815 inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
3818 template <typename _Tp, unsigned _Idx = 0>
3819 inline constexpr size_t extent_v = 0;
3820 template <typename _Tp, size_t _Size>
3821 inline constexpr size_t extent_v<_Tp[_Size], 0> = _Size;
3822 template <typename _Tp, unsigned _Idx, size_t _Size>
3823 inline constexpr size_t extent_v<_Tp[_Size], _Idx> = extent_v<_Tp, _Idx - 1>;
3824 template <typename _Tp>
3825 inline constexpr size_t extent_v<_Tp[], 0> = 0;
3826 template <typename _Tp, unsigned _Idx>
3827 inline constexpr size_t extent_v<_Tp[], _Idx> = extent_v<_Tp, _Idx - 1>;
3829 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
3830 template <typename _Tp, typename _Up>
3831 inline constexpr bool is_same_v = __is_same(_Tp, _Up);
3833 template <typename _Tp, typename _Up>
3834 inline constexpr bool is_same_v = false;
3835 template <typename _Tp>
3836 inline constexpr bool is_same_v<_Tp, _Tp> = true;
3838 template <typename _Base, typename _Derived>
3839 inline constexpr bool is_base_of_v = __is_base_of(_Base, _Derived);
3840 #ifdef __cpp_lib_is_virtual_base_of // C++ >= 26
3841 template <typename _Base, typename _Derived>
3842 inline constexpr bool is_virtual_base_of_v = __builtin_is_virtual_base_of(_Base, _Derived);
3844 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
3845 template <typename _From, typename _To>
3846 inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
3848 template <typename _From, typename _To>
3849 inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
3851 template<typename _Fn, typename... _Args>
3852 inline constexpr bool is_invocable_v
3853 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3854 = __is_invocable(_Fn, _Args...);
3856 = is_invocable<_Fn, _Args...>::value;
3858 template<typename _Fn, typename... _Args>
3859 inline constexpr bool is_nothrow_invocable_v
3860 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3861 = __is_nothrow_invocable(_Fn, _Args...);
3863 = is_nothrow_invocable<_Fn, _Args...>::value;
3865 template<typename _Ret, typename _Fn, typename... _Args>
3866 inline constexpr bool is_invocable_r_v
3867 = is_invocable_r<_Ret, _Fn, _Args...>::value;
3868 template<typename _Ret, typename _Fn, typename... _Args>
3869 inline constexpr bool is_nothrow_invocable_r_v
3870 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3872 #endif // __cpp_lib_type_trait_variable_templates
3874 #ifdef __cpp_lib_has_unique_object_representations // C++ >= 17 && HAS_UNIQ_OBJ_REP
3875 /// has_unique_object_representations
3877 template<typename _Tp>
3878 struct has_unique_object_representations
3879 : bool_constant<__has_unique_object_representations(
3880 remove_cv_t<remove_all_extents_t<_Tp>>
3883 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3884 "template argument must be a complete class or an unbounded array");
3887 # if __cpp_lib_type_trait_variable_templates // C++ >= 17
3888 /// @ingroup variable_templates
3889 template<typename _Tp>
3890 inline constexpr bool has_unique_object_representations_v
3891 = has_unique_object_representations<_Tp>::value;
3895 #ifdef __cpp_lib_is_aggregate // C++ >= 17 && builtin_is_aggregate
3896 /// is_aggregate - true if the type is an aggregate.
3898 template<typename _Tp>
3900 : bool_constant<__is_aggregate(remove_cv_t<_Tp>)>
3903 # if __cpp_lib_type_trait_variable_templates // C++ >= 17
3904 /** is_aggregate_v - true if the type is an aggregate.
3905 * @ingroup variable_templates
3908 template<typename _Tp>
3909 inline constexpr bool is_aggregate_v = __is_aggregate(remove_cv_t<_Tp>);
3913 #if __cpp_lib_is_structural >= 202603L // C++ >= 26
3914 /// is_structural - true if the type is a structural type.
3916 template<typename _Tp>
3917 struct is_structural
3918 : bool_constant<__builtin_is_structural(_Tp)>
3921 /** is_structural_v - true if the type is a structural only type.
3922 * @ingroup variable_templates
3925 template<typename _Tp>
3926 inline constexpr bool is_structural_v
3927 = __builtin_is_structural(_Tp);
3930 /** * Remove references and cv-qualifiers.
3934 #ifdef __cpp_lib_remove_cvref // C++ >= 20
3935 # if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cvref)
3936 template<typename _Tp>
3938 { using type = __remove_cvref(_Tp); };
3940 template<typename _Tp>
3942 { using type = typename remove_cv<_Tp>::type; };
3944 template<typename _Tp>
3945 struct remove_cvref<_Tp&>
3946 { using type = typename remove_cv<_Tp>::type; };
3948 template<typename _Tp>
3949 struct remove_cvref<_Tp&&>
3950 { using type = typename remove_cv<_Tp>::type; };
3953 template<typename _Tp>
3954 using remove_cvref_t = typename remove_cvref<_Tp>::type;
3956 #endif // __cpp_lib_remove_cvref
3958 #ifdef __cpp_lib_type_identity // C++ >= 20
3959 /** * Identity metafunction.
3963 template<typename _Tp>
3964 struct type_identity { using type = _Tp; };
3966 template<typename _Tp>
3967 using type_identity_t = typename type_identity<_Tp>::type;
3971 #ifdef __cpp_lib_unwrap_ref // C++ >= 20
3972 /** Unwrap a reference_wrapper
3976 template<typename _Tp>
3977 struct unwrap_reference { using type = _Tp; };
3979 template<typename _Tp>
3980 struct unwrap_reference<reference_wrapper<_Tp>> { using type = _Tp&; };
3982 template<typename _Tp>
3983 using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3986 /** Decay type and if it's a reference_wrapper, unwrap it
3990 template<typename _Tp>
3991 struct unwrap_ref_decay { using type = unwrap_reference_t<decay_t<_Tp>>; };
3993 template<typename _Tp>
3994 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3996 #endif // __cpp_lib_unwrap_ref
3998 #ifdef __cpp_lib_bounded_array_traits // C++ >= 20
3999 /// True for a type that is an array of known bound.
4000 /// @ingroup variable_templates
4002 # if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array)
4003 template<typename _Tp>
4004 inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp);
4006 template<typename _Tp>
4007 inline constexpr bool is_bounded_array_v = false;
4009 template<typename _Tp, size_t _Size>
4010 inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true;
4013 /// True for a type that is an array of unknown bound.
4014 /// @ingroup variable_templates
4016 # if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array)
4017 template<typename _Tp>
4018 inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp);
4020 template<typename _Tp>
4021 inline constexpr bool is_unbounded_array_v = false;
4023 template<typename _Tp>
4024 inline constexpr bool is_unbounded_array_v<_Tp[]> = true;
4027 /// True for a type that is an array of known bound.
4029 template<typename _Tp>
4030 struct is_bounded_array
4031 : public bool_constant<is_bounded_array_v<_Tp>>
4034 /// True for a type that is an array of unknown bound.
4036 template<typename _Tp>
4037 struct is_unbounded_array
4038 : public bool_constant<is_unbounded_array_v<_Tp>>
4040 #endif // __cpp_lib_bounded_array_traits
4042 #if __has_builtin(__is_layout_compatible) && __cplusplus >= 202002L
4045 template<typename _Tp, typename _Up>
4046 struct is_layout_compatible
4047 : bool_constant<__is_layout_compatible(_Tp, _Up)>
4050 /// @ingroup variable_templates
4052 template<typename _Tp, typename _Up>
4053 constexpr bool is_layout_compatible_v
4054 = __is_layout_compatible(_Tp, _Up);
4056 #if __has_builtin(__builtin_is_corresponding_member)
4057 # ifndef __cpp_lib_is_layout_compatible
4058 # error "libstdc++ bug: is_corresponding_member and is_layout_compatible are provided but their FTM is not set"
4062 template<typename _S1, typename _S2, typename _M1, typename _M2>
4064 is_corresponding_member(_M1 _S1::*__m1, _M2 _S2::*__m2) noexcept
4065 { return __builtin_is_corresponding_member(__m1, __m2); }
4069 #if __has_builtin(__is_pointer_interconvertible_base_of) \
4070 && __cplusplus >= 202002L
4071 /// True if `_Derived` is standard-layout and has a base class of type `_Base`
4073 template<typename _Base, typename _Derived>
4074 struct is_pointer_interconvertible_base_of
4075 : bool_constant<__is_pointer_interconvertible_base_of(_Base, _Derived)>
4078 /// @ingroup variable_templates
4080 template<typename _Base, typename _Derived>
4081 constexpr bool is_pointer_interconvertible_base_of_v
4082 = __is_pointer_interconvertible_base_of(_Base, _Derived);
4084 #if __has_builtin(__builtin_is_pointer_interconvertible_with_class)
4085 # ifndef __cpp_lib_is_pointer_interconvertible
4086 # error "libstdc++ bug: is_pointer_interconvertible available but FTM is not set"
4089 /// True if `__mp` points to the first member of a standard-layout type
4090 /// @returns true if `s.*__mp` is pointer-interconvertible with `s`
4092 template<typename _Tp, typename _Mem>
4094 is_pointer_interconvertible_with_class(_Mem _Tp::*__mp) noexcept
4095 { return __builtin_is_pointer_interconvertible_with_class(__mp); }
4099 #ifdef __cpp_lib_is_scoped_enum // C++ >= 23
4100 /// True if the type is a scoped enumeration type.
4103 # if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
4104 template<typename _Tp>
4105 struct is_scoped_enum
4106 : bool_constant<__is_scoped_enum(_Tp)>
4109 template<typename _Tp>
4110 struct is_scoped_enum
4114 template<typename _Tp>
4115 requires __is_enum(_Tp)
4116 && requires(remove_cv_t<_Tp> __t) { __t = __t; } // fails if incomplete
4117 struct is_scoped_enum<_Tp>
4118 : bool_constant<!requires(_Tp __t, void(*__f)(int)) { __f(__t); }>
4122 /// @ingroup variable_templates
4124 # if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
4125 template<typename _Tp>
4126 inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
4128 template<typename _Tp>
4129 inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
4133 #ifdef __cpp_lib_is_implicit_lifetime // C++ >= 23
4134 /// True if the type is an implicit-lifetime type.
4137 template<typename _Tp>
4138 struct is_implicit_lifetime
4139 : bool_constant<__builtin_is_implicit_lifetime(_Tp)>
4142 /// @ingroup variable_templates
4144 template<typename _Tp>
4145 inline constexpr bool is_implicit_lifetime_v
4146 = __builtin_is_implicit_lifetime(_Tp);
4149 #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp
4150 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
4151 /// direct-initialization, and a temporary object would be bound to
4152 /// the reference, false otherwise.
4154 template<typename _Tp, typename _Up>
4155 struct reference_constructs_from_temporary
4156 : public bool_constant<__reference_constructs_from_temporary(_Tp, _Up)>
4158 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
4159 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
4160 "template argument must be a complete class or an unbounded array");
4163 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
4164 /// copy-initialization, and a temporary object would be bound to
4165 /// the reference, false otherwise.
4167 template<typename _Tp, typename _Up>
4168 struct reference_converts_from_temporary
4169 : public bool_constant<__reference_converts_from_temporary(_Tp, _Up)>
4171 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
4172 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
4173 "template argument must be a complete class or an unbounded array");
4176 /// @ingroup variable_templates
4178 template<typename _Tp, typename _Up>
4179 inline constexpr bool reference_constructs_from_temporary_v
4180 = reference_constructs_from_temporary<_Tp, _Up>::value;
4182 /// @ingroup variable_templates
4184 template<typename _Tp, typename _Up>
4185 inline constexpr bool reference_converts_from_temporary_v
4186 = reference_converts_from_temporary<_Tp, _Up>::value;
4187 #endif // __cpp_lib_reference_from_temporary
4189 #ifdef __cpp_lib_is_constant_evaluated // C++ >= 20 && HAVE_IS_CONST_EVAL
4190 /// Returns true only when called during constant evaluation.
4192 [[__gnu__::__always_inline__]]
4194 is_constant_evaluated() noexcept
4196 #if __cpp_if_consteval >= 202106L
4197 if consteval { return true; } else { return false; }
4199 return __builtin_is_constant_evaluated();
4204 #if __cplusplus >= 202002L
4205 /// @cond undocumented
4206 template<typename _From, typename _To>
4207 using __copy_cv = typename __match_cv_qualifiers<_From, _To>::__type;
4209 template<typename _Xp, typename _Yp>
4211 = decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
4213 template<typename _Ap, typename _Bp, typename = void>
4214 struct __common_ref_impl
4217 // [meta.trans.other], COMMON-REF(A, B)
4218 template<typename _Ap, typename _Bp>
4219 using __common_ref = typename __common_ref_impl<_Ap, _Bp>::type;
4221 // COND-RES(COPYCV(X, Y) &, COPYCV(Y, X) &)
4222 template<typename _Xp, typename _Yp>
4223 using __condres_cvref
4224 = __cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>;
4226 // If A and B are both lvalue reference types, ...
4227 template<typename _Xp, typename _Yp>
4228 struct __common_ref_impl<_Xp&, _Yp&, __void_t<__condres_cvref<_Xp, _Yp>>>
4229 : enable_if<is_reference_v<__condres_cvref<_Xp, _Yp>>,
4230 __condres_cvref<_Xp, _Yp>>
4233 // let C be remove_reference_t<COMMON-REF(X&, Y&)>&&
4234 template<typename _Xp, typename _Yp>
4235 using __common_ref_C = remove_reference_t<__common_ref<_Xp&, _Yp&>>&&;
4237 // If A and B are both rvalue reference types, ...
4238 template<typename _Xp, typename _Yp>
4239 struct __common_ref_impl<_Xp&&, _Yp&&,
4240 _Require<is_convertible<_Xp&&, __common_ref_C<_Xp, _Yp>>,
4241 is_convertible<_Yp&&, __common_ref_C<_Xp, _Yp>>>>
4242 { using type = __common_ref_C<_Xp, _Yp>; };
4244 // let D be COMMON-REF(const X&, Y&)
4245 template<typename _Xp, typename _Yp>
4246 using __common_ref_D = __common_ref<const _Xp&, _Yp&>;
4248 // If A is an rvalue reference and B is an lvalue reference, ...
4249 template<typename _Xp, typename _Yp>
4250 struct __common_ref_impl<_Xp&&, _Yp&,
4251 _Require<is_convertible<_Xp&&, __common_ref_D<_Xp, _Yp>>>>
4252 { using type = __common_ref_D<_Xp, _Yp>; };
4254 // If A is an lvalue reference and B is an rvalue reference, ...
4255 template<typename _Xp, typename _Yp>
4256 struct __common_ref_impl<_Xp&, _Yp&&>
4257 : __common_ref_impl<_Yp&&, _Xp&>
4261 template<typename _Tp, typename _Up,
4262 template<typename> class _TQual, template<typename> class _UQual>
4263 struct basic_common_reference
4266 /// @cond undocumented
4267 template<typename _Tp>
4269 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>; };
4271 template<typename _Tp>
4273 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&; };
4275 template<typename _Tp>
4276 struct __xref<_Tp&&>
4277 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&&; };
4279 template<typename _Tp1, typename _Tp2>
4280 using __basic_common_ref
4281 = typename basic_common_reference<remove_cvref_t<_Tp1>,
4282 remove_cvref_t<_Tp2>,
4283 __xref<_Tp1>::template __type,
4284 __xref<_Tp2>::template __type>::type;
4287 template<typename... _Tp>
4288 struct common_reference;
4290 template<typename... _Tp>
4291 using common_reference_t = typename common_reference<_Tp...>::type;
4293 // If sizeof...(T) is zero, there shall be no member type.
4295 struct common_reference<>
4298 // If sizeof...(T) is one ...
4299 template<typename _Tp0>
4300 struct common_reference<_Tp0>
4301 { using type = _Tp0; };
4303 /// @cond undocumented
4304 template<typename _Tp1, typename _Tp2, int _Bullet = 1>
4305 struct __common_reference_impl
4306 : __common_reference_impl<_Tp1, _Tp2, _Bullet + 1>
4309 // If sizeof...(T) is two ...
4310 template<typename _Tp1, typename _Tp2>
4311 struct common_reference<_Tp1, _Tp2>
4312 : __common_reference_impl<_Tp1, _Tp2>
4315 // If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, ...
4316 template<typename _Tp1, typename _Tp2>
4317 requires is_reference_v<_Tp1> && is_reference_v<_Tp2>
4318 && requires { typename __common_ref<_Tp1, _Tp2>; }
4319 #if __cpp_lib_common_reference // C++ >= 20
4320 && is_convertible_v<add_pointer_t<_Tp1>,
4321 add_pointer_t<__common_ref<_Tp1, _Tp2>>>
4322 && is_convertible_v<add_pointer_t<_Tp2>,
4323 add_pointer_t<__common_ref<_Tp1, _Tp2>>>
4325 struct __common_reference_impl<_Tp1, _Tp2, 1>
4326 { using type = __common_ref<_Tp1, _Tp2>; };
4328 // Otherwise, if basic_common_reference<...>::type is well-formed, ...
4329 template<typename _Tp1, typename _Tp2>
4330 requires requires { typename __basic_common_ref<_Tp1, _Tp2>; }
4331 struct __common_reference_impl<_Tp1, _Tp2, 2>
4332 { using type = __basic_common_ref<_Tp1, _Tp2>; };
4334 // Otherwise, if COND-RES(T1, T2) is well-formed, ...
4335 template<typename _Tp1, typename _Tp2>
4336 requires requires { typename __cond_res<_Tp1, _Tp2>; }
4337 struct __common_reference_impl<_Tp1, _Tp2, 3>
4338 { using type = __cond_res<_Tp1, _Tp2>; };
4340 // Otherwise, if common_type_t<T1, T2> is well-formed, ...
4341 template<typename _Tp1, typename _Tp2>
4342 requires requires { typename common_type_t<_Tp1, _Tp2>; }
4343 struct __common_reference_impl<_Tp1, _Tp2, 4>
4344 { using type = common_type_t<_Tp1, _Tp2>; };
4346 // Otherwise, there shall be no member type.
4347 template<typename _Tp1, typename _Tp2>
4348 struct __common_reference_impl<_Tp1, _Tp2, 5>
4351 // Otherwise, if sizeof...(T) is greater than two, ...
4352 template<typename _Tp1, typename _Tp2, typename... _Rest>
4353 struct common_reference<_Tp1, _Tp2, _Rest...>
4354 : __common_type_fold<common_reference<_Tp1, _Tp2>,
4355 __common_type_pack<_Rest...>>
4358 // Reuse __common_type_fold for common_reference<T1, T2, Rest...>
4359 template<typename _Tp1, typename _Tp2, typename... _Rest>
4360 struct __common_type_fold<common_reference<_Tp1, _Tp2>,
4361 __common_type_pack<_Rest...>,
4362 void_t<common_reference_t<_Tp1, _Tp2>>>
4363 : public common_reference<common_reference_t<_Tp1, _Tp2>, _Rest...>
4369 #if __cplusplus >= 201103L
4370 // Stores a tuple of indices. Used by tuple and pair, and by bind() to
4371 // extract the elements in a tuple.
4372 template<size_t... _Indexes> struct _Index_tuple { };
4374 // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
4375 template<size_t _Num>
4376 struct _Build_index_tuple
4378 #if __has_builtin(__make_integer_seq)
4379 template<typename, size_t... _Indices>
4380 using _IdxTuple = _Index_tuple<_Indices...>;
4382 // Clang defines __make_integer_seq for this purpose.
4383 using __type = __make_integer_seq<_IdxTuple, size_t, _Num>;
4385 // For GCC and other compilers, use __integer_pack instead.
4386 using __type = _Index_tuple<__integer_pack(_Num)...>;
4391 /// @} group metaprogramming
4393 _GLIBCXX_END_NAMESPACE_VERSION
4399 #endif // _GLIBCXX_TYPE_TRAITS