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