libstdc++
type_traits
Go to the documentation of this file.
1// C++11 <type_traits> -*- C++ -*-
2
3// Copyright (C) 2007-2025 Free Software Foundation, Inc.
4//
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)
9// any later version.
10
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.
15
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.
19
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/>.
24
25/** @file include/type_traits
26 * This is a Standard C++ Library header.
27 */
28
29#ifndef _GLIBCXX_TYPE_TRAITS
30#define _GLIBCXX_TYPE_TRAITS 1
31
32#ifdef _GLIBCXX_SYSHDR
33#pragma GCC system_header
34#endif
35
36#if __cplusplus < 201103L
37# include <bits/c++0x_warning.h>
38#else
39
40#include <bits/c++config.h>
41
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>
67
68extern "C++"
69{
70namespace std _GLIBCXX_VISIBILITY(default)
71{
72_GLIBCXX_BEGIN_NAMESPACE_VERSION
73
74 template<typename _Tp>
75 class reference_wrapper;
76
77 /**
78 * @defgroup metaprogramming Metaprogramming
79 * @ingroup utilities
80 *
81 * Template utilities for compile-time introspection and modification,
82 * including type classification traits, type property inspection traits
83 * and type transformation traits.
84 *
85 * @since C++11
86 *
87 * @{
88 */
89
90 /// integral_constant
91 template<typename _Tp, _Tp __v>
92 struct integral_constant
93 {
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; }
98
99#ifdef __cpp_lib_integral_constant_callable // C++ >= 14
100 constexpr value_type operator()() const noexcept { return value; }
101#endif
102 };
103
104#if ! __cpp_inline_variables
105 template<typename _Tp, _Tp __v>
106 constexpr _Tp integral_constant<_Tp, __v>::value;
107#endif
108
109 /// @cond undocumented
110 /// bool_constant for C++11
111 template<bool __v>
112 using __bool_constant = integral_constant<bool, __v>;
113 /// @endcond
114
115 /// The type used as a compile-time boolean with true value.
116 using true_type = __bool_constant<true>;
117
118 /// The type used as a compile-time boolean with false value.
119 using false_type = __bool_constant<false>;
120
121#ifdef __cpp_lib_bool_constant // C++ >= 17
122 /// Alias template for compile-time boolean constant types.
123 /// @since C++17
124 template<bool __v>
125 using bool_constant = __bool_constant<__v>;
126#endif
127
128 // Metaprogramming helper types.
129
130 // Primary template.
131 /// Define a member typedef `type` only if a boolean constant is true.
132 template<bool, typename _Tp = void>
133 struct enable_if
134 { };
135
136 // Partial specialization for true.
137 template<typename _Tp>
138 struct enable_if<true, _Tp>
139 { using type = _Tp; };
140
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;
144
145 template<bool>
146 struct __conditional
147 {
148 template<typename _Tp, typename>
149 using type = _Tp;
150 };
151
152 template<>
153 struct __conditional<false>
154 {
155 template<typename, typename _Up>
156 using type = _Up;
157 };
158
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>;
163
164 /// @cond undocumented
165 template <typename _Type>
166 struct __type_identity
167 { using type = _Type; };
168
169 template<typename _Tp>
170 using __type_identity_t = typename __type_identity<_Tp>::type;
171
172 namespace __detail
173 {
174 // A variadic alias template that resolves to its first argument.
175 template<typename _Tp, typename...>
176 using __first_t = _Tp;
177
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)>...>;
182
183 template<typename... _Bn>
184 auto __or_fn(...) -> true_type;
185
186 template<typename... _Bn>
187 auto __and_fn(int) -> __first_t<true_type,
188 __enable_if_t<bool(_Bn::value)>...>;
189
190 template<typename... _Bn>
191 auto __and_fn(...) -> false_type;
192 } // namespace detail
193
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>
198 struct __or_
199 : decltype(__detail::__or_fn<_Bn...>(0))
200 { };
201
202 template<typename... _Bn>
203 struct __and_
204 : decltype(__detail::__and_fn<_Bn...>(0))
205 { };
206
207 template<typename _Pp>
208 struct __not_
209 : __bool_constant<!bool(_Pp::value)>
210 { };
211 /// @endcond
212
213#ifdef __cpp_lib_logical_traits // C++ >= 17
214
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;
220
221 namespace __detail
222 {
223 template<typename /* = void */, typename _B1, typename... _Bn>
224 struct __disjunction_impl
225 { using type = _B1; };
226
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; };
230
231 template<typename /* = void */, typename _B1, typename... _Bn>
232 struct __conjunction_impl
233 { using type = _B1; };
234
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
239 /// @endcond
240
241 template<typename... _Bn>
242 struct conjunction
243 : __detail::__conjunction_impl<void, _Bn...>::type
244 { };
245
246 template<>
247 struct conjunction<>
248 : true_type
249 { };
250
251 template<typename... _Bn>
252 struct disjunction
253 : __detail::__disjunction_impl<void, _Bn...>::type
254 { };
255
256 template<>
257 struct disjunction<>
258 : false_type
259 { };
260
261 template<typename _Pp>
262 struct negation
263 : __not_<_Pp>::type
264 { };
265
266 /** @ingroup variable_templates
267 * @{
268 */
269 template<typename... _Bn>
270 inline constexpr bool conjunction_v = conjunction<_Bn...>::value;
271
272 template<typename... _Bn>
273 inline constexpr bool disjunction_v = disjunction<_Bn...>::value;
274
275 template<typename _Pp>
276 inline constexpr bool negation_v = negation<_Pp>::value;
277 /// @}
278
279#endif // __cpp_lib_logical_traits
280
281 // Forward declarations
282 template<typename>
283 struct is_object;
284 template<typename>
285 struct remove_cv;
286 template<typename>
287 struct is_const;
288
289 /// @cond undocumented
290 template<typename>
291 struct __is_array_unknown_bounds;
292
293 // An object type which is not an unbounded array.
294 // It might still be an incomplete type, but if this is false_type
295 // then we can be certain it's not a complete object type.
296 template<typename _Tp>
297 using __maybe_complete_object_type
298 = __and_<is_object<_Tp>, __not_<__is_array_unknown_bounds<_Tp>>>;
299
300 // Helper functions that return false_type for incomplete classes,
301 // incomplete unions and arrays of known bound from those.
302
303 // More specialized overload for complete object types (returning true_type).
304 template<typename _Tp,
305 typename = __enable_if_t<__maybe_complete_object_type<_Tp>::value>,
306 size_t = sizeof(_Tp)>
307 constexpr true_type
308 __is_complete_or_unbounded(__type_identity<_Tp>)
309 { return {}; };
310
311 // Less specialized overload for reference and unknown-bound array types
312 // (returning true_type), and incomplete types (returning false_type).
313 template<typename _TypeIdentity,
314 typename _NestedType = typename _TypeIdentity::type>
315 constexpr typename __not_<__maybe_complete_object_type<_NestedType>>::type
316 __is_complete_or_unbounded(_TypeIdentity)
317 { return {}; }
318
319 // __remove_cv_t (std::remove_cv_t for C++11).
320 template<typename _Tp>
321 using __remove_cv_t = typename remove_cv<_Tp>::type;
322 /// @endcond
323
324 // Primary type categories.
325
326 /// is_void
327 template<typename _Tp>
328 struct is_void
329 : public false_type { };
330
331 template<>
332 struct is_void<void>
333 : public true_type { };
334
335 template<>
336 struct is_void<const void>
337 : public true_type { };
338
339 template<>
340 struct is_void<volatile void>
341 : public true_type { };
342
343 template<>
344 struct is_void<const volatile void>
345 : public true_type { };
346
347 /// @cond undocumented
348 template<typename>
349 struct __is_integral_helper
350 : public false_type { };
351
352 template<>
353 struct __is_integral_helper<bool>
354 : public true_type { };
355
356 template<>
357 struct __is_integral_helper<char>
358 : public true_type { };
359
360 template<>
361 struct __is_integral_helper<signed char>
362 : public true_type { };
363
364 template<>
365 struct __is_integral_helper<unsigned char>
366 : public true_type { };
367
368 // We want is_integral<wchar_t> to be true (and make_signed/unsigned to work)
369 // even when libc doesn't provide working <wchar.h> and related functions,
370 // so don't check _GLIBCXX_USE_WCHAR_T here.
371 template<>
372 struct __is_integral_helper<wchar_t>
373 : public true_type { };
374
375#ifdef _GLIBCXX_USE_CHAR8_T
376 template<>
377 struct __is_integral_helper<char8_t>
378 : public true_type { };
379#endif
380
381 template<>
382 struct __is_integral_helper<char16_t>
383 : public true_type { };
384
385 template<>
386 struct __is_integral_helper<char32_t>
387 : public true_type { };
388
389 template<>
390 struct __is_integral_helper<short>
391 : public true_type { };
392
393 template<>
394 struct __is_integral_helper<unsigned short>
395 : public true_type { };
396
397 template<>
398 struct __is_integral_helper<int>
399 : public true_type { };
400
401 template<>
402 struct __is_integral_helper<unsigned int>
403 : public true_type { };
404
405 template<>
406 struct __is_integral_helper<long>
407 : public true_type { };
408
409 template<>
410 struct __is_integral_helper<unsigned long>
411 : public true_type { };
412
413 template<>
414 struct __is_integral_helper<long long>
415 : public true_type { };
416
417 template<>
418 struct __is_integral_helper<unsigned long long>
419 : public true_type { };
420
421 // Conditionalizing on __STRICT_ANSI__ here will break any port that
422 // uses one of these types for size_t.
423#if defined(__GLIBCXX_TYPE_INT_N_0)
424 __extension__
425 template<>
426 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
427 : public true_type { };
428
429 __extension__
430 template<>
431 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
432 : public true_type { };
433#endif
434#if defined(__GLIBCXX_TYPE_INT_N_1)
435 __extension__
436 template<>
437 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
438 : public true_type { };
439
440 __extension__
441 template<>
442 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
443 : public true_type { };
444#endif
445#if defined(__GLIBCXX_TYPE_INT_N_2)
446 __extension__
447 template<>
448 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
449 : public true_type { };
450
451 __extension__
452 template<>
453 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
454 : public true_type { };
455#endif
456#if defined(__GLIBCXX_TYPE_INT_N_3)
457 __extension__
458 template<>
459 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
460 : public true_type { };
461
462 __extension__
463 template<>
464 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
465 : public true_type { };
466#endif
467
468#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
469 __extension__
470 template<>
471 struct __is_integral_helper<__int128>
472 : public true_type { };
473
474 __extension__
475 template<>
476 struct __is_integral_helper<unsigned __int128>
477 : public true_type { };
478#endif
479
480 /// @endcond
481
482 /// is_integral
483 template<typename _Tp>
484 struct is_integral
485 : public __is_integral_helper<__remove_cv_t<_Tp>>::type
486 { };
487
488 /// @cond undocumented
489 template<typename>
490 struct __is_floating_point_helper
491 : public false_type { };
492
493 template<>
494 struct __is_floating_point_helper<float>
495 : public true_type { };
496
497 template<>
498 struct __is_floating_point_helper<double>
499 : public true_type { };
500
501 template<>
502 struct __is_floating_point_helper<long double>
503 : public true_type { };
504
505#ifdef __STDCPP_FLOAT16_T__
506 template<>
507 struct __is_floating_point_helper<_Float16>
508 : public true_type { };
509#endif
510
511#ifdef __STDCPP_FLOAT32_T__
512 template<>
513 struct __is_floating_point_helper<_Float32>
514 : public true_type { };
515#endif
516
517#ifdef __STDCPP_FLOAT64_T__
518 template<>
519 struct __is_floating_point_helper<_Float64>
520 : public true_type { };
521#endif
522
523#ifdef __STDCPP_FLOAT128_T__
524 template<>
525 struct __is_floating_point_helper<_Float128>
526 : public true_type { };
527#endif
528
529#ifdef __STDCPP_BFLOAT16_T__
530 template<>
531 struct __is_floating_point_helper<__gnu_cxx::__bfloat16_t>
532 : public true_type { };
533#endif
534
535#ifdef _GLIBCXX_USE_FLOAT128
536 template<>
537 struct __is_floating_point_helper<__float128>
538 : public true_type { };
539#endif
540 /// @endcond
541
542 /// is_floating_point
543 template<typename _Tp>
544 struct is_floating_point
545 : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type
546 { };
547
548 /// is_array
549#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
550 template<typename _Tp>
551 struct is_array
552 : public __bool_constant<__is_array(_Tp)>
553 { };
554#else
555 template<typename>
556 struct is_array
557 : public false_type { };
558
559 template<typename _Tp, std::size_t _Size>
560 struct is_array<_Tp[_Size]>
561 : public true_type { };
562
563 template<typename _Tp>
564 struct is_array<_Tp[]>
565 : public true_type { };
566#endif
567
568 /// is_pointer
569#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
570 template<typename _Tp>
571 struct is_pointer
572 : public __bool_constant<__is_pointer(_Tp)>
573 { };
574#else
575 template<typename _Tp>
576 struct is_pointer
577 : public false_type { };
578
579 template<typename _Tp>
580 struct is_pointer<_Tp*>
581 : public true_type { };
582
583 template<typename _Tp>
584 struct is_pointer<_Tp* const>
585 : public true_type { };
586
587 template<typename _Tp>
588 struct is_pointer<_Tp* volatile>
589 : public true_type { };
590
591 template<typename _Tp>
592 struct is_pointer<_Tp* const volatile>
593 : public true_type { };
594#endif
595
596 /// is_lvalue_reference
597 template<typename>
598 struct is_lvalue_reference
599 : public false_type { };
600
601 template<typename _Tp>
602 struct is_lvalue_reference<_Tp&>
603 : public true_type { };
604
605 /// is_rvalue_reference
606 template<typename>
607 struct is_rvalue_reference
608 : public false_type { };
609
610 template<typename _Tp>
611 struct is_rvalue_reference<_Tp&&>
612 : public true_type { };
613
614 /// is_member_object_pointer
615#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
616 template<typename _Tp>
617 struct is_member_object_pointer
618 : public __bool_constant<__is_member_object_pointer(_Tp)>
619 { };
620#else
621 template<typename>
622 struct __is_member_object_pointer_helper
623 : public false_type { };
624
625 template<typename _Tp, typename _Cp>
626 struct __is_member_object_pointer_helper<_Tp _Cp::*>
627 : public __not_<is_function<_Tp>>::type { };
628
629
630 template<typename _Tp>
631 struct is_member_object_pointer
632 : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type
633 { };
634#endif
635
636#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
637 /// is_member_function_pointer
638 template<typename _Tp>
639 struct is_member_function_pointer
640 : public __bool_constant<__is_member_function_pointer(_Tp)>
641 { };
642#else
643 template<typename>
644 struct __is_member_function_pointer_helper
645 : public false_type { };
646
647 template<typename _Tp, typename _Cp>
648 struct __is_member_function_pointer_helper<_Tp _Cp::*>
649 : public is_function<_Tp>::type { };
650
651 /// is_member_function_pointer
652 template<typename _Tp>
653 struct is_member_function_pointer
654 : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type
655 { };
656#endif
657
658 /// is_enum
659 template<typename _Tp>
660 struct is_enum
661 : public __bool_constant<__is_enum(_Tp)>
662 { };
663
664 /// is_union
665 template<typename _Tp>
666 struct is_union
667 : public __bool_constant<__is_union(_Tp)>
668 { };
669
670 /// is_class
671 template<typename _Tp>
672 struct is_class
673 : public __bool_constant<__is_class(_Tp)>
674 { };
675
676 /// is_function
677#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
678 template<typename _Tp>
679 struct is_function
680 : public __bool_constant<__is_function(_Tp)>
681 { };
682#else
683 template<typename _Tp>
684 struct is_function
685 : public __bool_constant<!is_const<const _Tp>::value> { };
686
687 template<typename _Tp>
688 struct is_function<_Tp&>
689 : public false_type { };
690
691 template<typename _Tp>
692 struct is_function<_Tp&&>
693 : public false_type { };
694#endif
695
696#ifdef __cpp_lib_is_null_pointer // C++ >= 11
697 /// is_null_pointer (LWG 2247).
698 template<typename _Tp>
699 struct is_null_pointer
700 : public false_type { };
701
702 template<>
703 struct is_null_pointer<std::nullptr_t>
704 : public true_type { };
705
706 template<>
707 struct is_null_pointer<const std::nullptr_t>
708 : public true_type { };
709
710 template<>
711 struct is_null_pointer<volatile std::nullptr_t>
712 : public true_type { };
713
714 template<>
715 struct is_null_pointer<const volatile std::nullptr_t>
716 : public true_type { };
717
718 /// __is_nullptr_t (deprecated extension).
719 /// @deprecated Non-standard. Use `is_null_pointer` instead.
720 template<typename _Tp>
721 struct __is_nullptr_t
722 : public is_null_pointer<_Tp>
723 { } _GLIBCXX_DEPRECATED_SUGGEST("std::is_null_pointer");
724#endif // __cpp_lib_is_null_pointer
725
726 // Composite type categories.
727
728 /// is_reference
729#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
730 template<typename _Tp>
731 struct is_reference
732 : public __bool_constant<__is_reference(_Tp)>
733 { };
734#else
735 template<typename _Tp>
736 struct is_reference
737 : public false_type
738 { };
739
740 template<typename _Tp>
741 struct is_reference<_Tp&>
742 : public true_type
743 { };
744
745 template<typename _Tp>
746 struct is_reference<_Tp&&>
747 : public true_type
748 { };
749#endif
750
751 /// is_arithmetic
752 template<typename _Tp>
753 struct is_arithmetic
754 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
755 { };
756
757 /// is_fundamental
758 template<typename _Tp>
759 struct is_fundamental
760 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
761 is_null_pointer<_Tp>>::type
762 { };
763
764 /// is_object
765#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
766 template<typename _Tp>
767 struct is_object
768 : public __bool_constant<__is_object(_Tp)>
769 { };
770#else
771 template<typename _Tp>
772 struct is_object
773 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
774 is_void<_Tp>>>::type
775 { };
776#endif
777
778 template<typename>
779 struct is_member_pointer;
780
781 /// is_scalar
782 template<typename _Tp>
783 struct is_scalar
784 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
785 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
786 { };
787
788 /// is_compound
789 template<typename _Tp>
790 struct is_compound
791 : public __bool_constant<!is_fundamental<_Tp>::value> { };
792
793 /// is_member_pointer
794#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
795 template<typename _Tp>
796 struct is_member_pointer
797 : public __bool_constant<__is_member_pointer(_Tp)>
798 { };
799#else
800 /// @cond undocumented
801 template<typename _Tp>
802 struct __is_member_pointer_helper
803 : public false_type { };
804
805 template<typename _Tp, typename _Cp>
806 struct __is_member_pointer_helper<_Tp _Cp::*>
807 : public true_type { };
808 /// @endcond
809
810 template<typename _Tp>
811 struct is_member_pointer
812 : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type
813 { };
814#endif
815
816 template<typename, typename>
817 struct is_same;
818
819 /// @cond undocumented
820 template<typename _Tp, typename... _Types>
821 using __is_one_of = __or_<is_same<_Tp, _Types>...>;
822
823 // Check if a type is one of the signed integer types.
824 __extension__
825 template<typename _Tp>
826 using __is_signed_integer = __is_one_of<__remove_cv_t<_Tp>,
827 signed char, signed short, signed int, signed long,
828 signed long long
829#if defined(__GLIBCXX_TYPE_INT_N_0)
830 , signed __GLIBCXX_TYPE_INT_N_0
831#endif
832#if defined(__GLIBCXX_TYPE_INT_N_1)
833 , signed __GLIBCXX_TYPE_INT_N_1
834#endif
835#if defined(__GLIBCXX_TYPE_INT_N_2)
836 , signed __GLIBCXX_TYPE_INT_N_2
837#endif
838#if defined(__GLIBCXX_TYPE_INT_N_3)
839 , signed __GLIBCXX_TYPE_INT_N_3
840#endif
841 >;
842
843 // Check if a type is one of the unsigned integer types.
844 __extension__
845 template<typename _Tp>
846 using __is_unsigned_integer = __is_one_of<__remove_cv_t<_Tp>,
847 unsigned char, unsigned short, unsigned int, unsigned long,
848 unsigned long long
849#if defined(__GLIBCXX_TYPE_INT_N_0)
850 , unsigned __GLIBCXX_TYPE_INT_N_0
851#endif
852#if defined(__GLIBCXX_TYPE_INT_N_1)
853 , unsigned __GLIBCXX_TYPE_INT_N_1
854#endif
855#if defined(__GLIBCXX_TYPE_INT_N_2)
856 , unsigned __GLIBCXX_TYPE_INT_N_2
857#endif
858#if defined(__GLIBCXX_TYPE_INT_N_3)
859 , unsigned __GLIBCXX_TYPE_INT_N_3
860#endif
861 >;
862
863 // Check if a type is one of the signed or unsigned integer types.
864 template<typename _Tp>
865 using __is_standard_integer
866 = __or_<__is_signed_integer<_Tp>, __is_unsigned_integer<_Tp>>;
867
868 // __void_t (std::void_t for C++11)
869 template<typename...> using __void_t = void;
870 /// @endcond
871
872 // Type properties.
873
874 /// is_const
875#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const)
876 template<typename _Tp>
877 struct is_const
878 : public __bool_constant<__is_const(_Tp)>
879 { };
880#else
881 template<typename>
882 struct is_const
883 : public false_type { };
884
885 template<typename _Tp>
886 struct is_const<_Tp const>
887 : public true_type { };
888#endif
889
890 /// is_volatile
891#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile)
892 template<typename _Tp>
893 struct is_volatile
894 : public __bool_constant<__is_volatile(_Tp)>
895 { };
896#else
897 template<typename>
898 struct is_volatile
899 : public false_type { };
900
901 template<typename _Tp>
902 struct is_volatile<_Tp volatile>
903 : public true_type { };
904#endif
905
906 /** is_trivial
907 * @deprecated Deprecated in C++26.
908 * Use a combination of one or more more specialized type traits instead,
909 * such as `is_trivially_default_constructible`,
910 * `is_trivially_copy_constructible`, `is_trivially_copy_assignable`,
911 * etc., depending on the exact check(s) needed.
912 */
913 template<typename _Tp>
914 struct
915 _GLIBCXX26_DEPRECATED_SUGGEST("is_trivially_default_constructible && is_trivially_copyable")
916 is_trivial
917 : public __bool_constant<__is_trivial(_Tp)>
918 {
919 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
920 "template argument must be a complete class or an unbounded array");
921 };
922
923 /// is_trivially_copyable
924 template<typename _Tp>
925 struct is_trivially_copyable
926 : public __bool_constant<__is_trivially_copyable(_Tp)>
927 {
928 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
929 "template argument must be a complete class or an unbounded array");
930 };
931
932 /// is_standard_layout
933 template<typename _Tp>
934 struct is_standard_layout
935 : public __bool_constant<__is_standard_layout(_Tp)>
936 {
937 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
938 "template argument must be a complete class or an unbounded array");
939 };
940
941 /** is_pod
942 * @deprecated Deprecated in C++20.
943 * Use `is_standard_layout && is_trivial` instead.
944 */
945 // Could use is_standard_layout && is_trivial instead of the builtin.
946 template<typename _Tp>
947 struct
948 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout && is_trivial")
949 is_pod
950 : public __bool_constant<__is_pod(_Tp)>
951 {
952 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
953 "template argument must be a complete class or an unbounded array");
954 };
955
956 /** is_literal_type
957 * @deprecated Deprecated in C++17, removed in C++20.
958 * The idea of a literal type isn't useful.
959 */
960 template<typename _Tp>
961 struct
962 _GLIBCXX17_DEPRECATED
963 is_literal_type
964 : public __bool_constant<__is_literal_type(_Tp)>
965 {
966 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
967 "template argument must be a complete class or an unbounded array");
968 };
969
970 /// is_empty
971 template<typename _Tp>
972 struct is_empty
973 : public __bool_constant<__is_empty(_Tp)>
974 { };
975
976 /// is_polymorphic
977 template<typename _Tp>
978 struct is_polymorphic
979 : public __bool_constant<__is_polymorphic(_Tp)>
980 { };
981
982#ifdef __cpp_lib_is_final // C++ >= 14
983 /// is_final
984 /// @since C++14
985 template<typename _Tp>
986 struct is_final
987 : public __bool_constant<__is_final(_Tp)>
988 { };
989#endif
990
991 /// is_abstract
992 template<typename _Tp>
993 struct is_abstract
994 : public __bool_constant<__is_abstract(_Tp)>
995 { };
996
997 /// @cond undocumented
998 template<typename _Tp,
999 bool = is_arithmetic<_Tp>::value>
1000 struct __is_signed_helper
1001 : public false_type { };
1002
1003 template<typename _Tp>
1004 struct __is_signed_helper<_Tp, true>
1005 : public __bool_constant<_Tp(-1) < _Tp(0)>
1006 { };
1007 /// @endcond
1008
1009 /// is_signed
1010 template<typename _Tp>
1011 struct is_signed
1012 : public __is_signed_helper<_Tp>::type
1013 { };
1014
1015 /// is_unsigned
1016 template<typename _Tp>
1017 struct is_unsigned
1018 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
1019 { };
1020
1021 /// @cond undocumented
1022 template<typename _Tp, typename _Up = _Tp&&>
1023 _Up
1024 __declval(int);
1025
1026 template<typename _Tp>
1027 _Tp
1028 __declval(long);
1029 /// @endcond
1030
1031 template<typename _Tp>
1032 auto declval() noexcept -> decltype(__declval<_Tp>(0));
1033
1034 template<typename>
1035 struct remove_all_extents;
1036
1037 /// @cond undocumented
1038 template<typename _Tp>
1039 struct __is_array_known_bounds
1040 : public false_type
1041 { };
1042
1043 template<typename _Tp, size_t _Size>
1044 struct __is_array_known_bounds<_Tp[_Size]>
1045 : public true_type
1046 { };
1047
1048 template<typename _Tp>
1049 struct __is_array_unknown_bounds
1050 : public false_type
1051 { };
1052
1053 template<typename _Tp>
1054 struct __is_array_unknown_bounds<_Tp[]>
1055 : public true_type
1056 { };
1057 /// @endcond
1058
1059 // Destructible and constructible type properties.
1060
1061#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_destructible)
1062 /// is_destructible
1063 template<typename _Tp>
1064 struct is_destructible
1065 : public __bool_constant<__is_destructible(_Tp)>
1066 { };
1067#else
1068 /// @cond undocumented
1069
1070 // In N3290 is_destructible does not say anything about function
1071 // types and abstract types, see LWG 2049. This implementation
1072 // describes function types as non-destructible and all complete
1073 // object types as destructible, iff the explicit destructor
1074 // call expression is wellformed.
1075 struct __do_is_destructible_impl
1076 {
1077 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
1078 static true_type __test(int);
1079
1080 template<typename>
1081 static false_type __test(...);
1082 };
1083
1084 template<typename _Tp>
1085 struct __is_destructible_impl
1086 : public __do_is_destructible_impl
1087 {
1088 using type = decltype(__test<_Tp>(0));
1089 };
1090
1091 template<typename _Tp,
1092 bool = __or_<is_void<_Tp>,
1093 __is_array_unknown_bounds<_Tp>,
1094 is_function<_Tp>>::value,
1095 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1096 struct __is_destructible_safe;
1097
1098 template<typename _Tp>
1099 struct __is_destructible_safe<_Tp, false, false>
1100 : public __is_destructible_impl<typename
1101 remove_all_extents<_Tp>::type>::type
1102 { };
1103
1104 template<typename _Tp>
1105 struct __is_destructible_safe<_Tp, true, false>
1106 : public false_type { };
1107
1108 template<typename _Tp>
1109 struct __is_destructible_safe<_Tp, false, true>
1110 : public true_type { };
1111 /// @endcond
1112
1113 /// is_destructible
1114 template<typename _Tp>
1115 struct is_destructible
1116 : public __is_destructible_safe<_Tp>::type
1117 {
1118 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1119 "template argument must be a complete class or an unbounded array");
1120 };
1121#endif
1122
1123#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_destructible)
1124 /// is_nothrow_destructible
1125 template<typename _Tp>
1126 struct is_nothrow_destructible
1127 : public __bool_constant<__is_nothrow_destructible(_Tp)>
1128 { };
1129#else
1130 /// @cond undocumented
1131
1132 // is_nothrow_destructible requires that is_destructible is
1133 // satisfied as well. We realize that by mimicing the
1134 // implementation of is_destructible but refer to noexcept(expr)
1135 // instead of decltype(expr).
1136 struct __do_is_nt_destructible_impl
1137 {
1138 template<typename _Tp>
1139 static __bool_constant<noexcept(declval<_Tp&>().~_Tp())>
1140 __test(int);
1141
1142 template<typename>
1143 static false_type __test(...);
1144 };
1145
1146 template<typename _Tp>
1147 struct __is_nt_destructible_impl
1148 : public __do_is_nt_destructible_impl
1149 {
1150 using type = decltype(__test<_Tp>(0));
1151 };
1152
1153 template<typename _Tp,
1154 bool = __or_<is_void<_Tp>,
1155 __is_array_unknown_bounds<_Tp>,
1156 is_function<_Tp>>::value,
1157 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
1158 struct __is_nt_destructible_safe;
1159
1160 template<typename _Tp>
1161 struct __is_nt_destructible_safe<_Tp, false, false>
1162 : public __is_nt_destructible_impl<typename
1163 remove_all_extents<_Tp>::type>::type
1164 { };
1165
1166 template<typename _Tp>
1167 struct __is_nt_destructible_safe<_Tp, true, false>
1168 : public false_type { };
1169
1170 template<typename _Tp>
1171 struct __is_nt_destructible_safe<_Tp, false, true>
1172 : public true_type { };
1173 /// @endcond
1174
1175 /// is_nothrow_destructible
1176 template<typename _Tp>
1177 struct is_nothrow_destructible
1178 : public __is_nt_destructible_safe<_Tp>::type
1179 {
1180 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1181 "template argument must be a complete class or an unbounded array");
1182 };
1183#endif
1184
1185 /// @cond undocumented
1186 template<typename _Tp, typename... _Args>
1187 using __is_constructible_impl
1188 = __bool_constant<__is_constructible(_Tp, _Args...)>;
1189 /// @endcond
1190
1191 /// is_constructible
1192 template<typename _Tp, typename... _Args>
1193 struct is_constructible
1194 : public __is_constructible_impl<_Tp, _Args...>
1195 {
1196 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1197 "template argument must be a complete class or an unbounded array");
1198 };
1199
1200 /// is_default_constructible
1201 template<typename _Tp>
1202 struct is_default_constructible
1203 : public __is_constructible_impl<_Tp>
1204 {
1205 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1206 "template argument must be a complete class or an unbounded array");
1207 };
1208
1209 /// @cond undocumented
1210#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_lvalue_reference)
1211 template<typename _Tp>
1212 using __add_lval_ref_t = __add_lvalue_reference(_Tp);
1213#else
1214 template<typename _Tp, typename = void>
1215 struct __add_lvalue_reference_helper
1216 { using type = _Tp; };
1217
1218 template<typename _Tp>
1219 struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>>
1220 { using type = _Tp&; };
1221
1222 template<typename _Tp>
1223 using __add_lval_ref_t = typename __add_lvalue_reference_helper<_Tp>::type;
1224#endif
1225 /// @endcond
1226
1227 /// is_copy_constructible
1228 template<typename _Tp>
1229 struct is_copy_constructible
1230 : public __is_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1231 {
1232 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1233 "template argument must be a complete class or an unbounded array");
1234 };
1235
1236 /// @cond undocumented
1237#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_rvalue_reference)
1238 template<typename _Tp>
1239 using __add_rval_ref_t = __add_rvalue_reference(_Tp);
1240#else
1241 template<typename _Tp, typename = void>
1242 struct __add_rvalue_reference_helper
1243 { using type = _Tp; };
1244
1245 template<typename _Tp>
1246 struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>>
1247 { using type = _Tp&&; };
1248
1249 template<typename _Tp>
1250 using __add_rval_ref_t = typename __add_rvalue_reference_helper<_Tp>::type;
1251#endif
1252 /// @endcond
1253
1254 /// is_move_constructible
1255 template<typename _Tp>
1256 struct is_move_constructible
1257 : public __is_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1258 {
1259 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1260 "template argument must be a complete class or an unbounded array");
1261 };
1262
1263 /// @cond undocumented
1264 template<typename _Tp, typename... _Args>
1265 using __is_nothrow_constructible_impl
1266 = __bool_constant<__is_nothrow_constructible(_Tp, _Args...)>;
1267 /// @endcond
1268
1269 /// is_nothrow_constructible
1270 template<typename _Tp, typename... _Args>
1271 struct is_nothrow_constructible
1272 : public __is_nothrow_constructible_impl<_Tp, _Args...>
1273 {
1274 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1275 "template argument must be a complete class or an unbounded array");
1276 };
1277
1278 /// is_nothrow_default_constructible
1279 template<typename _Tp>
1280 struct is_nothrow_default_constructible
1281 : public __is_nothrow_constructible_impl<_Tp>
1282 {
1283 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1284 "template argument must be a complete class or an unbounded array");
1285 };
1286
1287 /// is_nothrow_copy_constructible
1288 template<typename _Tp>
1289 struct is_nothrow_copy_constructible
1290 : public __is_nothrow_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1291 {
1292 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1293 "template argument must be a complete class or an unbounded array");
1294 };
1295
1296 /// is_nothrow_move_constructible
1297 template<typename _Tp>
1298 struct is_nothrow_move_constructible
1299 : public __is_nothrow_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1300 {
1301 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1302 "template argument must be a complete class or an unbounded array");
1303 };
1304
1305 /// @cond undocumented
1306 template<typename _Tp, typename _Up>
1307 using __is_assignable_impl = __bool_constant<__is_assignable(_Tp, _Up)>;
1308 /// @endcond
1309
1310 /// is_assignable
1311 template<typename _Tp, typename _Up>
1312 struct is_assignable
1313 : public __is_assignable_impl<_Tp, _Up>
1314 {
1315 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1316 "template argument must be a complete class or an unbounded array");
1317 };
1318
1319 /// is_copy_assignable
1320 template<typename _Tp>
1321 struct is_copy_assignable
1322 : public __is_assignable_impl<__add_lval_ref_t<_Tp>,
1323 __add_lval_ref_t<const _Tp>>
1324 {
1325 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1326 "template argument must be a complete class or an unbounded array");
1327 };
1328
1329 /// is_move_assignable
1330 template<typename _Tp>
1331 struct is_move_assignable
1332 : public __is_assignable_impl<__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>>
1333 {
1334 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1335 "template argument must be a complete class or an unbounded array");
1336 };
1337
1338 /// @cond undocumented
1339 template<typename _Tp, typename _Up>
1340 using __is_nothrow_assignable_impl
1341 = __bool_constant<__is_nothrow_assignable(_Tp, _Up)>;
1342 /// @endcond
1343
1344 /// is_nothrow_assignable
1345 template<typename _Tp, typename _Up>
1346 struct is_nothrow_assignable
1347 : public __is_nothrow_assignable_impl<_Tp, _Up>
1348 {
1349 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1350 "template argument must be a complete class or an unbounded array");
1351 };
1352
1353 /// is_nothrow_copy_assignable
1354 template<typename _Tp>
1355 struct is_nothrow_copy_assignable
1356 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1357 __add_lval_ref_t<const _Tp>>
1358 {
1359 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1360 "template argument must be a complete class or an unbounded array");
1361 };
1362
1363 /// is_nothrow_move_assignable
1364 template<typename _Tp>
1365 struct is_nothrow_move_assignable
1366 : public __is_nothrow_assignable_impl<__add_lval_ref_t<_Tp>,
1367 __add_rval_ref_t<_Tp>>
1368 {
1369 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1370 "template argument must be a complete class or an unbounded array");
1371 };
1372
1373 /// @cond undocumented
1374 template<typename _Tp, typename... _Args>
1375 using __is_trivially_constructible_impl
1376 = __bool_constant<__is_trivially_constructible(_Tp, _Args...)>;
1377 /// @endcond
1378
1379 /// is_trivially_constructible
1380 template<typename _Tp, typename... _Args>
1381 struct is_trivially_constructible
1382 : public __is_trivially_constructible_impl<_Tp, _Args...>
1383 {
1384 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1385 "template argument must be a complete class or an unbounded array");
1386 };
1387
1388 /// is_trivially_default_constructible
1389 template<typename _Tp>
1390 struct is_trivially_default_constructible
1391 : public __is_trivially_constructible_impl<_Tp>
1392 {
1393 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1394 "template argument must be a complete class or an unbounded array");
1395 };
1396
1397#if __cpp_variable_templates && __cpp_concepts
1398 template<typename _Tp>
1399 constexpr bool __is_implicitly_default_constructible_v
1400 = requires (void(&__f)(_Tp)) { __f({}); };
1401
1402 template<typename _Tp>
1403 struct __is_implicitly_default_constructible
1404 : __bool_constant<__is_implicitly_default_constructible_v<_Tp>>
1405 { };
1406#else
1407 struct __do_is_implicitly_default_constructible_impl
1408 {
1409 template <typename _Tp>
1410 static void __helper(const _Tp&);
1411
1412 template <typename _Tp>
1413 static true_type __test(const _Tp&,
1414 decltype(__helper<const _Tp&>({}))* = 0);
1415
1416 static false_type __test(...);
1417 };
1418
1419 template<typename _Tp>
1420 struct __is_implicitly_default_constructible_impl
1421 : public __do_is_implicitly_default_constructible_impl
1422 {
1423 using type = decltype(__test(declval<_Tp>()));
1424 };
1425
1426 template<typename _Tp>
1427 struct __is_implicitly_default_constructible_safe
1428 : public __is_implicitly_default_constructible_impl<_Tp>::type
1429 { };
1430
1431 template <typename _Tp>
1432 struct __is_implicitly_default_constructible
1433 : public __and_<__is_constructible_impl<_Tp>,
1434 __is_implicitly_default_constructible_safe<_Tp>>::type
1435 { };
1436#endif
1437
1438 /// is_trivially_copy_constructible
1439 template<typename _Tp>
1440 struct is_trivially_copy_constructible
1441 : public __is_trivially_constructible_impl<_Tp, __add_lval_ref_t<const _Tp>>
1442 {
1443 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1444 "template argument must be a complete class or an unbounded array");
1445 };
1446
1447 /// is_trivially_move_constructible
1448 template<typename _Tp>
1449 struct is_trivially_move_constructible
1450 : public __is_trivially_constructible_impl<_Tp, __add_rval_ref_t<_Tp>>
1451 {
1452 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1453 "template argument must be a complete class or an unbounded array");
1454 };
1455
1456 /// @cond undocumented
1457 template<typename _Tp, typename _Up>
1458 using __is_trivially_assignable_impl
1459 = __bool_constant<__is_trivially_assignable(_Tp, _Up)>;
1460 /// @endcond
1461
1462 /// is_trivially_assignable
1463 template<typename _Tp, typename _Up>
1464 struct is_trivially_assignable
1465 : public __is_trivially_assignable_impl<_Tp, _Up>
1466 {
1467 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1468 "template argument must be a complete class or an unbounded array");
1469 };
1470
1471 /// is_trivially_copy_assignable
1472 template<typename _Tp>
1473 struct is_trivially_copy_assignable
1474 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1475 __add_lval_ref_t<const _Tp>>
1476 {
1477 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1478 "template argument must be a complete class or an unbounded array");
1479 };
1480
1481 /// is_trivially_move_assignable
1482 template<typename _Tp>
1483 struct is_trivially_move_assignable
1484 : public __is_trivially_assignable_impl<__add_lval_ref_t<_Tp>,
1485 __add_rval_ref_t<_Tp>>
1486 {
1487 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1488 "template argument must be a complete class or an unbounded array");
1489 };
1490
1491#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_trivially_destructible)
1492 /// is_trivially_destructible
1493 template<typename _Tp>
1494 struct is_trivially_destructible
1495 : public __bool_constant<__is_trivially_destructible(_Tp)>
1496 { };
1497#else
1498 /// is_trivially_destructible
1499 template<typename _Tp>
1500 struct is_trivially_destructible
1501 : public __and_<__is_destructible_safe<_Tp>,
1502 __bool_constant<__has_trivial_destructor(_Tp)>>::type
1503 {
1504 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1505 "template argument must be a complete class or an unbounded array");
1506 };
1507#endif
1508
1509 /// has_virtual_destructor
1510 template<typename _Tp>
1511 struct has_virtual_destructor
1512 : public __bool_constant<__has_virtual_destructor(_Tp)>
1513 {
1514 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1515 "template argument must be a complete class or an unbounded array");
1516 };
1517
1518
1519 // type property queries.
1520
1521 /// alignment_of
1522 template<typename _Tp>
1523 struct alignment_of
1524 : public integral_constant<std::size_t, alignof(_Tp)>
1525 {
1526 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
1527 "template argument must be a complete class or an unbounded array");
1528 };
1529
1530 /// rank
1531#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) \
1532 && (!defined(__clang__) || __clang_major__ >= 20) // PR118559
1533 template<typename _Tp>
1534 struct rank
1535 : public integral_constant<std::size_t, __array_rank(_Tp)> { };
1536#else
1537 template<typename>
1538 struct rank
1539 : public integral_constant<std::size_t, 0> { };
1540
1541 template<typename _Tp, std::size_t _Size>
1542 struct rank<_Tp[_Size]>
1543 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1544
1545 template<typename _Tp>
1546 struct rank<_Tp[]>
1547 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1548#endif
1549
1550 /// extent
1551 template<typename, unsigned _Uint = 0>
1552 struct extent
1553 : public integral_constant<size_t, 0> { };
1554
1555 template<typename _Tp, size_t _Size>
1556 struct extent<_Tp[_Size], 0>
1557 : public integral_constant<size_t, _Size> { };
1558
1559 template<typename _Tp, unsigned _Uint, size_t _Size>
1560 struct extent<_Tp[_Size], _Uint>
1561 : public extent<_Tp, _Uint - 1>::type { };
1562
1563 template<typename _Tp>
1564 struct extent<_Tp[], 0>
1565 : public integral_constant<size_t, 0> { };
1566
1567 template<typename _Tp, unsigned _Uint>
1568 struct extent<_Tp[], _Uint>
1569 : public extent<_Tp, _Uint - 1>::type { };
1570
1571
1572 // Type relations.
1573
1574 /// is_same
1575#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
1576 template<typename _Tp, typename _Up>
1577 struct is_same
1578 : public __bool_constant<__is_same(_Tp, _Up)>
1579 { };
1580#else
1581 template<typename _Tp, typename _Up>
1582 struct is_same
1583 : public false_type
1584 { };
1585
1586 template<typename _Tp>
1587 struct is_same<_Tp, _Tp>
1588 : public true_type
1589 { };
1590#endif
1591
1592 /// is_base_of
1593 template<typename _Base, typename _Derived>
1594 struct is_base_of
1595 : public __bool_constant<__is_base_of(_Base, _Derived)>
1596 { };
1597
1598#ifdef __cpp_lib_is_virtual_base_of // C++ >= 26
1599 /// is_virtual_base_of
1600 /// @since C++26
1601 template<typename _Base, typename _Derived>
1602 struct is_virtual_base_of
1603 : public bool_constant<__builtin_is_virtual_base_of(_Base, _Derived)>
1604 { };
1605#endif
1606
1607#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
1608 template<typename _From, typename _To>
1609 struct is_convertible
1610 : public __bool_constant<__is_convertible(_From, _To)>
1611 { };
1612#else
1613 template<typename _From, typename _To,
1614 bool = __or_<is_void<_From>, is_function<_To>,
1615 is_array<_To>>::value>
1616 struct __is_convertible_helper
1617 {
1618 using type = typename is_void<_To>::type;
1619 };
1620
1621#pragma GCC diagnostic push
1622#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1623 template<typename _From, typename _To>
1624 class __is_convertible_helper<_From, _To, false>
1625 {
1626 template<typename _To1>
1627 static void __test_aux(_To1) noexcept;
1628
1629 template<typename _From1, typename _To1,
1630 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1631 static true_type
1632 __test(int);
1633
1634 template<typename, typename>
1635 static false_type
1636 __test(...);
1637
1638 public:
1639 using type = decltype(__test<_From, _To>(0));
1640 };
1641#pragma GCC diagnostic pop
1642
1643 /// is_convertible
1644 template<typename _From, typename _To>
1645 struct is_convertible
1646 : public __is_convertible_helper<_From, _To>::type
1647 { };
1648#endif
1649
1650 // helper trait for unique_ptr<T[]>, shared_ptr<T[]>, and span<T, N>
1651 template<typename _ToElementType, typename _FromElementType>
1652 using __is_array_convertible
1653 = is_convertible<_FromElementType(*)[], _ToElementType(*)[]>;
1654
1655#ifdef __cpp_lib_is_nothrow_convertible // C++ >= 20
1656
1657#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_convertible)
1658 /// is_nothrow_convertible_v
1659 template<typename _From, typename _To>
1660 inline constexpr bool is_nothrow_convertible_v
1661 = __is_nothrow_convertible(_From, _To);
1662
1663 /// is_nothrow_convertible
1664 template<typename _From, typename _To>
1665 struct is_nothrow_convertible
1666 : public bool_constant<is_nothrow_convertible_v<_From, _To>>
1667 { };
1668#else
1669 template<typename _From, typename _To,
1670 bool = __or_<is_void<_From>, is_function<_To>,
1671 is_array<_To>>::value>
1672 struct __is_nt_convertible_helper
1673 : is_void<_To>
1674 { };
1675
1676#pragma GCC diagnostic push
1677#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
1678 template<typename _From, typename _To>
1679 class __is_nt_convertible_helper<_From, _To, false>
1680 {
1681 template<typename _To1>
1682 static void __test_aux(_To1) noexcept;
1683
1684 template<typename _From1, typename _To1>
1685 static
1686 __bool_constant<noexcept(__test_aux<_To1>(std::declval<_From1>()))>
1687 __test(int);
1688
1689 template<typename, typename>
1690 static false_type
1691 __test(...);
1692
1693 public:
1694 using type = decltype(__test<_From, _To>(0));
1695 };
1696#pragma GCC diagnostic pop
1697
1698 /// is_nothrow_convertible
1699 template<typename _From, typename _To>
1700 struct is_nothrow_convertible
1701 : public __is_nt_convertible_helper<_From, _To>::type
1702 { };
1703
1704 /// is_nothrow_convertible_v
1705 template<typename _From, typename _To>
1706 inline constexpr bool is_nothrow_convertible_v
1707 = is_nothrow_convertible<_From, _To>::value;
1708#endif
1709#endif // __cpp_lib_is_nothrow_convertible
1710
1711#pragma GCC diagnostic push
1712#pragma GCC diagnostic ignored "-Wc++14-extensions" // for variable templates
1713 template<typename _Tp, typename... _Args>
1714 struct __is_nothrow_new_constructible_impl
1715 : __bool_constant<
1716 noexcept(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))
1717 >
1718 { };
1719
1720 template<typename _Tp, typename... _Args>
1721 _GLIBCXX17_INLINE constexpr bool __is_nothrow_new_constructible
1722 = __and_<is_constructible<_Tp, _Args...>,
1723 __is_nothrow_new_constructible_impl<_Tp, _Args...>>::value;
1724#pragma GCC diagnostic pop
1725
1726 // Const-volatile modifications.
1727
1728 /// remove_const
1729 template<typename _Tp>
1730 struct remove_const
1731 { using type = _Tp; };
1732
1733 template<typename _Tp>
1734 struct remove_const<_Tp const>
1735 { using type = _Tp; };
1736
1737 /// remove_volatile
1738 template<typename _Tp>
1739 struct remove_volatile
1740 { using type = _Tp; };
1741
1742 template<typename _Tp>
1743 struct remove_volatile<_Tp volatile>
1744 { using type = _Tp; };
1745
1746 /// remove_cv
1747#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cv)
1748 template<typename _Tp>
1749 struct remove_cv
1750 { using type = __remove_cv(_Tp); };
1751#else
1752 template<typename _Tp>
1753 struct remove_cv
1754 { using type = _Tp; };
1755
1756 template<typename _Tp>
1757 struct remove_cv<const _Tp>
1758 { using type = _Tp; };
1759
1760 template<typename _Tp>
1761 struct remove_cv<volatile _Tp>
1762 { using type = _Tp; };
1763
1764 template<typename _Tp>
1765 struct remove_cv<const volatile _Tp>
1766 { using type = _Tp; };
1767#endif
1768
1769 /// add_const
1770 template<typename _Tp>
1771 struct add_const
1772 { using type = _Tp const; };
1773
1774 /// add_volatile
1775 template<typename _Tp>
1776 struct add_volatile
1777 { using type = _Tp volatile; };
1778
1779 /// add_cv
1780 template<typename _Tp>
1781 struct add_cv
1782 { using type = _Tp const volatile; };
1783
1784#ifdef __cpp_lib_transformation_trait_aliases // C++ >= 14
1785 /// Alias template for remove_const
1786 template<typename _Tp>
1787 using remove_const_t = typename remove_const<_Tp>::type;
1788
1789 /// Alias template for remove_volatile
1790 template<typename _Tp>
1791 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1792
1793 /// Alias template for remove_cv
1794 template<typename _Tp>
1795 using remove_cv_t = typename remove_cv<_Tp>::type;
1796
1797 /// Alias template for add_const
1798 template<typename _Tp>
1799 using add_const_t = typename add_const<_Tp>::type;
1800
1801 /// Alias template for add_volatile
1802 template<typename _Tp>
1803 using add_volatile_t = typename add_volatile<_Tp>::type;
1804
1805 /// Alias template for add_cv
1806 template<typename _Tp>
1807 using add_cv_t = typename add_cv<_Tp>::type;
1808#endif
1809
1810 // Reference transformations.
1811
1812 /// remove_reference
1813#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_reference)
1814 template<typename _Tp>
1815 struct remove_reference
1816 { using type = __remove_reference(_Tp); };
1817#else
1818 template<typename _Tp>
1819 struct remove_reference
1820 { using type = _Tp; };
1821
1822 template<typename _Tp>
1823 struct remove_reference<_Tp&>
1824 { using type = _Tp; };
1825
1826 template<typename _Tp>
1827 struct remove_reference<_Tp&&>
1828 { using type = _Tp; };
1829#endif
1830
1831 /// add_lvalue_reference
1832 template<typename _Tp>
1833 struct add_lvalue_reference
1834 { using type = __add_lval_ref_t<_Tp>; };
1835
1836 /// add_rvalue_reference
1837 template<typename _Tp>
1838 struct add_rvalue_reference
1839 { using type = __add_rval_ref_t<_Tp>; };
1840
1841#if __cplusplus > 201103L
1842 /// Alias template for remove_reference
1843 template<typename _Tp>
1844 using remove_reference_t = typename remove_reference<_Tp>::type;
1845
1846 /// Alias template for add_lvalue_reference
1847 template<typename _Tp>
1848 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1849
1850 /// Alias template for add_rvalue_reference
1851 template<typename _Tp>
1852 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1853#endif
1854
1855 // Sign modifications.
1856
1857 /// @cond undocumented
1858
1859 // Utility for constructing identically cv-qualified types.
1860 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1861 struct __cv_selector;
1862
1863 template<typename _Unqualified>
1864 struct __cv_selector<_Unqualified, false, false>
1865 { using __type = _Unqualified; };
1866
1867 template<typename _Unqualified>
1868 struct __cv_selector<_Unqualified, false, true>
1869 { using __type = volatile _Unqualified; };
1870
1871 template<typename _Unqualified>
1872 struct __cv_selector<_Unqualified, true, false>
1873 { using __type = const _Unqualified; };
1874
1875 template<typename _Unqualified>
1876 struct __cv_selector<_Unqualified, true, true>
1877 { using __type = const volatile _Unqualified; };
1878
1879 template<typename _Qualified, typename _Unqualified,
1880 bool _IsConst = is_const<_Qualified>::value,
1881 bool _IsVol = is_volatile<_Qualified>::value>
1882 class __match_cv_qualifiers
1883 {
1884 using __match = __cv_selector<_Unqualified, _IsConst, _IsVol>;
1885
1886 public:
1887 using __type = typename __match::__type;
1888 };
1889
1890 // Utility for finding the unsigned versions of signed integral types.
1891 template<typename _Tp>
1892 struct __make_unsigned
1893 { using __type = _Tp; };
1894
1895 template<>
1896 struct __make_unsigned<char>
1897 { using __type = unsigned char; };
1898
1899 template<>
1900 struct __make_unsigned<signed char>
1901 { using __type = unsigned char; };
1902
1903 template<>
1904 struct __make_unsigned<short>
1905 { using __type = unsigned short; };
1906
1907 template<>
1908 struct __make_unsigned<int>
1909 { using __type = unsigned int; };
1910
1911 template<>
1912 struct __make_unsigned<long>
1913 { using __type = unsigned long; };
1914
1915 template<>
1916 struct __make_unsigned<long long>
1917 { using __type = unsigned long long; };
1918
1919#if defined(__GLIBCXX_TYPE_INT_N_0)
1920 __extension__
1921 template<>
1922 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1923 { using __type = unsigned __GLIBCXX_TYPE_INT_N_0; };
1924#endif
1925#if defined(__GLIBCXX_TYPE_INT_N_1)
1926 __extension__
1927 template<>
1928 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1929 { using __type = unsigned __GLIBCXX_TYPE_INT_N_1; };
1930#endif
1931#if defined(__GLIBCXX_TYPE_INT_N_2)
1932 __extension__
1933 template<>
1934 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1935 { using __type = unsigned __GLIBCXX_TYPE_INT_N_2; };
1936#endif
1937#if defined(__GLIBCXX_TYPE_INT_N_3)
1938 __extension__
1939 template<>
1940 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1941 { using __type = unsigned __GLIBCXX_TYPE_INT_N_3; };
1942#endif
1943#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
1944 __extension__
1945 template<>
1946 struct __make_unsigned<__int128>
1947 { using __type = unsigned __int128; };
1948#endif
1949
1950 // Select between integral and enum: not possible to be both.
1951 template<typename _Tp,
1952 bool _IsInt = is_integral<_Tp>::value,
1953 bool _IsEnum = __is_enum(_Tp)>
1954 class __make_unsigned_selector;
1955
1956 template<typename _Tp>
1957 class __make_unsigned_selector<_Tp, true, false>
1958 {
1959 using __unsigned_type
1960 = typename __make_unsigned<__remove_cv_t<_Tp>>::__type;
1961
1962 public:
1963 using __type
1964 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
1965 };
1966
1967 class __make_unsigned_selector_base
1968 {
1969 protected:
1970 template<typename...> struct _List { };
1971
1972 template<typename _Tp, typename... _Up>
1973 struct _List<_Tp, _Up...> : _List<_Up...>
1974 { static constexpr size_t __size = sizeof(_Tp); };
1975
1976 template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
1977 struct __select;
1978
1979 template<size_t _Sz, typename _Uint, typename... _UInts>
1980 struct __select<_Sz, _List<_Uint, _UInts...>, true>
1981 { using __type = _Uint; };
1982
1983 template<size_t _Sz, typename _Uint, typename... _UInts>
1984 struct __select<_Sz, _List<_Uint, _UInts...>, false>
1985 : __select<_Sz, _List<_UInts...>>
1986 { };
1987 };
1988
1989 // Choose unsigned integer type with the smallest rank and same size as _Tp
1990 template<typename _Tp>
1991 class __make_unsigned_selector<_Tp, false, true>
1992 : __make_unsigned_selector_base
1993 {
1994 // With -fshort-enums, an enum may be as small as a char.
1995 __extension__
1996 using _UInts = _List<unsigned char, unsigned short, unsigned int,
1997 unsigned long, unsigned long long
1998#ifdef __SIZEOF_INT128__
1999 , unsigned __int128
2000#endif
2001 >;
2002
2003 using __unsigned_type = typename __select<sizeof(_Tp), _UInts>::__type;
2004
2005 public:
2006 using __type
2007 = typename __match_cv_qualifiers<_Tp, __unsigned_type>::__type;
2008 };
2009
2010 // wchar_t, char8_t, char16_t and char32_t are integral types but are
2011 // neither signed integer types nor unsigned integer types, so must be
2012 // transformed to the unsigned integer type with the smallest rank.
2013 // Use the partial specialization for enumeration types to do that.
2014 template<>
2015 struct __make_unsigned<wchar_t>
2016 {
2017 using __type
2018 = typename __make_unsigned_selector<wchar_t, false, true>::__type;
2019 };
2020
2021#ifdef _GLIBCXX_USE_CHAR8_T
2022 template<>
2023 struct __make_unsigned<char8_t>
2024 {
2025 using __type
2026 = typename __make_unsigned_selector<char8_t, false, true>::__type;
2027 };
2028#endif
2029
2030 template<>
2031 struct __make_unsigned<char16_t>
2032 {
2033 using __type
2034 = typename __make_unsigned_selector<char16_t, false, true>::__type;
2035 };
2036
2037 template<>
2038 struct __make_unsigned<char32_t>
2039 {
2040 using __type
2041 = typename __make_unsigned_selector<char32_t, false, true>::__type;
2042 };
2043 /// @endcond
2044
2045 // Given an integral/enum type, return the corresponding unsigned
2046 // integer type.
2047 // Primary template.
2048 /// make_unsigned
2049 template<typename _Tp>
2050 struct make_unsigned
2051 { using type = typename __make_unsigned_selector<_Tp>::__type; };
2052
2053 // Integral, but don't define.
2054 template<> struct make_unsigned<bool>;
2055 template<> struct make_unsigned<bool const>;
2056 template<> struct make_unsigned<bool volatile>;
2057 template<> struct make_unsigned<bool const volatile>;
2058
2059 /// @cond undocumented
2060
2061 // Utility for finding the signed versions of unsigned integral types.
2062 template<typename _Tp>
2063 struct __make_signed
2064 { using __type = _Tp; };
2065
2066 template<>
2067 struct __make_signed<char>
2068 { using __type = signed char; };
2069
2070 template<>
2071 struct __make_signed<unsigned char>
2072 { using __type = signed char; };
2073
2074 template<>
2075 struct __make_signed<unsigned short>
2076 { using __type = signed short; };
2077
2078 template<>
2079 struct __make_signed<unsigned int>
2080 { using __type = signed int; };
2081
2082 template<>
2083 struct __make_signed<unsigned long>
2084 { using __type = signed long; };
2085
2086 template<>
2087 struct __make_signed<unsigned long long>
2088 { using __type = signed long long; };
2089
2090#if defined(__GLIBCXX_TYPE_INT_N_0)
2091 __extension__
2092 template<>
2093 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
2094 { using __type = __GLIBCXX_TYPE_INT_N_0; };
2095#endif
2096#if defined(__GLIBCXX_TYPE_INT_N_1)
2097 __extension__
2098 template<>
2099 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
2100 { using __type = __GLIBCXX_TYPE_INT_N_1; };
2101#endif
2102#if defined(__GLIBCXX_TYPE_INT_N_2)
2103 __extension__
2104 template<>
2105 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
2106 { using __type = __GLIBCXX_TYPE_INT_N_2; };
2107#endif
2108#if defined(__GLIBCXX_TYPE_INT_N_3)
2109 __extension__
2110 template<>
2111 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
2112 { using __type = __GLIBCXX_TYPE_INT_N_3; };
2113#endif
2114#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
2115 __extension__
2116 template<>
2117 struct __make_signed<unsigned __int128>
2118 { using __type = __int128; };
2119#endif
2120
2121 // Select between integral and enum: not possible to be both.
2122 template<typename _Tp,
2123 bool _IsInt = is_integral<_Tp>::value,
2124 bool _IsEnum = __is_enum(_Tp)>
2125 class __make_signed_selector;
2126
2127 template<typename _Tp>
2128 class __make_signed_selector<_Tp, true, false>
2129 {
2130 using __signed_type
2131 = typename __make_signed<__remove_cv_t<_Tp>>::__type;
2132
2133 public:
2134 using __type
2135 = typename __match_cv_qualifiers<_Tp, __signed_type>::__type;
2136 };
2137
2138 // Choose signed integer type with the smallest rank and same size as _Tp
2139 template<typename _Tp>
2140 class __make_signed_selector<_Tp, false, true>
2141 {
2142 using __unsigned_type = typename __make_unsigned_selector<_Tp>::__type;
2143
2144 public:
2145 using __type = typename __make_signed_selector<__unsigned_type>::__type;
2146 };
2147
2148 // wchar_t, char16_t and char32_t are integral types but are neither
2149 // signed integer types nor unsigned integer types, so must be
2150 // transformed to the signed integer type with the smallest rank.
2151 // Use the partial specialization for enumeration types to do that.
2152 template<>
2153 struct __make_signed<wchar_t>
2154 {
2155 using __type
2156 = typename __make_signed_selector<wchar_t, false, true>::__type;
2157 };
2158
2159#if defined(_GLIBCXX_USE_CHAR8_T)
2160 template<>
2161 struct __make_signed<char8_t>
2162 {
2163 using __type
2164 = typename __make_signed_selector<char8_t, false, true>::__type;
2165 };
2166#endif
2167
2168 template<>
2169 struct __make_signed<char16_t>
2170 {
2171 using __type
2172 = typename __make_signed_selector<char16_t, false, true>::__type;
2173 };
2174
2175 template<>
2176 struct __make_signed<char32_t>
2177 {
2178 using __type
2179 = typename __make_signed_selector<char32_t, false, true>::__type;
2180 };
2181 /// @endcond
2182
2183 // Given an integral/enum type, return the corresponding signed
2184 // integer type.
2185 // Primary template.
2186 /// make_signed
2187 template<typename _Tp>
2188 struct make_signed
2189 { using type = typename __make_signed_selector<_Tp>::__type; };
2190
2191 // Integral, but don't define.
2192 template<> struct make_signed<bool>;
2193 template<> struct make_signed<bool const>;
2194 template<> struct make_signed<bool volatile>;
2195 template<> struct make_signed<bool const volatile>;
2196
2197#if __cplusplus > 201103L
2198 /// Alias template for make_signed
2199 template<typename _Tp>
2200 using make_signed_t = typename make_signed<_Tp>::type;
2201
2202 /// Alias template for make_unsigned
2203 template<typename _Tp>
2204 using make_unsigned_t = typename make_unsigned<_Tp>::type;
2205#endif
2206
2207 // Array modifications.
2208
2209 /// remove_extent
2210#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_extent)
2211 template<typename _Tp>
2212 struct remove_extent
2213 { using type = __remove_extent(_Tp); };
2214#else
2215 template<typename _Tp>
2216 struct remove_extent
2217 { using type = _Tp; };
2218
2219 template<typename _Tp, std::size_t _Size>
2220 struct remove_extent<_Tp[_Size]>
2221 { using type = _Tp; };
2222
2223 template<typename _Tp>
2224 struct remove_extent<_Tp[]>
2225 { using type = _Tp; };
2226#endif
2227
2228 /// remove_all_extents
2229#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_all_extents)
2230 template<typename _Tp>
2231 struct remove_all_extents
2232 { using type = __remove_all_extents(_Tp); };
2233#else
2234 template<typename _Tp>
2235 struct remove_all_extents
2236 { using type = _Tp; };
2237
2238 template<typename _Tp, std::size_t _Size>
2239 struct remove_all_extents<_Tp[_Size]>
2240 { using type = typename remove_all_extents<_Tp>::type; };
2241
2242 template<typename _Tp>
2243 struct remove_all_extents<_Tp[]>
2244 { using type = typename remove_all_extents<_Tp>::type; };
2245#endif
2246
2247#if __cplusplus > 201103L
2248 /// Alias template for remove_extent
2249 template<typename _Tp>
2250 using remove_extent_t = typename remove_extent<_Tp>::type;
2251
2252 /// Alias template for remove_all_extents
2253 template<typename _Tp>
2254 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
2255#endif
2256
2257 // Pointer modifications.
2258
2259 /// remove_pointer
2260#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer)
2261 template<typename _Tp>
2262 struct remove_pointer
2263 { using type = __remove_pointer(_Tp); };
2264#else
2265 template<typename _Tp, typename>
2266 struct __remove_pointer_helper
2267 { using type = _Tp; };
2268
2269 template<typename _Tp, typename _Up>
2270 struct __remove_pointer_helper<_Tp, _Up*>
2271 { using type = _Up; };
2272
2273 template<typename _Tp>
2274 struct remove_pointer
2275 : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>>
2276 { };
2277#endif
2278
2279 /// add_pointer
2280#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer)
2281 template<typename _Tp>
2282 struct add_pointer
2283 { using type = __add_pointer(_Tp); };
2284#else
2285 template<typename _Tp, typename = void>
2286 struct __add_pointer_helper
2287 { using type = _Tp; };
2288
2289 template<typename _Tp>
2290 struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
2291 { using type = _Tp*; };
2292
2293 template<typename _Tp>
2294 struct add_pointer
2295 : public __add_pointer_helper<_Tp>
2296 { };
2297
2298 template<typename _Tp>
2299 struct add_pointer<_Tp&>
2300 { using type = _Tp*; };
2301
2302 template<typename _Tp>
2303 struct add_pointer<_Tp&&>
2304 { using type = _Tp*; };
2305#endif
2306
2307#if __cplusplus > 201103L
2308 /// Alias template for remove_pointer
2309 template<typename _Tp>
2310 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2311
2312 /// Alias template for add_pointer
2313 template<typename _Tp>
2314 using add_pointer_t = typename add_pointer<_Tp>::type;
2315#endif
2316
2317 /// @cond undocumented
2318
2319 // Aligned to maximum fundamental alignment
2320 struct __attribute__((__aligned__)) __aligned_storage_max_align_t
2321 { };
2322
2323 constexpr size_t
2324 __aligned_storage_default_alignment([[__maybe_unused__]] size_t __len)
2325 {
2326#if _GLIBCXX_INLINE_VERSION
2327 using _Max_align
2328 = integral_constant<size_t, alignof(__aligned_storage_max_align_t)>;
2329
2330 return __len > (_Max_align::value / 2)
2331 ? _Max_align::value
2332# if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_clzg)
2333 : 1 << (__SIZE_WIDTH__ - __builtin_clzg(__len - 1u));
2334# else
2335 : 1 << (__LLONG_WIDTH__ - __builtin_clzll(__len - 1ull));
2336# endif
2337#else
2338 // Returning a fixed value is incorrect, but kept for ABI compatibility.
2339 // XXX GLIBCXX_ABI Deprecated
2340 return alignof(__aligned_storage_max_align_t);
2341#endif
2342 }
2343 /// @endcond
2344
2345 /**
2346 * @brief Aligned storage
2347 *
2348 * The member typedef `type` is be a POD type suitable for use as
2349 * uninitialized storage for any object whose size is at most `_Len`
2350 * and whose alignment is a divisor of `_Align`.
2351 *
2352 * It is important to use the nested `type` as uninitialized storage,
2353 * not the `std::aligned_storage` type itself which is an empty class
2354 * with 1-byte alignment. So this is correct:
2355 *
2356 * `typename std::aligned_storage<sizeof(X), alignof(X)>::type m_xobj;`
2357 *
2358 * This is wrong:
2359 *
2360 * `std::aligned_storage<sizeof(X), alignof(X)> m_xobj;`
2361 *
2362 * In C++14 and later `std::aligned_storage_t<sizeof(X), alignof(X)>`
2363 * can be used to refer to the `type` member typedef.
2364 *
2365 * The default value of _Align is supposed to be the most stringent
2366 * fundamental alignment requirement for any C++ object type whose size
2367 * is no greater than `_Len` (see [basic.align] in the C++ standard).
2368 *
2369 * @bug In this implementation the default value for _Align is always the
2370 * maximum fundamental alignment, i.e. `alignof(max_align_t)`, which is
2371 * incorrect. It should be an alignment value no greater than `_Len`.
2372 *
2373 * @deprecated Deprecated in C++23. Uses can be replaced by an
2374 * array `std::byte[_Len]` declared with `alignas(_Align)`.
2375 */
2376 template<size_t _Len,
2377 size_t _Align = __aligned_storage_default_alignment(_Len)>
2378 struct
2379 _GLIBCXX23_DEPRECATED
2380 aligned_storage
2381 {
2382 struct type
2383 {
2384 alignas(_Align) unsigned char __data[_Len];
2385 };
2386 };
2387
2388 template <typename... _Types>
2389 struct __strictest_alignment
2390 {
2391 static const size_t _S_alignment = 0;
2392 static const size_t _S_size = 0;
2393 };
2394
2395 template <typename _Tp, typename... _Types>
2396 struct __strictest_alignment<_Tp, _Types...>
2397 {
2398 static const size_t _S_alignment =
2399 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2400 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2401 static const size_t _S_size =
2402 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2403 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2404 };
2405
2406#pragma GCC diagnostic push
2407#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2408
2409 /**
2410 * @brief Provide aligned storage for types.
2411 *
2412 * [meta.trans.other]
2413 *
2414 * Provides aligned storage for any of the provided types of at
2415 * least size _Len.
2416 *
2417 * @see aligned_storage
2418 *
2419 * @deprecated Deprecated in C++23.
2420 */
2421 template <size_t _Len, typename... _Types>
2422 struct
2423 _GLIBCXX23_DEPRECATED
2424 aligned_union
2425 {
2426 private:
2427 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2428
2429 using __strictest = __strictest_alignment<_Types...>;
2430 static const size_t _S_len = _Len > __strictest::_S_size
2431 ? _Len : __strictest::_S_size;
2432 public:
2433 /// The value of the strictest alignment of _Types.
2434 static const size_t alignment_value = __strictest::_S_alignment;
2435 /// The storage.
2436 using type = typename aligned_storage<_S_len, alignment_value>::type;
2437 };
2438
2439 template <size_t _Len, typename... _Types>
2440 const size_t aligned_union<_Len, _Types...>::alignment_value;
2441#pragma GCC diagnostic pop
2442
2443 /// @cond undocumented
2444
2445#if _GLIBCXX_USE_BUILTIN_TRAIT(__decay)
2446 template<typename _Tp>
2447 struct decay
2448 { using type = __decay(_Tp); };
2449#else
2450 // Decay trait for arrays and functions, used for perfect forwarding
2451 // in make_pair, make_tuple, etc.
2452 template<typename _Up>
2453 struct __decay_selector
2454 : __conditional_t<is_const<const _Up>::value, // false for functions
2455 remove_cv<_Up>, // N.B. DR 705.
2456 add_pointer<_Up>> // function decays to pointer
2457 { };
2458
2459 template<typename _Up, size_t _Nm>
2460 struct __decay_selector<_Up[_Nm]>
2461 { using type = _Up*; };
2462
2463 template<typename _Up>
2464 struct __decay_selector<_Up[]>
2465 { using type = _Up*; };
2466
2467 /// @endcond
2468
2469 /// decay
2470 template<typename _Tp>
2471 struct decay
2472 { using type = typename __decay_selector<_Tp>::type; };
2473
2474 template<typename _Tp>
2475 struct decay<_Tp&>
2476 { using type = typename __decay_selector<_Tp>::type; };
2477
2478 template<typename _Tp>
2479 struct decay<_Tp&&>
2480 { using type = typename __decay_selector<_Tp>::type; };
2481#endif
2482
2483 /// @cond undocumented
2484
2485 // Helper which adds a reference to a type when given a reference_wrapper
2486 template<typename _Tp>
2487 struct __strip_reference_wrapper
2488 {
2489 using __type = _Tp;
2490 };
2491
2492 template<typename _Tp>
2493 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2494 {
2495 using __type = _Tp&;
2496 };
2497
2498 // __decay_t (std::decay_t for C++11).
2499 template<typename _Tp>
2500 using __decay_t = typename decay<_Tp>::type;
2501
2502 template<typename _Tp>
2503 using __decay_and_strip = __strip_reference_wrapper<__decay_t<_Tp>>;
2504 /// @endcond
2505
2506 /// @cond undocumented
2507
2508 // Helper for SFINAE constraints
2509 template<typename... _Cond>
2510 using _Require = __enable_if_t<__and_<_Cond...>::value>;
2511
2512 // __remove_cvref_t (std::remove_cvref_t for C++11).
2513 template<typename _Tp>
2514 using __remove_cvref_t
2515 = typename remove_cv<typename remove_reference<_Tp>::type>::type;
2516 /// @endcond
2517
2518 // Primary template.
2519 /// Define a member typedef @c type to one of two argument types.
2520 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2521 struct conditional
2522 { using type = _Iftrue; };
2523
2524 // Partial specialization for false.
2525 template<typename _Iftrue, typename _Iffalse>
2526 struct conditional<false, _Iftrue, _Iffalse>
2527 { using type = _Iffalse; };
2528
2529 /// common_type
2530 template<typename... _Tp>
2531 struct common_type;
2532
2533 // Sfinae-friendly common_type implementation:
2534
2535 /// @cond undocumented
2536
2537 // For several sfinae-friendly trait implementations we transport both the
2538 // result information (as the member type) and the failure information (no
2539 // member type). This is very similar to std::enable_if, but we cannot use
2540 // that, because we need to derive from them as an implementation detail.
2541
2542 template<typename _Tp>
2543 struct __success_type
2544 { using type = _Tp; };
2545
2546 struct __failure_type
2547 { };
2548
2549 struct __do_common_type_impl
2550 {
2551 template<typename _Tp, typename _Up>
2552 using __cond_t
2553 = decltype(true ? std::declval<_Tp>() : std::declval<_Up>());
2554
2555 // if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2556 // denotes a valid type, let C denote that type.
2557 template<typename _Tp, typename _Up>
2558 static __success_type<__decay_t<__cond_t<_Tp, _Up>>>
2559 _S_test(int);
2560
2561#if __cplusplus > 201703L
2562 // Otherwise, if COND-RES(CREF(D1), CREF(D2)) denotes a type,
2563 // let C denote the type decay_t<COND-RES(CREF(D1), CREF(D2))>.
2564 template<typename _Tp, typename _Up>
2565 static __success_type<__remove_cvref_t<__cond_t<const _Tp&, const _Up&>>>
2566 _S_test_2(int);
2567#endif
2568
2569 template<typename, typename>
2570 static __failure_type
2571 _S_test_2(...);
2572
2573 template<typename _Tp, typename _Up>
2574 static decltype(_S_test_2<_Tp, _Up>(0))
2575 _S_test(...);
2576 };
2577
2578 // If sizeof...(T) is zero, there shall be no member type.
2579 template<>
2580 struct common_type<>
2581 { };
2582
2583 // If sizeof...(T) is one, the same type, if any, as common_type_t<T0, T0>.
2584 template<typename _Tp0>
2585 struct common_type<_Tp0>
2586 : public common_type<_Tp0, _Tp0>
2587 { };
2588
2589 // If sizeof...(T) is two, ...
2590 template<typename _Tp1, typename _Tp2,
2591 typename _Dp1 = __decay_t<_Tp1>, typename _Dp2 = __decay_t<_Tp2>>
2592 struct __common_type_impl
2593 {
2594 // If is_same_v<T1, D1> is false or is_same_v<T2, D2> is false,
2595 // let C denote the same type, if any, as common_type_t<D1, D2>.
2596 using type = common_type<_Dp1, _Dp2>;
2597 };
2598
2599 template<typename _Tp1, typename _Tp2>
2600 struct __common_type_impl<_Tp1, _Tp2, _Tp1, _Tp2>
2601 : private __do_common_type_impl
2602 {
2603 // Otherwise, if decay_t<decltype(false ? declval<D1>() : declval<D2>())>
2604 // denotes a valid type, let C denote that type.
2605 using type = decltype(_S_test<_Tp1, _Tp2>(0));
2606 };
2607
2608 // If sizeof...(T) is two, ...
2609 template<typename _Tp1, typename _Tp2>
2610 struct common_type<_Tp1, _Tp2>
2611 : public __common_type_impl<_Tp1, _Tp2>::type
2612 { };
2613
2614 template<typename...>
2615 struct __common_type_pack
2616 { };
2617
2618 template<typename, typename, typename = void>
2619 struct __common_type_fold;
2620
2621 // If sizeof...(T) is greater than two, ...
2622 template<typename _Tp1, typename _Tp2, typename... _Rp>
2623 struct common_type<_Tp1, _Tp2, _Rp...>
2624 : public __common_type_fold<common_type<_Tp1, _Tp2>,
2625 __common_type_pack<_Rp...>>
2626 { };
2627
2628 // Let C denote the same type, if any, as common_type_t<T1, T2>.
2629 // If there is such a type C, type shall denote the same type, if any,
2630 // as common_type_t<C, R...>.
2631 template<typename _CTp, typename... _Rp>
2632 struct __common_type_fold<_CTp, __common_type_pack<_Rp...>,
2633 __void_t<typename _CTp::type>>
2634 : public common_type<typename _CTp::type, _Rp...>
2635 { };
2636
2637 // Otherwise, there shall be no member type.
2638 template<typename _CTp, typename _Rp>
2639 struct __common_type_fold<_CTp, _Rp, void>
2640 { };
2641
2642 template<typename _Tp, bool = __is_enum(_Tp)>
2643 struct __underlying_type_impl
2644 {
2645 using type = __underlying_type(_Tp);
2646 };
2647
2648 template<typename _Tp>
2649 struct __underlying_type_impl<_Tp, false>
2650 { };
2651 /// @endcond
2652
2653 /// The underlying type of an enum.
2654 template<typename _Tp>
2655 struct underlying_type
2656 : public __underlying_type_impl<_Tp>
2657 { };
2658
2659 /// @cond undocumented
2660 template<typename _Tp>
2661 struct __declval_protector
2662 {
2663 static const bool __stop = false;
2664 };
2665 /// @endcond
2666
2667 /** Utility to simplify expressions used in unevaluated operands
2668 * @since C++11
2669 * @ingroup utilities
2670 */
2671 template<typename _Tp>
2672 auto declval() noexcept -> decltype(__declval<_Tp>(0))
2673 {
2674 static_assert(__declval_protector<_Tp>::__stop,
2675 "declval() must not be used!");
2676 return __declval<_Tp>(0);
2677 }
2678
2679 /// result_of
2680 template<typename _Signature>
2681 struct result_of;
2682
2683 // Sfinae-friendly result_of implementation:
2684
2685 /// @cond undocumented
2686 struct __invoke_memfun_ref { };
2687 struct __invoke_memfun_deref { };
2688 struct __invoke_memobj_ref { };
2689 struct __invoke_memobj_deref { };
2690 struct __invoke_other { };
2691
2692 // Associate a tag type with a specialization of __success_type.
2693 template<typename _Tp, typename _Tag>
2694 struct __result_of_success : __success_type<_Tp>
2695 { using __invoke_type = _Tag; };
2696
2697 // [func.require] paragraph 1 bullet 1:
2698 struct __result_of_memfun_ref_impl
2699 {
2700 template<typename _Fp, typename _Tp1, typename... _Args>
2701 static __result_of_success<decltype(
2702 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
2703 ), __invoke_memfun_ref> _S_test(int);
2704
2705 template<typename...>
2706 static __failure_type _S_test(...);
2707 };
2708
2709 template<typename _MemPtr, typename _Arg, typename... _Args>
2710 struct __result_of_memfun_ref
2711 : private __result_of_memfun_ref_impl
2712 {
2713 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2714 };
2715
2716 // [func.require] paragraph 1 bullet 2:
2717 struct __result_of_memfun_deref_impl
2718 {
2719 template<typename _Fp, typename _Tp1, typename... _Args>
2720 static __result_of_success<decltype(
2721 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
2722 ), __invoke_memfun_deref> _S_test(int);
2723
2724 template<typename...>
2725 static __failure_type _S_test(...);
2726 };
2727
2728 template<typename _MemPtr, typename _Arg, typename... _Args>
2729 struct __result_of_memfun_deref
2730 : private __result_of_memfun_deref_impl
2731 {
2732 using type = decltype(_S_test<_MemPtr, _Arg, _Args...>(0));
2733 };
2734
2735 // [func.require] paragraph 1 bullet 3:
2736 struct __result_of_memobj_ref_impl
2737 {
2738 template<typename _Fp, typename _Tp1>
2739 static __result_of_success<decltype(
2740 std::declval<_Tp1>().*std::declval<_Fp>()
2741 ), __invoke_memobj_ref> _S_test(int);
2742
2743 template<typename, typename>
2744 static __failure_type _S_test(...);
2745 };
2746
2747 template<typename _MemPtr, typename _Arg>
2748 struct __result_of_memobj_ref
2749 : private __result_of_memobj_ref_impl
2750 {
2751 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2752 };
2753
2754 // [func.require] paragraph 1 bullet 4:
2755 struct __result_of_memobj_deref_impl
2756 {
2757 template<typename _Fp, typename _Tp1>
2758 static __result_of_success<decltype(
2759 (*std::declval<_Tp1>()).*std::declval<_Fp>()
2760 ), __invoke_memobj_deref> _S_test(int);
2761
2762 template<typename, typename>
2763 static __failure_type _S_test(...);
2764 };
2765
2766 template<typename _MemPtr, typename _Arg>
2767 struct __result_of_memobj_deref
2768 : private __result_of_memobj_deref_impl
2769 {
2770 using type = decltype(_S_test<_MemPtr, _Arg>(0));
2771 };
2772
2773 template<typename _MemPtr, typename _Arg>
2774 struct __result_of_memobj;
2775
2776 template<typename _Res, typename _Class, typename _Arg>
2777 struct __result_of_memobj<_Res _Class::*, _Arg>
2778 {
2779 using _Argval = __remove_cvref_t<_Arg>;
2780 using _MemPtr = _Res _Class::*;
2781 using type = typename __conditional_t<__or_<is_same<_Argval, _Class>,
2782 is_base_of<_Class, _Argval>>::value,
2783 __result_of_memobj_ref<_MemPtr, _Arg>,
2784 __result_of_memobj_deref<_MemPtr, _Arg>
2785 >::type;
2786 };
2787
2788 template<typename _MemPtr, typename _Arg, typename... _Args>
2789 struct __result_of_memfun;
2790
2791 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2792 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2793 {
2794 using _Argval = typename remove_reference<_Arg>::type;
2795 using _MemPtr = _Res _Class::*;
2796 using type = typename __conditional_t<is_base_of<_Class, _Argval>::value,
2797 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2798 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2799 >::type;
2800 };
2801
2802 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2803 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2804 // as the object expression
2805
2806 // Used by result_of, invoke etc. to unwrap a reference_wrapper.
2807 template<typename _Tp, typename _Up = __remove_cvref_t<_Tp>>
2808 struct __inv_unwrap
2809 {
2810 using type = _Tp;
2811 };
2812
2813 template<typename _Tp, typename _Up>
2814 struct __inv_unwrap<_Tp, reference_wrapper<_Up>>
2815 {
2816 using type = _Up&;
2817 };
2818
2819 template<bool, bool, typename _Functor, typename... _ArgTypes>
2820 struct __result_of_impl
2821 {
2822 using type = __failure_type;
2823 };
2824
2825 template<typename _MemPtr, typename _Arg>
2826 struct __result_of_impl<true, false, _MemPtr, _Arg>
2827 : public __result_of_memobj<__decay_t<_MemPtr>,
2828 typename __inv_unwrap<_Arg>::type>
2829 { };
2830
2831 template<typename _MemPtr, typename _Arg, typename... _Args>
2832 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2833 : public __result_of_memfun<__decay_t<_MemPtr>,
2834 typename __inv_unwrap<_Arg>::type, _Args...>
2835 { };
2836
2837 // [func.require] paragraph 1 bullet 5:
2838 struct __result_of_other_impl
2839 {
2840 template<typename _Fn, typename... _Args>
2841 static __result_of_success<decltype(
2842 std::declval<_Fn>()(std::declval<_Args>()...)
2843 ), __invoke_other> _S_test(int);
2844
2845 template<typename...>
2846 static __failure_type _S_test(...);
2847 };
2848
2849 template<typename _Functor, typename... _ArgTypes>
2850 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2851 : private __result_of_other_impl
2852 {
2853 using type = decltype(_S_test<_Functor, _ArgTypes...>(0));
2854 };
2855
2856 // __invoke_result (std::invoke_result for C++11)
2857 template<typename _Functor, typename... _ArgTypes>
2858 struct __invoke_result
2859 : public __result_of_impl<
2860 is_member_object_pointer<
2861 typename remove_reference<_Functor>::type
2862 >::value,
2863 is_member_function_pointer<
2864 typename remove_reference<_Functor>::type
2865 >::value,
2866 _Functor, _ArgTypes...
2867 >::type
2868 { };
2869
2870 // __invoke_result_t (std::invoke_result_t for C++11)
2871 template<typename _Fn, typename... _Args>
2872 using __invoke_result_t = typename __invoke_result<_Fn, _Args...>::type;
2873 /// @endcond
2874
2875 template<typename _Functor, typename... _ArgTypes>
2876 struct result_of<_Functor(_ArgTypes...)>
2877 : public __invoke_result<_Functor, _ArgTypes...>
2878 { } _GLIBCXX17_DEPRECATED_SUGGEST("std::invoke_result");
2879
2880#if __cplusplus >= 201402L
2881#pragma GCC diagnostic push
2882#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2883 /// Alias template for aligned_storage
2884 template<size_t _Len,
2885 size_t _Align = __aligned_storage_default_alignment(_Len)>
2886 using aligned_storage_t _GLIBCXX23_DEPRECATED = typename aligned_storage<_Len, _Align>::type;
2887
2888 template <size_t _Len, typename... _Types>
2889 using aligned_union_t _GLIBCXX23_DEPRECATED = typename aligned_union<_Len, _Types...>::type;
2890#pragma GCC diagnostic pop
2891
2892 /// Alias template for decay
2893 template<typename _Tp>
2894 using decay_t = typename decay<_Tp>::type;
2895
2896 /// Alias template for enable_if
2897 template<bool _Cond, typename _Tp = void>
2898 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2899
2900 /// Alias template for conditional
2901 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2902 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2903
2904 /// Alias template for common_type
2905 template<typename... _Tp>
2906 using common_type_t = typename common_type<_Tp...>::type;
2907
2908 /// Alias template for underlying_type
2909 template<typename _Tp>
2910 using underlying_type_t = typename underlying_type<_Tp>::type;
2911
2912 /// Alias template for result_of
2913 template<typename _Tp>
2914 using result_of_t = typename result_of<_Tp>::type;
2915#endif // C++14
2916
2917#ifdef __cpp_lib_void_t // C++ >= 17 || GNU++ >= 11
2918 /// A metafunction that always yields void, used for detecting valid types.
2919 template<typename...> using void_t = void;
2920#endif
2921
2922 /// @cond undocumented
2923
2924 // Detection idiom.
2925 // Detect whether _Op<_Args...> is a valid type, use default _Def if not.
2926
2927#if __cpp_concepts
2928 // Implementation of the detection idiom (negative case).
2929 template<typename _Def, template<typename...> class _Op, typename... _Args>
2930 struct __detected_or
2931 {
2932 using type = _Def;
2933 using __is_detected = false_type;
2934 };
2935
2936 // Implementation of the detection idiom (positive case).
2937 template<typename _Def, template<typename...> class _Op, typename... _Args>
2938 requires requires { typename _Op<_Args...>; }
2939 struct __detected_or<_Def, _Op, _Args...>
2940 {
2941 using type = _Op<_Args...>;
2942 using __is_detected = true_type;
2943 };
2944#else
2945 /// Implementation of the detection idiom (negative case).
2946 template<typename _Default, typename _AlwaysVoid,
2947 template<typename...> class _Op, typename... _Args>
2948 struct __detector
2949 {
2950 using type = _Default;
2951 using __is_detected = false_type;
2952 };
2953
2954 /// Implementation of the detection idiom (positive case).
2955 template<typename _Default, template<typename...> class _Op,
2956 typename... _Args>
2957 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2958 {
2959 using type = _Op<_Args...>;
2960 using __is_detected = true_type;
2961 };
2962
2963 template<typename _Default, template<typename...> class _Op,
2964 typename... _Args>
2965 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2966#endif // __cpp_concepts
2967
2968 // _Op<_Args...> if that is a valid type, otherwise _Default.
2969 template<typename _Default, template<typename...> class _Op,
2970 typename... _Args>
2971 using __detected_or_t
2972 = typename __detected_or<_Default, _Op, _Args...>::type;
2973
2974 /**
2975 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2976 * member type _NTYPE.
2977 */
2978#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2979 template<typename _Tp, typename = __void_t<>> \
2980 struct __has_##_NTYPE \
2981 : false_type \
2982 { }; \
2983 template<typename _Tp> \
2984 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2985 : true_type \
2986 { };
2987
2988 template <typename _Tp>
2989 struct __is_swappable;
2990
2991 template <typename _Tp>
2992 struct __is_nothrow_swappable;
2993
2994 template<typename>
2995 struct __is_tuple_like_impl : false_type
2996 { };
2997
2998 // Internal type trait that allows us to sfinae-protect tuple_cat.
2999 template<typename _Tp>
3000 struct __is_tuple_like
3001 : public __is_tuple_like_impl<__remove_cvref_t<_Tp>>::type
3002 { };
3003 /// @endcond
3004
3005 template<typename _Tp>
3006 _GLIBCXX20_CONSTEXPR
3007 inline
3008 _Require<__not_<__is_tuple_like<_Tp>>,
3009 is_move_constructible<_Tp>,
3010 is_move_assignable<_Tp>>
3011 swap(_Tp&, _Tp&)
3012 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
3013 is_nothrow_move_assignable<_Tp>>::value);
3014
3015 template<typename _Tp, size_t _Nm>
3016 _GLIBCXX20_CONSTEXPR
3017 inline
3018 __enable_if_t<__is_swappable<_Tp>::value>
3019 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
3020 noexcept(__is_nothrow_swappable<_Tp>::value);
3021
3022 /// @cond undocumented
3023 namespace __swappable_details {
3024 using std::swap;
3025
3026 struct __do_is_swappable_impl
3027 {
3028 template<typename _Tp, typename
3029 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
3030 static true_type __test(int);
3031
3032 template<typename>
3033 static false_type __test(...);
3034 };
3035
3036 struct __do_is_nothrow_swappable_impl
3037 {
3038 template<typename _Tp>
3039 static __bool_constant<
3040 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
3041 > __test(int);
3042
3043 template<typename>
3044 static false_type __test(...);
3045 };
3046
3047 } // namespace __swappable_details
3048
3049 template<typename _Tp>
3050 struct __is_swappable_impl
3051 : public __swappable_details::__do_is_swappable_impl
3052 {
3053 using type = decltype(__test<_Tp>(0));
3054 };
3055
3056 template<typename _Tp>
3057 struct __is_nothrow_swappable_impl
3058 : public __swappable_details::__do_is_nothrow_swappable_impl
3059 {
3060 using type = decltype(__test<_Tp>(0));
3061 };
3062
3063 template<typename _Tp>
3064 struct __is_swappable
3065 : public __is_swappable_impl<_Tp>::type
3066 { };
3067
3068 template<typename _Tp>
3069 struct __is_nothrow_swappable
3070 : public __is_nothrow_swappable_impl<_Tp>::type
3071 { };
3072 /// @endcond
3073
3074#ifdef __cpp_lib_is_swappable // C++ >= 17 || GNU++ >= 11
3075 /// Metafunctions used for detecting swappable types: p0185r1
3076
3077 /// is_swappable
3078 template<typename _Tp>
3079 struct is_swappable
3080 : public __is_swappable_impl<_Tp>::type
3081 {
3082 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3083 "template argument must be a complete class or an unbounded array");
3084 };
3085
3086 /// is_nothrow_swappable
3087 template<typename _Tp>
3088 struct is_nothrow_swappable
3089 : public __is_nothrow_swappable_impl<_Tp>::type
3090 {
3091 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3092 "template argument must be a complete class or an unbounded array");
3093 };
3094
3095#if __cplusplus >= 201402L
3096 /// is_swappable_v
3097 template<typename _Tp>
3098 _GLIBCXX17_INLINE constexpr bool is_swappable_v =
3099 is_swappable<_Tp>::value;
3100
3101 /// is_nothrow_swappable_v
3102 template<typename _Tp>
3103 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_v =
3104 is_nothrow_swappable<_Tp>::value;
3105#endif // __cplusplus >= 201402L
3106
3107 /// @cond undocumented
3108 namespace __swappable_with_details {
3109 using std::swap;
3110
3111 struct __do_is_swappable_with_impl
3112 {
3113 template<typename _Tp, typename _Up, typename
3114 = decltype(swap(std::declval<_Tp>(), std::declval<_Up>())),
3115 typename
3116 = decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))>
3117 static true_type __test(int);
3118
3119 template<typename, typename>
3120 static false_type __test(...);
3121 };
3122
3123 struct __do_is_nothrow_swappable_with_impl
3124 {
3125 template<typename _Tp, typename _Up>
3126 static __bool_constant<
3127 noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()))
3128 &&
3129 noexcept(swap(std::declval<_Up>(), std::declval<_Tp>()))
3130 > __test(int);
3131
3132 template<typename, typename>
3133 static false_type __test(...);
3134 };
3135
3136 } // namespace __swappable_with_details
3137
3138 template<typename _Tp, typename _Up>
3139 struct __is_swappable_with_impl
3140 : public __swappable_with_details::__do_is_swappable_with_impl
3141 {
3142 using type = decltype(__test<_Tp, _Up>(0));
3143 };
3144
3145 // Optimization for the homogenous lvalue case, not required:
3146 template<typename _Tp>
3147 struct __is_swappable_with_impl<_Tp&, _Tp&>
3148 : public __swappable_details::__do_is_swappable_impl
3149 {
3150 using type = decltype(__test<_Tp&>(0));
3151 };
3152
3153 template<typename _Tp, typename _Up>
3154 struct __is_nothrow_swappable_with_impl
3155 : public __swappable_with_details::__do_is_nothrow_swappable_with_impl
3156 {
3157 using type = decltype(__test<_Tp, _Up>(0));
3158 };
3159
3160 // Optimization for the homogenous lvalue case, not required:
3161 template<typename _Tp>
3162 struct __is_nothrow_swappable_with_impl<_Tp&, _Tp&>
3163 : public __swappable_details::__do_is_nothrow_swappable_impl
3164 {
3165 using type = decltype(__test<_Tp&>(0));
3166 };
3167 /// @endcond
3168
3169 /// is_swappable_with
3170 template<typename _Tp, typename _Up>
3171 struct is_swappable_with
3172 : public __is_swappable_with_impl<_Tp, _Up>::type
3173 {
3174 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3175 "first template argument must be a complete class or an unbounded array");
3176 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3177 "second template argument must be a complete class or an unbounded array");
3178 };
3179
3180 /// is_nothrow_swappable_with
3181 template<typename _Tp, typename _Up>
3182 struct is_nothrow_swappable_with
3183 : public __is_nothrow_swappable_with_impl<_Tp, _Up>::type
3184 {
3185 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3186 "first template argument must be a complete class or an unbounded array");
3187 static_assert(std::__is_complete_or_unbounded(__type_identity<_Up>{}),
3188 "second template argument must be a complete class or an unbounded array");
3189 };
3190
3191#if __cplusplus >= 201402L
3192 /// is_swappable_with_v
3193 template<typename _Tp, typename _Up>
3194 _GLIBCXX17_INLINE constexpr bool is_swappable_with_v =
3195 is_swappable_with<_Tp, _Up>::value;
3196
3197 /// is_nothrow_swappable_with_v
3198 template<typename _Tp, typename _Up>
3199 _GLIBCXX17_INLINE constexpr bool is_nothrow_swappable_with_v =
3200 is_nothrow_swappable_with<_Tp, _Up>::value;
3201#endif // __cplusplus >= 201402L
3202
3203#endif // __cpp_lib_is_swappable
3204
3205 /// @cond undocumented
3206
3207 // __is_invocable (std::is_invocable for C++11)
3208
3209 // The primary template is used for invalid INVOKE expressions.
3210 template<typename _Result, typename _Ret,
3211 bool = is_void<_Ret>::value, typename = void>
3212 struct __is_invocable_impl
3213 : false_type
3214 {
3215 using __nothrow_conv = false_type; // For is_nothrow_invocable_r
3216 };
3217
3218 // Used for valid INVOKE and INVOKE<void> expressions.
3219 template<typename _Result, typename _Ret>
3220 struct __is_invocable_impl<_Result, _Ret,
3221 /* is_void<_Ret> = */ true,
3222 __void_t<typename _Result::type>>
3223 : true_type
3224 {
3225 using __nothrow_conv = true_type; // For is_nothrow_invocable_r
3226 };
3227
3228#pragma GCC diagnostic push
3229#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3230 // Used for INVOKE<R> expressions to check the implicit conversion to R.
3231 template<typename _Result, typename _Ret>
3232 struct __is_invocable_impl<_Result, _Ret,
3233 /* is_void<_Ret> = */ false,
3234 __void_t<typename _Result::type>>
3235 {
3236 private:
3237 // The type of the INVOKE expression.
3238 using _Res_t = typename _Result::type;
3239
3240 // Unlike declval, this doesn't add_rvalue_reference, so it respects
3241 // guaranteed copy elision.
3242 static _Res_t _S_get() noexcept;
3243
3244 // Used to check if _Res_t can implicitly convert to _Tp.
3245 template<typename _Tp>
3246 static void _S_conv(__type_identity_t<_Tp>) noexcept;
3247
3248 // This overload is viable if INVOKE(f, args...) can convert to _Tp.
3249 template<typename _Tp,
3250 bool _Nothrow = noexcept(_S_conv<_Tp>(_S_get())),
3251 typename = decltype(_S_conv<_Tp>(_S_get())),
3252#if __has_builtin(__reference_converts_from_temporary)
3253 bool _Dangle = __reference_converts_from_temporary(_Tp, _Res_t)
3254#else
3255 bool _Dangle = false
3256#endif
3257 >
3258 static __bool_constant<_Nothrow && !_Dangle>
3259 _S_test(int);
3260
3261 template<typename _Tp, bool = false>
3262 static false_type
3263 _S_test(...);
3264
3265 public:
3266 // For is_invocable_r
3267 using type = decltype(_S_test<_Ret, /* Nothrow = */ true>(1));
3268
3269 // For is_nothrow_invocable_r
3270 using __nothrow_conv = decltype(_S_test<_Ret>(1));
3271 };
3272#pragma GCC diagnostic pop
3273
3274 template<typename _Fn, typename... _ArgTypes>
3275 struct __is_invocable
3276#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3277 : __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
3278#else
3279 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3280#endif
3281 { };
3282
3283 template<typename _Fn, typename _Tp, typename... _Args>
3284 constexpr bool __call_is_nt(__invoke_memfun_ref)
3285 {
3286 using _Up = typename __inv_unwrap<_Tp>::type;
3287 return noexcept((std::declval<_Up>().*std::declval<_Fn>())(
3288 std::declval<_Args>()...));
3289 }
3290
3291 template<typename _Fn, typename _Tp, typename... _Args>
3292 constexpr bool __call_is_nt(__invoke_memfun_deref)
3293 {
3294 return noexcept(((*std::declval<_Tp>()).*std::declval<_Fn>())(
3295 std::declval<_Args>()...));
3296 }
3297
3298 template<typename _Fn, typename _Tp>
3299 constexpr bool __call_is_nt(__invoke_memobj_ref)
3300 {
3301 using _Up = typename __inv_unwrap<_Tp>::type;
3302 return noexcept(std::declval<_Up>().*std::declval<_Fn>());
3303 }
3304
3305 template<typename _Fn, typename _Tp>
3306 constexpr bool __call_is_nt(__invoke_memobj_deref)
3307 {
3308 return noexcept((*std::declval<_Tp>()).*std::declval<_Fn>());
3309 }
3310
3311 template<typename _Fn, typename... _Args>
3312 constexpr bool __call_is_nt(__invoke_other)
3313 {
3314 return noexcept(std::declval<_Fn>()(std::declval<_Args>()...));
3315 }
3316
3317 template<typename _Result, typename _Fn, typename... _Args>
3318 struct __call_is_nothrow
3319 : __bool_constant<
3320 std::__call_is_nt<_Fn, _Args...>(typename _Result::__invoke_type{})
3321 >
3322 { };
3323
3324 template<typename _Fn, typename... _Args>
3325 using __call_is_nothrow_
3326 = __call_is_nothrow<__invoke_result<_Fn, _Args...>, _Fn, _Args...>;
3327
3328 // __is_nothrow_invocable (std::is_nothrow_invocable for C++11)
3329 template<typename _Fn, typename... _Args>
3330 struct __is_nothrow_invocable
3331#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3332 : __bool_constant<__is_nothrow_invocable(_Fn, _Args...)>
3333#else
3334 : __and_<__is_invocable<_Fn, _Args...>,
3335 __call_is_nothrow_<_Fn, _Args...>>::type
3336#endif
3337 { };
3338
3339#pragma GCC diagnostic push
3340#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
3341 struct __nonesuchbase {};
3342 struct __nonesuch : private __nonesuchbase {
3343 ~__nonesuch() = delete;
3344 __nonesuch(__nonesuch const&) = delete;
3345 void operator=(__nonesuch const&) = delete;
3346 };
3347#pragma GCC diagnostic pop
3348 /// @endcond
3349
3350#ifdef __cpp_lib_is_invocable // C++ >= 17
3351 /// std::invoke_result
3352 template<typename _Functor, typename... _ArgTypes>
3353 struct invoke_result
3354 : public __invoke_result<_Functor, _ArgTypes...>
3355 {
3356 static_assert(std::__is_complete_or_unbounded(__type_identity<_Functor>{}),
3357 "_Functor must be a complete class or an unbounded array");
3358 static_assert((std::__is_complete_or_unbounded(
3359 __type_identity<_ArgTypes>{}) && ...),
3360 "each argument type must be a complete class or an unbounded array");
3361 };
3362
3363 /// std::invoke_result_t
3364 template<typename _Fn, typename... _Args>
3365 using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3366
3367 /// std::is_invocable
3368 template<typename _Fn, typename... _ArgTypes>
3369 struct is_invocable
3370#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3371 : public __bool_constant<__is_invocable(_Fn, _ArgTypes...)>
3372#else
3373 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type
3374#endif
3375 {
3376 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3377 "_Fn must be a complete class or an unbounded array");
3378 static_assert((std::__is_complete_or_unbounded(
3379 __type_identity<_ArgTypes>{}) && ...),
3380 "each argument type must be a complete class or an unbounded array");
3381 };
3382
3383 /// std::is_invocable_r
3384 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3385 struct is_invocable_r
3386 : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>::type
3387 {
3388 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3389 "_Fn must be a complete class or an unbounded array");
3390 static_assert((std::__is_complete_or_unbounded(
3391 __type_identity<_ArgTypes>{}) && ...),
3392 "each argument type must be a complete class or an unbounded array");
3393 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3394 "_Ret must be a complete class or an unbounded array");
3395 };
3396
3397 /// std::is_nothrow_invocable
3398 template<typename _Fn, typename... _ArgTypes>
3399 struct is_nothrow_invocable
3400#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3401 : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)>
3402#else
3403 : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>,
3404 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3405#endif
3406 {
3407 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3408 "_Fn must be a complete class or an unbounded array");
3409 static_assert((std::__is_complete_or_unbounded(
3410 __type_identity<_ArgTypes>{}) && ...),
3411 "each argument type must be a complete class or an unbounded array");
3412 };
3413
3414 /// @cond undocumented
3415 // This checks that the INVOKE<R> expression is well-formed and that the
3416 // conversion to R does not throw. It does *not* check whether the INVOKE
3417 // expression itself can throw. That is done by __call_is_nothrow_ instead.
3418 template<typename _Result, typename _Ret>
3419 using __is_nt_invocable_impl
3420 = typename __is_invocable_impl<_Result, _Ret>::__nothrow_conv;
3421 /// @endcond
3422
3423 /// std::is_nothrow_invocable_r
3424 template<typename _Ret, typename _Fn, typename... _ArgTypes>
3425 struct is_nothrow_invocable_r
3426 : __and_<__is_nt_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, _Ret>,
3427 __call_is_nothrow_<_Fn, _ArgTypes...>>::type
3428 {
3429 static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}),
3430 "_Fn must be a complete class or an unbounded array");
3431 static_assert((std::__is_complete_or_unbounded(
3432 __type_identity<_ArgTypes>{}) && ...),
3433 "each argument type must be a complete class or an unbounded array");
3434 static_assert(std::__is_complete_or_unbounded(__type_identity<_Ret>{}),
3435 "_Ret must be a complete class or an unbounded array");
3436 };
3437#endif // __cpp_lib_is_invocable
3438
3439#if __cpp_lib_type_trait_variable_templates // C++ >= 17
3440 /**
3441 * @defgroup variable_templates Variable templates for type traits
3442 * @ingroup metaprogramming
3443 *
3444 * Each variable `is_xxx_v<T>` is a boolean constant with the same value
3445 * as the `value` member of the corresponding type trait `is_xxx<T>`.
3446 *
3447 * @since C++17 unless noted otherwise.
3448 */
3449
3450 /**
3451 * @{
3452 * @ingroup variable_templates
3453 */
3454template <typename _Tp>
3455 inline constexpr bool is_void_v = is_void<_Tp>::value;
3456template <typename _Tp>
3457 inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
3458template <typename _Tp>
3459 inline constexpr bool is_integral_v = is_integral<_Tp>::value;
3460template <typename _Tp>
3461 inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
3462
3463#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
3464template <typename _Tp>
3465 inline constexpr bool is_array_v = __is_array(_Tp);
3466#else
3467template <typename _Tp>
3468 inline constexpr bool is_array_v = false;
3469template <typename _Tp>
3470 inline constexpr bool is_array_v<_Tp[]> = true;
3471template <typename _Tp, size_t _Num>
3472 inline constexpr bool is_array_v<_Tp[_Num]> = true;
3473#endif
3474
3475#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
3476template <typename _Tp>
3477 inline constexpr bool is_pointer_v = __is_pointer(_Tp);
3478#else
3479template <typename _Tp>
3480 inline constexpr bool is_pointer_v = false;
3481template <typename _Tp>
3482 inline constexpr bool is_pointer_v<_Tp*> = true;
3483template <typename _Tp>
3484 inline constexpr bool is_pointer_v<_Tp* const> = true;
3485template <typename _Tp>
3486 inline constexpr bool is_pointer_v<_Tp* volatile> = true;
3487template <typename _Tp>
3488 inline constexpr bool is_pointer_v<_Tp* const volatile> = true;
3489#endif
3490
3491template <typename _Tp>
3492 inline constexpr bool is_lvalue_reference_v = false;
3493template <typename _Tp>
3494 inline constexpr bool is_lvalue_reference_v<_Tp&> = true;
3495template <typename _Tp>
3496 inline constexpr bool is_rvalue_reference_v = false;
3497template <typename _Tp>
3498 inline constexpr bool is_rvalue_reference_v<_Tp&&> = true;
3499
3500#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer)
3501template <typename _Tp>
3502 inline constexpr bool is_member_object_pointer_v =
3503 __is_member_object_pointer(_Tp);
3504#else
3505template <typename _Tp>
3506 inline constexpr bool is_member_object_pointer_v =
3507 is_member_object_pointer<_Tp>::value;
3508#endif
3509
3510#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
3511template <typename _Tp>
3512 inline constexpr bool is_member_function_pointer_v =
3513 __is_member_function_pointer(_Tp);
3514#else
3515template <typename _Tp>
3516 inline constexpr bool is_member_function_pointer_v =
3517 is_member_function_pointer<_Tp>::value;
3518#endif
3519
3520template <typename _Tp>
3521 inline constexpr bool is_enum_v = __is_enum(_Tp);
3522template <typename _Tp>
3523 inline constexpr bool is_union_v = __is_union(_Tp);
3524template <typename _Tp>
3525 inline constexpr bool is_class_v = __is_class(_Tp);
3526// is_function_v is defined below, after is_const_v.
3527
3528#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference)
3529template <typename _Tp>
3530 inline constexpr bool is_reference_v = __is_reference(_Tp);
3531#else
3532template <typename _Tp>
3533 inline constexpr bool is_reference_v = false;
3534template <typename _Tp>
3535 inline constexpr bool is_reference_v<_Tp&> = true;
3536template <typename _Tp>
3537 inline constexpr bool is_reference_v<_Tp&&> = true;
3538#endif
3539
3540template <typename _Tp>
3541 inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
3542template <typename _Tp>
3543 inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
3544
3545#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object)
3546template <typename _Tp>
3547 inline constexpr bool is_object_v = __is_object(_Tp);
3548#else
3549template <typename _Tp>
3550 inline constexpr bool is_object_v = is_object<_Tp>::value;
3551#endif
3552
3553template <typename _Tp>
3554 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
3555template <typename _Tp>
3556 inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;
3557
3558#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer)
3559template <typename _Tp>
3560 inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
3561#else
3562template <typename _Tp>
3563 inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
3564#endif
3565
3566#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const)
3567template <typename _Tp>
3568 inline constexpr bool is_const_v = __is_const(_Tp);
3569#else
3570template <typename _Tp>
3571 inline constexpr bool is_const_v = false;
3572template <typename _Tp>
3573 inline constexpr bool is_const_v<const _Tp> = true;
3574#endif
3575
3576#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function)
3577template <typename _Tp>
3578 inline constexpr bool is_function_v = __is_function(_Tp);
3579#else
3580template <typename _Tp>
3581 inline constexpr bool is_function_v = !is_const_v<const _Tp>;
3582template <typename _Tp>
3583 inline constexpr bool is_function_v<_Tp&> = false;
3584template <typename _Tp>
3585 inline constexpr bool is_function_v<_Tp&&> = false;
3586#endif
3587
3588#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile)
3589template <typename _Tp>
3590 inline constexpr bool is_volatile_v = __is_volatile(_Tp);
3591#else
3592template <typename _Tp>
3593 inline constexpr bool is_volatile_v = false;
3594template <typename _Tp>
3595 inline constexpr bool is_volatile_v<volatile _Tp> = true;
3596#endif
3597
3598template <typename _Tp>
3599 _GLIBCXX26_DEPRECATED_SUGGEST("is_trivially_default_constructible_v && is_trivially_copyable_v")
3600 inline constexpr bool is_trivial_v = __is_trivial(_Tp);
3601template <typename _Tp>
3602 inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
3603template <typename _Tp>
3604 inline constexpr bool is_standard_layout_v = __is_standard_layout(_Tp);
3605template <typename _Tp>
3606 _GLIBCXX20_DEPRECATED_SUGGEST("is_standard_layout_v && is_trivial_v")
3607 inline constexpr bool is_pod_v = __is_pod(_Tp);
3608template <typename _Tp>
3609 _GLIBCXX17_DEPRECATED
3610 inline constexpr bool is_literal_type_v = __is_literal_type(_Tp);
3611template <typename _Tp>
3612 inline constexpr bool is_empty_v = __is_empty(_Tp);
3613template <typename _Tp>
3614 inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
3615template <typename _Tp>
3616 inline constexpr bool is_abstract_v = __is_abstract(_Tp);
3617template <typename _Tp>
3618 inline constexpr bool is_final_v = __is_final(_Tp);
3619
3620template <typename _Tp>
3621 inline constexpr bool is_signed_v = is_signed<_Tp>::value;
3622template <typename _Tp>
3623 inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
3624
3625template <typename _Tp, typename... _Args>
3626 inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
3627template <typename _Tp>
3628 inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
3629template <typename _Tp>
3630 inline constexpr bool is_copy_constructible_v
3631 = __is_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3632template <typename _Tp>
3633 inline constexpr bool is_move_constructible_v
3634 = __is_constructible(_Tp, __add_rval_ref_t<_Tp>);
3635
3636template <typename _Tp, typename _Up>
3637 inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Up);
3638template <typename _Tp>
3639 inline constexpr bool is_copy_assignable_v
3640 = __is_assignable(__add_lval_ref_t<_Tp>, __add_lval_ref_t<const _Tp>);
3641template <typename _Tp>
3642 inline constexpr bool is_move_assignable_v
3643 = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3644
3645#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_destructible)
3646template <typename _Tp>
3647 inline constexpr bool is_destructible_v = __is_destructible(_Tp);
3648#else
3649template <typename _Tp>
3650 inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
3651#endif
3652
3653template <typename _Tp, typename... _Args>
3654 inline constexpr bool is_trivially_constructible_v
3655 = __is_trivially_constructible(_Tp, _Args...);
3656template <typename _Tp>
3657 inline constexpr bool is_trivially_default_constructible_v
3658 = __is_trivially_constructible(_Tp);
3659template <typename _Tp>
3660 inline constexpr bool is_trivially_copy_constructible_v
3661 = __is_trivially_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3662template <typename _Tp>
3663 inline constexpr bool is_trivially_move_constructible_v
3664 = __is_trivially_constructible(_Tp, __add_rval_ref_t<_Tp>);
3665
3666template <typename _Tp, typename _Up>
3667 inline constexpr bool is_trivially_assignable_v
3668 = __is_trivially_assignable(_Tp, _Up);
3669template <typename _Tp>
3670 inline constexpr bool is_trivially_copy_assignable_v
3671 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3672 __add_lval_ref_t<const _Tp>);
3673template <typename _Tp>
3674 inline constexpr bool is_trivially_move_assignable_v
3675 = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
3676 __add_rval_ref_t<_Tp>);
3677
3678#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_trivially_destructible)
3679template <typename _Tp>
3680 inline constexpr bool is_trivially_destructible_v
3681 = __is_trivially_destructible(_Tp);
3682#elif __cpp_concepts
3683template <typename _Tp>
3684 inline constexpr bool is_trivially_destructible_v = false;
3685
3686template <typename _Tp>
3687 requires (!is_reference_v<_Tp>) && requires (_Tp& __t) { __t.~_Tp(); }
3688 inline constexpr bool is_trivially_destructible_v<_Tp>
3689 = __has_trivial_destructor(_Tp);
3690template <typename _Tp>
3691 inline constexpr bool is_trivially_destructible_v<_Tp&> = true;
3692template <typename _Tp>
3693 inline constexpr bool is_trivially_destructible_v<_Tp&&> = true;
3694template <typename _Tp, size_t _Nm>
3695 inline constexpr bool is_trivially_destructible_v<_Tp[_Nm]>
3696 = is_trivially_destructible_v<_Tp>;
3697#else
3698template <typename _Tp>
3699 inline constexpr bool is_trivially_destructible_v =
3700 is_trivially_destructible<_Tp>::value;
3701#endif
3702
3703template <typename _Tp, typename... _Args>
3704 inline constexpr bool is_nothrow_constructible_v
3705 = __is_nothrow_constructible(_Tp, _Args...);
3706template <typename _Tp>
3707 inline constexpr bool is_nothrow_default_constructible_v
3708 = __is_nothrow_constructible(_Tp);
3709template <typename _Tp>
3710 inline constexpr bool is_nothrow_copy_constructible_v
3711 = __is_nothrow_constructible(_Tp, __add_lval_ref_t<const _Tp>);
3712template <typename _Tp>
3713 inline constexpr bool is_nothrow_move_constructible_v
3714 = __is_nothrow_constructible(_Tp, __add_rval_ref_t<_Tp>);
3715
3716template <typename _Tp, typename _Up>
3717 inline constexpr bool is_nothrow_assignable_v
3718 = __is_nothrow_assignable(_Tp, _Up);
3719template <typename _Tp>
3720 inline constexpr bool is_nothrow_copy_assignable_v
3721 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>,
3722 __add_lval_ref_t<const _Tp>);
3723template <typename _Tp>
3724 inline constexpr bool is_nothrow_move_assignable_v
3725 = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
3726
3727#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_destructible)
3728template <typename _Tp>
3729 inline constexpr bool is_nothrow_destructible_v
3730 = __is_nothrow_destructible(_Tp);
3731#else
3732template <typename _Tp>
3733 inline constexpr bool is_nothrow_destructible_v =
3734 is_nothrow_destructible<_Tp>::value;
3735#endif
3736
3737template <typename _Tp>
3738 inline constexpr bool has_virtual_destructor_v
3739 = __has_virtual_destructor(_Tp);
3740
3741template <typename _Tp>
3742 inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
3743
3744#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) \
3745 && (!defined(__clang__) || __clang_major__ >= 20) // PR118559
3746template <typename _Tp>
3747 inline constexpr size_t rank_v = __array_rank(_Tp);
3748#else
3749template <typename _Tp>
3750 inline constexpr size_t rank_v = 0;
3751template <typename _Tp, size_t _Size>
3752 inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
3753template <typename _Tp>
3754 inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
3755#endif
3756
3757template <typename _Tp, unsigned _Idx = 0>
3758 inline constexpr size_t extent_v = 0;
3759template <typename _Tp, size_t _Size>
3760 inline constexpr size_t extent_v<_Tp[_Size], 0> = _Size;
3761template <typename _Tp, unsigned _Idx, size_t _Size>
3762 inline constexpr size_t extent_v<_Tp[_Size], _Idx> = extent_v<_Tp, _Idx - 1>;
3763template <typename _Tp>
3764 inline constexpr size_t extent_v<_Tp[], 0> = 0;
3765template <typename _Tp, unsigned _Idx>
3766 inline constexpr size_t extent_v<_Tp[], _Idx> = extent_v<_Tp, _Idx - 1>;
3767
3768#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
3769template <typename _Tp, typename _Up>
3770 inline constexpr bool is_same_v = __is_same(_Tp, _Up);
3771#else
3772template <typename _Tp, typename _Up>
3773 inline constexpr bool is_same_v = false;
3774template <typename _Tp>
3775 inline constexpr bool is_same_v<_Tp, _Tp> = true;
3776#endif
3777template <typename _Base, typename _Derived>
3778 inline constexpr bool is_base_of_v = __is_base_of(_Base, _Derived);
3779#ifdef __cpp_lib_is_virtual_base_of // C++ >= 26
3780template <typename _Base, typename _Derived>
3781 inline constexpr bool is_virtual_base_of_v = __builtin_is_virtual_base_of(_Base, _Derived);
3782#endif
3783#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_convertible)
3784template <typename _From, typename _To>
3785 inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
3786#else
3787template <typename _From, typename _To>
3788 inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
3789#endif
3790template<typename _Fn, typename... _Args>
3791 inline constexpr bool is_invocable_v
3792#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable)
3793 = __is_invocable(_Fn, _Args...);
3794#else
3795 = is_invocable<_Fn, _Args...>::value;
3796#endif
3797template<typename _Fn, typename... _Args>
3798 inline constexpr bool is_nothrow_invocable_v
3799#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable)
3800 = __is_nothrow_invocable(_Fn, _Args...);
3801#else
3802 = is_nothrow_invocable<_Fn, _Args...>::value;
3803#endif
3804template<typename _Ret, typename _Fn, typename... _Args>
3805 inline constexpr bool is_invocable_r_v
3806 = is_invocable_r<_Ret, _Fn, _Args...>::value;
3807template<typename _Ret, typename _Fn, typename... _Args>
3808 inline constexpr bool is_nothrow_invocable_r_v
3809 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3810/// @}
3811#endif // __cpp_lib_type_trait_variable_templates
3812
3813#ifdef __cpp_lib_has_unique_object_representations // C++ >= 17 && HAS_UNIQ_OBJ_REP
3814 /// has_unique_object_representations
3815 /// @since C++17
3816 template<typename _Tp>
3817 struct has_unique_object_representations
3818 : bool_constant<__has_unique_object_representations(
3819 remove_cv_t<remove_all_extents_t<_Tp>>
3820 )>
3821 {
3822 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
3823 "template argument must be a complete class or an unbounded array");
3824 };
3825
3826# if __cpp_lib_type_trait_variable_templates // C++ >= 17
3827 /// @ingroup variable_templates
3828 template<typename _Tp>
3829 inline constexpr bool has_unique_object_representations_v
3830 = has_unique_object_representations<_Tp>::value;
3831# endif
3832#endif
3833
3834#ifdef __cpp_lib_is_aggregate // C++ >= 17 && builtin_is_aggregate
3835 /// is_aggregate - true if the type is an aggregate.
3836 /// @since C++17
3837 template<typename _Tp>
3838 struct is_aggregate
3839 : bool_constant<__is_aggregate(remove_cv_t<_Tp>)>
3840 { };
3841
3842# if __cpp_lib_type_trait_variable_templates // C++ >= 17
3843 /** is_aggregate_v - true if the type is an aggregate.
3844 * @ingroup variable_templates
3845 * @since C++17
3846 */
3847 template<typename _Tp>
3848 inline constexpr bool is_aggregate_v = __is_aggregate(remove_cv_t<_Tp>);
3849# endif
3850#endif
3851
3852 /** * Remove references and cv-qualifiers.
3853 * @since C++20
3854 * @{
3855 */
3856#ifdef __cpp_lib_remove_cvref // C++ >= 20
3857# if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_cvref)
3858 template<typename _Tp>
3859 struct remove_cvref
3860 { using type = __remove_cvref(_Tp); };
3861# else
3862 template<typename _Tp>
3863 struct remove_cvref
3864 { using type = typename remove_cv<_Tp>::type; };
3865
3866 template<typename _Tp>
3867 struct remove_cvref<_Tp&>
3868 { using type = typename remove_cv<_Tp>::type; };
3869
3870 template<typename _Tp>
3871 struct remove_cvref<_Tp&&>
3872 { using type = typename remove_cv<_Tp>::type; };
3873# endif
3874
3875 template<typename _Tp>
3876 using remove_cvref_t = typename remove_cvref<_Tp>::type;
3877 /// @}
3878#endif // __cpp_lib_remove_cvref
3879
3880#ifdef __cpp_lib_type_identity // C++ >= 20
3881 /** * Identity metafunction.
3882 * @since C++20
3883 * @{
3884 */
3885 template<typename _Tp>
3886 struct type_identity { using type = _Tp; };
3887
3888 template<typename _Tp>
3889 using type_identity_t = typename type_identity<_Tp>::type;
3890 /// @}
3891#endif
3892
3893#ifdef __cpp_lib_unwrap_ref // C++ >= 20
3894 /** Unwrap a reference_wrapper
3895 * @since C++20
3896 * @{
3897 */
3898 template<typename _Tp>
3899 struct unwrap_reference { using type = _Tp; };
3900
3901 template<typename _Tp>
3902 struct unwrap_reference<reference_wrapper<_Tp>> { using type = _Tp&; };
3903
3904 template<typename _Tp>
3905 using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3906 /// @}
3907
3908 /** Decay type and if it's a reference_wrapper, unwrap it
3909 * @since C++20
3910 * @{
3911 */
3912 template<typename _Tp>
3913 struct unwrap_ref_decay { using type = unwrap_reference_t<decay_t<_Tp>>; };
3914
3915 template<typename _Tp>
3916 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3917 /// @}
3918#endif // __cpp_lib_unwrap_ref
3919
3920#ifdef __cpp_lib_bounded_array_traits // C++ >= 20
3921 /// True for a type that is an array of known bound.
3922 /// @ingroup variable_templates
3923 /// @since C++20
3924# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array)
3925 template<typename _Tp>
3926 inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp);
3927# else
3928 template<typename _Tp>
3929 inline constexpr bool is_bounded_array_v = false;
3930
3931 template<typename _Tp, size_t _Size>
3932 inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true;
3933# endif
3934
3935 /// True for a type that is an array of unknown bound.
3936 /// @ingroup variable_templates
3937 /// @since C++20
3938# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array)
3939 template<typename _Tp>
3940 inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp);
3941# else
3942 template<typename _Tp>
3943 inline constexpr bool is_unbounded_array_v = false;
3944
3945 template<typename _Tp>
3946 inline constexpr bool is_unbounded_array_v<_Tp[]> = true;
3947# endif
3948
3949 /// True for a type that is an array of known bound.
3950 /// @since C++20
3951 template<typename _Tp>
3952 struct is_bounded_array
3953 : public bool_constant<is_bounded_array_v<_Tp>>
3954 { };
3955
3956 /// True for a type that is an array of unknown bound.
3957 /// @since C++20
3958 template<typename _Tp>
3959 struct is_unbounded_array
3960 : public bool_constant<is_unbounded_array_v<_Tp>>
3961 { };
3962#endif // __cpp_lib_bounded_array_traits
3963
3964#if __has_builtin(__is_layout_compatible) && __cplusplus >= 202002L
3965
3966 /// @since C++20
3967 template<typename _Tp, typename _Up>
3968 struct is_layout_compatible
3969 : bool_constant<__is_layout_compatible(_Tp, _Up)>
3970 { };
3971
3972 /// @ingroup variable_templates
3973 /// @since C++20
3974 template<typename _Tp, typename _Up>
3975 constexpr bool is_layout_compatible_v
3976 = __is_layout_compatible(_Tp, _Up);
3977
3978#if __has_builtin(__builtin_is_corresponding_member)
3979# ifndef __cpp_lib_is_layout_compatible
3980# error "libstdc++ bug: is_corresponding_member and is_layout_compatible are provided but their FTM is not set"
3981# endif
3982
3983 /// @since C++20
3984 template<typename _S1, typename _S2, typename _M1, typename _M2>
3985 constexpr bool
3986 is_corresponding_member(_M1 _S1::*__m1, _M2 _S2::*__m2) noexcept
3987 { return __builtin_is_corresponding_member(__m1, __m2); }
3988#endif
3989#endif
3990
3991#if __has_builtin(__is_pointer_interconvertible_base_of) \
3992 && __cplusplus >= 202002L
3993 /// True if `_Derived` is standard-layout and has a base class of type `_Base`
3994 /// @since C++20
3995 template<typename _Base, typename _Derived>
3996 struct is_pointer_interconvertible_base_of
3997 : bool_constant<__is_pointer_interconvertible_base_of(_Base, _Derived)>
3998 { };
3999
4000 /// @ingroup variable_templates
4001 /// @since C++20
4002 template<typename _Base, typename _Derived>
4003 constexpr bool is_pointer_interconvertible_base_of_v
4004 = __is_pointer_interconvertible_base_of(_Base, _Derived);
4005
4006#if __has_builtin(__builtin_is_pointer_interconvertible_with_class)
4007# ifndef __cpp_lib_is_pointer_interconvertible
4008# error "libstdc++ bug: is_pointer_interconvertible available but FTM is not set"
4009# endif
4010
4011 /// True if `__mp` points to the first member of a standard-layout type
4012 /// @returns true if `s.*__mp` is pointer-interconvertible with `s`
4013 /// @since C++20
4014 template<typename _Tp, typename _Mem>
4015 constexpr bool
4016 is_pointer_interconvertible_with_class(_Mem _Tp::*__mp) noexcept
4017 { return __builtin_is_pointer_interconvertible_with_class(__mp); }
4018#endif
4019#endif
4020
4021#ifdef __cpp_lib_is_scoped_enum // C++ >= 23
4022 /// True if the type is a scoped enumeration type.
4023 /// @since C++23
4024
4025# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
4026 template<typename _Tp>
4027 struct is_scoped_enum
4028 : bool_constant<__is_scoped_enum(_Tp)>
4029 { };
4030# else
4031 template<typename _Tp>
4032 struct is_scoped_enum
4033 : false_type
4034 { };
4035
4036 template<typename _Tp>
4037 requires __is_enum(_Tp)
4038 && requires(remove_cv_t<_Tp> __t) { __t = __t; } // fails if incomplete
4039 struct is_scoped_enum<_Tp>
4040 : bool_constant<!requires(_Tp __t, void(*__f)(int)) { __f(__t); }>
4041 { };
4042# endif
4043
4044 /// @ingroup variable_templates
4045 /// @since C++23
4046# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
4047 template<typename _Tp>
4048 inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
4049# else
4050 template<typename _Tp>
4051 inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
4052# endif
4053#endif
4054
4055#ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp
4056 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
4057 /// direct-initialization, and a temporary object would be bound to
4058 /// the reference, false otherwise.
4059 /// @since C++23
4060 template<typename _Tp, typename _Up>
4061 struct reference_constructs_from_temporary
4062 : public bool_constant<__reference_constructs_from_temporary(_Tp, _Up)>
4063 {
4064 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
4065 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
4066 "template argument must be a complete class or an unbounded array");
4067 };
4068
4069 /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
4070 /// copy-initialization, and a temporary object would be bound to
4071 /// the reference, false otherwise.
4072 /// @since C++23
4073 template<typename _Tp, typename _Up>
4074 struct reference_converts_from_temporary
4075 : public bool_constant<__reference_converts_from_temporary(_Tp, _Up)>
4076 {
4077 static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
4078 && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
4079 "template argument must be a complete class or an unbounded array");
4080 };
4081
4082 /// @ingroup variable_templates
4083 /// @since C++23
4084 template<typename _Tp, typename _Up>
4085 inline constexpr bool reference_constructs_from_temporary_v
4086 = reference_constructs_from_temporary<_Tp, _Up>::value;
4087
4088 /// @ingroup variable_templates
4089 /// @since C++23
4090 template<typename _Tp, typename _Up>
4091 inline constexpr bool reference_converts_from_temporary_v
4092 = reference_converts_from_temporary<_Tp, _Up>::value;
4093#endif // __cpp_lib_reference_from_temporary
4094
4095#ifdef __cpp_lib_is_constant_evaluated // C++ >= 20 && HAVE_IS_CONST_EVAL
4096 /// Returns true only when called during constant evaluation.
4097 /// @since C++20
4098 [[__gnu__::__always_inline__]]
4099 constexpr bool
4100 is_constant_evaluated() noexcept
4101 {
4102#if __cpp_if_consteval >= 202106L
4103 if consteval { return true; } else { return false; }
4104#else
4105 return __builtin_is_constant_evaluated();
4106#endif
4107 }
4108#endif
4109
4110#if __cplusplus >= 202002L
4111 /// @cond undocumented
4112 template<typename _From, typename _To>
4113 using __copy_cv = typename __match_cv_qualifiers<_From, _To>::__type;
4114
4115 template<typename _Xp, typename _Yp>
4116 using __cond_res
4117 = decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
4118
4119 template<typename _Ap, typename _Bp, typename = void>
4120 struct __common_ref_impl
4121 { };
4122
4123 // [meta.trans.other], COMMON-REF(A, B)
4124 template<typename _Ap, typename _Bp>
4125 using __common_ref = typename __common_ref_impl<_Ap, _Bp>::type;
4126
4127 // COND-RES(COPYCV(X, Y) &, COPYCV(Y, X) &)
4128 template<typename _Xp, typename _Yp>
4129 using __condres_cvref
4130 = __cond_res<__copy_cv<_Xp, _Yp>&, __copy_cv<_Yp, _Xp>&>;
4131
4132 // If A and B are both lvalue reference types, ...
4133 template<typename _Xp, typename _Yp>
4134 struct __common_ref_impl<_Xp&, _Yp&, __void_t<__condres_cvref<_Xp, _Yp>>>
4135 : enable_if<is_reference_v<__condres_cvref<_Xp, _Yp>>,
4136 __condres_cvref<_Xp, _Yp>>
4137 { };
4138
4139 // let C be remove_reference_t<COMMON-REF(X&, Y&)>&&
4140 template<typename _Xp, typename _Yp>
4141 using __common_ref_C = remove_reference_t<__common_ref<_Xp&, _Yp&>>&&;
4142
4143 // If A and B are both rvalue reference types, ...
4144 template<typename _Xp, typename _Yp>
4145 struct __common_ref_impl<_Xp&&, _Yp&&,
4146 _Require<is_convertible<_Xp&&, __common_ref_C<_Xp, _Yp>>,
4147 is_convertible<_Yp&&, __common_ref_C<_Xp, _Yp>>>>
4148 { using type = __common_ref_C<_Xp, _Yp>; };
4149
4150 // let D be COMMON-REF(const X&, Y&)
4151 template<typename _Xp, typename _Yp>
4152 using __common_ref_D = __common_ref<const _Xp&, _Yp&>;
4153
4154 // If A is an rvalue reference and B is an lvalue reference, ...
4155 template<typename _Xp, typename _Yp>
4156 struct __common_ref_impl<_Xp&&, _Yp&,
4157 _Require<is_convertible<_Xp&&, __common_ref_D<_Xp, _Yp>>>>
4158 { using type = __common_ref_D<_Xp, _Yp>; };
4159
4160 // If A is an lvalue reference and B is an rvalue reference, ...
4161 template<typename _Xp, typename _Yp>
4162 struct __common_ref_impl<_Xp&, _Yp&&>
4163 : __common_ref_impl<_Yp&&, _Xp&>
4164 { };
4165 /// @endcond
4166
4167 template<typename _Tp, typename _Up,
4168 template<typename> class _TQual, template<typename> class _UQual>
4169 struct basic_common_reference
4170 { };
4171
4172 /// @cond undocumented
4173 template<typename _Tp>
4174 struct __xref
4175 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>; };
4176
4177 template<typename _Tp>
4178 struct __xref<_Tp&>
4179 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&; };
4180
4181 template<typename _Tp>
4182 struct __xref<_Tp&&>
4183 { template<typename _Up> using __type = __copy_cv<_Tp, _Up>&&; };
4184
4185 template<typename _Tp1, typename _Tp2>
4186 using __basic_common_ref
4187 = typename basic_common_reference<remove_cvref_t<_Tp1>,
4188 remove_cvref_t<_Tp2>,
4189 __xref<_Tp1>::template __type,
4190 __xref<_Tp2>::template __type>::type;
4191 /// @endcond
4192
4193 template<typename... _Tp>
4194 struct common_reference;
4195
4196 template<typename... _Tp>
4197 using common_reference_t = typename common_reference<_Tp...>::type;
4198
4199 // If sizeof...(T) is zero, there shall be no member type.
4200 template<>
4201 struct common_reference<>
4202 { };
4203
4204 // If sizeof...(T) is one ...
4205 template<typename _Tp0>
4206 struct common_reference<_Tp0>
4207 { using type = _Tp0; };
4208
4209 /// @cond undocumented
4210 template<typename _Tp1, typename _Tp2, int _Bullet = 1, typename = void>
4211 struct __common_reference_impl
4212 : __common_reference_impl<_Tp1, _Tp2, _Bullet + 1>
4213 { };
4214
4215 // If sizeof...(T) is two ...
4216 template<typename _Tp1, typename _Tp2>
4217 struct common_reference<_Tp1, _Tp2>
4218 : __common_reference_impl<_Tp1, _Tp2>
4219 { };
4220
4221 // If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, ...
4222 template<typename _Tp1, typename _Tp2>
4223 struct __common_reference_impl<_Tp1&, _Tp2&, 1,
4224 void_t<__common_ref<_Tp1&, _Tp2&>>>
4225 { using type = __common_ref<_Tp1&, _Tp2&>; };
4226
4227 template<typename _Tp1, typename _Tp2>
4228 struct __common_reference_impl<_Tp1&&, _Tp2&&, 1,
4229 void_t<__common_ref<_Tp1&&, _Tp2&&>>>
4230 { using type = __common_ref<_Tp1&&, _Tp2&&>; };
4231
4232 template<typename _Tp1, typename _Tp2>
4233 struct __common_reference_impl<_Tp1&, _Tp2&&, 1,
4234 void_t<__common_ref<_Tp1&, _Tp2&&>>>
4235 { using type = __common_ref<_Tp1&, _Tp2&&>; };
4236
4237 template<typename _Tp1, typename _Tp2>
4238 struct __common_reference_impl<_Tp1&&, _Tp2&, 1,
4239 void_t<__common_ref<_Tp1&&, _Tp2&>>>
4240 { using type = __common_ref<_Tp1&&, _Tp2&>; };
4241
4242 // Otherwise, if basic_common_reference<...>::type is well-formed, ...
4243 template<typename _Tp1, typename _Tp2>
4244 struct __common_reference_impl<_Tp1, _Tp2, 2,
4245 void_t<__basic_common_ref<_Tp1, _Tp2>>>
4246 { using type = __basic_common_ref<_Tp1, _Tp2>; };
4247
4248 // Otherwise, if COND-RES(T1, T2) is well-formed, ...
4249 template<typename _Tp1, typename _Tp2>
4250 struct __common_reference_impl<_Tp1, _Tp2, 3,
4251 void_t<__cond_res<_Tp1, _Tp2>>>
4252 { using type = __cond_res<_Tp1, _Tp2>; };
4253
4254 // Otherwise, if common_type_t<T1, T2> is well-formed, ...
4255 template<typename _Tp1, typename _Tp2>
4256 struct __common_reference_impl<_Tp1, _Tp2, 4,
4257 void_t<common_type_t<_Tp1, _Tp2>>>
4258 { using type = common_type_t<_Tp1, _Tp2>; };
4259
4260 // Otherwise, there shall be no member type.
4261 template<typename _Tp1, typename _Tp2>
4262 struct __common_reference_impl<_Tp1, _Tp2, 5, void>
4263 { };
4264
4265 // Otherwise, if sizeof...(T) is greater than two, ...
4266 template<typename _Tp1, typename _Tp2, typename... _Rest>
4267 struct common_reference<_Tp1, _Tp2, _Rest...>
4268 : __common_type_fold<common_reference<_Tp1, _Tp2>,
4269 __common_type_pack<_Rest...>>
4270 { };
4271
4272 // Reuse __common_type_fold for common_reference<T1, T2, Rest...>
4273 template<typename _Tp1, typename _Tp2, typename... _Rest>
4274 struct __common_type_fold<common_reference<_Tp1, _Tp2>,
4275 __common_type_pack<_Rest...>,
4276 void_t<common_reference_t<_Tp1, _Tp2>>>
4277 : public common_reference<common_reference_t<_Tp1, _Tp2>, _Rest...>
4278 { };
4279 /// @endcond
4280
4281#endif // C++2a
4282
4283#if __cplusplus >= 201103L
4284 // Stores a tuple of indices. Used by tuple and pair, and by bind() to
4285 // extract the elements in a tuple.
4286 template<size_t... _Indexes> struct _Index_tuple { };
4287
4288 // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
4289 template<size_t _Num>
4290 struct _Build_index_tuple
4291 {
4292#if __has_builtin(__make_integer_seq)
4293 template<typename, size_t... _Indices>
4294 using _IdxTuple = _Index_tuple<_Indices...>;
4295
4296 // Clang defines __make_integer_seq for this purpose.
4297 using __type = __make_integer_seq<_IdxTuple, size_t, _Num>;
4298#else
4299 // For GCC and other compilers, use __integer_pack instead.
4300 using __type = _Index_tuple<__integer_pack(_Num)...>;
4301#endif
4302 };
4303#endif // C++11
4304
4305 /// @} group metaprogramming
4306
4307_GLIBCXX_END_NAMESPACE_VERSION
4308} // namespace std
4309} // extern "C++"
4310
4311#endif // C++11
4312
4313#endif // _GLIBCXX_TYPE_TRAITS