libstdc++
type_traits
Go to the documentation of this file.
1 // C++11 <type_traits> -*- C++ -*-
2 
3 // Copyright (C) 2007-2013 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>
58  {
59  static constexpr _Tp value = __v;
60  typedef _Tp value_type;
62  constexpr operator value_type() const { return value; }
63 #if __cplusplus > 201103L
64  constexpr value_type operator()() const { return value; }
65 #endif
66  };
67 
68  template<typename _Tp, _Tp __v>
70 
71  /// The type used as a compile-time boolean with true value.
73 
74  /// The type used as a compile-time boolean with false value.
76 
77  // Meta programming helper types.
78 
79  template<bool, typename, typename>
80  struct conditional;
81 
82  template<typename...>
83  struct __or_;
84 
85  template<>
86  struct __or_<>
87  : public false_type
88  { };
89 
90  template<typename _B1>
91  struct __or_<_B1>
92  : public _B1
93  { };
94 
95  template<typename _B1, typename _B2>
96  struct __or_<_B1, _B2>
97  : public conditional<_B1::value, _B1, _B2>::type
98  { };
99 
100  template<typename _B1, typename _B2, typename _B3, typename... _Bn>
101  struct __or_<_B1, _B2, _B3, _Bn...>
102  : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
103  { };
104 
105  template<typename...>
106  struct __and_;
107 
108  template<>
109  struct __and_<>
110  : public true_type
111  { };
112 
113  template<typename _B1>
114  struct __and_<_B1>
115  : public _B1
116  { };
117 
118  template<typename _B1, typename _B2>
119  struct __and_<_B1, _B2>
120  : public conditional<_B1::value, _B2, _B1>::type
121  { };
122 
123  template<typename _B1, typename _B2, typename _B3, typename... _Bn>
124  struct __and_<_B1, _B2, _B3, _Bn...>
125  : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
126  { };
127 
128  template<typename _Pp>
129  struct __not_
130  : public integral_constant<bool, !_Pp::value>
131  { };
132 
133  // For several sfinae-friendly trait implementations we transport both the
134  // result information (as the member type) and the failure information (no
135  // member type). This is very similar to std::enable_if, but we cannot use
136  // them, because we need to derive from them as an implementation detail.
137 
138  template<typename _Tp>
139  struct __success_type
140  { typedef _Tp type; };
141 
142  struct __failure_type
143  { };
144 
145  // Primary type categories.
146 
147  template<typename>
148  struct remove_cv;
149 
150  template<typename>
151  struct __is_void_helper
152  : public false_type { };
153 
154  template<>
155  struct __is_void_helper<void>
156  : public true_type { };
157 
158  /// is_void
159  template<typename _Tp>
160  struct is_void
161  : public __is_void_helper<typename remove_cv<_Tp>::type>::type
162  { };
163 
164  template<typename>
165  struct __is_integral_helper
166  : public false_type { };
167 
168  template<>
169  struct __is_integral_helper<bool>
170  : public true_type { };
171 
172  template<>
173  struct __is_integral_helper<char>
174  : public true_type { };
175 
176  template<>
177  struct __is_integral_helper<signed char>
178  : public true_type { };
179 
180  template<>
181  struct __is_integral_helper<unsigned char>
182  : public true_type { };
183 
184 #ifdef _GLIBCXX_USE_WCHAR_T
185  template<>
186  struct __is_integral_helper<wchar_t>
187  : public true_type { };
188 #endif
189 
190  template<>
191  struct __is_integral_helper<char16_t>
192  : public true_type { };
193 
194  template<>
195  struct __is_integral_helper<char32_t>
196  : public true_type { };
197 
198  template<>
199  struct __is_integral_helper<short>
200  : public true_type { };
201 
202  template<>
203  struct __is_integral_helper<unsigned short>
204  : public true_type { };
205 
206  template<>
207  struct __is_integral_helper<int>
208  : public true_type { };
209 
210  template<>
211  struct __is_integral_helper<unsigned int>
212  : public true_type { };
213 
214  template<>
215  struct __is_integral_helper<long>
216  : public true_type { };
217 
218  template<>
219  struct __is_integral_helper<unsigned long>
220  : public true_type { };
221 
222  template<>
223  struct __is_integral_helper<long long>
224  : public true_type { };
225 
226  template<>
227  struct __is_integral_helper<unsigned long long>
228  : public true_type { };
229 
230 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
231  template<>
232  struct __is_integral_helper<__int128>
233  : public true_type { };
234 
235  template<>
236  struct __is_integral_helper<unsigned __int128>
237  : public true_type { };
238 #endif
239 
240  /// is_integral
241  template<typename _Tp>
242  struct is_integral
243  : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
244  { };
245 
246  template<typename>
247  struct __is_floating_point_helper
248  : public false_type { };
249 
250  template<>
251  struct __is_floating_point_helper<float>
252  : public true_type { };
253 
254  template<>
255  struct __is_floating_point_helper<double>
256  : public true_type { };
257 
258  template<>
259  struct __is_floating_point_helper<long double>
260  : public true_type { };
261 
262 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
263  template<>
264  struct __is_floating_point_helper<__float128>
265  : public true_type { };
266 #endif
267 
268  /// is_floating_point
269  template<typename _Tp>
271  : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type
272  { };
273 
274  /// is_array
275  template<typename>
276  struct is_array
277  : public false_type { };
278 
279  template<typename _Tp, std::size_t _Size>
280  struct is_array<_Tp[_Size]>
281  : public true_type { };
282 
283  template<typename _Tp>
284  struct is_array<_Tp[]>
285  : public true_type { };
286 
287  template<typename>
288  struct __is_pointer_helper
289  : public false_type { };
290 
291  template<typename _Tp>
292  struct __is_pointer_helper<_Tp*>
293  : public true_type { };
294 
295  /// is_pointer
296  template<typename _Tp>
297  struct is_pointer
298  : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type
299  { };
300 
301  /// is_lvalue_reference
302  template<typename>
304  : public false_type { };
305 
306  template<typename _Tp>
307  struct is_lvalue_reference<_Tp&>
308  : public true_type { };
309 
310  /// is_rvalue_reference
311  template<typename>
313  : public false_type { };
314 
315  template<typename _Tp>
316  struct is_rvalue_reference<_Tp&&>
317  : public true_type { };
318 
319  template<typename>
320  struct is_function;
321 
322  template<typename>
323  struct __is_member_object_pointer_helper
324  : public false_type { };
325 
326  template<typename _Tp, typename _Cp>
327  struct __is_member_object_pointer_helper<_Tp _Cp::*>
328  : public integral_constant<bool, !is_function<_Tp>::value> { };
329 
330  /// is_member_object_pointer
331  template<typename _Tp>
333  : public __is_member_object_pointer_helper<
334  typename remove_cv<_Tp>::type>::type
335  { };
336 
337  template<typename>
338  struct __is_member_function_pointer_helper
339  : public false_type { };
340 
341  template<typename _Tp, typename _Cp>
342  struct __is_member_function_pointer_helper<_Tp _Cp::*>
343  : public integral_constant<bool, is_function<_Tp>::value> { };
344 
345  /// is_member_function_pointer
346  template<typename _Tp>
348  : public __is_member_function_pointer_helper<
349  typename remove_cv<_Tp>::type>::type
350  { };
351 
352  /// is_enum
353  template<typename _Tp>
354  struct is_enum
355  : public integral_constant<bool, __is_enum(_Tp)>
356  { };
357 
358  /// is_union
359  template<typename _Tp>
360  struct is_union
361  : public integral_constant<bool, __is_union(_Tp)>
362  { };
363 
364  /// is_class
365  template<typename _Tp>
366  struct is_class
367  : public integral_constant<bool, __is_class(_Tp)>
368  { };
369 
370  /// is_function
371  template<typename>
372  struct is_function
373  : public false_type { };
374 
375  template<typename _Res, typename... _ArgTypes>
376  struct is_function<_Res(_ArgTypes...)>
377  : public true_type { };
378 
379  template<typename _Res, typename... _ArgTypes>
380  struct is_function<_Res(_ArgTypes...) &>
381  : public true_type { };
382 
383  template<typename _Res, typename... _ArgTypes>
384  struct is_function<_Res(_ArgTypes...) &&>
385  : public true_type { };
386 
387  template<typename _Res, typename... _ArgTypes>
388  struct is_function<_Res(_ArgTypes......)>
389  : public true_type { };
390 
391  template<typename _Res, typename... _ArgTypes>
392  struct is_function<_Res(_ArgTypes......) &>
393  : public true_type { };
394 
395  template<typename _Res, typename... _ArgTypes>
396  struct is_function<_Res(_ArgTypes......) &&>
397  : public true_type { };
398 
399  template<typename _Res, typename... _ArgTypes>
400  struct is_function<_Res(_ArgTypes...) const>
401  : public true_type { };
402 
403  template<typename _Res, typename... _ArgTypes>
404  struct is_function<_Res(_ArgTypes...) const &>
405  : public true_type { };
406 
407  template<typename _Res, typename... _ArgTypes>
408  struct is_function<_Res(_ArgTypes...) const &&>
409  : public true_type { };
410 
411  template<typename _Res, typename... _ArgTypes>
412  struct is_function<_Res(_ArgTypes......) const>
413  : public true_type { };
414 
415  template<typename _Res, typename... _ArgTypes>
416  struct is_function<_Res(_ArgTypes......) const &>
417  : public true_type { };
418 
419  template<typename _Res, typename... _ArgTypes>
420  struct is_function<_Res(_ArgTypes......) const &&>
421  : public true_type { };
422 
423  template<typename _Res, typename... _ArgTypes>
424  struct is_function<_Res(_ArgTypes...) volatile>
425  : public true_type { };
426 
427  template<typename _Res, typename... _ArgTypes>
428  struct is_function<_Res(_ArgTypes...) volatile &>
429  : public true_type { };
430 
431  template<typename _Res, typename... _ArgTypes>
432  struct is_function<_Res(_ArgTypes...) volatile &&>
433  : public true_type { };
434 
435  template<typename _Res, typename... _ArgTypes>
436  struct is_function<_Res(_ArgTypes......) volatile>
437  : public true_type { };
438 
439  template<typename _Res, typename... _ArgTypes>
440  struct is_function<_Res(_ArgTypes......) volatile &>
441  : public true_type { };
442 
443  template<typename _Res, typename... _ArgTypes>
444  struct is_function<_Res(_ArgTypes......) volatile &&>
445  : public true_type { };
446 
447  template<typename _Res, typename... _ArgTypes>
448  struct is_function<_Res(_ArgTypes...) const volatile>
449  : public true_type { };
450 
451  template<typename _Res, typename... _ArgTypes>
452  struct is_function<_Res(_ArgTypes...) const volatile &>
453  : public true_type { };
454 
455  template<typename _Res, typename... _ArgTypes>
456  struct is_function<_Res(_ArgTypes...) const volatile &&>
457  : public true_type { };
458 
459  template<typename _Res, typename... _ArgTypes>
460  struct is_function<_Res(_ArgTypes......) const volatile>
461  : public true_type { };
462 
463  template<typename _Res, typename... _ArgTypes>
464  struct is_function<_Res(_ArgTypes......) const volatile &>
465  : public true_type { };
466 
467  template<typename _Res, typename... _ArgTypes>
468  struct is_function<_Res(_ArgTypes......) const volatile &&>
469  : public true_type { };
470 
471  template<typename>
472  struct __is_null_pointer_helper
473  : public false_type { };
474 
475  template<>
476  struct __is_null_pointer_helper<std::nullptr_t>
477  : public true_type { };
478 
479  /// is_null_pointer (LWG 2247).
480  template<typename _Tp>
482  : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type
483  { };
484 
485  /// __is_nullptr_t (extension).
486  template<typename _Tp>
488  : public is_null_pointer<_Tp>
489  { };
490 
491  // Composite type categories.
492 
493  /// is_reference
494  template<typename _Tp>
496  : public __or_<is_lvalue_reference<_Tp>,
497  is_rvalue_reference<_Tp>>::type
498  { };
499 
500  /// is_arithmetic
501  template<typename _Tp>
503  : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
504  { };
505 
506  /// is_fundamental
507  template<typename _Tp>
509  : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
510  is_null_pointer<_Tp>>::type
511  { };
512 
513  /// is_object
514  template<typename _Tp>
515  struct is_object
516  : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
517  is_void<_Tp>>>::type
518  { };
519 
520  template<typename>
522 
523  /// is_scalar
524  template<typename _Tp>
525  struct is_scalar
526  : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
527  is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
528  { };
529 
530  /// is_compound
531  template<typename _Tp>
532  struct is_compound
533  : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
534 
535  template<typename _Tp>
536  struct __is_member_pointer_helper
537  : public false_type { };
538 
539  template<typename _Tp, typename _Cp>
540  struct __is_member_pointer_helper<_Tp _Cp::*>
541  : public true_type { };
542 
543  /// is_member_pointer
544  template<typename _Tp>
545  struct is_member_pointer
546  : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
547  { };
548 
549  // Utility to detect referenceable types ([defns.referenceable]).
550 
551  template<typename _Tp>
552  struct __is_referenceable
553  : public __or_<is_object<_Tp>, is_reference<_Tp>>::type
554  { };
555 
556  template<typename _Res, typename... _Args>
557  struct __is_referenceable<_Res(_Args...)>
558  : public true_type
559  { };
560 
561  template<typename _Res, typename... _Args>
562  struct __is_referenceable<_Res(_Args......)>
563  : public true_type
564  { };
565 
566  // Type properties.
567 
568  /// is_const
569  template<typename>
570  struct is_const
571  : public false_type { };
572 
573  template<typename _Tp>
574  struct is_const<_Tp const>
575  : public true_type { };
576 
577  /// is_volatile
578  template<typename>
579  struct is_volatile
580  : public false_type { };
581 
582  template<typename _Tp>
583  struct is_volatile<_Tp volatile>
584  : public true_type { };
585 
586  /// is_trivial
587  template<typename _Tp>
588  struct is_trivial
589  : public integral_constant<bool, __is_trivial(_Tp)>
590  { };
591 
592  // is_trivially_copyable (still unimplemented)
593 
594  /// is_standard_layout
595  template<typename _Tp>
597  : public integral_constant<bool, __is_standard_layout(_Tp)>
598  { };
599 
600  /// is_pod
601  // Could use is_standard_layout && is_trivial instead of the builtin.
602  template<typename _Tp>
603  struct is_pod
604  : public integral_constant<bool, __is_pod(_Tp)>
605  { };
606 
607  /// is_literal_type
608  template<typename _Tp>
610  : public integral_constant<bool, __is_literal_type(_Tp)>
611  { };
612 
613  /// is_empty
614  template<typename _Tp>
615  struct is_empty
616  : public integral_constant<bool, __is_empty(_Tp)>
617  { };
618 
619  /// is_polymorphic
620  template<typename _Tp>
622  : public integral_constant<bool, __is_polymorphic(_Tp)>
623  { };
624 
625  /// is_abstract
626  template<typename _Tp>
627  struct is_abstract
628  : public integral_constant<bool, __is_abstract(_Tp)>
629  { };
630 
631  template<typename _Tp,
633  struct __is_signed_helper
634  : public false_type { };
635 
636  template<typename _Tp>
637  struct __is_signed_helper<_Tp, true>
638  : public integral_constant<bool, _Tp(-1) < _Tp(0)>
639  { };
640 
641  /// is_signed
642  template<typename _Tp>
643  struct is_signed
644  : public __is_signed_helper<_Tp>::type
645  { };
646 
647  /// is_unsigned
648  template<typename _Tp>
649  struct is_unsigned
650  : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
651  { };
652 
653 
654  // Destructible and constructible type properties.
655 
656  template<typename>
657  struct add_rvalue_reference;
658 
659  /**
660  * @brief Utility to simplify expressions used in unevaluated operands
661  * @ingroup utilities
662  */
663  template<typename _Tp>
664  typename add_rvalue_reference<_Tp>::type declval() noexcept;
665 
666  template<typename, unsigned = 0>
667  struct extent;
668 
669  template<typename>
670  struct remove_all_extents;
671 
672  template<typename _Tp>
673  struct __is_array_known_bounds
674  : public integral_constant<bool, (extent<_Tp>::value > 0)>
675  { };
676 
677  template<typename _Tp>
678  struct __is_array_unknown_bounds
679  : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
680  { };
681 
682  // In N3290 is_destructible does not say anything about function
683  // types and abstract types, see LWG 2049. This implementation
684  // describes function types as non-destructible and all complete
685  // object types as destructible, iff the explicit destructor
686  // call expression is wellformed.
687  struct __do_is_destructible_impl
688  {
689  template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
690  static true_type __test(int);
691 
692  template<typename>
693  static false_type __test(...);
694  };
695 
696  template<typename _Tp>
697  struct __is_destructible_impl
698  : public __do_is_destructible_impl
699  {
700  typedef decltype(__test<_Tp>(0)) type;
701  };
702 
703  template<typename _Tp,
704  bool = __or_<is_void<_Tp>,
705  __is_array_unknown_bounds<_Tp>,
706  is_function<_Tp>>::value,
707  bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
708  struct __is_destructible_safe;
709 
710  template<typename _Tp>
711  struct __is_destructible_safe<_Tp, false, false>
712  : public __is_destructible_impl<typename
713  remove_all_extents<_Tp>::type>::type
714  { };
715 
716  template<typename _Tp>
717  struct __is_destructible_safe<_Tp, true, false>
718  : public false_type { };
719 
720  template<typename _Tp>
721  struct __is_destructible_safe<_Tp, false, true>
722  : public true_type { };
723 
724  /// is_destructible
725  template<typename _Tp>
726  struct is_destructible
727  : public __is_destructible_safe<_Tp>::type
728  { };
729 
730  // is_nothrow_destructible requires that is_destructible is
731  // satisfied as well. We realize that by mimicing the
732  // implementation of is_destructible but refer to noexcept(expr)
733  // instead of decltype(expr).
734  struct __do_is_nt_destructible_impl
735  {
736  template<typename _Tp>
737  static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
738  __test(int);
739 
740  template<typename>
741  static false_type __test(...);
742  };
743 
744  template<typename _Tp>
745  struct __is_nt_destructible_impl
746  : public __do_is_nt_destructible_impl
747  {
748  typedef decltype(__test<_Tp>(0)) type;
749  };
750 
751  template<typename _Tp,
752  bool = __or_<is_void<_Tp>,
753  __is_array_unknown_bounds<_Tp>,
754  is_function<_Tp>>::value,
755  bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
756  struct __is_nt_destructible_safe;
757 
758  template<typename _Tp>
759  struct __is_nt_destructible_safe<_Tp, false, false>
760  : public __is_nt_destructible_impl<typename
761  remove_all_extents<_Tp>::type>::type
762  { };
763 
764  template<typename _Tp>
765  struct __is_nt_destructible_safe<_Tp, true, false>
766  : public false_type { };
767 
768  template<typename _Tp>
769  struct __is_nt_destructible_safe<_Tp, false, true>
770  : public true_type { };
771 
772  /// is_nothrow_destructible
773  template<typename _Tp>
774  struct is_nothrow_destructible
775  : public __is_nt_destructible_safe<_Tp>::type
776  { };
777 
778  struct __do_is_default_constructible_impl
779  {
780  template<typename _Tp, typename = decltype(_Tp())>
781  static true_type __test(int);
782 
783  template<typename>
784  static false_type __test(...);
785  };
786 
787  template<typename _Tp>
788  struct __is_default_constructible_impl
789  : public __do_is_default_constructible_impl
790  {
791  typedef decltype(__test<_Tp>(0)) type;
792  };
793 
794  template<typename _Tp>
795  struct __is_default_constructible_atom
796  : public __and_<__not_<is_void<_Tp>>,
797  __is_default_constructible_impl<_Tp>>::type
798  { };
799 
800  template<typename _Tp, bool = is_array<_Tp>::value>
801  struct __is_default_constructible_safe;
802 
803  // The following technique is a workaround for a current core language
804  // restriction, which does not allow for array types to occur in
805  // functional casts of the form T(). Complete arrays can be default-
806  // constructed, if the element type is default-constructible, but
807  // arrays with unknown bounds are not.
808  template<typename _Tp>
809  struct __is_default_constructible_safe<_Tp, true>
810  : public __and_<__is_array_known_bounds<_Tp>,
811  __is_default_constructible_atom<typename
812  remove_all_extents<_Tp>::type>>::type
813  { };
814 
815  template<typename _Tp>
816  struct __is_default_constructible_safe<_Tp, false>
817  : public __is_default_constructible_atom<_Tp>::type
818  { };
819 
820  /// is_default_constructible
821  template<typename _Tp>
822  struct is_default_constructible
823  : public __is_default_constructible_safe<_Tp>::type
824  { };
825 
826 
827  // Implementation of is_constructible.
828 
829  // The hardest part of this trait is the binary direct-initialization
830  // case, because we hit into a functional cast of the form T(arg).
831  // This implementation uses different strategies depending on the
832  // target type to reduce the test overhead as much as possible:
833  //
834  // a) For a reference target type, we use a static_cast expression
835  // modulo its extra cases.
836  //
837  // b) For a non-reference target type we use a ::new expression.
838  struct __do_is_static_castable_impl
839  {
840  template<typename _From, typename _To, typename
841  = decltype(static_cast<_To>(declval<_From>()))>
842  static true_type __test(int);
843 
844  template<typename, typename>
845  static false_type __test(...);
846  };
847 
848  template<typename _From, typename _To>
849  struct __is_static_castable_impl
850  : public __do_is_static_castable_impl
851  {
852  typedef decltype(__test<_From, _To>(0)) type;
853  };
854 
855  template<typename _From, typename _To>
856  struct __is_static_castable_safe
857  : public __is_static_castable_impl<_From, _To>::type
858  { };
859 
860  // __is_static_castable
861  template<typename _From, typename _To>
862  struct __is_static_castable
863  : public integral_constant<bool, (__is_static_castable_safe<
864  _From, _To>::value)>
865  { };
866 
867  // Implementation for non-reference types. To meet the proper
868  // variable definition semantics, we also need to test for
869  // is_destructible in this case.
870  // This form should be simplified by a single expression:
871  // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
872  struct __do_is_direct_constructible_impl
873  {
874  template<typename _Tp, typename _Arg, typename
875  = decltype(::new _Tp(declval<_Arg>()))>
876  static true_type __test(int);
877 
878  template<typename, typename>
879  static false_type __test(...);
880  };
881 
882  template<typename _Tp, typename _Arg>
883  struct __is_direct_constructible_impl
884  : public __do_is_direct_constructible_impl
885  {
886  typedef decltype(__test<_Tp, _Arg>(0)) type;
887  };
888 
889  template<typename _Tp, typename _Arg>
890  struct __is_direct_constructible_new_safe
891  : public __and_<is_destructible<_Tp>,
892  __is_direct_constructible_impl<_Tp, _Arg>>::type
893  { };
894 
895  template<typename, typename>
896  struct is_same;
897 
898  template<typename, typename>
899  struct is_base_of;
900 
901  template<typename>
902  struct remove_reference;
903 
904  template<typename _From, typename _To, bool
905  = __not_<__or_<is_void<_From>,
906  is_function<_From>>>::value>
907  struct __is_base_to_derived_ref;
908 
909  // Detect whether we have a downcast situation during
910  // reference binding.
911  template<typename _From, typename _To>
912  struct __is_base_to_derived_ref<_From, _To, true>
913  {
914  typedef typename remove_cv<typename remove_reference<_From
915  >::type>::type __src_t;
916  typedef typename remove_cv<typename remove_reference<_To
917  >::type>::type __dst_t;
918  typedef __and_<__not_<is_same<__src_t, __dst_t>>,
919  is_base_of<__src_t, __dst_t>> type;
920  static constexpr bool value = type::value;
921  };
922 
923  template<typename _From, typename _To>
924  struct __is_base_to_derived_ref<_From, _To, false>
925  : public false_type
926  { };
927 
928  template<typename _From, typename _To, bool
929  = __and_<is_lvalue_reference<_From>,
930  is_rvalue_reference<_To>>::value>
931  struct __is_lvalue_to_rvalue_ref;
932 
933  // Detect whether we have an lvalue of non-function type
934  // bound to a reference-compatible rvalue-reference.
935  template<typename _From, typename _To>
936  struct __is_lvalue_to_rvalue_ref<_From, _To, true>
937  {
938  typedef typename remove_cv<typename remove_reference<
939  _From>::type>::type __src_t;
940  typedef typename remove_cv<typename remove_reference<
941  _To>::type>::type __dst_t;
942  typedef __and_<__not_<is_function<__src_t>>,
943  __or_<is_same<__src_t, __dst_t>,
944  is_base_of<__dst_t, __src_t>>> type;
945  static constexpr bool value = type::value;
946  };
947 
948  template<typename _From, typename _To>
949  struct __is_lvalue_to_rvalue_ref<_From, _To, false>
950  : public false_type
951  { };
952 
953  // Here we handle direct-initialization to a reference type as
954  // equivalent to a static_cast modulo overshooting conversions.
955  // These are restricted to the following conversions:
956  // a) A base class value to a derived class reference
957  // b) An lvalue to an rvalue-reference of reference-compatible
958  // types that are not functions
959  template<typename _Tp, typename _Arg>
960  struct __is_direct_constructible_ref_cast
961  : public __and_<__is_static_castable<_Arg, _Tp>,
962  __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
963  __is_lvalue_to_rvalue_ref<_Arg, _Tp>
964  >>>::type
965  { };
966 
967  template<typename _Tp, typename _Arg>
968  struct __is_direct_constructible_new
969  : public conditional<is_reference<_Tp>::value,
970  __is_direct_constructible_ref_cast<_Tp, _Arg>,
971  __is_direct_constructible_new_safe<_Tp, _Arg>
972  >::type
973  { };
974 
975  template<typename _Tp, typename _Arg>
976  struct __is_direct_constructible
977  : public __is_direct_constructible_new<_Tp, _Arg>::type
978  { };
979 
980  // Since default-construction and binary direct-initialization have
981  // been handled separately, the implementation of the remaining
982  // n-ary construction cases is rather straightforward. We can use
983  // here a functional cast, because array types are excluded anyway
984  // and this form is never interpreted as a C cast.
985  struct __do_is_nary_constructible_impl
986  {
987  template<typename _Tp, typename... _Args, typename
988  = decltype(_Tp(declval<_Args>()...))>
989  static true_type __test(int);
990 
991  template<typename, typename...>
992  static false_type __test(...);
993  };
994 
995  template<typename _Tp, typename... _Args>
996  struct __is_nary_constructible_impl
997  : public __do_is_nary_constructible_impl
998  {
999  typedef decltype(__test<_Tp, _Args...>(0)) type;
1000  };
1001 
1002  template<typename _Tp, typename... _Args>
1003  struct __is_nary_constructible
1004  : public __is_nary_constructible_impl<_Tp, _Args...>::type
1005  {
1006  static_assert(sizeof...(_Args) > 1,
1007  "Only useful for > 1 arguments");
1008  };
1009 
1010  template<typename _Tp, typename... _Args>
1011  struct __is_constructible_impl
1012  : public __is_nary_constructible<_Tp, _Args...>
1013  { };
1014 
1015  template<typename _Tp, typename _Arg>
1016  struct __is_constructible_impl<_Tp, _Arg>
1017  : public __is_direct_constructible<_Tp, _Arg>
1018  { };
1019 
1020  template<typename _Tp>
1021  struct __is_constructible_impl<_Tp>
1022  : public is_default_constructible<_Tp>
1023  { };
1024 
1025  /// is_constructible
1026  template<typename _Tp, typename... _Args>
1027  struct is_constructible
1028  : public __is_constructible_impl<_Tp, _Args...>::type
1029  { };
1030 
1031  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1032  struct __is_copy_constructible_impl;
1033 
1034  template<typename _Tp>
1035  struct __is_copy_constructible_impl<_Tp, false>
1036  : public false_type { };
1037 
1038  template<typename _Tp>
1039  struct __is_copy_constructible_impl<_Tp, true>
1040  : public is_constructible<_Tp, const _Tp&>
1041  { };
1042 
1043  /// is_copy_constructible
1044  template<typename _Tp>
1045  struct is_copy_constructible
1046  : public __is_copy_constructible_impl<_Tp>
1047  { };
1048 
1049  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1050  struct __is_move_constructible_impl;
1051 
1052  template<typename _Tp>
1053  struct __is_move_constructible_impl<_Tp, false>
1054  : public false_type { };
1055 
1056  template<typename _Tp>
1057  struct __is_move_constructible_impl<_Tp, true>
1058  : public is_constructible<_Tp, _Tp&&>
1059  { };
1060 
1061  /// is_move_constructible
1062  template<typename _Tp>
1063  struct is_move_constructible
1064  : public __is_move_constructible_impl<_Tp>
1065  { };
1066 
1067  template<typename _Tp>
1068  struct __is_nt_default_constructible_atom
1069  : public integral_constant<bool, noexcept(_Tp())>
1070  { };
1071 
1072  template<typename _Tp, bool = is_array<_Tp>::value>
1073  struct __is_nt_default_constructible_impl;
1074 
1075  template<typename _Tp>
1076  struct __is_nt_default_constructible_impl<_Tp, true>
1077  : public __and_<__is_array_known_bounds<_Tp>,
1078  __is_nt_default_constructible_atom<typename
1079  remove_all_extents<_Tp>::type>>::type
1080  { };
1081 
1082  template<typename _Tp>
1083  struct __is_nt_default_constructible_impl<_Tp, false>
1084  : public __is_nt_default_constructible_atom<_Tp>
1085  { };
1086 
1087  /// is_nothrow_default_constructible
1088  template<typename _Tp>
1089  struct is_nothrow_default_constructible
1090  : public __and_<is_default_constructible<_Tp>,
1091  __is_nt_default_constructible_impl<_Tp>>::type
1092  { };
1093 
1094  template<typename _Tp, typename... _Args>
1095  struct __is_nt_constructible_impl
1096  : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1097  { };
1098 
1099  template<typename _Tp, typename _Arg>
1100  struct __is_nt_constructible_impl<_Tp, _Arg>
1101  : public integral_constant<bool,
1102  noexcept(static_cast<_Tp>(declval<_Arg>()))>
1103  { };
1104 
1105  template<typename _Tp>
1106  struct __is_nt_constructible_impl<_Tp>
1107  : public is_nothrow_default_constructible<_Tp>
1108  { };
1109 
1110  /// is_nothrow_constructible
1111  template<typename _Tp, typename... _Args>
1112  struct is_nothrow_constructible
1113  : public __and_<is_constructible<_Tp, _Args...>,
1114  __is_nt_constructible_impl<_Tp, _Args...>>::type
1115  { };
1116 
1117  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1118  struct __is_nothrow_copy_constructible_impl;
1119 
1120  template<typename _Tp>
1121  struct __is_nothrow_copy_constructible_impl<_Tp, false>
1122  : public false_type { };
1123 
1124  template<typename _Tp>
1125  struct __is_nothrow_copy_constructible_impl<_Tp, true>
1126  : public is_nothrow_constructible<_Tp, const _Tp&>
1127  { };
1128 
1129  /// is_nothrow_copy_constructible
1130  template<typename _Tp>
1131  struct is_nothrow_copy_constructible
1132  : public __is_nothrow_copy_constructible_impl<_Tp>
1133  { };
1134 
1135  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1136  struct __is_nothrow_move_constructible_impl;
1137 
1138  template<typename _Tp>
1139  struct __is_nothrow_move_constructible_impl<_Tp, false>
1140  : public false_type { };
1141 
1142  template<typename _Tp>
1143  struct __is_nothrow_move_constructible_impl<_Tp, true>
1144  : public is_nothrow_constructible<_Tp, _Tp&&>
1145  { };
1146 
1147  /// is_nothrow_move_constructible
1148  template<typename _Tp>
1149  struct is_nothrow_move_constructible
1150  : public __is_nothrow_move_constructible_impl<_Tp>
1151  { };
1152 
1153  template<typename _Tp, typename _Up>
1154  class __is_assignable_helper
1155  {
1156  template<typename _Tp1, typename _Up1,
1157  typename = decltype(declval<_Tp1>() = declval<_Up1>())>
1158  static true_type
1159  __test(int);
1160 
1161  template<typename, typename>
1162  static false_type
1163  __test(...);
1164 
1165  public:
1166  typedef decltype(__test<_Tp, _Up>(0)) type;
1167  };
1168 
1169  /// is_assignable
1170  template<typename _Tp, typename _Up>
1171  struct is_assignable
1172  : public __is_assignable_helper<_Tp, _Up>::type
1173  { };
1174 
1175  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1176  struct __is_copy_assignable_impl;
1177 
1178  template<typename _Tp>
1179  struct __is_copy_assignable_impl<_Tp, false>
1180  : public false_type { };
1181 
1182  template<typename _Tp>
1183  struct __is_copy_assignable_impl<_Tp, true>
1184  : public is_assignable<_Tp&, const _Tp&>
1185  { };
1186 
1187  /// is_copy_assignable
1188  template<typename _Tp>
1189  struct is_copy_assignable
1190  : public __is_copy_assignable_impl<_Tp>
1191  { };
1192 
1193  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1194  struct __is_move_assignable_impl;
1195 
1196  template<typename _Tp>
1197  struct __is_move_assignable_impl<_Tp, false>
1198  : public false_type { };
1199 
1200  template<typename _Tp>
1201  struct __is_move_assignable_impl<_Tp, true>
1202  : public is_assignable<_Tp&, _Tp&&>
1203  { };
1204 
1205  /// is_move_assignable
1206  template<typename _Tp>
1207  struct is_move_assignable
1208  : public __is_move_assignable_impl<_Tp>
1209  { };
1210 
1211  template<typename _Tp, typename _Up>
1212  struct __is_nt_assignable_impl
1213  : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1214  { };
1215 
1216  /// is_nothrow_assignable
1217  template<typename _Tp, typename _Up>
1218  struct is_nothrow_assignable
1219  : public __and_<is_assignable<_Tp, _Up>,
1220  __is_nt_assignable_impl<_Tp, _Up>>::type
1221  { };
1222 
1223  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1224  struct __is_nt_copy_assignable_impl;
1225 
1226  template<typename _Tp>
1227  struct __is_nt_copy_assignable_impl<_Tp, false>
1228  : public false_type { };
1229 
1230  template<typename _Tp>
1231  struct __is_nt_copy_assignable_impl<_Tp, true>
1232  : public is_nothrow_assignable<_Tp&, const _Tp&>
1233  { };
1234 
1235  /// is_nothrow_copy_assignable
1236  template<typename _Tp>
1237  struct is_nothrow_copy_assignable
1238  : public __is_nt_copy_assignable_impl<_Tp>
1239  { };
1240 
1241  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1242  struct __is_nt_move_assignable_impl;
1243 
1244  template<typename _Tp>
1245  struct __is_nt_move_assignable_impl<_Tp, false>
1246  : public false_type { };
1247 
1248  template<typename _Tp>
1249  struct __is_nt_move_assignable_impl<_Tp, true>
1250  : public is_nothrow_assignable<_Tp&, _Tp&&>
1251  { };
1252 
1253  /// is_nothrow_move_assignable
1254  template<typename _Tp>
1255  struct is_nothrow_move_assignable
1256  : public __is_nt_move_assignable_impl<_Tp>
1257  { };
1258 
1259  /// is_trivially_constructible (still unimplemented)
1260 
1261  /// is_trivially_default_constructible (still unimplemented)
1262 
1263  /// is_trivially_copy_constructible (still unimplemented)
1264 
1265  /// is_trivially_move_constructible (still unimplemented)
1266 
1267  /// is_trivially_assignable (still unimplemented)
1268 
1269  /// is_trivially_copy_assignable (still unimplemented)
1270 
1271  /// is_trivially_move_assignable (still unimplemented)
1272 
1273  /// is_trivially_destructible
1274  template<typename _Tp>
1275  struct is_trivially_destructible
1276  : public __and_<is_destructible<_Tp>, integral_constant<bool,
1277  __has_trivial_destructor(_Tp)>>::type
1278  { };
1279 
1280  /// has_trivial_default_constructor (temporary legacy)
1281  template<typename _Tp>
1282  struct has_trivial_default_constructor
1283  : public integral_constant<bool, __has_trivial_constructor(_Tp)>
1284  { };
1285 
1286  /// has_trivial_copy_constructor (temporary legacy)
1287  template<typename _Tp>
1288  struct has_trivial_copy_constructor
1289  : public integral_constant<bool, __has_trivial_copy(_Tp)>
1290  { };
1291 
1292  /// has_trivial_copy_assign (temporary legacy)
1293  template<typename _Tp>
1294  struct has_trivial_copy_assign
1295  : public integral_constant<bool, __has_trivial_assign(_Tp)>
1296  { };
1297 
1298  /// has_virtual_destructor
1299  template<typename _Tp>
1300  struct has_virtual_destructor
1301  : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1302  { };
1303 
1304 
1305  // type property queries.
1306 
1307  /// alignment_of
1308  template<typename _Tp>
1309  struct alignment_of
1310  : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1311 
1312  /// rank
1313  template<typename>
1314  struct rank
1315  : public integral_constant<std::size_t, 0> { };
1316 
1317  template<typename _Tp, std::size_t _Size>
1318  struct rank<_Tp[_Size]>
1319  : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1320 
1321  template<typename _Tp>
1322  struct rank<_Tp[]>
1323  : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1324 
1325  /// extent
1326  template<typename, unsigned _Uint>
1327  struct extent
1328  : public integral_constant<std::size_t, 0> { };
1329 
1330  template<typename _Tp, unsigned _Uint, std::size_t _Size>
1331  struct extent<_Tp[_Size], _Uint>
1332  : public integral_constant<std::size_t,
1333  _Uint == 0 ? _Size : extent<_Tp,
1334  _Uint - 1>::value>
1335  { };
1336 
1337  template<typename _Tp, unsigned _Uint>
1338  struct extent<_Tp[], _Uint>
1339  : public integral_constant<std::size_t,
1340  _Uint == 0 ? 0 : extent<_Tp,
1341  _Uint - 1>::value>
1342  { };
1343 
1344 
1345  // Type relations.
1346 
1347  /// is_same
1348  template<typename, typename>
1349  struct is_same
1350  : public false_type { };
1351 
1352  template<typename _Tp>
1353  struct is_same<_Tp, _Tp>
1354  : public true_type { };
1355 
1356  /// is_base_of
1357  template<typename _Base, typename _Derived>
1358  struct is_base_of
1359  : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1360  { };
1361 
1362  template<typename _From, typename _To,
1363  bool = __or_<is_void<_From>, is_function<_To>,
1364  is_array<_To>>::value>
1365  struct __is_convertible_helper
1366  { typedef typename is_void<_To>::type type; };
1367 
1368  template<typename _From, typename _To>
1369  class __is_convertible_helper<_From, _To, false>
1370  {
1371  template<typename _To1>
1372  static void __test_aux(_To1);
1373 
1374  template<typename _From1, typename _To1,
1375  typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1376  static true_type
1377  __test(int);
1378 
1379  template<typename, typename>
1380  static false_type
1381  __test(...);
1382 
1383  public:
1384  typedef decltype(__test<_From, _To>(0)) type;
1385  };
1386 
1387 
1388  /// is_convertible
1389  template<typename _From, typename _To>
1390  struct is_convertible
1391  : public __is_convertible_helper<_From, _To>::type
1392  { };
1393 
1394 
1395  // Const-volatile modifications.
1396 
1397  /// remove_const
1398  template<typename _Tp>
1399  struct remove_const
1400  { typedef _Tp type; };
1401 
1402  template<typename _Tp>
1403  struct remove_const<_Tp const>
1404  { typedef _Tp type; };
1405 
1406  /// remove_volatile
1407  template<typename _Tp>
1408  struct remove_volatile
1409  { typedef _Tp type; };
1410 
1411  template<typename _Tp>
1412  struct remove_volatile<_Tp volatile>
1413  { typedef _Tp type; };
1414 
1415  /// remove_cv
1416  template<typename _Tp>
1417  struct remove_cv
1418  {
1419  typedef typename
1420  remove_const<typename remove_volatile<_Tp>::type>::type type;
1421  };
1422 
1423  /// add_const
1424  template<typename _Tp>
1425  struct add_const
1426  { typedef _Tp const type; };
1427 
1428  /// add_volatile
1429  template<typename _Tp>
1430  struct add_volatile
1431  { typedef _Tp volatile type; };
1432 
1433  /// add_cv
1434  template<typename _Tp>
1435  struct add_cv
1436  {
1437  typedef typename
1438  add_const<typename add_volatile<_Tp>::type>::type type;
1439  };
1440 
1441 
1442  // Reference transformations.
1443 
1444  /// remove_reference
1445  template<typename _Tp>
1446  struct remove_reference
1447  { typedef _Tp type; };
1448 
1449  template<typename _Tp>
1450  struct remove_reference<_Tp&>
1451  { typedef _Tp type; };
1452 
1453  template<typename _Tp>
1454  struct remove_reference<_Tp&&>
1455  { typedef _Tp type; };
1456 
1457  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1458  struct __add_lvalue_reference_helper
1459  { typedef _Tp type; };
1460 
1461  template<typename _Tp>
1462  struct __add_lvalue_reference_helper<_Tp, true>
1463  { typedef _Tp& type; };
1464 
1465  /// add_lvalue_reference
1466  template<typename _Tp>
1467  struct add_lvalue_reference
1468  : public __add_lvalue_reference_helper<_Tp>
1469  { };
1470 
1471  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
1472  struct __add_rvalue_reference_helper
1473  { typedef _Tp type; };
1474 
1475  template<typename _Tp>
1476  struct __add_rvalue_reference_helper<_Tp, true>
1477  { typedef _Tp&& type; };
1478 
1479  /// add_rvalue_reference
1480  template<typename _Tp>
1481  struct add_rvalue_reference
1482  : public __add_rvalue_reference_helper<_Tp>
1483  { };
1484 
1485 
1486  // Sign modifications.
1487 
1488  // Utility for constructing identically cv-qualified types.
1489  template<typename _Unqualified, bool _IsConst, bool _IsVol>
1490  struct __cv_selector;
1491 
1492  template<typename _Unqualified>
1493  struct __cv_selector<_Unqualified, false, false>
1494  { typedef _Unqualified __type; };
1495 
1496  template<typename _Unqualified>
1497  struct __cv_selector<_Unqualified, false, true>
1498  { typedef volatile _Unqualified __type; };
1499 
1500  template<typename _Unqualified>
1501  struct __cv_selector<_Unqualified, true, false>
1502  { typedef const _Unqualified __type; };
1503 
1504  template<typename _Unqualified>
1505  struct __cv_selector<_Unqualified, true, true>
1506  { typedef const volatile _Unqualified __type; };
1507 
1508  template<typename _Qualified, typename _Unqualified,
1509  bool _IsConst = is_const<_Qualified>::value,
1510  bool _IsVol = is_volatile<_Qualified>::value>
1511  class __match_cv_qualifiers
1512  {
1513  typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1514 
1515  public:
1516  typedef typename __match::__type __type;
1517  };
1518 
1519  // Utility for finding the unsigned versions of signed integral types.
1520  template<typename _Tp>
1521  struct __make_unsigned
1522  { typedef _Tp __type; };
1523 
1524  template<>
1525  struct __make_unsigned<char>
1526  { typedef unsigned char __type; };
1527 
1528  template<>
1529  struct __make_unsigned<signed char>
1530  { typedef unsigned char __type; };
1531 
1532  template<>
1533  struct __make_unsigned<short>
1534  { typedef unsigned short __type; };
1535 
1536  template<>
1537  struct __make_unsigned<int>
1538  { typedef unsigned int __type; };
1539 
1540  template<>
1541  struct __make_unsigned<long>
1542  { typedef unsigned long __type; };
1543 
1544  template<>
1545  struct __make_unsigned<long long>
1546  { typedef unsigned long long __type; };
1547 
1548 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1549  template<>
1550  struct __make_unsigned<__int128>
1551  { typedef unsigned __int128 __type; };
1552 #endif
1553 
1554  // Select between integral and enum: not possible to be both.
1555  template<typename _Tp,
1556  bool _IsInt = is_integral<_Tp>::value,
1557  bool _IsEnum = is_enum<_Tp>::value>
1558  class __make_unsigned_selector;
1559 
1560  template<typename _Tp>
1561  class __make_unsigned_selector<_Tp, true, false>
1562  {
1563  typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1564  typedef typename __unsignedt::__type __unsigned_type;
1565  typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1566 
1567  public:
1568  typedef typename __cv_unsigned::__type __type;
1569  };
1570 
1571  template<typename _Tp>
1572  class __make_unsigned_selector<_Tp, false, true>
1573  {
1574  // With -fshort-enums, an enum may be as small as a char.
1575  typedef unsigned char __smallest;
1576  static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1577  static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
1578  static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
1579  typedef conditional<__b2, unsigned int, unsigned long> __cond2;
1580  typedef typename __cond2::type __cond2_type;
1581  typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1582  typedef typename __cond1::type __cond1_type;
1583 
1584  public:
1585  typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1586  };
1587 
1588  // Given an integral/enum type, return the corresponding unsigned
1589  // integer type.
1590  // Primary template.
1591  /// make_unsigned
1592  template<typename _Tp>
1593  struct make_unsigned
1594  { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1595 
1596  // Integral, but don't define.
1597  template<>
1598  struct make_unsigned<bool>;
1599 
1600 
1601  // Utility for finding the signed versions of unsigned integral types.
1602  template<typename _Tp>
1603  struct __make_signed
1604  { typedef _Tp __type; };
1605 
1606  template<>
1607  struct __make_signed<char>
1608  { typedef signed char __type; };
1609 
1610  template<>
1611  struct __make_signed<unsigned char>
1612  { typedef signed char __type; };
1613 
1614  template<>
1615  struct __make_signed<unsigned short>
1616  { typedef signed short __type; };
1617 
1618  template<>
1619  struct __make_signed<unsigned int>
1620  { typedef signed int __type; };
1621 
1622  template<>
1623  struct __make_signed<unsigned long>
1624  { typedef signed long __type; };
1625 
1626  template<>
1627  struct __make_signed<unsigned long long>
1628  { typedef signed long long __type; };
1629 
1630 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1631  template<>
1632  struct __make_signed<unsigned __int128>
1633  { typedef __int128 __type; };
1634 #endif
1635 
1636  // Select between integral and enum: not possible to be both.
1637  template<typename _Tp,
1638  bool _IsInt = is_integral<_Tp>::value,
1639  bool _IsEnum = is_enum<_Tp>::value>
1640  class __make_signed_selector;
1641 
1642  template<typename _Tp>
1643  class __make_signed_selector<_Tp, true, false>
1644  {
1645  typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1646  typedef typename __signedt::__type __signed_type;
1647  typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1648 
1649  public:
1650  typedef typename __cv_signed::__type __type;
1651  };
1652 
1653  template<typename _Tp>
1654  class __make_signed_selector<_Tp, false, true>
1655  {
1656  // With -fshort-enums, an enum may be as small as a char.
1657  typedef signed char __smallest;
1658  static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1659  static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
1660  static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
1661  typedef conditional<__b2, signed int, signed long> __cond2;
1662  typedef typename __cond2::type __cond2_type;
1663  typedef conditional<__b1, signed short, __cond2_type> __cond1;
1664  typedef typename __cond1::type __cond1_type;
1665 
1666  public:
1667  typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
1668  };
1669 
1670  // Given an integral/enum type, return the corresponding signed
1671  // integer type.
1672  // Primary template.
1673  /// make_signed
1674  template<typename _Tp>
1675  struct make_signed
1676  { typedef typename __make_signed_selector<_Tp>::__type type; };
1677 
1678  // Integral, but don't define.
1679  template<>
1680  struct make_signed<bool>;
1681 
1682 
1683  // Array modifications.
1684 
1685  /// remove_extent
1686  template<typename _Tp>
1687  struct remove_extent
1688  { typedef _Tp type; };
1689 
1690  template<typename _Tp, std::size_t _Size>
1691  struct remove_extent<_Tp[_Size]>
1692  { typedef _Tp type; };
1693 
1694  template<typename _Tp>
1695  struct remove_extent<_Tp[]>
1696  { typedef _Tp type; };
1697 
1698  /// remove_all_extents
1699  template<typename _Tp>
1700  struct remove_all_extents
1701  { typedef _Tp type; };
1702 
1703  template<typename _Tp, std::size_t _Size>
1704  struct remove_all_extents<_Tp[_Size]>
1705  { typedef typename remove_all_extents<_Tp>::type type; };
1706 
1707  template<typename _Tp>
1708  struct remove_all_extents<_Tp[]>
1709  { typedef typename remove_all_extents<_Tp>::type type; };
1710 
1711 
1712  // Pointer modifications.
1713 
1714  template<typename _Tp, typename>
1715  struct __remove_pointer_helper
1716  { typedef _Tp type; };
1717 
1718  template<typename _Tp, typename _Up>
1719  struct __remove_pointer_helper<_Tp, _Up*>
1720  { typedef _Up type; };
1721 
1722  /// remove_pointer
1723  template<typename _Tp>
1724  struct remove_pointer
1725  : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1726  { };
1727 
1728  /// add_pointer
1729  template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1730  is_void<_Tp>>::value>
1731  struct __add_pointer_helper
1732  { typedef _Tp type; };
1733 
1734  template<typename _Tp>
1735  struct __add_pointer_helper<_Tp, true>
1736  { typedef typename remove_reference<_Tp>::type* type; };
1737 
1738  template<typename _Tp>
1739  struct add_pointer
1740  : public __add_pointer_helper<_Tp>
1741  { };
1742 
1743 
1744  template<std::size_t _Len>
1745  struct __aligned_storage_msa
1746  {
1747  union __type
1748  {
1749  unsigned char __data[_Len];
1750  struct __attribute__((__aligned__)) { } __align;
1751  };
1752  };
1753 
1754  /**
1755  * @brief Alignment type.
1756  *
1757  * The value of _Align is a default-alignment which shall be the
1758  * most stringent alignment requirement for any C++ object type
1759  * whose size is no greater than _Len (3.9). The member typedef
1760  * type shall be a POD type suitable for use as uninitialized
1761  * storage for any object whose size is at most _Len and whose
1762  * alignment is a divisor of _Align.
1763  */
1764  template<std::size_t _Len, std::size_t _Align =
1765  __alignof__(typename __aligned_storage_msa<_Len>::__type)>
1766  struct aligned_storage
1767  {
1768  union type
1769  {
1770  unsigned char __data[_Len];
1771  struct __attribute__((__aligned__((_Align)))) { } __align;
1772  };
1773  };
1774 
1775 
1776  // Decay trait for arrays and functions, used for perfect forwarding
1777  // in make_pair, make_tuple, etc.
1778  template<typename _Up,
1779  bool _IsArray = is_array<_Up>::value,
1780  bool _IsFunction = is_function<_Up>::value>
1781  struct __decay_selector;
1782 
1783  // NB: DR 705.
1784  template<typename _Up>
1785  struct __decay_selector<_Up, false, false>
1786  { typedef typename remove_cv<_Up>::type __type; };
1787 
1788  template<typename _Up>
1789  struct __decay_selector<_Up, true, false>
1790  { typedef typename remove_extent<_Up>::type* __type; };
1791 
1792  template<typename _Up>
1793  struct __decay_selector<_Up, false, true>
1794  { typedef typename add_pointer<_Up>::type __type; };
1795 
1796  /// decay
1797  template<typename _Tp>
1798  class decay
1799  {
1800  typedef typename remove_reference<_Tp>::type __remove_type;
1801 
1802  public:
1803  typedef typename __decay_selector<__remove_type>::__type type;
1804  };
1805 
1806  template<typename _Tp>
1807  class reference_wrapper;
1808 
1809  // Helper which adds a reference to a type when given a reference_wrapper
1810  template<typename _Tp>
1811  struct __strip_reference_wrapper
1812  {
1813  typedef _Tp __type;
1814  };
1815 
1816  template<typename _Tp>
1817  struct __strip_reference_wrapper<reference_wrapper<_Tp> >
1818  {
1819  typedef _Tp& __type;
1820  };
1821 
1822  template<typename _Tp>
1823  struct __decay_and_strip
1824  {
1825  typedef typename __strip_reference_wrapper<
1826  typename decay<_Tp>::type>::__type __type;
1827  };
1828 
1829 
1830  // Primary template.
1831  /// Define a member typedef @c type only if a boolean constant is true.
1832  template<bool, typename _Tp = void>
1833  struct enable_if
1834  { };
1835 
1836  // Partial specialization for true.
1837  template<typename _Tp>
1838  struct enable_if<true, _Tp>
1839  { typedef _Tp type; };
1840 
1841  template<typename... _Cond>
1842  using _Require = typename enable_if<__and_<_Cond...>::value>::type;
1843 
1844  // Primary template.
1845  /// Define a member typedef @c type to one of two argument types.
1846  template<bool _Cond, typename _Iftrue, typename _Iffalse>
1847  struct conditional
1848  { typedef _Iftrue type; };
1849 
1850  // Partial specialization for false.
1851  template<typename _Iftrue, typename _Iffalse>
1852  struct conditional<false, _Iftrue, _Iffalse>
1853  { typedef _Iffalse type; };
1854 
1855  /// common_type
1856  template<typename... _Tp>
1857  struct common_type;
1858 
1859  // Sfinae-friendly common_type implementation:
1860 
1861  struct __do_common_type_impl
1862  {
1863  template<typename _Tp, typename _Up>
1864  static __success_type<typename decay<decltype
1865  (true ? std::declval<_Tp>()
1866  : std::declval<_Up>())>::type> _S_test(int);
1867 
1868  template<typename, typename>
1869  static __failure_type _S_test(...);
1870  };
1871 
1872  template<typename _Tp, typename _Up>
1873  struct __common_type_impl
1874  : private __do_common_type_impl
1875  {
1876  typedef decltype(_S_test<_Tp, _Up>(0)) type;
1877  };
1878 
1879  struct __do_member_type_wrapper
1880  {
1881  template<typename _Tp>
1882  static __success_type<typename _Tp::type> _S_test(int);
1883 
1884  template<typename>
1885  static __failure_type _S_test(...);
1886  };
1887 
1888  template<typename _Tp>
1889  struct __member_type_wrapper
1890  : private __do_member_type_wrapper
1891  {
1892  typedef decltype(_S_test<_Tp>(0)) type;
1893  };
1894 
1895  template<typename _CTp, typename... _Args>
1896  struct __expanded_common_type_wrapper
1897  {
1898  typedef common_type<typename _CTp::type, _Args...> type;
1899  };
1900 
1901  template<typename... _Args>
1902  struct __expanded_common_type_wrapper<__failure_type, _Args...>
1903  { typedef __failure_type type; };
1904 
1905  template<typename _Tp>
1906  struct common_type<_Tp>
1907  { typedef typename decay<_Tp>::type type; };
1908 
1909  template<typename _Tp, typename _Up>
1910  struct common_type<_Tp, _Up>
1911  : public __common_type_impl<_Tp, _Up>::type
1912  { };
1913 
1914  template<typename _Tp, typename _Up, typename... _Vp>
1915  struct common_type<_Tp, _Up, _Vp...>
1916  : public __expanded_common_type_wrapper<typename __member_type_wrapper<
1917  common_type<_Tp, _Up>>::type, _Vp...>::type
1918  { };
1919 
1920  /// The underlying type of an enum.
1921  template<typename _Tp>
1922  struct underlying_type
1923  {
1924  typedef __underlying_type(_Tp) type;
1925  };
1926 
1927  template<typename _Tp>
1928  struct __declval_protector
1929  {
1930  static const bool __stop = false;
1931  static typename add_rvalue_reference<_Tp>::type __delegate();
1932  };
1933 
1934  template<typename _Tp>
1935  inline typename add_rvalue_reference<_Tp>::type
1936  declval() noexcept
1937  {
1938  static_assert(__declval_protector<_Tp>::__stop,
1939  "declval() must not be used!");
1940  return __declval_protector<_Tp>::__delegate();
1941  }
1942 
1943  /// result_of
1944  template<typename _Signature>
1945  class result_of;
1946 
1947  // Sfinae-friendly result_of implementation:
1948 
1949  // [func.require] paragraph 1 bullet 1:
1950  struct __result_of_memfun_ref_impl
1951  {
1952  template<typename _Fp, typename _Tp1, typename... _Args>
1953  static __success_type<decltype(
1954  (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
1955  )> _S_test(int);
1956 
1957  template<typename...>
1958  static __failure_type _S_test(...);
1959  };
1960 
1961  template<typename _MemPtr, typename _Arg, typename... _Args>
1962  struct __result_of_memfun_ref
1963  : private __result_of_memfun_ref_impl
1964  {
1965  typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
1966  };
1967 
1968  // [func.require] paragraph 1 bullet 2:
1969  struct __result_of_memfun_deref_impl
1970  {
1971  template<typename _Fp, typename _Tp1, typename... _Args>
1972  static __success_type<decltype(
1973  ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
1974  )> _S_test(int);
1975 
1976  template<typename...>
1977  static __failure_type _S_test(...);
1978  };
1979 
1980  template<typename _MemPtr, typename _Arg, typename... _Args>
1981  struct __result_of_memfun_deref
1982  : private __result_of_memfun_deref_impl
1983  {
1984  typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
1985  };
1986 
1987  // [func.require] paragraph 1 bullet 3:
1988  struct __result_of_memobj_ref_impl
1989  {
1990  template<typename _Fp, typename _Tp1>
1991  static __success_type<decltype(
1992  std::declval<_Tp1>().*std::declval<_Fp>()
1993  )> _S_test(int);
1994 
1995  template<typename, typename>
1996  static __failure_type _S_test(...);
1997  };
1998 
1999  template<typename _MemPtr, typename _Arg>
2000  struct __result_of_memobj_ref
2001  : private __result_of_memobj_ref_impl
2002  {
2003  typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2004  };
2005 
2006  // [func.require] paragraph 1 bullet 4:
2007  struct __result_of_memobj_deref_impl
2008  {
2009  template<typename _Fp, typename _Tp1>
2010  static __success_type<decltype(
2011  (*std::declval<_Tp1>()).*std::declval<_Fp>()
2012  )> _S_test(int);
2013 
2014  template<typename, typename>
2015  static __failure_type _S_test(...);
2016  };
2017 
2018  template<typename _MemPtr, typename _Arg>
2019  struct __result_of_memobj_deref
2020  : private __result_of_memobj_deref_impl
2021  {
2022  typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2023  };
2024 
2025  template<typename _MemPtr, typename _Arg>
2026  struct __result_of_memobj;
2027 
2028  template<typename _Res, typename _Class, typename _Arg>
2029  struct __result_of_memobj<_Res _Class::*, _Arg>
2030  {
2031  typedef typename remove_cv<typename remove_reference<
2032  _Arg>::type>::type _Argval;
2033  typedef _Res _Class::* _MemPtr;
2034  typedef typename conditional<__or_<is_same<_Argval, _Class>,
2035  is_base_of<_Class, _Argval>>::value,
2036  __result_of_memobj_ref<_MemPtr, _Arg>,
2037  __result_of_memobj_deref<_MemPtr, _Arg>
2038  >::type::type type;
2039  };
2040 
2041  template<typename _MemPtr, typename _Arg, typename... _Args>
2042  struct __result_of_memfun;
2043 
2044  template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2045  struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
2046  {
2047  typedef typename remove_cv<typename remove_reference<
2048  _Arg>::type>::type _Argval;
2049  typedef _Res _Class::* _MemPtr;
2050  typedef typename conditional<__or_<is_same<_Argval, _Class>,
2051  is_base_of<_Class, _Argval>>::value,
2052  __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2053  __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2054  >::type::type type;
2055  };
2056 
2057  template<bool, bool, typename _Functor, typename... _ArgTypes>
2058  struct __result_of_impl
2059  {
2060  typedef __failure_type type;
2061  };
2062 
2063  template<typename _MemPtr, typename _Arg>
2064  struct __result_of_impl<true, false, _MemPtr, _Arg>
2065  : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
2066  { };
2067 
2068  template<typename _MemPtr, typename _Arg, typename... _Args>
2069  struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2070  : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
2071  { };
2072 
2073  // [func.require] paragraph 1 bullet 5:
2074  struct __result_of_other_impl
2075  {
2076  template<typename _Fn, typename... _Args>
2077  static __success_type<decltype(
2078  std::declval<_Fn>()(std::declval<_Args>()...)
2079  )> _S_test(int);
2080 
2081  template<typename...>
2082  static __failure_type _S_test(...);
2083  };
2084 
2085  template<typename _Functor, typename... _ArgTypes>
2086  struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2087  : private __result_of_other_impl
2088  {
2089  typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
2090  };
2091 
2092  template<typename _Functor, typename... _ArgTypes>
2093  struct result_of<_Functor(_ArgTypes...)>
2094  : public __result_of_impl<
2095  is_member_object_pointer<
2096  typename remove_reference<_Functor>::type
2097  >::value,
2098  is_member_function_pointer<
2099  typename remove_reference<_Functor>::type
2100  >::value,
2101  _Functor, _ArgTypes...
2102  >::type
2103  { };
2104 
2105  /// @} group metaprogramming
2106 
2107  /**
2108  * Use SFINAE to determine if the type _Tp has a publicly-accessible
2109  * member type _NTYPE.
2110  */
2111 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2112  template<typename _Tp> \
2113  class __has_##_NTYPE##_helper \
2114  { \
2115  template<typename _Up> \
2116  struct _Wrap_type \
2117  { }; \
2118  \
2119  template<typename _Up> \
2120  static true_type __test(_Wrap_type<typename _Up::_NTYPE>*); \
2121  \
2122  template<typename _Up> \
2123  static false_type __test(...); \
2124  \
2125  public: \
2126  typedef decltype(__test<_Tp>(0)) type; \
2127  }; \
2128  \
2129  template<typename _Tp> \
2130  struct __has_##_NTYPE \
2131  : public __has_##_NTYPE##_helper \
2132  <typename remove_cv<_Tp>::type>::type \
2133  { };
2134 
2135 _GLIBCXX_END_NAMESPACE_VERSION
2136 } // namespace std
2137 
2138 #endif // C++11
2139 
2140 #endif // _GLIBCXX_TYPE_TRAITS