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