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