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