1// C++11 <type_traits> -*- C++ -*-
3// Copyright (C) 2007-2024 Free Software Foundation, Inc.
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
25/** @file include/type_traits
26 * This is a Standard C++ Library header.
29#ifndef _GLIBCXX_TYPE_TRAITS
30#define _GLIBCXX_TYPE_TRAITS 1
33#pragma GCC system_header
36#if __cplusplus < 201103L
37# include <bits/c++0x_warning.h>
40#include <bits/c++config.h>
42#define __glibcxx_want_bool_constant
43#define __glibcxx_want_bounded_array_traits
44#define __glibcxx_want_has_unique_object_representations
45#define __glibcxx_want_integral_constant_callable
46#define __glibcxx_want_is_aggregate
47#define __glibcxx_want_is_constant_evaluated
48#define __glibcxx_want_is_final
49#define __glibcxx_want_is_invocable
50#define __glibcxx_want_is_layout_compatible
51#define __glibcxx_want_is_nothrow_convertible
52#define __glibcxx_want_is_null_pointer
53#define __glibcxx_want_is_pointer_interconvertible
54#define __glibcxx_want_is_scoped_enum
55#define __glibcxx_want_is_swappable
56#define __glibcxx_want_is_virtual_base_of
57#define __glibcxx_want_logical_traits
58#define __glibcxx_want_reference_from_temporary
59#define __glibcxx_want_remove_cvref
60#define __glibcxx_want_result_of_sfinae
61#define __glibcxx_want_transformation_trait_aliases
62#define __glibcxx_want_type_identity
63#define __glibcxx_want_type_trait_variable_templates
64#define __glibcxx_want_unwrap_ref
65#define __glibcxx_want_void_t
66#include <bits/version.h>
70namespace std _GLIBCXX_VISIBILITY(default)
72_GLIBCXX_BEGIN_NAMESPACE_VERSION
74 template<typename _Tp>
75 class reference_wrapper;
78 * @defgroup metaprogramming Metaprogramming
81 * Template utilities for compile-time introspection and modification,
82 * including type classification traits, type property inspection traits
83 * and type transformation traits.
91 template<typename _Tp, _Tp __v>
92 struct integral_constant
94 static constexpr _Tp value = __v;
95 using value_type = _Tp;
96 using type = integral_constant<_Tp, __v>;
97 constexpr operator value_type() const noexcept { return value; }
99#ifdef __cpp_lib_integral_constant_callable // C++ >= 14
100 constexpr value_type operator()() const noexcept { return value; }
104#if ! __cpp_inline_variables
105 template<typename _Tp, _Tp __v>
106 constexpr _Tp integral_constant<_Tp, __v>::value;
109 /// @cond undocumented
110 /// bool_constant for C++11
112 using __bool_constant = integral_constant<bool, __v>;
115 /// The type used as a compile-time boolean with true value.
116 using true_type = __bool_constant<true>;
118 /// The type used as a compile-time boolean with false value.
119 using false_type = __bool_constant<false>;
121#ifdef __cpp_lib_bool_constant // C++ >= 17
122 /// Alias template for compile-time boolean constant types.
125 using bool_constant = __bool_constant<__v>;
128 // Metaprogramming helper types.
131 /// Define a member typedef `type` only if a boolean constant is true.
132 template<bool, typename _Tp = void>
136 // Partial specialization for true.
137 template<typename _Tp>
138 struct enable_if<true, _Tp>
139 { using type = _Tp; };
141 // __enable_if_t (std::enable_if_t for C++11)
142 template<bool _Cond, typename _Tp = void>
143 using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
148 template<typename _Tp, typename>
153 struct __conditional<false>
155 template<typename, typename _Up>
159 // More efficient version of std::conditional_t for internal use (and C++11)
160 template<bool _Cond, typename _If, typename _Else>
161 using __conditional_t
162 = typename __conditional<_Cond>::template type<_If, _Else>;
164 /// @cond undocumented
165 template <typename _Type>
166 struct __type_identity
167 { using type = _Type; };
169 template<typename _Tp>
170 using __type_identity_t = typename __type_identity<_Tp>::type;
174 // A variadic alias template that resolves to its first argument.
175 template<typename _Tp, typename...>
176 using __first_t = _Tp;
178 // These are deliberately not defined.
179 template<typename... _Bn>
180 auto __or_fn(int) -> __first_t<false_type,
181 __enable_if_t<!bool(_Bn::value)>...>;
183 template<typename... _Bn>
184 auto __or_fn(...) -> true_type;
186 template<typename... _Bn>
187 auto __and_fn(int) -> __first_t<true_type,
188 __enable_if_t<bool(_Bn::value)>...>;
190 template<typename... _Bn>
191 auto __and_fn(...) -> false_type;
192 } // namespace detail
194 // Like C++17 std::dis/conjunction, but usable in C++11 and resolves
195 // to either true_type or false_type which allows for a more efficient
196 // implementation that avoids recursive class template instantiation.
197 template<typename... _Bn>
199 : decltype(__detail::__or_fn<_Bn...>(0))
202 template<typename... _Bn>
204 : decltype(__detail::__and_fn<_Bn...>(0))
207 template<typename _Pp>
209 : __bool_constant<!bool(_Pp::value)>
213#ifdef __cpp_lib_logical_traits // C++ >= 17
215 /// @cond undocumented
216 template<typename... _Bn>
217 inline constexpr bool __or_v = __or_<_Bn...>::value;
218 template<typename... _Bn>
219 inline constexpr bool __and_v = __and_<_Bn...>::value;
223 template<typename /* = void */, typename _B1, typename... _Bn>
224 struct __disjunction_impl
225 { using type = _B1; };
227 template<typename _B1, typename _B2, typename... _Bn>
228 struct __disjunction_impl<__enable_if_t<!bool(_B1::value)>, _B1, _B2, _Bn...>
229 { using type = typename __disjunction_impl<void, _B2, _Bn...>::type; };
231 template<typename /* = void */, typename _B1, typename... _Bn>
232 struct __conjunction_impl
233 { using type = _B1; };
235 template<typename _B1, typename _B2, typename... _Bn>
236 struct __conjunction_impl<__enable_if_t<bool(_B1::value)>, _B1, _B2, _Bn...>
237 { using type = typename __conjunction_impl<void, _B2, _Bn...>::type; };
238 } // namespace __detail
241 template<typename... _Bn>
243 : __detail::__conjunction_impl<void, _Bn...>::type
251 template<typename... _Bn>
253 : __detail::__disjunction_impl<void, _Bn...>::type
261 template<typename _Pp>
266 /** @ingroup variable_templates
269 template<typename... _Bn>
270 inline constexpr bool conjunction_v = conjunction<_Bn...>::value;
272 template<typename... _Bn>
273 inline constexpr bool disjunction_v = disjunction<_Bn...>::value;
275 template<typename _Pp>
276 inline constexpr bool negation_v = negation<_Pp>::value;
279#endif // __cpp_lib_logical_traits
281 // Forward declarations
293 /// @cond undocumented
295 struct __is_array_unknown_bounds;
297 // Helper functions that return false_type for incomplete classes,
298 // incomplete unions and arrays of known bound from those.
300 template <typename _Tp, size_t = sizeof(_Tp)>
301 constexpr true_type __is_complete_or_unbounded(__type_identity<_Tp>)
304 template <typename _TypeIdentity,
305 typename _NestedType = typename _TypeIdentity::type>
306 constexpr typename __or_<
307 is_reference<_NestedType>,
308 is_function<_NestedType>,
309 is_void<_NestedType>,
310 __is_array_unknown_bounds<_NestedType>
311 >::type __is_complete_or_unbounded(_TypeIdentity)
314 // __remove_cv_t (std::remove_cv_t for C++11).
315 template<typename _Tp>
316 using __remove_cv_t = typename remove_cv<_Tp>::type;
319 // Primary type categories.
322 template<typename _Tp>
324 : public false_type { };
328 : public true_type { };
331 struct is_void<const void>
332 : public true_type { };
335 struct is_void<volatile void>
336 : public true_type { };
339 struct is_void<const volatile void>
340 : public true_type { };
342 /// @cond undocumented
344 struct __is_integral_helper
345 : public false_type { };
348 struct __is_integral_helper<bool>
349 : public true_type { };
352 struct __is_integral_helper<char>
353 : public true_type { };
356 struct __is_integral_helper<signed char>
357 : public true_type { };
360 struct __is_integral_helper<unsigned char>
361 : public true_type { };
363 // We want is_integral<wchar_t> to be true (and make_signed/unsigned to work)
364 // even when libc doesn't provide working <wchar.h> and related functions,
365 // so don't check _GLIBCXX_USE_WCHAR_T here.
367 struct __is_integral_helper<wchar_t>
368 : public true_type { };
370#ifdef _GLIBCXX_USE_CHAR8_T
372 struct __is_integral_helper<char8_t>
373 : public true_type { };
377 struct __is_integral_helper<char16_t>
378 : public true_type { };
381 struct __is_integral_helper<char32_t>
382 : public true_type { };
385 struct __is_integral_helper<short>
386 : public true_type { };
389 struct __is_integral_helper<unsigned short>
390 : public true_type { };
393 struct __is_integral_helper<int>
394 : public true_type { };
397 struct __is_integral_helper<unsigned int>
398 : public true_type { };
401 struct __is_integral_helper<long>
402 : public true_type { };
405 struct __is_integral_helper<unsigned long>
406 : public true_type { };
409 struct __is_integral_helper<long long>
410 : public true_type { };
413 struct __is_integral_helper<unsigned long long>
414 : public true_type { };
416 // Conditionalizing on __STRICT_ANSI__ here will break any port that
417 // uses one of these types for size_t.
418#if defined(__GLIBCXX_TYPE_INT_N_0)
421 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
422 : public true_type { };
426 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
427 : public true_type { };
429#if defined(__GLIBCXX_TYPE_INT_N_1)
432 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
433 : public true_type { };
437 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
438 : public true_type { };
440#if defined(__GLIBCXX_TYPE_INT_N_2)
443 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
444 : public true_type { };
448 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
449 : public true_type { };
451#if defined(__GLIBCXX_TYPE_INT_N_3)
454 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
455 : public true_type { };
459 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
460 : public true_type { };
465 template<typename _Tp>
467 : public __is_integral_helper<__remove_cv_t<_Tp>>::type
470 /// @cond undocumented
472 struct __is_floating_point_helper
473 : public false_type { };
476 struct __is_floating_point_helper<float>
477 : public true_type { };
480 struct __is_floating_point_helper<double>
481 : public true_type { };
484 struct __is_floating_point_helper<long double>
485 : public true_type { };
487#ifdef __STDCPP_FLOAT16_T__
489 struct __is_floating_point_helper<_Float16>
490 : public true_type { };
493#ifdef __STDCPP_FLOAT32_T__
495 struct __is_floating_point_helper<_Float32>
496 : public true_type { };
499#ifdef __STDCPP_FLOAT64_T__
501 struct __is_floating_point_helper<_Float64>
502 : public true_type { };
505#ifdef __STDCPP_FLOAT128_T__
507 struct __is_floating_point_helper<_Float128>
508 : public true_type { };
511#ifdef __STDCPP_BFLOAT16_T__
513 struct __is_floating_point_helper<__gnu_cxx::__bfloat16_t>
514 : public true_type { };
517#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
519 struct __is_floating_point_helper<__float128>
520 : public true_type { };
524 /// is_floating_point
525 template<typename _Tp>
526 struct is_floating_point
527 : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type
531#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
532 template<typename _Tp>
534 : public __bool_constant<__is_array(_Tp)>
539 : public false_type { };
541 template<typename _Tp, std::size_t _Size>
542 struct is_array<_Tp[_Size]>
543 : public true_type { };
545 template<typename _Tp>
546 struct is_array<_Tp[]>
547 : public true_type { };
551#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
552 template<typename _Tp>
554 : public __bool_constant<__is_pointer(_Tp)>
557 template<typename _Tp>
559 : public false_type { };
561 template<typename _Tp>
562 struct is_pointer<_Tp*>
563 : public true_type { };
565 template<typename _Tp>
566 struct is_pointer<_Tp* const>
567 : public true_type { };
569 template<typename _Tp>
570 struct is_pointer<_Tp* volatile>
571 : public true_type { };
573 template<typename _Tp>
574 struct is_pointer<_Tp* const volatile>
575 : public true_type { };
578 /// is_lvalue_reference
580 struct is_lvalue_reference
581 : public false_type { };
583 template<typename _Tp>
584 struct is_lvalue_reference<_Tp&>
585 : public true_type { };
587 /// is_rvalue_reference
589 struct is_rvalue_reference
590 : public false_type { };
592 template<typename _Tp>
593 struct is_rvalue_reference<_Tp&&>
594 : public true_type { };
596 /// is_member_object_pointer
597#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
598 template<typename _Tp>
599 struct is_member_object_pointer
600 : public __bool_constant<__is_member_object_pointer(_Tp)>
604 struct __is_member_object_pointer_helper
605 : public false_type { };
607 template<typename _Tp, typename _Cp>
608 struct __is_member_object_pointer_helper<_Tp _Cp::*>
609 : public __not_<is_function<_Tp>>::type { };
612 template<typename _Tp>
613 struct is_member_object_pointer
614 : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type
618#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
619 /// is_member_function_pointer
620 template<typename _Tp>
621 struct is_member_function_pointer
622 : public __bool_constant<__is_member_function_pointer(_Tp)>
626 struct __is_member_function_pointer_helper
627 : public false_type { };
629 template<typename _Tp, typename _Cp>
630 struct __is_member_function_pointer_helper<_Tp _Cp::*>
631 : public is_function<_Tp>::type { };
633 /// is_member_function_pointer
634 template<typename _Tp>
635 struct is_member_function_pointer
636 : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type
641 template<typename _Tp>
643 : public __bool_constant<__is_enum(_Tp)>
647 template<typename _Tp>
649 : public __bool_constant<__is_union(_Tp)>
653 template<typename _Tp>
655 : public __bool_constant<__is_class(_Tp)>
659#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
660 template<typename _Tp>
662 : public __bool_constant<__is_function(_Tp)>
665 template<typename _Tp>
667 : public __bool_constant<!is_const<const _Tp>::value> { };
669 template<typename _Tp>
670 struct is_function<_Tp&>
671 : public false_type { };
673 template<typename _Tp>
674 struct is_function<_Tp&&>
675 : public false_type { };
678#ifdef __cpp_lib_is_null_pointer // C++ >= 11
679 /// is_null_pointer (LWG 2247).
680 template<typename _Tp>
681 struct is_null_pointer
682 : public false_type { };
685 struct is_null_pointer<std::nullptr_t>
686 : public true_type { };
689 struct is_null_pointer<const std::nullptr_t>
690 : public true_type { };
693 struct is_null_pointer<volatile std::nullptr_t>
694 : public true_type { };
697 struct is_null_pointer<const volatile std::nullptr_t>
698 : public true_type { };
700 /// __is_nullptr_t (deprecated extension).
701 /// @deprecated Non-standard. Use `is_null_pointer` instead.
702 template<typename _Tp>
703 struct __is_nullptr_t
704 : public is_null_pointer<_Tp>
705 { } _GLIBCXX_DEPRECATED_SUGGEST("std::is_null_pointer");
706#endif // __cpp_lib_is_null_pointer
708 // Composite type categories.
711#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
712 template<typename _Tp>
714 : public __bool_constant<__is_reference(_Tp)>
717 template<typename _Tp>
722 template<typename _Tp>
723 struct is_reference<_Tp&>
727 template<typename _Tp>
728 struct is_reference<_Tp&&>
734 template<typename _Tp>
736 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
740 template<typename _Tp>
741 struct is_fundamental
742 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
743 is_null_pointer<_Tp>>::type
747#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
748 template<typename _Tp>
750 : public __bool_constant<__is_object(_Tp)>
753 template<typename _Tp>
755 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
761 struct is_member_pointer;
764 template<typename _Tp>
766 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
767 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
771 template<typename _Tp>
773 : public __bool_constant<!is_fundamental<_Tp>::value> { };
775 /// is_member_pointer
776#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
777 template<typename _Tp>
778 struct is_member_pointer
779 : public __bool_constant<__is_member_pointer(_Tp)>
782 /// @cond undocumented
783 template<typename _Tp>
784 struct __is_member_pointer_helper
785 : public false_type { };
787 template<typename _Tp, typename _Cp>
788 struct __is_member_pointer_helper<_Tp _Cp::*>
789 : public true_type { };
792 template<typename _Tp>
793 struct is_member_pointer
794 : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type
798 template<typename, typename>
801 /// @cond undocumented
802 template<typename _Tp, typename... _Types>
803 using __is_one_of = __or_<is_same<_Tp, _Types>...>;
805 // Check if a type is one of the signed integer types.
807 template<typename _Tp>
808 using __is_signed_integer = __is_one_of<__remove_cv_t<_Tp>,
809 signed char, signed short, signed int, signed long,
811#if defined(__GLIBCXX_TYPE_INT_N_0)
812 , signed __GLIBCXX_TYPE_INT_N_0
814#if defined(__GLIBCXX_TYPE_INT_N_1)
815 , signed __GLIBCXX_TYPE_INT_N_1
817#if defined(__GLIBCXX_TYPE_INT_N_2)
818 , signed __GLIBCXX_TYPE_INT_N_2
820#if defined(__GLIBCXX_TYPE_INT_N_3)
821 , signed __GLIBCXX_TYPE_INT_N_3
825 // Check if a type is one of the unsigned integer types.
827 template<typename _Tp>
828 using __is_unsigned_integer = __is_one_of<__remove_cv_t<_Tp>,
829 unsigned char, unsigned short, unsigned int, unsigned long,
831#if defined(__GLIBCXX_TYPE_INT_N_0)
832 , unsigned __GLIBCXX_TYPE_INT_N_0
834#if defined(__GLIBCXX_TYPE_INT_N_1)
835 , unsigned __GLIBCXX_TYPE_INT_N_1
837#if defined(__GLIBCXX_TYPE_INT_N_2)
838 , unsigned __GLIBCXX_TYPE_INT_N_2
840#if defined(__GLIBCXX_TYPE_INT_N_3)
841 , unsigned __GLIBCXX_TYPE_INT_N_3
845 // Check if a type is one of the signed or unsigned integer types.
846 template<typename _Tp>
847 using __is_standard_integer
848 = __or_<__is_signed_integer<_Tp>, __is_unsigned_integer<_Tp>>;
850 // __void_t (std::void_t for C++11)
851 template<typename...> using __void_t = void;
857#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const)
858 template<typename _Tp>
860 : public __bool_constant<__is_const(_Tp)>
865 : public false_type { };
867 template<typename _Tp>
868 struct is_const<_Tp const>
869 : public true_type { };
873#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile)
874 template<typename _Tp>
876 : public __bool_constant<__is_volatile(_Tp)>
881 : public false_type { };
883 template<typename _Tp>
884 struct is_volatile<_Tp volatile>
885 : public true_type { };
889 template<typename _Tp>
891 : public __bool_constant<__is_trivial(_Tp)>
893 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
894 "template argument must be a complete class or an unbounded array");
897 /// is_trivially_copyable
898 template<typename _Tp>
899 struct is_trivially_copyable
900 : public __bool_constant<__is_trivially_copyable(_Tp)>
902 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
903 "template argument must be a complete class or an unbounded array");
906 /// is_standard_layout
907 template<typename _Tp>
908 struct is_standard_layout
909 : public __bool_constant<__is_standard_layout(_Tp)>
911 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
912 "template argument must be a complete class or an unbounded array");
916 * @deprecated Deprecated in C++20.
917 * Use `is_standard_layout && is_trivial` instead.
919 // Could use is_standard_layout && is_trivial instead of the builtin.
920 template<typename _Tp>
922 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout && is_trivial")
924 : public __bool_constant<__is_pod(_Tp)>
926 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
927 "template argument must be a complete class or an unbounded array");
931 * @deprecated Deprecated in C++17, removed in C++20.
932 * The idea of a literal type isn't useful.
934 template<typename _Tp>
936 _GLIBCXX17_DEPRECATED
938 : public __bool_constant<__is_literal_type(_Tp)>
940 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
941 "template argument must be a complete class or an unbounded array");
945 template<typename _Tp>
947 : public __bool_constant<__is_empty(_Tp)>
951 template<typename _Tp>
952 struct is_polymorphic
953 : public __bool_constant<__is_polymorphic(_Tp)>
956#ifdef __cpp_lib_is_final // C++ >= 14
959 template<typename _Tp>
961 : public __bool_constant<__is_final(_Tp)>
966 template<typename _Tp>
968 : public __bool_constant<__is_abstract(_Tp)>
971 /// @cond undocumented
972 template<typename _Tp,
973 bool = is_arithmetic<_Tp>::value>
974 struct __is_signed_helper
975 : public false_type { };
977 template<typename _Tp>
978 struct __is_signed_helper<_Tp, true>
979 : public __bool_constant<_Tp(-1) < _Tp(0)>
984 template<typename _Tp>
986 : public __is_signed_helper<_Tp>::type
990 template<typename _Tp>
992 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
995 /// @cond undocumented
996 template<typename _Tp, typename _Up = _Tp&&>
1000 template<typename _Tp>
1005 template<typename _Tp>
1006 auto declval() noexcept -> decltype(__declval<_Tp>(0));
1009 struct remove_all_extents;
1011 /// @cond undocumented
1012 template<typename _Tp>
1013 struct __is_array_known_bounds
1017 template<typename _Tp, size_t _Size>
1018 struct __is_array_known_bounds<_Tp[_Size]>
1022 template<typename _Tp>
1023 struct __is_array_unknown_bounds
1027 template<typename _Tp>
1028 struct __is_array_unknown_bounds<_Tp[]>
1032 // Destructible and constructible type properties.
1034 // In N3290 is_destructible does not say anything about function
1035 // types and abstract types, see LWG 2049. This implementation
1036 // describes function types as non-destructible and all complete
1037 // object types as destructible, iff the explicit destructor
1038 // call expression is wellformed.
1039 struct __do_is_destructible_impl
1041 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
1042 static true_type __test(int);
1045 static false_type __test(...);
1048 template<typename _Tp>
1049 struct __is_destructible_impl
1050 : public __do_is_destructible_impl
1052 using type = decltype(__test<_Tp>(0));
1055 template<typename _Tp,
1056 bool = __or_<is_void<_Tp>,
1057 __is_array_unknown_bounds<_Tp>,
1058 is_function<_Tp>>::value,
1059 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1060 struct __is_destructible_safe;
1062 template<typename _Tp>
1063 struct __is_destructible_safe<_Tp, false, false>
1064 : public __is_destructible_impl<typename
1065 remove_all_extents<_Tp>::type>::type
1068 template<typename _Tp>
1069 struct __is_destructible_safe<_Tp, true, false>
1070 : public false_type { };
1072 template<typename _Tp>
1073 struct __is_destructible_safe<_Tp, false, true>
1074 : public true_type { };
1078 template<typename _Tp>
1079 struct is_destructible
1080 : public __is_destructible_safe<_Tp>::type
1082 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1083 "template argument must be a complete class or an unbounded array");
1086 /// @cond undocumented
1088 // is_nothrow_destructible requires that is_destructible is
1089 // satisfied as well. We realize that by mimicing the
1090 // implementation of is_destructible but refer to noexcept(expr)
1091 // instead of decltype(expr).
1092 struct __do_is_nt_destructible_impl
1094 template<typename _Tp>
1095 static __bool_constant<noexcept(declval<_Tp&>().~_Tp())>
1099 static false_type __test(...);
1102 template<typename _Tp>
1103 struct __is_nt_destructible_impl
1104 : public __do_is_nt_destructible_impl
1106 using type = decltype(__test<_Tp>(0));
1109 template<typename _Tp,
1110 bool = __or_<is_void<_Tp>,
1111 __is_array_unknown_bounds<_Tp>,
1112 is_function<_Tp>>::value,
1113 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1114 struct __is_nt_destructible_safe;
1116 template<typename _Tp>
1117 struct __is_nt_destructible_safe<_Tp, false, false>
1118 : public __is_nt_destructible_impl<typename
1119 remove_all_extents<_Tp>::type>::type
1122 template<typename _Tp>
1123 struct __is_nt_destructible_safe<_Tp, true, false>
1124 : public false_type { };
1126 template<typename _Tp>
1127 struct __is_nt_destructible_safe<_Tp, false, true>
1128 : public true_type { };
1131 /// is_nothrow_destructible
1132 template<typename _Tp>
1133 struct is_nothrow_destructible
1134 : public __is_nt_destructible_safe<_Tp>::type
1136 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1137 "template argument must be a complete class or an unbounded array");
1140 /// @cond undocumented
1141 template<typename _Tp, typename... _Args>
1142 using __is_constructible_impl
1143 = __bool_constant<__is_constructible(_Tp, _Args...)>;
1146 /// is_constructible
1147 template<typename _Tp, typename... _Args>
1148 struct is_constructible
1149 : public __is_constructible_impl<_Tp, _Args...>
1151 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1152 "template argument must be a complete class or an unbounded array");
1155 /// is_default_constructible
1156 template<typename _Tp>
1157 struct is_default_constructible
1158 : public __is_constructible_impl<_Tp>
1160 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1161 "template argument must be a complete class or an unbounded array");
1164 /// @cond undocumented
1165#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_lvalue_reference)
1166 template<typename _Tp>
1167 using __add_lval_ref_t = __add_lvalue_reference(_Tp);
1169 template<typename _Tp, typename = void>
1170 struct __add_lvalue_reference_helper
1171 { using type = _Tp; };
1173 template<typename _Tp>
1174 struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>>
1175 { using type = _Tp&; };
1177 template<typename _Tp>
1178 using __add_lval_ref_t = typename __add_lvalue_reference_helper<_Tp>::type;
1182 /// is_copy_constructible
1183 template<typename _Tp>
1184 struct is_copy_constructible
1185 : public __is_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1187 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1188 "template argument must be a complete class or an unbounded array");
1191 /// @cond undocumented
1192#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_rvalue_reference)
1193 template<typename _Tp>
1194 using __add_rval_ref_t = __add_rvalue_reference(_Tp);
1196 template<typename _Tp, typename = void>
1197 struct __add_rvalue_reference_helper
1198 { using type = _Tp; };
1200 template<typename _Tp>
1201 struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>>
1202 { using type = _Tp&&; };
1204 template<typename _Tp>
1205 using __add_rval_ref_t = typename __add_rvalue_reference_helper<_Tp>::type;
1209 /// is_move_constructible
1210 template<typename _Tp>
1211 struct is_move_constructible
1212 : public __is_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1214 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1215 "template argument must be a complete class or an unbounded array");
1218 /// @cond undocumented
1219 template<typename _Tp, typename... _Args>
1220 using __is_nothrow_constructible_impl
1221 = __bool_constant<__is_nothrow_constructible(_Tp, _Args...)>;
1224 /// is_nothrow_constructible
1225 template<typename _Tp, typename... _Args>
1226 struct is_nothrow_constructible
1227 : public __is_nothrow_constructible_impl<_Tp, _Args...>
1229 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1230 "template argument must be a complete class or an unbounded array");
1233 /// is_nothrow_default_constructible
1234 template<typename _Tp>
1235 struct is_nothrow_default_constructible
1236 : public __is_nothrow_constructible_impl<_Tp>
1238 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1239 "template argument must be a complete class or an unbounded array");
1242 /// is_nothrow_copy_constructible
1243 template<typename _Tp>
1244 struct is_nothrow_copy_constructible
1245 : public __is_nothrow_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1247 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1248 "template argument must be a complete class or an unbounded array");
1251 /// is_nothrow_move_constructible
1252 template<typename _Tp>
1253 struct is_nothrow_move_constructible
1254 : public __is_nothrow_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1256 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1257 "template argument must be a complete class or an unbounded array");
1260 /// @cond undocumented
1261 template<typename _Tp, typename _Up>
1262 using __is_assignable_impl = __bool_constant<__is_assignable(_Tp, _Up)>;
1266 template<typename _Tp, typename _Up>
1267 struct is_assignable
1268 : public __is_assignable_impl<_Tp, _Up>
1270 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1271 "template argument must be a complete class or an unbounded array");
1274 /// is_copy_assignable
1275 template<typename _Tp>
1276 struct is_copy_assignable
1277 : public __is_assignable_impl<__add_lval_ref_t<_Tp>,
1278 __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 /// is_move_assignable
1285 template<typename _Tp>
1286 struct is_move_assignable
1287 : public __is_assignable_impl<__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>>
1289 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1290 "template argument must be a complete class or an unbounded array");
1293 /// @cond undocumented
1294 template<typename _Tp, typename _Up>
1295 using __is_nothrow_assignable_impl
1296 = __bool_constant<__is_nothrow_assignable(_Tp, _Up)>;
1299 /// is_nothrow_assignable
1300 template<typename _Tp, typename _Up>
1301 struct is_nothrow_assignable
1302 : public __is_nothrow_assignable_impl<_Tp, _Up>
1304 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1305 "template argument must be a complete class or an unbounded array");
1308 /// is_nothrow_copy_assignable
1309 template<typename _Tp>
1310 struct is_nothrow_copy_assignable
1311 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1312 __add_lval_ref_t<const _Tp>>
1314 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1315 "template argument must be a complete class or an unbounded array");
1318 /// is_nothrow_move_assignable
1319 template<typename _Tp>
1320 struct is_nothrow_move_assignable
1321 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1322 __add_rval_ref_t<_Tp>>
1324 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1325 "template argument must be a complete class or an unbounded array");
1328 /// @cond undocumented
1329 template<typename _Tp, typename... _Args>
1330 using __is_trivially_constructible_impl
1331 = __bool_constant<__is_trivially_constructible(_Tp, _Args...)>;
1334 /// is_trivially_constructible
1335 template<typename _Tp, typename... _Args>
1336 struct is_trivially_constructible
1337 : public __is_trivially_constructible_impl<_Tp, _Args...>
1339 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1340 "template argument must be a complete class or an unbounded array");
1343 /// is_trivially_default_constructible
1344 template<typename _Tp>
1345 struct is_trivially_default_constructible
1346 : public __is_trivially_constructible_impl<_Tp>
1348 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1349 "template argument must be a complete class or an unbounded array");
1352#if __cpp_variable_templates && __cpp_concepts
1353 template<typename _Tp>
1354 constexpr bool __is_implicitly_default_constructible_v
1355 = requires (void(&__f)(_Tp)) { __f({}); };
1357 template<typename _Tp>
1358 struct __is_implicitly_default_constructible
1359 : __bool_constant<__is_implicitly_default_constructible_v<_Tp>>
1362 struct __do_is_implicitly_default_constructible_impl
1364 template <typename _Tp>
1365 static void __helper(const _Tp&);
1367 template <typename _Tp>
1368 static true_type __test(const _Tp&,
1369 decltype(__helper<const _Tp&>({}))* = 0);
1371 static false_type __test(...);
1374 template<typename _Tp>
1375 struct __is_implicitly_default_constructible_impl
1376 : public __do_is_implicitly_default_constructible_impl
1378 using type = decltype(__test(declval<_Tp>()));
1381 template<typename _Tp>
1382 struct __is_implicitly_default_constructible_safe
1383 : public __is_implicitly_default_constructible_impl<_Tp>::type
1386 template <typename _Tp>
1387 struct __is_implicitly_default_constructible
1388 : public __and_<__is_constructible_impl<_Tp>,
1389 __is_implicitly_default_constructible_safe<_Tp>>::type
1393 /// is_trivially_copy_constructible
1394 template<typename _Tp>
1395 struct is_trivially_copy_constructible
1396 : public __is_trivially_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1398 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1399 "template argument must be a complete class or an unbounded array");
1402 /// is_trivially_move_constructible
1403 template<typename _Tp>
1404 struct is_trivially_move_constructible
1405 : public __is_trivially_constructible_impl<_Tp, __add_rval_ref_t<_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 /// @cond undocumented
1412 template<typename _Tp, typename _Up>
1413 using __is_trivially_assignable_impl
1414 = __bool_constant<__is_trivially_assignable(_Tp, _Up)>;
1417 /// is_trivially_assignable
1418 template<typename _Tp, typename _Up>
1419 struct is_trivially_assignable
1420 : public __is_trivially_assignable_impl<_Tp, _Up>
1422 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1423 "template argument must be a complete class or an unbounded array");
1426 /// is_trivially_copy_assignable
1427 template<typename _Tp>
1428 struct is_trivially_copy_assignable
1429 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1430 __add_lval_ref_t<const _Tp>>
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_move_assignable
1437 template<typename _Tp>
1438 struct is_trivially_move_assignable
1439 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1440 __add_rval_ref_t<_Tp>>
1442 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1443 "template argument must be a complete class or an unbounded array");
1446 /// is_trivially_destructible
1447 template<typename _Tp>
1448 struct is_trivially_destructible
1449 : public __and_<__is_destructible_safe<_Tp>,
1450 __bool_constant<__has_trivial_destructor(_Tp)>>::type
1452 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1453 "template argument must be a complete class or an unbounded array");
1457 /// has_virtual_destructor
1458 template<typename _Tp>
1459 struct has_virtual_destructor
1460 : public __bool_constant<__has_virtual_destructor(_Tp)>
1462 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1463 "template argument must be a complete class or an unbounded array");
1467 // type property queries.
1470 template<typename _Tp>
1472 : public integral_constant<std::size_t, alignof(_Tp)>
1474 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1475 "template argument must be a complete class or an unbounded array");
1479#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank)
1480 template<typename _Tp>
1482 : public integral_constant<std::size_t, __array_rank(_Tp)> { };
1486 : public integral_constant<std::size_t, 0> { };
1488 template<typename _Tp, std::size_t _Size>
1489 struct rank<_Tp[_Size]>
1490 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1492 template<typename _Tp>
1494 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1498 template<typename, unsigned _Uint = 0>
1500 : public integral_constant<size_t, 0> { };
1502 template<typename _Tp, size_t _Size>
1503 struct extent<_Tp[_Size], 0>
1504 : public integral_constant<size_t, _Size> { };
1506 template<typename _Tp, unsigned _Uint, size_t _Size>
1507 struct extent<_Tp[_Size], _Uint>
1508 : public extent<_Tp, _Uint - 1>::type { };
1510 template<typename _Tp>
1511 struct extent<_Tp[], 0>
1512 : public integral_constant<size_t, 0> { };
1514 template<typename _Tp, unsigned _Uint>
1515 struct extent<_Tp[], _Uint>
1516 : public extent<_Tp, _Uint - 1>::type { };
1522#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
1523 template<typename _Tp, typename _Up>
1525 : public __bool_constant<__is_same(_Tp, _Up)>
1528 template<typename _Tp, typename _Up>
1533 template<typename _Tp>
1534 struct is_same<_Tp, _Tp>
1540 template<typename _Base, typename _Derived>
1542 : public __bool_constant<__is_base_of(_Base, _Derived)>
1545#ifdef __cpp_lib_is_virtual_base_of // C++ >= 26
1546 /// is_virtual_base_of
1548 template<typename _Base, typename _Derived>
1549 struct is_virtual_base_of
1550 : public bool_constant<__builtin_is_virtual_base_of(_Base, _Derived)>
1554#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
1555 template<typename _From, typename _To>
1556 struct is_convertible
1557 : public __bool_constant<__is_convertible(_From, _To)>
1560 template<typename _From, typename _To,
1561 bool = __or_<is_void<_From>, is_function<_To>,
1562 is_array<_To>>::value>
1563 struct __is_convertible_helper
1565 using type = typename is_void<_To>::type;
1568#pragma GCC diagnostic push
1569#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1570 template<typename _From, typename _To>
1571 class __is_convertible_helper<_From, _To, false>
1573 template<typename _To1>
1574 static void __test_aux(_To1) noexcept;
1576 template<typename _From1, typename _To1,
1577 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1581 template<typename, typename>
1586 using type = decltype(__test<_From, _To>(0));
1588#pragma GCC diagnostic pop
1591 template<typename _From, typename _To>
1592 struct is_convertible
1593 : public __is_convertible_helper<_From, _To>::type
1597 // helper trait for unique_ptr<T[]>, shared_ptr<T[]>, and span<T, N>
1598 template<typename _ToElementType, typename _FromElementType>
1599 using __is_array_convertible
1600 = is_convertible<_FromElementType(*)[], _ToElementType(*)[]>;
1602#ifdef __cpp_lib_is_nothrow_convertible // C++ >= 20
1604#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_convertible)
1605 /// is_nothrow_convertible_v
1606 template<typename _From, typename _To>
1607 inline constexpr bool is_nothrow_convertible_v
1608 = __is_nothrow_convertible(_From, _To);
1610 /// is_nothrow_convertible
1611 template<typename _From, typename _To>
1612 struct is_nothrow_convertible
1613 : public bool_constant<is_nothrow_convertible_v<_From, _To>>
1616 template<typename _From, typename _To,
1617 bool = __or_<is_void<_From>, is_function<_To>,
1618 is_array<_To>>::value>
1619 struct __is_nt_convertible_helper
1623#pragma GCC diagnostic push
1624#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1625 template<typename _From, typename _To>
1626 class __is_nt_convertible_helper<_From, _To, false>
1628 template<typename _To1>
1629 static void __test_aux(_To1) noexcept;
1631 template<typename _From1, typename _To1>
1633 __bool_constant<noexcept(__test_aux<_To1>(std::declval<_From1>()))>
1636 template<typename, typename>
1641 using type = decltype(__test<_From, _To>(0));
1643#pragma GCC diagnostic pop
1645 /// is_nothrow_convertible
1646 template<typename _From, typename _To>
1647 struct is_nothrow_convertible
1648 : public __is_nt_convertible_helper<_From, _To>::type
1651 /// is_nothrow_convertible_v
1652 template<typename _From, typename _To>
1653 inline constexpr bool is_nothrow_convertible_v
1654 = is_nothrow_convertible<_From, _To>::value;
1656#endif // __cpp_lib_is_nothrow_convertible
1658#pragma GCC diagnostic push
1659#pragma GCC diagnostic ignored "-Wc++14-extensions" // for variable templates
1660 template<typename _Tp, typename... _Args>
1661 struct __is_nothrow_new_constructible_impl
1663 noexcept(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))
1667 template<typename _Tp, typename... _Args>
1668 _GLIBCXX17_INLINE constexpr bool __is_nothrow_new_constructible
1669 = __and_<is_constructible<_Tp, _Args...>,
1670 __is_nothrow_new_constructible_impl<_Tp, _Args...>>::value;
1671#pragma GCC diagnostic pop
1673 // Const-volatile modifications.
1676 template<typename _Tp>
1678 { using type = _Tp; };
1680 template<typename _Tp>
1681 struct remove_const<_Tp const>
1682 { using type = _Tp; };
1685 template<typename _Tp>
1686 struct remove_volatile
1687 { using type = _Tp; };
1689 template<typename _Tp>
1690 struct remove_volatile<_Tp volatile>
1691 { using type = _Tp; };
1694#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cv)
1695 template<typename _Tp>
1697 { using type = __remove_cv(_Tp); };
1699 template<typename _Tp>
1701 { using type = _Tp; };
1703 template<typename _Tp>
1704 struct remove_cv<const _Tp>
1705 { using type = _Tp; };
1707 template<typename _Tp>
1708 struct remove_cv<volatile _Tp>
1709 { using type = _Tp; };
1711 template<typename _Tp>
1712 struct remove_cv<const volatile _Tp>
1713 { using type = _Tp; };
1717 template<typename _Tp>
1719 { using type = _Tp const; };
1722 template<typename _Tp>
1724 { using type = _Tp volatile; };
1727 template<typename _Tp>
1729 { using type = _Tp const volatile; };
1731#ifdef __cpp_lib_transformation_trait_aliases // C++ >= 14
1732 /// Alias template for remove_const
1733 template<typename _Tp>
1734 using remove_const_t = typename remove_const<_Tp>::type;
1736 /// Alias template for remove_volatile
1737 template<typename _Tp>
1738 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1740 /// Alias template for remove_cv
1741 template<typename _Tp>
1742 using remove_cv_t = typename remove_cv<_Tp>::type;
1744 /// Alias template for add_const
1745 template<typename _Tp>
1746 using add_const_t = typename add_const<_Tp>::type;
1748 /// Alias template for add_volatile
1749 template<typename _Tp>
1750 using add_volatile_t = typename add_volatile<_Tp>::type;
1752 /// Alias template for add_cv
1753 template<typename _Tp>
1754 using add_cv_t = typename add_cv<_Tp>::type;
1757 // Reference transformations.
1759 /// remove_reference
1760#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_reference)
1761 template<typename _Tp>
1762 struct remove_reference
1763 { using type = __remove_reference(_Tp); };
1765 template<typename _Tp>
1766 struct remove_reference
1767 { using type = _Tp; };
1769 template<typename _Tp>
1770 struct remove_reference<_Tp&>
1771 { using type = _Tp; };
1773 template<typename _Tp>
1774 struct remove_reference<_Tp&&>
1775 { using type = _Tp; };
1778 /// add_lvalue_reference
1779 template<typename _Tp>
1780 struct add_lvalue_reference
1781 { using type = __add_lval_ref_t<_Tp>; };
1783 /// add_rvalue_reference
1784 template<typename _Tp>
1785 struct add_rvalue_reference
1786 { using type = __add_rval_ref_t<_Tp>; };
1788#if __cplusplus > 201103L
1789 /// Alias template for remove_reference
1790 template<typename _Tp>
1791 using remove_reference_t = typename remove_reference<_Tp>::type;
1793 /// Alias template for add_lvalue_reference
1794 template<typename _Tp>
1795 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1797 /// Alias template for add_rvalue_reference
1798 template<typename _Tp>
1799 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1802 // Sign modifications.
1804 /// @cond undocumented
1806 // Utility for constructing identically cv-qualified types.
1807 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1808 struct __cv_selector;
1810 template<typename _Unqualified>
1811 struct __cv_selector<_Unqualified, false, false>
1812 { using __type = _Unqualified; };
1814 template<typename _Unqualified>
1815 struct __cv_selector<_Unqualified, false, true>
1816 { using __type = volatile _Unqualified; };
1818 template<typename _Unqualified>
1819 struct __cv_selector<_Unqualified, true, false>
1820 { using __type = const _Unqualified; };
1822 template<typename _Unqualified>
1823 struct __cv_selector<_Unqualified, true, true>
1824 { using __type = const volatile _Unqualified; };
1826 template<typename _Qualified, typename _Unqualified,
1827 bool _IsConst = is_const<_Qualified>::value,
1828 bool _IsVol = is_volatile<_Qualified>::value>
1829 class __match_cv_qualifiers
1831 using __match = __cv_selector<_Unqualified, _IsConst, _IsVol>;
1834 using __type = typename __match::__type;
1837 // Utility for finding the unsigned versions of signed integral types.
1838 template<typename _Tp>
1839 struct __make_unsigned
1840 { using __type = _Tp; };
1843 struct __make_unsigned<char>
1844 { using __type = unsigned char; };
1847 struct __make_unsigned<signed char>
1848 { using __type = unsigned char; };
1851 struct __make_unsigned<short>
1852 { using __type = unsigned short; };
1855 struct __make_unsigned<int>
1856 { using __type = unsigned int; };
1859 struct __make_unsigned<long>
1860 { using __type = unsigned long; };
1863 struct __make_unsigned<long long>
1864 { using __type = unsigned long long; };
1866#if defined(__GLIBCXX_TYPE_INT_N_0)
1869 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1870 { using __type = unsigned __GLIBCXX_TYPE_INT_N_0; };
1872#if defined(__GLIBCXX_TYPE_INT_N_1)
1875 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1876 { using __type = unsigned __GLIBCXX_TYPE_INT_N_1; };
1878#if defined(__GLIBCXX_TYPE_INT_N_2)
1881 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1882 { using __type = unsigned __GLIBCXX_TYPE_INT_N_2; };
1884#if defined(__GLIBCXX_TYPE_INT_N_3)
1887 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1888 { using __type = unsigned __GLIBCXX_TYPE_INT_N_3; };
1891 // Select between integral and enum: not possible to be both.
1892 template<typename _Tp,
1893 bool _IsInt = is_integral<_Tp>::value,
1894 bool _IsEnum = __is_enum(_Tp)>
1895 class __make_unsigned_selector;
1897 template<typename _Tp>
1898 class __make_unsigned_selector<_Tp, true, false>
1900 using __unsigned_type
1901 = typename __make_unsigned<__remove_cv_t<_Tp>>::__type;
1905 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1908 class __make_unsigned_selector_base
1911 template<typename...> struct _List { };
1913 template<typename _Tp, typename... _Up>
1914 struct _List<_Tp, _Up...> : _List<_Up...>
1915 { static constexpr size_t __size = sizeof(_Tp); };
1917 template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
1920 template<size_t _Sz, typename _Uint, typename... _UInts>
1921 struct __select<_Sz, _List<_Uint, _UInts...>, true>
1922 { using __type = _Uint; };
1924 template<size_t _Sz, typename _Uint, typename... _UInts>
1925 struct __select<_Sz, _List<_Uint, _UInts...>, false>
1926 : __select<_Sz, _List<_UInts...>>
1930 // Choose unsigned integer type with the smallest rank and same size as _Tp
1931 template<typename _Tp>
1932 class __make_unsigned_selector<_Tp, false, true>
1933 : __make_unsigned_selector_base
1935 // With -fshort-enums, an enum may be as small as a char.
1936 using _UInts = _List<unsigned char, unsigned short, unsigned int,
1937 unsigned long, unsigned long long>;
1939 using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
1943 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1946 // wchar_t, char8_t, char16_t and char32_t are integral types but are
1947 // neither signed integer types nor unsigned integer types, so must be
1948 // transformed to the unsigned integer type with the smallest rank.
1949 // Use the partial specialization for enumeration types to do that.
1951 struct __make_unsigned<wchar_t>
1954 = typename __make_unsigned_selector<wchar_t, false, true>::__type;
1957#ifdef _GLIBCXX_USE_CHAR8_T
1959 struct __make_unsigned<char8_t>
1962 = typename __make_unsigned_selector<char8_t, false, true>::__type;
1967 struct __make_unsigned<char16_t>
1970 = typename __make_unsigned_selector<char16_t, false, true>::__type;
1974 struct __make_unsigned<char32_t>
1977 = typename __make_unsigned_selector<char32_t, false, true>::__type;
1981 // Given an integral/enum type, return the corresponding unsigned
1983 // Primary template.
1985 template<typename _Tp>
1986 struct make_unsigned
1987 { using type = typename __make_unsigned_selector<_Tp>::__type; };
1989 // Integral, but don't define.
1990 template<> struct make_unsigned<bool>;
1991 template<> struct make_unsigned<bool const>;
1992 template<> struct make_unsigned<bool volatile>;
1993 template<> struct make_unsigned<bool const volatile>;
1995 /// @cond undocumented
1997 // Utility for finding the signed versions of unsigned integral types.
1998 template<typename _Tp>
1999 struct __make_signed
2000 { using __type = _Tp; };
2003 struct __make_signed<char>
2004 { using __type = signed char; };
2007 struct __make_signed<unsigned char>
2008 { using __type = signed char; };
2011 struct __make_signed<unsigned short>
2012 { using __type = signed short; };
2015 struct __make_signed<unsigned int>
2016 { using __type = signed int; };
2019 struct __make_signed<unsigned long>
2020 { using __type = signed long; };
2023 struct __make_signed<unsigned long long>
2024 { using __type = signed long long; };
2026#if defined(__GLIBCXX_TYPE_INT_N_0)
2029 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
2030 { using __type = __GLIBCXX_TYPE_INT_N_0; };
2032#if defined(__GLIBCXX_TYPE_INT_N_1)
2035 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
2036 { using __type = __GLIBCXX_TYPE_INT_N_1; };
2038#if defined(__GLIBCXX_TYPE_INT_N_2)
2041 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
2042 { using __type = __GLIBCXX_TYPE_INT_N_2; };
2044#if defined(__GLIBCXX_TYPE_INT_N_3)
2047 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
2048 { using __type = __GLIBCXX_TYPE_INT_N_3; };
2051 // Select between integral and enum: not possible to be both.
2052 template<typename _Tp,
2053 bool _IsInt = is_integral<_Tp>::value,
2054 bool _IsEnum = __is_enum(_Tp)>
2055 class __make_signed_selector;
2057 template<typename _Tp>
2058 class __make_signed_selector<_Tp, true, false>
2061 = typename __make_signed<__remove_cv_t<_Tp>>::__type;
2065 = typename __match_cv_qualifiers<_Tp, __signed_type>::__type;
2068 // Choose signed integer type with the smallest rank and same size as _Tp
2069 template<typename _Tp>
2070 class __make_signed_selector<_Tp, false, true>
2072 using __unsigned_type = typename __make_unsigned_selector<_Tp>::__type;
2075 using __type = typename __make_signed_selector<__unsigned_type>::__type;
2078 // wchar_t, char16_t and char32_t are integral types but are neither
2079 // signed integer types nor unsigned integer types, so must be
2080 // transformed to the signed integer type with the smallest rank.
2081 // Use the partial specialization for enumeration types to do that.
2083 struct __make_signed<wchar_t>
2086 = typename __make_signed_selector<wchar_t, false, true>::__type;
2089#if defined(_GLIBCXX_USE_CHAR8_T)
2091 struct __make_signed<char8_t>
2094 = typename __make_signed_selector<char8_t, false, true>::__type;
2099 struct __make_signed<char16_t>
2102 = typename __make_signed_selector<char16_t, false, true>::__type;
2106 struct __make_signed<char32_t>
2109 = typename __make_signed_selector<char32_t, false, true>::__type;
2113 // Given an integral/enum type, return the corresponding signed
2115 // Primary template.
2117 template<typename _Tp>
2119 { using type = typename __make_signed_selector<_Tp>::__type; };
2121 // Integral, but don't define.
2122 template<> struct make_signed<bool>;
2123 template<> struct make_signed<bool const>;
2124 template<> struct make_signed<bool volatile>;
2125 template<> struct make_signed<bool const volatile>;
2127#if __cplusplus > 201103L
2128 /// Alias template for make_signed
2129 template<typename _Tp>
2130 using make_signed_t = typename make_signed<_Tp>::type;
2132 /// Alias template for make_unsigned
2133 template<typename _Tp>
2134 using make_unsigned_t = typename make_unsigned<_Tp>::type;
2137 // Array modifications.
2140#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_extent)
2141 template<typename _Tp>
2142 struct remove_extent
2143 { using type = __remove_extent(_Tp); };
2145 template<typename _Tp>
2146 struct remove_extent
2147 { using type = _Tp; };
2149 template<typename _Tp, std::size_t _Size>
2150 struct remove_extent<_Tp[_Size]>
2151 { using type = _Tp; };
2153 template<typename _Tp>
2154 struct remove_extent<_Tp[]>
2155 { using type = _Tp; };
2158 /// remove_all_extents
2159#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_all_extents)
2160 template<typename _Tp>
2161 struct remove_all_extents
2162 { using type = __remove_all_extents(_Tp); };
2164 template<typename _Tp>
2165 struct remove_all_extents
2166 { using type = _Tp; };
2168 template<typename _Tp, std::size_t _Size>
2169 struct remove_all_extents<_Tp[_Size]>
2170 { using type = typename remove_all_extents<_Tp>::type; };
2172 template<typename _Tp>
2173 struct remove_all_extents<_Tp[]>
2174 { using type = typename remove_all_extents<_Tp>::type; };
2177#if __cplusplus > 201103L
2178 /// Alias template for remove_extent
2179 template<typename _Tp>
2180 using remove_extent_t = typename remove_extent<_Tp>::type;
2182 /// Alias template for remove_all_extents
2183 template<typename _Tp>
2184 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
2187 // Pointer modifications.
2190#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer)
2191 template<typename _Tp>
2192 struct remove_pointer
2193 { using type = __remove_pointer(_Tp); };
2195 template<typename _Tp, typename>
2196 struct __remove_pointer_helper
2197 { using type = _Tp; };
2199 template<typename _Tp, typename _Up>
2200 struct __remove_pointer_helper<_Tp, _Up*>
2201 { using type = _Up; };
2203 template<typename _Tp>
2204 struct remove_pointer
2205 : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>>
2210#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer)
2211 template<typename _Tp>
2213 { using type = __add_pointer(_Tp); };
2215 template<typename _Tp, typename = void>
2216 struct __add_pointer_helper
2217 { using type = _Tp; };
2219 template<typename _Tp>
2220 struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
2221 { using type = _Tp*; };
2223 template<typename _Tp>
2225 : public __add_pointer_helper<_Tp>
2228 template<typename _Tp>
2229 struct add_pointer<_Tp&>
2230 { using type = _Tp*; };
2232 template<typename _Tp>
2233 struct add_pointer<_Tp&&>
2234 { using type = _Tp*; };
2237#if __cplusplus > 201103L
2238 /// Alias template for remove_pointer
2239 template<typename _Tp>
2240 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2242 /// Alias template for add_pointer
2243 template<typename _Tp>
2244 using add_pointer_t = typename add_pointer<_Tp>::type;
2247 /// @cond undocumented
2249 // Aligned to maximum fundamental alignment
2250 struct __attribute__((__aligned__)) __aligned_storage_max_align_t
2254 __aligned_storage_default_alignment([[__maybe_unused__]] size_t __len)
2256#if _GLIBCXX_INLINE_VERSION
2258 = integral_constant<size_t, alignof(__aligned_storage_max_align_t)>;
2260 return __len > (_Max_align::value / 2)
2262# if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_clzg)
2263 : 1 << (__SIZE_WIDTH__ - __builtin_clzg(__len - 1u));
2265 : 1 << (__LLONG_WIDTH__ - __builtin_clzll(__len - 1ull));
2268 // Returning a fixed value is incorrect, but kept for ABI compatibility.
2269 // XXX GLIBCXX_ABI Deprecated
2270 return alignof(__aligned_storage_max_align_t);
2276 * @brief Aligned storage
2278 * The member typedef `type` is be a POD type suitable for use as
2279 * uninitialized storage for any object whose size is at most `_Len`
2280 * and whose alignment is a divisor of `_Align`.
2282 * It is important to use the nested `type` as uninitialized storage,
2283 * not the `std::aligned_storage` type itself which is an empty class
2284 * with 1-byte alignment. So this is correct:
2286 * `typename std::aligned_storage<sizeof(X), alignof(X)>::type m_xobj;`
2290 * `std::aligned_storage<sizeof(X), alignof(X)> m_xobj;`
2292 * In C++14 and later `std::aligned_storage_t<sizeof(X), alignof(X)>`
2293 * can be used to refer to the `type` member typedef.
2295 * The default value of _Align is supposed to be the most stringent
2296 * fundamental alignment requirement for any C++ object type whose size
2297 * is no greater than `_Len` (see [basic.align] in the C++ standard).
2299 * @bug In this implementation the default value for _Align is always the
2300 * maximum fundamental alignment, i.e. `alignof(max_align_t)`, which is
2301 * incorrect. It should be an alignment value no greater than `_Len`.
2303 * @deprecated Deprecated in C++23. Uses can be replaced by an
2304 * array `std::byte[_Len]` declared with `alignas(_Align)`.
2306 template<size_t _Len,
2307 size_t _Align = __aligned_storage_default_alignment(_Len)>
2309 _GLIBCXX23_DEPRECATED
2314 alignas(_Align) unsigned char __data[_Len];
2318 template <typename... _Types>
2319 struct __strictest_alignment
2321 static const size_t _S_alignment = 0;
2322 static const size_t _S_size = 0;
2325 template <typename _Tp, typename... _Types>
2326 struct __strictest_alignment<_Tp, _Types...>
2328 static const size_t _S_alignment =
2329 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2330 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2331 static const size_t _S_size =
2332 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2333 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2336#pragma GCC diagnostic push
2337#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2340 * @brief Provide aligned storage for types.
2342 * [meta.trans.other]
2344 * Provides aligned storage for any of the provided types of at
2347 * @see aligned_storage
2349 * @deprecated Deprecated in C++23.
2351 template <size_t _Len, typename... _Types>
2353 _GLIBCXX23_DEPRECATED
2357 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2359 using __strictest = __strictest_alignment<_Types...>;
2360 static const size_t _S_len = _Len > __strictest::_S_size
2361 ? _Len : __strictest::_S_size;
2363 /// The value of the strictest alignment of _Types.
2364 static const size_t alignment_value = __strictest::_S_alignment;
2366 using type = typename aligned_storage<_S_len, alignment_value>::type;
2369 template <size_t _Len, typename... _Types>
2370 const size_t aligned_union<_Len, _Types...>::alignment_value;
2371#pragma GCC diagnostic pop
2373 /// @cond undocumented
2375#if _GLIBCXX_USE_BUILTIN_TRAIT(__decay)
2376 template<typename _Tp>
2378 { using type = __decay(_Tp); };
2380 // Decay trait for arrays and functions, used for perfect forwarding
2381 // in make_pair, make_tuple, etc.
2382 template<typename _Up>
2383 struct __decay_selector
2384 : __conditional_t<is_const<const _Up>::value, // false for functions
2385 remove_cv<_Up>, // N.B. DR 705.
2386 add_pointer<_Up>> // function decays to pointer
2389 template<typename _Up, size_t _Nm>
2390 struct __decay_selector<_Up[_Nm]>
2391 { using type = _Up*; };
2393 template<typename _Up>
2394 struct __decay_selector<_Up[]>
2395 { using type = _Up*; };
2400 template<typename _Tp>
2402 { using type = typename __decay_selector<_Tp>::type; };
2404 template<typename _Tp>
2406 { using type = typename __decay_selector<_Tp>::type; };
2408 template<typename _Tp>
2410 { using type = typename __decay_selector<_Tp>::type; };
2413 /// @cond undocumented
2415 // Helper which adds a reference to a type when given a reference_wrapper
2416 template<typename _Tp>
2417 struct __strip_reference_wrapper
2422 template<typename _Tp>
2423 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2425 using __type = _Tp&;
2428 // __decay_t (std::decay_t for C++11).
2429 template<typename _Tp>
2430 using __decay_t = typename decay<_Tp>::type;
2432 template<typename _Tp>
2433 using __decay_and_strip = __strip_reference_wrapper<__decay_t<_Tp>>;
2436 /// @cond undocumented
2438 // Helper for SFINAE constraints
2439 template<typename... _Cond>
2440 using _Require = __enable_if_t<__and_<_Cond...>::value>;
2442 // __remove_cvref_t (std::remove_cvref_t for C++11).
2443 template<typename _Tp>
2444 using __remove_cvref_t
2445 = typename remove_cv<typename remove_reference<_Tp>::type>::type;
2448 // Primary template.
2449 /// Define a member typedef @c type to one of two argument types.
2450 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2452 { using type = _Iftrue; };
2454 // Partial specialization for false.
2455 template<typename _Iftrue, typename _Iffalse>
2456 struct conditional<false, _Iftrue, _Iffalse>
2457 { using type = _Iffalse; };
2460 template<typename... _Tp>
2463 // Sfinae-friendly common_type implementation:
2465 /// @cond undocumented
2467 // For several sfinae-friendly trait implementations we transport both the
2468 // result information (as the member type) and the failure information (no
2469 // member type). This is very similar to std::enable_if, but we cannot use
2470 // that, because we need to derive from them as an implementation detail.
2472 template<typename _Tp>
2473 struct __success_type
2474 { using type = _Tp; };
2476 struct __failure_type
2479 struct __do_common_type_impl
2481 template<typename _Tp, typename _Up>
2483 = decltype(true ? std::declval<_Tp>() : std::declval<_Up>());
2485 // if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2486 // denotes a valid type, let C denote that type.
2487 template<typename _Tp, typename _Up>
2488 static __success_type<__decay_t<__cond_t<_Tp, _Up>>>
2491#if __cplusplus > 201703L
2492 // Otherwise, if COND-RES(CREF(D1), CREF(D2)) denotes a type,
2493 // let C denote the type decay_t<COND-RES(CREF(D1), CREF(D2))>.
2494 template<typename _Tp, typename _Up>
2495 static __success_type<__remove_cvref_t<__cond_t<const _Tp&, const _Up&>>>
2499 template<typename, typename>
2500 static __failure_type
2503 template<typename _Tp, typename _Up>
2504 static decltype(_S_test_2<_Tp, _Up>(0))
2508 // If sizeof...(T) is zero, there shall be no member type.
2510 struct common_type<>
2513 // If sizeof...(T) is one, the same type, if any, as common_type_t<T0, T0>.
2514 template<typename _Tp0>
2515 struct common_type<_Tp0>
2516 : public common_type<_Tp0, _Tp0>
2519 // If sizeof...(T) is two, ...
2520 template<typename _Tp1, typename _Tp2,
2521 typename _Dp1 = __decay_t<_Tp1>, typename _Dp2 = __decay_t<_Tp2>>
2522 struct __common_type_impl
2524 // If is_same_v<T1, D1> is false or is_same_v<T2, D2> is false,
2525 // let C denote the same type, if any, as common_type_t<D1, D2>.
2526 using type = common_type<_Dp1, _Dp2>;
2529 template<typename _Tp1, typename _Tp2>
2530 struct __common_type_impl<_Tp1, _Tp2, _Tp1, _Tp2>
2531 : private __do_common_type_impl
2533 // Otherwise, if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2534 // denotes a valid type, let C denote that type.
2535 using type = decltype(_S_test<_Tp1, _Tp2>(0));
2538 // If sizeof...(T) is two, ...
2539 template<typename _Tp1, typename _Tp2>
2540 struct common_type<_Tp1, _Tp2>
2541 : public __common_type_impl<_Tp1, _Tp2>::type
2544 template<typename...>
2545 struct __common_type_pack
2548 template<typename, typename, typename = void>
2549 struct __common_type_fold;
2551 // If sizeof...(T) is greater than two, ...
2552 template<typename _Tp1, typename _Tp2, typename... _Rp>
2553 struct common_type<_Tp1, _Tp2, _Rp...>
2554 : public __common_type_fold<common_type<_Tp1, _Tp2>,
2555 __common_type_pack<_Rp...>>
2558 // Let C denote the same type, if any, as common_type_t<T1, T2>.
2559 // If there is such a type C, type shall denote the same type, if any,
2560 // as common_type_t<C, R...>.
2561 template<typename _CTp, typename... _Rp>
2562 struct __common_type_fold<_CTp, __common_type_pack<_Rp...>,
2563 __void_t<typename _CTp::type>>
2564 : public common_type<typename _CTp::type, _Rp...>
2567 // Otherwise, there shall be no member type.
2568 template<typename _CTp, typename _Rp>
2569 struct __common_type_fold<_CTp, _Rp, void>
2572 template<typename _Tp, bool = __is_enum(_Tp)>
2573 struct __underlying_type_impl
2575 using type = __underlying_type(_Tp);
2578 template<typename _Tp>
2579 struct __underlying_type_impl<_Tp, false>
2583 /// The underlying type of an enum.
2584 template<typename _Tp>
2585 struct underlying_type
2586 : public __underlying_type_impl<_Tp>
2589 /// @cond undocumented
2590 template<typename _Tp>
2591 struct __declval_protector
2593 static const bool __stop = false;
2597 /** Utility to simplify expressions used in unevaluated operands
2599 * @ingroup utilities
2601 template<typename _Tp>
2602 auto declval() noexcept -> decltype(__declval<_Tp>(0))
2604 static_assert(__declval_protector<_Tp>::__stop,
2605 "declval() must not be used!");
2606 return __declval<_Tp>(0);
2610 template<typename _Signature>
2613 // Sfinae-friendly result_of implementation:
2615 /// @cond undocumented
2616 struct __invoke_memfun_ref { };
2617 struct __invoke_memfun_deref { };
2618 struct __invoke_memobj_ref { };
2619 struct __invoke_memobj_deref { };
2620 struct __invoke_other { };
2622 // Associate a tag type with a specialization of __success_type.
2623 template<typename _Tp, typename _Tag>
2624 struct __result_of_success : __success_type<_Tp>
2625 { using __invoke_type = _Tag; };
2627 // [func.require] paragraph 1 bullet 1:
2628 struct __result_of_memfun_ref_impl
2630 template<typename _Fp, typename _Tp1, typename... _Args>
2631 static __result_of_success<decltype(
2632 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2633 ), __invoke_memfun_ref> _S_test(int);
2635 template<typename...>
2636 static __failure_type _S_test(...);
2639 template<typename _MemPtr, typename _Arg, typename... _Args>
2640 struct __result_of_memfun_ref
2641 : private __result_of_memfun_ref_impl
2643 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2646 // [func.require] paragraph 1 bullet 2:
2647 struct __result_of_memfun_deref_impl
2649 template<typename _Fp, typename _Tp1, typename... _Args>
2650 static __result_of_success<decltype(
2651 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2652 ), __invoke_memfun_deref> _S_test(int);
2654 template<typename...>
2655 static __failure_type _S_test(...);
2658 template<typename _MemPtr, typename _Arg, typename... _Args>
2659 struct __result_of_memfun_deref
2660 : private __result_of_memfun_deref_impl
2662 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2665 // [func.require] paragraph 1 bullet 3:
2666 struct __result_of_memobj_ref_impl
2668 template<typename _Fp, typename _Tp1>
2669 static __result_of_success<decltype(
2670 std::declval<_Tp1>().*std::declval<_Fp>()
2671 ), __invoke_memobj_ref> _S_test(int);
2673 template<typename, typename>
2674 static __failure_type _S_test(...);
2677 template<typename _MemPtr, typename _Arg>
2678 struct __result_of_memobj_ref
2679 : private __result_of_memobj_ref_impl
2681 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2684 // [func.require] paragraph 1 bullet 4:
2685 struct __result_of_memobj_deref_impl
2687 template<typename _Fp, typename _Tp1>
2688 static __result_of_success<decltype(
2689 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2690 ), __invoke_memobj_deref> _S_test(int);
2692 template<typename, typename>
2693 static __failure_type _S_test(...);
2696 template<typename _MemPtr, typename _Arg>
2697 struct __result_of_memobj_deref
2698 : private __result_of_memobj_deref_impl
2700 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2703 template<typename _MemPtr, typename _Arg>
2704 struct __result_of_memobj;
2706 template<typename _Res, typename _Class, typename _Arg>
2707 struct __result_of_memobj<_Res _Class::*, _Arg>
2709 using _Argval = __remove_cvref_t<_Arg>;
2710 using _MemPtr = _Res _Class::*;
2711 using type = typename __conditional_t<__or_<is_same<_Argval, _Class>,
2712 is_base_of<_Class, _Argval>>::value,
2713 __result_of_memobj_ref<_MemPtr, _Arg>,
2714 __result_of_memobj_deref<_MemPtr, _Arg>
2718 template<typename _MemPtr, typename _Arg, typename... _Args>
2719 struct __result_of_memfun;
2721 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2722 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2724 using _Argval = typename remove_reference<_Arg>::type;
2725 using _MemPtr = _Res _Class::*;
2726 using type = typename __conditional_t<is_base_of<_Class, _Argval>::value,
2727 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2728 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2732 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2733 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2734 // as the object expression
2736 // Used by result_of, invoke etc. to unwrap a reference_wrapper.
2737 template<typename _Tp, typename _Up = __remove_cvref_t<_Tp>>
2743 template<typename _Tp, typename _Up>
2744 struct __inv_unwrap<_Tp, reference_wrapper<_Up>>
2749 template<bool, bool, typename _Functor, typename... _ArgTypes>
2750 struct __result_of_impl
2752 using type = __failure_type;
2755 template<typename _MemPtr, typename _Arg>
2756 struct __result_of_impl<true, false, _MemPtr, _Arg>
2757 : public __result_of_memobj<__decay_t<_MemPtr>,
2758 typename __inv_unwrap<_Arg>::type>
2761 template<typename _MemPtr, typename _Arg, typename... _Args>
2762 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2763 : public __result_of_memfun<__decay_t<_MemPtr>,
2764 typename __inv_unwrap<_Arg>::type, _Args...>
2767 // [func.require] paragraph 1 bullet 5:
2768 struct __result_of_other_impl
2770 template<typename _Fn, typename... _Args>
2771 static __result_of_success<decltype(
2772 std::declval<_Fn>()(std::declval<_Args>()...)
2773 ), __invoke_other> _S_test(int);
2775 template<typename...>
2776 static __failure_type _S_test(...);
2779 template<typename _Functor, typename... _ArgTypes>
2780 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2781 : private __result_of_other_impl
2783 using type = decltype(_S_test<_Functor, _ArgTypes...>(0));
2786 // __invoke_result (std::invoke_result for C++11)
2787 template<typename _Functor, typename... _ArgTypes>
2788 struct __invoke_result
2789 : public __result_of_impl<
2790 is_member_object_pointer<
2791 typename remove_reference<_Functor>::type
2793 is_member_function_pointer<
2794 typename remove_reference<_Functor>::type
2796 _Functor, _ArgTypes...
2800 // __invoke_result_t (std::invoke_result_t for C++11)
2801 template<typename _Fn, typename... _Args>
2802 using __invoke_result_t = typename __invoke_result<_Fn, _Args...>::type;
2805 template<typename _Functor, typename... _ArgTypes>
2806 struct result_of<_Functor(_ArgTypes...)>
2807 : public __invoke_result<_Functor, _ArgTypes...>
2808 { } _GLIBCXX17_DEPRECATED_SUGGEST("std::invoke_result");
2810#if __cplusplus >= 201402L
2811#pragma GCC diagnostic push
2812#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2813 /// Alias template for aligned_storage
2814 template<size_t _Len,
2815 size_t _Align = __aligned_storage_default_alignment(_Len)>
2816 using aligned_storage_t _GLIBCXX23_DEPRECATED = typename aligned_storage<_Len, _Align>::type;
2818 template <size_t _Len, typename... _Types>
2819 using aligned_union_t _GLIBCXX23_DEPRECATED = typename aligned_union<_Len, _Types...>::type;
2820#pragma GCC diagnostic pop
2822 /// Alias template for decay
2823 template<typename _Tp>
2824 using decay_t = typename decay<_Tp>::type;
2826 /// Alias template for enable_if
2827 template<bool _Cond, typename _Tp = void>
2828 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2830 /// Alias template for conditional
2831 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2832 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2834 /// Alias template for common_type
2835 template<typename... _Tp>
2836 using common_type_t = typename common_type<_Tp...>::type;
2838 /// Alias template for underlying_type
2839 template<typename _Tp>
2840 using underlying_type_t = typename underlying_type<_Tp>::type;
2842 /// Alias template for result_of
2843 template<typename _Tp>
2844 using result_of_t = typename result_of<_Tp>::type;
2847#ifdef __cpp_lib_void_t // C++ >= 17 || GNU++ >= 11
2848 /// A metafunction that always yields void, used for detecting valid types.
2849 template<typename...> using void_t = void;
2852 /// @cond undocumented
2855 // Detect whether _Op<_Args...> is a valid type, use default _Def if not.
2858 // Implementation of the detection idiom (negative case).
2859 template<typename _Def, template<typename...> class _Op, typename... _Args>
2860 struct __detected_or
2863 using __is_detected = false_type;
2866 // Implementation of the detection idiom (positive case).
2867 template<typename _Def, template<typename...> class _Op, typename... _Args>
2868 requires requires { typename _Op<_Args...>; }
2869 struct __detected_or<_Def, _Op, _Args...>
2871 using type = _Op<_Args...>;
2872 using __is_detected = true_type;
2875 /// Implementation of the detection idiom (negative case).
2876 template<typename _Default, typename _AlwaysVoid,
2877 template<typename...> class _Op, typename... _Args>
2880 using type = _Default;
2881 using __is_detected = false_type;
2884 /// Implementation of the detection idiom (positive case).
2885 template<typename _Default, template<typename...> class _Op,
2887 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2889 using type = _Op<_Args...>;
2890 using __is_detected = true_type;
2893 template<typename _Default, template<typename...> class _Op,
2895 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2896#endif // __cpp_concepts
2898 // _Op<_Args...> if that is a valid type, otherwise _Default.
2899 template<typename _Default, template<typename...> class _Op,
2901 using __detected_or_t
2902 = typename __detected_or<_Default, _Op, _Args...>::type;
2905 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2906 * member type _NTYPE.
2908#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2909 template<typename _Tp, typename = __void_t<>> \
2910 struct __has_##_NTYPE \
2913 template<typename _Tp> \
2914 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2918 template <typename _Tp>
2919 struct __is_swappable;
2921 template <typename _Tp>
2922 struct __is_nothrow_swappable;
2925 struct __is_tuple_like_impl : false_type
2928 // Internal type trait that allows us to sfinae-protect tuple_cat.
2929 template<typename _Tp>
2930 struct __is_tuple_like
2931 : public __is_tuple_like_impl<__remove_cvref_t<_Tp>>::type
2935 template<typename _Tp>
2936 _GLIBCXX20_CONSTEXPR
2938 _Require<__not_<__is_tuple_like<_Tp>>,
2939 is_move_constructible<_Tp>,
2940 is_move_assignable<_Tp>>
2942 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
2943 is_nothrow_move_assignable<_Tp>>::value);
2945 template<typename _Tp, size_t _Nm>
2946 _GLIBCXX20_CONSTEXPR
2948 __enable_if_t<__is_swappable<_Tp>::value>
2949 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
2950 noexcept(__is_nothrow_swappable<_Tp>::value);
2952 /// @cond undocumented
2953 namespace __swappable_details {
2956 struct __do_is_swappable_impl
2958 template<typename _Tp, typename
2959 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
2960 static true_type __test(int);
2963 static false_type __test(...);
2966 struct __do_is_nothrow_swappable_impl
2968 template<typename _Tp>
2969 static __bool_constant<
2970 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
2974 static false_type __test(...);
2977 } // namespace __swappable_details
2979 template<typename _Tp>
2980 struct __is_swappable_impl
2981 : public __swappable_details::__do_is_swappable_impl
2983 using type = decltype(__test<_Tp>(0));
2986 template<typename _Tp>
2987 struct __is_nothrow_swappable_impl
2988 : public __swappable_details::__do_is_nothrow_swappable_impl
2990 using type = decltype(__test<_Tp>(0));
2993 template<typename _Tp>
2994 struct __is_swappable
2995 : public __is_swappable_impl<_Tp>::type
2998 template<typename _Tp>
2999 struct __is_nothrow_swappable
3000 : public __is_nothrow_swappable_impl<_Tp>::type
3004#ifdef __cpp_lib_is_swappable // C++ >= 17 || GNU++ >= 11
3005 /// Metafunctions used for detecting swappable types: p0185r1
3008 template<typename _Tp>
3010 : public __is_swappable_impl<_Tp>::type
3012 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3013 "template argument must be a complete class or an unbounded array");
3016 /// is_nothrow_swappable
3017 template<typename _Tp>
3018 struct is_nothrow_swappable
3019 : public __is_nothrow_swappable_impl<_Tp>::type
3021 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3022 "template argument must be a complete class or an unbounded array");
3025#if __cplusplus >= 201402L
3027 template<typename _Tp>
3028 _GLIBCXX17_INLINE constexpr bool is_swappable_v =
3029 is_swappable<_Tp>::value;
3031 /// is_nothrow_swappable_v
3032 template<typename _Tp>
3033 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_v =
3034 is_nothrow_swappable<_Tp>::value;
3035#endif // __cplusplus >= 201402L
3037 /// @cond undocumented
3038 namespace __swappable_with_details {
3041 struct __do_is_swappable_with_impl
3043 template<typename _Tp, typename _Up, typename
3044 = decltype(swap(std::declval<_Tp>(), std::declval<_Up>())),
3046 = decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))>
3047 static true_type __test(int);
3049 template<typename, typename>
3050 static false_type __test(...);
3053 struct __do_is_nothrow_swappable_with_impl
3055 template<typename _Tp, typename _Up>
3056 static __bool_constant<
3057 noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
3059 noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()))
3062 template<typename, typename>
3063 static false_type __test(...);
3066 } // namespace __swappable_with_details
3068 template<typename _Tp, typename _Up>
3069 struct __is_swappable_with_impl
3070 : public __swappable_with_details::__do_is_swappable_with_impl
3072 using type = decltype(__test<_Tp, _Up>(0));
3075 // Optimization for the homogenous lvalue case, not required:
3076 template<typename _Tp>
3077 struct __is_swappable_with_impl<_Tp&, _Tp&>
3078 : public __swappable_details::__do_is_swappable_impl
3080 using type = decltype(__test<_Tp&>(0));
3083 template<typename _Tp, typename _Up>
3084 struct __is_nothrow_swappable_with_impl
3085 : public __swappable_with_details::__do_is_nothrow_swappable_with_impl
3087 using type = decltype(__test<_Tp, _Up>(0));
3090 // Optimization for the homogenous lvalue case, not required:
3091 template<typename _Tp>
3092 struct __is_nothrow_swappable_with_impl<_Tp&, _Tp&>
3093 : public __swappable_details::__do_is_nothrow_swappable_impl
3095 using type = decltype(__test<_Tp&>(0));
3099 /// is_swappable_with
3100 template<typename _Tp, typename _Up>
3101 struct is_swappable_with
3102 : public __is_swappable_with_impl<_Tp, _Up>::type
3104 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3105 "first template argument must be a complete class or an unbounded array");
3106 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3107 "second template argument must be a complete class or an unbounded array");
3110 /// is_nothrow_swappable_with
3111 template<typename _Tp, typename _Up>
3112 struct is_nothrow_swappable_with
3113 : public __is_nothrow_swappable_with_impl<_Tp, _Up>::type
3115 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3116 "first template argument must be a complete class or an unbounded array");
3117 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3118 "second template argument must be a complete class or an unbounded array");
3121#if __cplusplus >= 201402L
3122 /// is_swappable_with_v
3123 template<typename _Tp, typename _Up>
3124 _GLIBCXX17_INLINE constexpr bool is_swappable_with_v =
3125 is_swappable_with<_Tp, _Up>::value;
3127 /// is_nothrow_swappable_with_v
3128 template<typename _Tp, typename _Up>
3129 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_with_v =
3130 is_nothrow_swappable_with<_Tp, _Up>::value;
3131#endif // __cplusplus >= 201402L
3133#endif // __cpp_lib_is_swappable
3135 /// @cond undocumented
3137 // __is_invocable (std::is_invocable for C++11)
3139 // The primary template is used for invalid INVOKE expressions.
3140 template<typename _Result, typename _Ret,
3141 bool = is_void<_Ret>::value, typename = void>
3142 struct __is_invocable_impl
3145 using __nothrow_conv = false_type; // For is_nothrow_invocable_r
3148 // Used for valid INVOKE and INVOKE<void> expressions.
3149 template<typename _Result, typename _Ret>
3150 struct __is_invocable_impl<_Result, _Ret,
3151 /* is_void<_Ret> = */ true,
3152 __void_t<typename _Result::type>>
3155 using __nothrow_conv = true_type; // For is_nothrow_invocable_r
3158#pragma GCC diagnostic push
3159#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3160 // Used for INVOKE<R> expressions to check the implicit conversion to R.
3161 template<typename _Result, typename _Ret>
3162 struct __is_invocable_impl<_Result, _Ret,
3163 /* is_void<_Ret> = */ false,
3164 __void_t<typename _Result::type>>
3167 // The type of the INVOKE expression.
3168 using _Res_t = typename _Result::type;
3170 // Unlike declval, this doesn't add_rvalue_reference, so it respects
3171 // guaranteed copy elision.
3172 static _Res_t _S_get() noexcept;
3174 // Used to check if _Res_t can implicitly convert to _Tp.
3175 template<typename _Tp>
3176 static void _S_conv(__type_identity_t<_Tp>) noexcept;
3178 // This overload is viable if INVOKE(f, args...) can convert to _Tp.
3179 template<typename _Tp,
3180 bool _Nothrow = noexcept(_S_conv<_Tp>(_S_get())),
3181 typename = decltype(_S_conv<_Tp>(_S_get())),
3182#if __has_builtin(__reference_converts_from_temporary)
3183 bool _Dangle = __reference_converts_from_temporary(_Tp, _Res_t)
3185 bool _Dangle = false
3188 static __bool_constant<_Nothrow && !_Dangle>
3191 template<typename _Tp, bool = false>
3196 // For is_invocable_r
3197 using type = decltype(_S_test<_Ret, /* Nothrow = */ true>(1));
3199 // For is_nothrow_invocable_r
3200 using __nothrow_conv = decltype(_S_test<_Ret>(1));
3202#pragma GCC diagnostic pop
3204 template<typename _Fn, typename... _ArgTypes>
3205 struct __is_invocable
3206 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3209 template<typename _Fn, typename _Tp, typename... _Args>
3210 constexpr bool __call_is_nt(__invoke_memfun_ref)
3212 using _Up = typename __inv_unwrap<_Tp>::type;
3213 return noexcept((std::declval<_Up>().*std::declval<_Fn>())(
3214 std::declval<_Args>()...));
3217 template<typename _Fn, typename _Tp, typename... _Args>
3218 constexpr bool __call_is_nt(__invoke_memfun_deref)
3220 return noexcept(((*std::declval<_Tp>()).*std::declval<_Fn>())(
3221 std::declval<_Args>()...));
3224 template<typename _Fn, typename _Tp>
3225 constexpr bool __call_is_nt(__invoke_memobj_ref)
3227 using _Up = typename __inv_unwrap<_Tp>::type;
3228 return noexcept(std::declval<_Up>().*std::declval<_Fn>());
3231 template<typename _Fn, typename _Tp>
3232 constexpr bool __call_is_nt(__invoke_memobj_deref)
3234 return noexcept((*std::declval<_Tp>()).*std::declval<_Fn>());
3237 template<typename _Fn, typename... _Args>
3238 constexpr bool __call_is_nt(__invoke_other)
3240 return noexcept(std::declval<_Fn>()(std::declval<_Args>()...));
3243 template<typename _Result, typename _Fn, typename... _Args>
3244 struct __call_is_nothrow
3246 std::__call_is_nt<_Fn, _Args...>(typename _Result::__invoke_type{})
3250 template<typename _Fn, typename... _Args>
3251 using __call_is_nothrow_
3252 = __call_is_nothrow<__invoke_result<_Fn, _Args...>, _Fn, _Args...>;
3254 // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
3255 template<typename _Fn, typename... _Args>
3256 struct __is_nothrow_invocable
3257 : __and_<__is_invocable<_Fn, _Args...>,
3258 __call_is_nothrow_<_Fn, _Args...>>::type
3261#pragma GCC diagnostic push
3262#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3263 struct __nonesuchbase {};
3264 struct __nonesuch : private __nonesuchbase {
3265 ~__nonesuch() = delete;
3266 __nonesuch(__nonesuch const&) = delete;
3267 void operator=(__nonesuch const&) = delete;
3269#pragma GCC diagnostic pop
3272#ifdef __cpp_lib_is_invocable // C++ >= 17
3273 /// std::invoke_result
3274 template<typename _Functor, typename... _ArgTypes>
3275 struct invoke_result
3276 : public __invoke_result<_Functor, _ArgTypes...>
3278 static_assert(std::__is_complete_or_unbounded(__type_identity<_Functor>{}),
3279 "_Functor must be a complete class or an unbounded array");
3280 static_assert((std::__is_complete_or_unbounded(
3281 __type_identity<_ArgTypes>{}) && ...),
3282 "each argument type must be a complete class or an unbounded array");
3285 /// std::invoke_result_t
3286 template<typename _Fn, typename... _Args>
3287 using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3289 /// std::is_invocable
3290 template<typename _Fn, typename... _ArgTypes>
3292#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3293 : public __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
3295 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3298 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3299 "_Fn must be a complete class or an unbounded array");
3300 static_assert((std::__is_complete_or_unbounded(
3301 __type_identity<_ArgTypes>{}) && ...),
3302 "each argument type must be a complete class or an unbounded array");
3305 /// std::is_invocable_r
3306 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3307 struct is_invocable_r
3308 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>::type
3310 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3311 "_Fn must be a complete class or an unbounded array");
3312 static_assert((std::__is_complete_or_unbounded(
3313 __type_identity<_ArgTypes>{}) && ...),
3314 "each argument type must be a complete class or an unbounded array");
3315 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3316 "_Ret must be a complete class or an unbounded array");
3319 /// std::is_nothrow_invocable
3320 template<typename _Fn, typename... _ArgTypes>
3321 struct is_nothrow_invocable
3322#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3323 : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)>
3325 : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>,
3326 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3329 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3330 "_Fn must be a complete class or an unbounded array");
3331 static_assert((std::__is_complete_or_unbounded(
3332 __type_identity<_ArgTypes>{}) && ...),
3333 "each argument type must be a complete class or an unbounded array");
3336 /// @cond undocumented
3337 // This checks that the INVOKE<R> expression is well-formed and that the
3338 // conversion to R does not throw. It does *not* check whether the INVOKE
3339 // expression itself can throw. That is done by __call_is_nothrow_ instead.
3340 template<typename _Result, typename _Ret>
3341 using __is_nt_invocable_impl
3342 = typename __is_invocable_impl<_Result, _Ret>::__nothrow_conv;
3345 /// std::is_nothrow_invocable_r
3346 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3347 struct is_nothrow_invocable_r
3348 : __and_<__is_nt_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>,
3349 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3351 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3352 "_Fn must be a complete class or an unbounded array");
3353 static_assert((std::__is_complete_or_unbounded(
3354 __type_identity<_ArgTypes>{}) && ...),
3355 "each argument type must be a complete class or an unbounded array");
3356 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3357 "_Ret must be a complete class or an unbounded array");
3359#endif // __cpp_lib_is_invocable
3361#if __cpp_lib_type_trait_variable_templates // C++ >= 17
3363 * @defgroup variable_templates Variable templates for type traits
3364 * @ingroup metaprogramming
3366 * Each variable `is_xxx_v<T>` is a boolean constant with the same value
3367 * as the `value` member of the corresponding type trait `is_xxx<T>`.
3369 * @since C++17 unless noted otherwise.
3374 * @ingroup variable_templates
3376template <typename _Tp>
3377 inline constexpr bool is_void_v = is_void<_Tp>::value;
3378template <typename _Tp>
3379 inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
3380template <typename _Tp>
3381 inline constexpr bool is_integral_v = is_integral<_Tp>::value;
3382template <typename _Tp>
3383 inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
3385#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
3386template <typename _Tp>
3387 inline constexpr bool is_array_v = __is_array(_Tp);
3389template <typename _Tp>
3390 inline constexpr bool is_array_v = false;
3391template <typename _Tp>
3392 inline constexpr bool is_array_v<_Tp[]> = true;
3393template <typename _Tp, size_t _Num>
3394 inline constexpr bool is_array_v<_Tp[_Num]> = true;
3397#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
3398template <typename _Tp>
3399 inline constexpr bool is_pointer_v = __is_pointer(_Tp);
3401template <typename _Tp>
3402 inline constexpr bool is_pointer_v = false;
3403template <typename _Tp>
3404 inline constexpr bool is_pointer_v<_Tp*> = true;
3405template <typename _Tp>
3406 inline constexpr bool is_pointer_v<_Tp* const> = true;
3407template <typename _Tp>
3408 inline constexpr bool is_pointer_v<_Tp* volatile> = true;
3409template <typename _Tp>
3410 inline constexpr bool is_pointer_v<_Tp* const volatile> = true;
3413template <typename _Tp>
3414 inline constexpr bool is_lvalue_reference_v = false;
3415template <typename _Tp>
3416 inline constexpr bool is_lvalue_reference_v<_Tp&> = true;
3417template <typename _Tp>
3418 inline constexpr bool is_rvalue_reference_v = false;
3419template <typename _Tp>
3420 inline constexpr bool is_rvalue_reference_v<_Tp&&> = true;
3422#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
3423template <typename _Tp>
3424 inline constexpr bool is_member_object_pointer_v =
3425 __is_member_object_pointer(_Tp);
3427template <typename _Tp>
3428 inline constexpr bool is_member_object_pointer_v =
3429 is_member_object_pointer<_Tp>::value;
3432#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
3433template <typename _Tp>
3434 inline constexpr bool is_member_function_pointer_v =
3435 __is_member_function_pointer(_Tp);
3437template <typename _Tp>
3438 inline constexpr bool is_member_function_pointer_v =
3439 is_member_function_pointer<_Tp>::value;
3442template <typename _Tp>
3443 inline constexpr bool is_enum_v = __is_enum(_Tp);
3444template <typename _Tp>
3445 inline constexpr bool is_union_v = __is_union(_Tp);
3446template <typename _Tp>
3447 inline constexpr bool is_class_v = __is_class(_Tp);
3448// is_function_v is defined below, after is_const_v.
3450#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
3451template <typename _Tp>
3452 inline constexpr bool is_reference_v = __is_reference(_Tp);
3454template <typename _Tp>
3455 inline constexpr bool is_reference_v = false;
3456template <typename _Tp>
3457 inline constexpr bool is_reference_v<_Tp&> = true;
3458template <typename _Tp>
3459 inline constexpr bool is_reference_v<_Tp&&> = true;
3462template <typename _Tp>
3463 inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
3464template <typename _Tp>
3465 inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
3467#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
3468template <typename _Tp>
3469 inline constexpr bool is_object_v = __is_object(_Tp);
3471template <typename _Tp>
3472 inline constexpr bool is_object_v = is_object<_Tp>::value;
3475template <typename _Tp>
3476 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
3477template <typename _Tp>
3478 inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;
3480#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
3481template <typename _Tp>
3482 inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
3484template <typename _Tp>
3485 inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
3488#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const)
3489template <typename _Tp>
3490 inline constexpr bool is_const_v = __is_const(_Tp);
3492template <typename _Tp>
3493 inline constexpr bool is_const_v = false;
3494template <typename _Tp>
3495 inline constexpr bool is_const_v<const _Tp> = true;
3498#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
3499template <typename _Tp>
3500 inline constexpr bool is_function_v = __is_function(_Tp);
3502template <typename _Tp>
3503 inline constexpr bool is_function_v = !is_const_v<const _Tp>;
3504template <typename _Tp>
3505 inline constexpr bool is_function_v<_Tp&> = false;
3506template <typename _Tp>
3507 inline constexpr bool is_function_v<_Tp&&> = false;
3510#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile)
3511template <typename _Tp>
3512 inline constexpr bool is_volatile_v = __is_volatile(_Tp);
3514template <typename _Tp>
3515 inline constexpr bool is_volatile_v = false;
3516template <typename _Tp>
3517 inline constexpr bool is_volatile_v<volatile _Tp> = true;
3520template <typename _Tp>
3521 inline constexpr bool is_trivial_v = __is_trivial(_Tp);
3522template <typename _Tp>
3523 inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
3524template <typename _Tp>
3525 inline constexpr bool is_standard_layout_v = __is_standard_layout(_Tp);
3526template <typename _Tp>
3527 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout_v && is_trivial_v")
3528 inline constexpr bool is_pod_v = __is_pod(_Tp);
3529template <typename _Tp>
3530 _GLIBCXX17_DEPRECATED
3531 inline constexpr bool is_literal_type_v = __is_literal_type(_Tp);
3532template <typename _Tp>
3533 inline constexpr bool is_empty_v = __is_empty(_Tp);
3534template <typename _Tp>
3535 inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
3536template <typename _Tp>
3537 inline constexpr bool is_abstract_v = __is_abstract(_Tp);
3538template <typename _Tp>
3539 inline constexpr bool is_final_v = __is_final(_Tp);
3541template <typename _Tp>
3542 inline constexpr bool is_signed_v = is_signed<_Tp>::value;
3543template <typename _Tp>
3544 inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
3546template <typename _Tp, typename... _Args>
3547 inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
3548template <typename _Tp>
3549 inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
3550template <typename _Tp>
3551 inline constexpr bool is_copy_constructible_v
3552 = __is_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3553template <typename _Tp>
3554 inline constexpr bool is_move_constructible_v
3555 = __is_constructible(_Tp, __add_rval_ref_t<_Tp>);
3557template <typename _Tp, typename _Up>
3558 inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Up);
3559template <typename _Tp>
3560 inline constexpr bool is_copy_assignable_v
3561 = __is_assignable(__add_lval_ref_t<_Tp>, __add_lval_ref_t<const _Tp>);
3562template <typename _Tp>
3563 inline constexpr bool is_move_assignable_v
3564 = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3566template <typename _Tp>
3567 inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
3569template <typename _Tp, typename... _Args>
3570 inline constexpr bool is_trivially_constructible_v
3571 = __is_trivially_constructible(_Tp, _Args...);
3572template <typename _Tp>
3573 inline constexpr bool is_trivially_default_constructible_v
3574 = __is_trivially_constructible(_Tp);
3575template <typename _Tp>
3576 inline constexpr bool is_trivially_copy_constructible_v
3577 = __is_trivially_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3578template <typename _Tp>
3579 inline constexpr bool is_trivially_move_constructible_v
3580 = __is_trivially_constructible(_Tp, __add_rval_ref_t<_Tp>);
3582template <typename _Tp, typename _Up>
3583 inline constexpr bool is_trivially_assignable_v
3584 = __is_trivially_assignable(_Tp, _Up);
3585template <typename _Tp>
3586 inline constexpr bool is_trivially_copy_assignable_v
3587 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3588 __add_lval_ref_t<const _Tp>);
3589template <typename _Tp>
3590 inline constexpr bool is_trivially_move_assignable_v
3591 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3592 __add_rval_ref_t<_Tp>);
3595template <typename _Tp>
3596 inline constexpr bool is_trivially_destructible_v = false;
3598template <typename _Tp>
3599 requires (!is_reference_v<_Tp>) && requires (_Tp& __t) { __t.~_Tp(); }
3600 inline constexpr bool is_trivially_destructible_v<_Tp>
3601 = __has_trivial_destructor(_Tp);
3602template <typename _Tp>
3603 inline constexpr bool is_trivially_destructible_v<_Tp&> = true;
3604template <typename _Tp>
3605 inline constexpr bool is_trivially_destructible_v<_Tp&&> = true;
3606template <typename _Tp, size_t _Nm>
3607 inline constexpr bool is_trivially_destructible_v<_Tp[_Nm]>
3608 = is_trivially_destructible_v<_Tp>;
3610template <typename _Tp>
3611 inline constexpr bool is_trivially_destructible_v =
3612 is_trivially_destructible<_Tp>::value;
3615template <typename _Tp, typename... _Args>
3616 inline constexpr bool is_nothrow_constructible_v
3617 = __is_nothrow_constructible(_Tp, _Args...);
3618template <typename _Tp>
3619 inline constexpr bool is_nothrow_default_constructible_v
3620 = __is_nothrow_constructible(_Tp);
3621template <typename _Tp>
3622 inline constexpr bool is_nothrow_copy_constructible_v
3623 = __is_nothrow_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3624template <typename _Tp>
3625 inline constexpr bool is_nothrow_move_constructible_v
3626 = __is_nothrow_constructible(_Tp, __add_rval_ref_t<_Tp>);
3628template <typename _Tp, typename _Up>
3629 inline constexpr bool is_nothrow_assignable_v
3630 = __is_nothrow_assignable(_Tp, _Up);
3631template <typename _Tp>
3632 inline constexpr bool is_nothrow_copy_assignable_v
3633 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>,
3634 __add_lval_ref_t<const _Tp>);
3635template <typename _Tp>
3636 inline constexpr bool is_nothrow_move_assignable_v
3637 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3639template <typename _Tp>
3640 inline constexpr bool is_nothrow_destructible_v =
3641 is_nothrow_destructible<_Tp>::value;
3643template <typename _Tp>
3644 inline constexpr bool has_virtual_destructor_v
3645 = __has_virtual_destructor(_Tp);
3647template <typename _Tp>
3648 inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
3650#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank)
3651template <typename _Tp>
3652 inline constexpr size_t rank_v = __array_rank(_Tp);
3654template <typename _Tp>
3655 inline constexpr size_t rank_v = 0;
3656template <typename _Tp, size_t _Size>
3657 inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
3658template <typename _Tp>
3659 inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
3662template <typename _Tp, unsigned _Idx = 0>
3663 inline constexpr size_t extent_v = 0;
3664template <typename _Tp, size_t _Size>
3665 inline constexpr size_t extent_v<_Tp[_Size], 0> = _Size;
3666template <typename _Tp, unsigned _Idx, size_t _Size>
3667 inline constexpr size_t extent_v<_Tp[_Size], _Idx> = extent_v<_Tp, _Idx - 1>;
3668template <typename _Tp>
3669 inline constexpr size_t extent_v<_Tp[], 0> = 0;
3670template <typename _Tp, unsigned _Idx>
3671 inline constexpr size_t extent_v<_Tp[], _Idx> = extent_v<_Tp, _Idx - 1>;
3673#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
3674template <typename _Tp, typename _Up>
3675 inline constexpr bool is_same_v = __is_same(_Tp, _Up);
3677template <typename _Tp, typename _Up>
3678 inline constexpr bool is_same_v = false;
3679template <typename _Tp>
3680 inline constexpr bool is_same_v<_Tp, _Tp> = true;
3682template <typename _Base, typename _Derived>
3683 inline constexpr bool is_base_of_v = __is_base_of(_Base, _Derived);
3684#ifdef __cpp_lib_is_virtual_base_of // C++ >= 26
3685template <typename _Base, typename _Derived>
3686 inline constexpr bool is_virtual_base_of_v = __builtin_is_virtual_base_of(_Base, _Derived);
3688#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
3689template <typename _From, typename _To>
3690 inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
3692template <typename _From, typename _To>
3693 inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
3695template<typename _Fn, typename... _Args>
3696 inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
3697template<typename _Fn, typename... _Args>
3698 inline constexpr bool is_nothrow_invocable_v
3699 = is_nothrow_invocable<_Fn, _Args...>::value;
3700template<typename _Ret, typename _Fn, typename... _Args>
3701 inline constexpr bool is_invocable_r_v
3702 = is_invocable_r<_Ret, _Fn, _Args...>::value;
3703template<typename _Ret, typename _Fn, typename... _Args>
3704 inline constexpr bool is_nothrow_invocable_r_v
3705 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3707#endif // __cpp_lib_type_trait_variable_templates
3709#ifdef __cpp_lib_has_unique_object_representations // C++ >= 17 && HAS_UNIQ_OBJ_REP
3710 /// has_unique_object_representations
3712 template<typename _Tp>
3713 struct has_unique_object_representations
3714 : bool_constant<__has_unique_object_representations(
3715 remove_cv_t<remove_all_extents_t<_Tp>>
3718 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3719 "template argument must be a complete class or an unbounded array");
3722# if __cpp_lib_type_trait_variable_templates // C++ >= 17
3723 /// @ingroup variable_templates
3724 template<typename _Tp>
3725 inline constexpr bool has_unique_object_representations_v
3726 = has_unique_object_representations<_Tp>::value;
3730#ifdef __cpp_lib_is_aggregate // C++ >= 17 && builtin_is_aggregate
3731 /// is_aggregate - true if the type is an aggregate.
3733 template<typename _Tp>
3735 : bool_constant<__is_aggregate(remove_cv_t<_Tp>)>
3738# if __cpp_lib_type_trait_variable_templates // C++ >= 17
3739 /** is_aggregate_v - true if the type is an aggregate.
3740 * @ingroup variable_templates
3743 template<typename _Tp>
3744 inline constexpr bool is_aggregate_v = __is_aggregate(remove_cv_t<_Tp>);
3748 /** * Remove references and cv-qualifiers.
3752#ifdef __cpp_lib_remove_cvref // C++ >= 20
3753# if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cvref)
3754 template<typename _Tp>
3756 { using type = __remove_cvref(_Tp); };
3758 template<typename _Tp>
3760 { using type = typename remove_cv<_Tp>::type; };
3762 template<typename _Tp>
3763 struct remove_cvref<_Tp&>
3764 { using type = typename remove_cv<_Tp>::type; };
3766 template<typename _Tp>
3767 struct remove_cvref<_Tp&&>
3768 { using type = typename remove_cv<_Tp>::type; };
3771 template<typename _Tp>
3772 using remove_cvref_t = typename remove_cvref<_Tp>::type;
3774#endif // __cpp_lib_remove_cvref
3776#ifdef __cpp_lib_type_identity // C++ >= 20
3777 /** * Identity metafunction.
3781 template<typename _Tp>
3782 struct type_identity { using type = _Tp; };
3784 template<typename _Tp>
3785 using type_identity_t = typename type_identity<_Tp>::type;
3789#ifdef __cpp_lib_unwrap_ref // C++ >= 20
3790 /** Unwrap a reference_wrapper
3794 template<typename _Tp>
3795 struct unwrap_reference { using type = _Tp; };
3797 template<typename _Tp>
3798 struct unwrap_reference<reference_wrapper<_Tp>> { using type = _Tp&; };
3800 template<typename _Tp>
3801 using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3804 /** Decay type and if it's a reference_wrapper, unwrap it
3808 template<typename _Tp>
3809 struct unwrap_ref_decay { using type = unwrap_reference_t<decay_t<_Tp>>; };
3811 template<typename _Tp>
3812 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3814#endif // __cpp_lib_unwrap_ref
3816#ifdef __cpp_lib_bounded_array_traits // C++ >= 20
3817 /// True for a type that is an array of known bound.
3818 /// @ingroup variable_templates
3820# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array)
3821 template<typename _Tp>
3822 inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp);
3824 template<typename _Tp>
3825 inline constexpr bool is_bounded_array_v = false;
3827 template<typename _Tp, size_t _Size>
3828 inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true;
3831 /// True for a type that is an array of unknown bound.
3832 /// @ingroup variable_templates
3834# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array)
3835 template<typename _Tp>
3836 inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp);
3838 template<typename _Tp>
3839 inline constexpr bool is_unbounded_array_v = false;
3841 template<typename _Tp>
3842 inline constexpr bool is_unbounded_array_v<_Tp[]> = true;
3845 /// True for a type that is an array of known bound.
3847 template<typename _Tp>
3848 struct is_bounded_array
3849 : public bool_constant<is_bounded_array_v<_Tp>>
3852 /// True for a type that is an array of unknown bound.
3854 template<typename _Tp>
3855 struct is_unbounded_array
3856 : public bool_constant<is_unbounded_array_v<_Tp>>
3858#endif // __cpp_lib_bounded_array_traits
3860#if __has_builtin(__is_layout_compatible) && __cplusplus >= 202002L
3863 template<typename _Tp, typename _Up>
3864 struct is_layout_compatible
3865 : bool_constant<__is_layout_compatible(_Tp, _Up)>
3868 /// @ingroup variable_templates
3870 template<typename _Tp, typename _Up>
3871 constexpr bool is_layout_compatible_v
3872 = __is_layout_compatible(_Tp, _Up);
3874#if __has_builtin(__builtin_is_corresponding_member)
3875# ifndef __cpp_lib_is_layout_compatible
3876# error "libstdc++ bug: is_corresponding_member and is_layout_compatible are provided but their FTM is not set"
3880 template<typename _S1, typename _S2, typename _M1, typename _M2>
3882 is_corresponding_member(_M1 _S1::*__m1, _M2 _S2::*__m2) noexcept
3883 { return __builtin_is_corresponding_member(__m1, __m2); }
3887#if __has_builtin(__is_pointer_interconvertible_base_of) \
3888 && __cplusplus >= 202002L
3889 /// True if `_Derived` is standard-layout and has a base class of type `_Base`
3891 template<typename _Base, typename _Derived>
3892 struct is_pointer_interconvertible_base_of
3893 : bool_constant<__is_pointer_interconvertible_base_of(_Base, _Derived)>
3896 /// @ingroup variable_templates
3898 template<typename _Base, typename _Derived>
3899 constexpr bool is_pointer_interconvertible_base_of_v
3900 = __is_pointer_interconvertible_base_of(_Base, _Derived);
3902#if __has_builtin(__builtin_is_pointer_interconvertible_with_class)
3903# ifndef __cpp_lib_is_pointer_interconvertible
3904# error "libstdc++ bug: is_pointer_interconvertible available but FTM is not set"
3907 /// True if `__mp` points to the first member of a standard-layout type
3908 /// @returns true if `s.*__mp` is pointer-interconvertible with `s`
3910 template<typename _Tp, typename _Mem>
3912 is_pointer_interconvertible_with_class(_Mem _Tp::*__mp) noexcept
3913 { return __builtin_is_pointer_interconvertible_with_class(__mp); }
3917#ifdef __cpp_lib_is_scoped_enum // C++ >= 23
3918 /// True if the type is a scoped enumeration type.
3921# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
3922 template<typename _Tp>
3923 struct is_scoped_enum
3924 : bool_constant<__is_scoped_enum(_Tp)>
3927 template<typename _Tp>
3928 struct is_scoped_enum
3932 template<typename _Tp>
3933 requires __is_enum(_Tp)
3934 && requires(remove_cv_t<_Tp> __t) { __t = __t; } // fails if incomplete
3935 struct is_scoped_enum<_Tp>
3936 : bool_constant<!requires(_Tp __t, void(*__f)(int)) { __f(__t); }>
3940 /// @ingroup variable_templates
3942# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
3943 template<typename _Tp>
3944 inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
3946 template<typename _Tp>
3947 inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
3951#ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp
3952 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
3953 /// direct-initialization, and a temporary object would be bound to
3954 /// the reference, false otherwise.
3956 template<typename _Tp, typename _Up>
3957 struct reference_constructs_from_temporary
3958 : public bool_constant<__reference_constructs_from_temporary(_Tp, _Up)>
3960 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
3961 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3962 "template argument must be a complete class or an unbounded array");
3965 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
3966 /// copy-initialization, and a temporary object would be bound to
3967 /// the reference, false otherwise.
3969 template<typename _Tp, typename _Up>
3970 struct reference_converts_from_temporary
3971 : public bool_constant<__reference_converts_from_temporary(_Tp, _Up)>
3973 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
3974 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3975 "template argument must be a complete class or an unbounded array");
3978 /// @ingroup variable_templates
3980 template<typename _Tp, typename _Up>
3981 inline constexpr bool reference_constructs_from_temporary_v
3982 = reference_constructs_from_temporary<_Tp, _Up>::value;
3984 /// @ingroup variable_templates
3986 template<typename _Tp, typename _Up>
3987 inline constexpr bool reference_converts_from_temporary_v
3988 = reference_converts_from_temporary<_Tp, _Up>::value;
3989#endif // __cpp_lib_reference_from_temporary
3991#ifdef __cpp_lib_is_constant_evaluated // C++ >= 20 && HAVE_IS_CONST_EVAL
3992 /// Returns true only when called during constant evaluation.
3994 constexpr inline bool
3995 is_constant_evaluated() noexcept
3997#if __cpp_if_consteval >= 202106L
3998 if consteval { return true; } else { return false; }
4000 return __builtin_is_constant_evaluated();
4005#if __cplusplus >= 202002L
4006 /// @cond undocumented
4007 template<typename _From, typename _To>
4008 using __copy_cv = typename __match_cv_qualifiers<_From, _To>::__type;
4010 template<typename _Xp, typename _Yp>
4012 = decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
4014 template<typename _Ap, typename _Bp, typename = void>
4015 struct __common_ref_impl
4018 // [meta.trans.other], COMMON-REF(A, B)
4019 template<typename _Ap, typename _Bp>
4020 using __common_ref = typename __common_ref_impl<_Ap, _Bp>::type;
4022 // COND-RES(COPYCV(X, Y) &, COPYCV(Y, X) &)
4023 template<typename _Xp, typename _Yp>
4024 using __condres_cvref
4025 = __cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>;
4027 // If A and B are both lvalue reference types, ...
4028 template<typename _Xp, typename _Yp>
4029 struct __common_ref_impl<_Xp&, _Yp&, __void_t<__condres_cvref<_Xp, _Yp>>>
4030 : enable_if<is_reference_v<__condres_cvref<_Xp, _Yp>>,
4031 __condres_cvref<_Xp, _Yp>>
4034 // let C be remove_reference_t<COMMON-REF(X&, Y&)>&&
4035 template<typename _Xp, typename _Yp>
4036 using __common_ref_C = remove_reference_t<__common_ref<_Xp&, _Yp&>>&&;
4038 // If A and B are both rvalue reference types, ...
4039 template<typename _Xp, typename _Yp>
4040 struct __common_ref_impl<_Xp&&, _Yp&&,
4041 _Require<is_convertible<_Xp&&, __common_ref_C<_Xp, _Yp>>,
4042 is_convertible<_Yp&&, __common_ref_C<_Xp, _Yp>>>>
4043 { using type = __common_ref_C<_Xp, _Yp>; };
4045 // let D be COMMON-REF(const X&, Y&)
4046 template<typename _Xp, typename _Yp>
4047 using __common_ref_D = __common_ref<const _Xp&, _Yp&>;
4049 // If A is an rvalue reference and B is an lvalue reference, ...
4050 template<typename _Xp, typename _Yp>
4051 struct __common_ref_impl<_Xp&&, _Yp&,
4052 _Require<is_convertible<_Xp&&, __common_ref_D<_Xp, _Yp>>>>
4053 { using type = __common_ref_D<_Xp, _Yp>; };
4055 // If A is an lvalue reference and B is an rvalue reference, ...
4056 template<typename _Xp, typename _Yp>
4057 struct __common_ref_impl<_Xp&, _Yp&&>
4058 : __common_ref_impl<_Yp&&, _Xp&>
4062 template<typename _Tp, typename _Up,
4063 template<typename> class _TQual, template<typename> class _UQual>
4064 struct basic_common_reference
4067 /// @cond undocumented
4068 template<typename _Tp>
4070 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>; };
4072 template<typename _Tp>
4074 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&; };
4076 template<typename _Tp>
4077 struct __xref<_Tp&&>
4078 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&&; };
4080 template<typename _Tp1, typename _Tp2>
4081 using __basic_common_ref
4082 = typename basic_common_reference<remove_cvref_t<_Tp1>,
4083 remove_cvref_t<_Tp2>,
4084 __xref<_Tp1>::template __type,
4085 __xref<_Tp2>::template __type>::type;
4088 template<typename... _Tp>
4089 struct common_reference;
4091 template<typename... _Tp>
4092 using common_reference_t = typename common_reference<_Tp...>::type;
4094 // If sizeof...(T) is zero, there shall be no member type.
4096 struct common_reference<>
4099 // If sizeof...(T) is one ...
4100 template<typename _Tp0>
4101 struct common_reference<_Tp0>
4102 { using type = _Tp0; };
4104 /// @cond undocumented
4105 template<typename _Tp1, typename _Tp2, int _Bullet = 1, typename = void>
4106 struct __common_reference_impl
4107 : __common_reference_impl<_Tp1, _Tp2, _Bullet + 1>
4110 // If sizeof...(T) is two ...
4111 template<typename _Tp1, typename _Tp2>
4112 struct common_reference<_Tp1, _Tp2>
4113 : __common_reference_impl<_Tp1, _Tp2>
4116 // If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, ...
4117 template<typename _Tp1, typename _Tp2>
4118 struct __common_reference_impl<_Tp1&, _Tp2&, 1,
4119 void_t<__common_ref<_Tp1&, _Tp2&>>>
4120 { using type = __common_ref<_Tp1&, _Tp2&>; };
4122 template<typename _Tp1, typename _Tp2>
4123 struct __common_reference_impl<_Tp1&&, _Tp2&&, 1,
4124 void_t<__common_ref<_Tp1&&, _Tp2&&>>>
4125 { using type = __common_ref<_Tp1&&, _Tp2&&>; };
4127 template<typename _Tp1, typename _Tp2>
4128 struct __common_reference_impl<_Tp1&, _Tp2&&, 1,
4129 void_t<__common_ref<_Tp1&, _Tp2&&>>>
4130 { using type = __common_ref<_Tp1&, _Tp2&&>; };
4132 template<typename _Tp1, typename _Tp2>
4133 struct __common_reference_impl<_Tp1&&, _Tp2&, 1,
4134 void_t<__common_ref<_Tp1&&, _Tp2&>>>
4135 { using type = __common_ref<_Tp1&&, _Tp2&>; };
4137 // Otherwise, if basic_common_reference<...>::type is well-formed, ...
4138 template<typename _Tp1, typename _Tp2>
4139 struct __common_reference_impl<_Tp1, _Tp2, 2,
4140 void_t<__basic_common_ref<_Tp1, _Tp2>>>
4141 { using type = __basic_common_ref<_Tp1, _Tp2>; };
4143 // Otherwise, if COND-RES(T1, T2) is well-formed, ...
4144 template<typename _Tp1, typename _Tp2>
4145 struct __common_reference_impl<_Tp1, _Tp2, 3,
4146 void_t<__cond_res<_Tp1, _Tp2>>>
4147 { using type = __cond_res<_Tp1, _Tp2>; };
4149 // Otherwise, if common_type_t<T1, T2> is well-formed, ...
4150 template<typename _Tp1, typename _Tp2>
4151 struct __common_reference_impl<_Tp1, _Tp2, 4,
4152 void_t<common_type_t<_Tp1, _Tp2>>>
4153 { using type = common_type_t<_Tp1, _Tp2>; };
4155 // Otherwise, there shall be no member type.
4156 template<typename _Tp1, typename _Tp2>
4157 struct __common_reference_impl<_Tp1, _Tp2, 5, void>
4160 // Otherwise, if sizeof...(T) is greater than two, ...
4161 template<typename _Tp1, typename _Tp2, typename... _Rest>
4162 struct common_reference<_Tp1, _Tp2, _Rest...>
4163 : __common_type_fold<common_reference<_Tp1, _Tp2>,
4164 __common_type_pack<_Rest...>>
4167 // Reuse __common_type_fold for common_reference<T1, T2, Rest...>
4168 template<typename _Tp1, typename _Tp2, typename... _Rest>
4169 struct __common_type_fold<common_reference<_Tp1, _Tp2>,
4170 __common_type_pack<_Rest...>,
4171 void_t<common_reference_t<_Tp1, _Tp2>>>
4172 : public common_reference<common_reference_t<_Tp1, _Tp2>, _Rest...>
4178 /// @} group metaprogramming
4180_GLIBCXX_END_NAMESPACE_VERSION
4186#endif // _GLIBCXX_TYPE_TRAITS