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