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