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