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