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