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