Home | History | Annotate | Download | only in include
      1 // -*- C++ -*-
      2 //===------------------------ type_traits ---------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 #ifndef _LIBCPP_TYPE_TRAITS
     12 #define _LIBCPP_TYPE_TRAITS
     13 
     14 /*
     15     type_traits synopsis
     16 
     17 namespace std
     18 {
     19 
     20     // helper class:
     21     template <class T, T v> struct integral_constant;
     22     typedef integral_constant<bool, true>  true_type;
     23     typedef integral_constant<bool, false> false_type;
     24 
     25     // helper traits
     26     template <bool, class T = void> struct enable_if;
     27     template <bool, class T, class F> struct conditional;
     28 
     29     // Primary classification traits:
     30     template <class T> struct is_void;
     31     template <class T> struct is_integral;
     32     template <class T> struct is_floating_point;
     33     template <class T> struct is_array;
     34     template <class T> struct is_pointer;
     35     template <class T> struct is_lvalue_reference;
     36     template <class T> struct is_rvalue_reference;
     37     template <class T> struct is_member_object_pointer;
     38     template <class T> struct is_member_function_pointer;
     39     template <class T> struct is_enum;
     40     template <class T> struct is_union;
     41     template <class T> struct is_class;
     42     template <class T> struct is_function;
     43 
     44     // Secondary classification traits:
     45     template <class T> struct is_reference;
     46     template <class T> struct is_arithmetic;
     47     template <class T> struct is_fundamental;
     48     template <class T> struct is_member_pointer;
     49     template <class T> struct is_scalar;
     50     template <class T> struct is_object;
     51     template <class T> struct is_compound;
     52 
     53     // Const-volatile properties and transformations:
     54     template <class T> struct is_const;
     55     template <class T> struct is_volatile;
     56     template <class T> struct remove_const;
     57     template <class T> struct remove_volatile;
     58     template <class T> struct remove_cv;
     59     template <class T> struct add_const;
     60     template <class T> struct add_volatile;
     61     template <class T> struct add_cv;
     62 
     63     // Reference transformations:
     64     template <class T> struct remove_reference;
     65     template <class T> struct add_lvalue_reference;
     66     template <class T> struct add_rvalue_reference;
     67 
     68     // Pointer transformations:
     69     template <class T> struct remove_pointer;
     70     template <class T> struct add_pointer;
     71 
     72     // Integral properties:
     73     template <class T> struct is_signed;
     74     template <class T> struct is_unsigned;
     75     template <class T> struct make_signed;
     76     template <class T> struct make_unsigned;
     77 
     78     // Array properties and transformations:
     79     template <class T> struct rank;
     80     template <class T, unsigned I = 0> struct extent;
     81     template <class T> struct remove_extent;
     82     template <class T> struct remove_all_extents;
     83 
     84     // Member introspection:
     85     template <class T> struct is_pod;
     86     template <class T> struct is_trivial;
     87     template <class T> struct is_trivially_copyable;
     88     template <class T> struct is_standard_layout;
     89     template <class T> struct is_literal_type;
     90     template <class T> struct is_empty;
     91     template <class T> struct is_polymorphic;
     92     template <class T> struct is_abstract;
     93 
     94     template <class T, class... Args> struct is_constructible;
     95     template <class T>                struct is_default_constructible;
     96     template <class T>                struct is_copy_constructible;
     97     template <class T>                struct is_move_constructible;
     98     template <class T, class U>       struct is_assignable;
     99     template <class T>                struct is_copy_assignable;
    100     template <class T>                struct is_move_assignable;
    101     template <class T>                struct is_destructible;
    102 
    103     template <class T, class... Args> struct is_trivially_constructible;
    104     template <class T>                struct is_trivially_default_constructible;
    105     template <class T>                struct is_trivially_copy_constructible;
    106     template <class T>                struct is_trivially_move_constructible;
    107     template <class T, class U>       struct is_trivially_assignable;
    108     template <class T>                struct is_trivially_copy_assignable;
    109     template <class T>                struct is_trivially_move_assignable;
    110     template <class T>                struct is_trivially_destructible;
    111 
    112     template <class T, class... Args> struct is_nothrow_constructible;
    113     template <class T>                struct is_nothrow_default_constructible;
    114     template <class T>                struct is_nothrow_copy_constructible;
    115     template <class T>                struct is_nothrow_move_constructible;
    116     template <class T, class U>       struct is_nothrow_assignable;
    117     template <class T>                struct is_nothrow_copy_assignable;
    118     template <class T>                struct is_nothrow_move_assignable;
    119     template <class T>                struct is_nothrow_destructible;
    120 
    121     template <class T> struct has_virtual_destructor;
    122 
    123     // Relationships between types:
    124     template <class T, class U> struct is_same;
    125     template <class Base, class Derived> struct is_base_of;
    126     template <class From, class To> struct is_convertible;
    127 
    128     // Alignment properties and transformations:
    129     template <class T> struct alignment_of;
    130     template <size_t Len, size_t Align = most_stringent_alignment_requirement>
    131         struct aligned_storage;
    132     template <size_t Len, class... Types> struct aligned_union;
    133 
    134     template <class T> struct decay;
    135     template <class... T> struct common_type;
    136     template <class T> struct underlying_type;
    137     template <class> class result_of; // undefined
    138     template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
    139 
    140     // const-volatile modifications:
    141     template <class T>
    142       using remove_const_t    = typename remove_const<T>::type;  // C++14
    143     template <class T>
    144       using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
    145     template <class T>
    146       using remove_cv_t       = typename remove_cv<T>::type;  // C++14
    147     template <class T>
    148       using add_const_t       = typename add_const<T>::type;  // C++14
    149     template <class T>
    150       using add_volatile_t    = typename add_volatile<T>::type;  // C++14
    151     template <class T>
    152       using add_cv_t          = typename add_cv<T>::type;  // C++14
    153   
    154     // reference modifications:
    155     template <class T>
    156       using remove_reference_t     = typename remove_reference<T>::type;  // C++14
    157     template <class T>
    158       using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
    159     template <class T>
    160       using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
    161   
    162     // sign modifications:
    163     template <class T>
    164       using make_signed_t   = typename make_signed<T>::type;  // C++14
    165     template <class T>
    166       using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
    167   
    168     // array modifications:
    169     template <class T>
    170       using remove_extent_t      = typename remove_extent<T>::type;  // C++14
    171     template <class T>
    172       using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
    173 
    174     // pointer modifications:
    175     template <class T>
    176       using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
    177     template <class T>
    178       using add_pointer_t    = typename add_pointer<T>::type;  // C++14
    179 
    180     // other transformations:
    181     template <size_t Len, std::size_t Align=default-alignment>
    182       using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
    183     template <std::size_t Len, class... Types>
    184       using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
    185     template <class T>
    186       using decay_t           = typename decay<T>::type;  // C++14
    187     template <bool b, class T=void>
    188       using enable_if_t       = typename enable_if<b,T>::type;  // C++14
    189     template <bool b, class T, class F>
    190       using conditional_t     = typename conditional<b,T,F>::type;  // C++14
    191     template <class... T>
    192       using common_type_t     = typename common_type<T...>::type;  // C++14
    193     template <class T>
    194       using underlying_type_t = typename underlying_type<T>::type;  // C++14
    195     template <class F, class... ArgTypes>
    196       using result_of_t       = typename result_of<F(ArgTypes...)>::type;  // C++14
    197 
    198 }  // std
    199 
    200 */
    201 #include <__config>
    202 #include <cstddef>
    203 
    204 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
    205 #pragma GCC system_header
    206 #endif
    207 
    208 _LIBCPP_BEGIN_NAMESPACE_STD
    209 
    210 template <bool _Bp, class _If, class _Then>
    211     struct _LIBCPP_TYPE_VIS conditional {typedef _If type;};
    212 template <class _If, class _Then>
    213     struct _LIBCPP_TYPE_VIS conditional<false, _If, _Then> {typedef _Then type;};
    214 
    215 #if _LIBCPP_STD_VER > 11
    216 template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
    217 #endif
    218 
    219 template <bool, class _Tp = void> struct _LIBCPP_TYPE_VIS enable_if {};
    220 template <class _Tp> struct _LIBCPP_TYPE_VIS enable_if<true, _Tp> {typedef _Tp type;};
    221 
    222 #if _LIBCPP_STD_VER > 11
    223 template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
    224 #endif
    225 
    226 
    227 struct __two {char __lx[2];};
    228 
    229 // helper class:
    230 
    231 template <class _Tp, _Tp __v>
    232 struct _LIBCPP_TYPE_VIS integral_constant
    233 {
    234     static _LIBCPP_CONSTEXPR const _Tp      value = __v;
    235     typedef _Tp               value_type;
    236     typedef integral_constant type;
    237     _LIBCPP_INLINE_VISIBILITY
    238         _LIBCPP_CONSTEXPR operator value_type() const {return value;}
    239 #if _LIBCPP_STD_VER > 11
    240     _LIBCPP_INLINE_VISIBILITY
    241          constexpr value_type operator ()() const {return value;}
    242 #endif
    243 };
    244 
    245 template <class _Tp, _Tp __v>
    246 _LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
    247 
    248 typedef integral_constant<bool, true>  true_type;
    249 typedef integral_constant<bool, false> false_type;
    250 
    251 // is_const
    252 
    253 template <class _Tp> struct _LIBCPP_TYPE_VIS is_const            : public false_type {};
    254 template <class _Tp> struct _LIBCPP_TYPE_VIS is_const<_Tp const> : public true_type {};
    255 
    256 // is_volatile
    257 
    258 template <class _Tp> struct _LIBCPP_TYPE_VIS is_volatile               : public false_type {};
    259 template <class _Tp> struct _LIBCPP_TYPE_VIS is_volatile<_Tp volatile> : public true_type {};
    260 
    261 // remove_const
    262 
    263 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_const            {typedef _Tp type;};
    264 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_const<const _Tp> {typedef _Tp type;};
    265 #if _LIBCPP_STD_VER > 11
    266 template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
    267 #endif
    268 
    269 // remove_volatile
    270 
    271 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_volatile               {typedef _Tp type;};
    272 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;};
    273 #if _LIBCPP_STD_VER > 11
    274 template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
    275 #endif
    276 
    277 // remove_cv
    278 
    279 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_cv
    280 {typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
    281 #if _LIBCPP_STD_VER > 11
    282 template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
    283 #endif
    284 
    285 // is_void
    286 
    287 template <class _Tp> struct __is_void       : public false_type {};
    288 template <>          struct __is_void<void> : public true_type {};
    289 
    290 template <class _Tp> struct _LIBCPP_TYPE_VIS is_void
    291     : public __is_void<typename remove_cv<_Tp>::type> {};
    292 
    293 // __is_nullptr_t
    294 
    295 template <class _Tp> struct ____is_nullptr_t       : public false_type {};
    296 template <>          struct ____is_nullptr_t<nullptr_t> : public true_type {};
    297 
    298 template <class _Tp> struct _LIBCPP_TYPE_VIS __is_nullptr_t
    299     : public ____is_nullptr_t<typename remove_cv<_Tp>::type> {};
    300 
    301 // is_integral
    302 
    303 template <class _Tp> struct __is_integral                     : public false_type {};
    304 template <>          struct __is_integral<bool>               : public true_type {};
    305 template <>          struct __is_integral<char>               : public true_type {};
    306 template <>          struct __is_integral<signed char>        : public true_type {};
    307 template <>          struct __is_integral<unsigned char>      : public true_type {};
    308 template <>          struct __is_integral<wchar_t>            : public true_type {};
    309 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
    310 template <>          struct __is_integral<char16_t>           : public true_type {};
    311 template <>          struct __is_integral<char32_t>           : public true_type {};
    312 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
    313 template <>          struct __is_integral<short>              : public true_type {};
    314 template <>          struct __is_integral<unsigned short>     : public true_type {};
    315 template <>          struct __is_integral<int>                : public true_type {};
    316 template <>          struct __is_integral<unsigned int>       : public true_type {};
    317 template <>          struct __is_integral<long>               : public true_type {};
    318 template <>          struct __is_integral<unsigned long>      : public true_type {};
    319 template <>          struct __is_integral<long long>          : public true_type {};
    320 template <>          struct __is_integral<unsigned long long> : public true_type {};
    321 
    322 template <class _Tp> struct _LIBCPP_TYPE_VIS is_integral
    323     : public __is_integral<typename remove_cv<_Tp>::type> {};
    324 
    325 // is_floating_point
    326 
    327 template <class _Tp> struct __is_floating_point              : public false_type {};
    328 template <>          struct __is_floating_point<float>       : public true_type {};
    329 template <>          struct __is_floating_point<double>      : public true_type {};
    330 template <>          struct __is_floating_point<long double> : public true_type {};
    331 
    332 template <class _Tp> struct _LIBCPP_TYPE_VIS is_floating_point
    333     : public __is_floating_point<typename remove_cv<_Tp>::type> {};
    334 
    335 // is_array
    336 
    337 template <class _Tp> struct _LIBCPP_TYPE_VIS is_array
    338     : public false_type {};
    339 template <class _Tp> struct _LIBCPP_TYPE_VIS is_array<_Tp[]>
    340     : public true_type {};
    341 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS is_array<_Tp[_Np]>
    342     : public true_type {};
    343 
    344 // is_pointer
    345 
    346 template <class _Tp> struct __is_pointer       : public false_type {};
    347 template <class _Tp> struct __is_pointer<_Tp*> : public true_type {};
    348 
    349 template <class _Tp> struct _LIBCPP_TYPE_VIS is_pointer
    350     : public __is_pointer<typename remove_cv<_Tp>::type> {};
    351 
    352 // is_reference
    353 
    354 template <class _Tp> struct _LIBCPP_TYPE_VIS is_lvalue_reference       : public false_type {};
    355 template <class _Tp> struct _LIBCPP_TYPE_VIS is_lvalue_reference<_Tp&> : public true_type {};
    356 
    357 template <class _Tp> struct _LIBCPP_TYPE_VIS is_rvalue_reference        : public false_type {};
    358 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    359 template <class _Tp> struct _LIBCPP_TYPE_VIS is_rvalue_reference<_Tp&&> : public true_type {};
    360 #endif
    361 
    362 template <class _Tp> struct _LIBCPP_TYPE_VIS is_reference        : public false_type {};
    363 template <class _Tp> struct _LIBCPP_TYPE_VIS is_reference<_Tp&>  : public true_type {};
    364 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    365 template <class _Tp> struct _LIBCPP_TYPE_VIS is_reference<_Tp&&> : public true_type {};
    366 #endif
    367 
    368 #if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
    369 #define _LIBCPP_HAS_TYPE_TRAITS
    370 #endif
    371 
    372 // is_union
    373 
    374 #if __has_feature(is_union) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
    375 
    376 template <class _Tp> struct _LIBCPP_TYPE_VIS is_union
    377     : public integral_constant<bool, __is_union(_Tp)> {};
    378 
    379 #else
    380 
    381 template <class _Tp> struct __libcpp_union : public false_type {};
    382 template <class _Tp> struct _LIBCPP_TYPE_VIS is_union
    383     : public __libcpp_union<typename remove_cv<_Tp>::type> {};
    384 
    385 #endif
    386 
    387 // is_class
    388 
    389 #if __has_feature(is_class) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
    390 
    391 template <class _Tp> struct _LIBCPP_TYPE_VIS is_class
    392     : public integral_constant<bool, __is_class(_Tp)> {};
    393 
    394 #else
    395 
    396 namespace __is_class_imp
    397 {
    398 template <class _Tp> char  __test(int _Tp::*);
    399 template <class _Tp> __two __test(...);
    400 }
    401 
    402 template <class _Tp> struct _LIBCPP_TYPE_VIS is_class
    403     : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
    404 
    405 #endif
    406 
    407 // is_same
    408 
    409 template <class _Tp, class _Up> struct _LIBCPP_TYPE_VIS is_same           : public false_type {};
    410 template <class _Tp>            struct _LIBCPP_TYPE_VIS is_same<_Tp, _Tp> : public true_type {};
    411 
    412 // is_function
    413 
    414 namespace __is_function_imp
    415 {
    416 template <class _Tp> char  __test(_Tp*);
    417 template <class _Tp> __two __test(...);
    418 template <class _Tp> _Tp&  __source();
    419 }
    420 
    421 template <class _Tp, bool = is_class<_Tp>::value ||
    422                             is_union<_Tp>::value ||
    423                             is_void<_Tp>::value  ||
    424                             is_reference<_Tp>::value ||
    425                             is_same<_Tp, nullptr_t>::value >
    426 struct __is_function
    427     : public integral_constant<bool, sizeof(__is_function_imp::__test<_Tp>(__is_function_imp::__source<_Tp>())) == 1>
    428     {};
    429 template <class _Tp> struct __is_function<_Tp, true> : public false_type {};
    430 
    431 template <class _Tp> struct _LIBCPP_TYPE_VIS is_function
    432     : public __is_function<_Tp> {};
    433 
    434 // is_member_function_pointer
    435 
    436 template <class _Tp> struct            __is_member_function_pointer             : public false_type {};
    437 template <class _Tp, class _Up> struct __is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
    438 
    439 template <class _Tp> struct _LIBCPP_TYPE_VIS is_member_function_pointer
    440     : public __is_member_function_pointer<typename remove_cv<_Tp>::type> {};
    441 
    442 // is_member_pointer
    443 
    444 template <class _Tp>            struct __is_member_pointer             : public false_type {};
    445 template <class _Tp, class _Up> struct __is_member_pointer<_Tp _Up::*> : public true_type {};
    446 
    447 template <class _Tp> struct _LIBCPP_TYPE_VIS is_member_pointer
    448     : public __is_member_pointer<typename remove_cv<_Tp>::type> {};
    449 
    450 // is_member_object_pointer
    451 
    452 template <class _Tp> struct _LIBCPP_TYPE_VIS is_member_object_pointer
    453     : public integral_constant<bool, is_member_pointer<_Tp>::value &&
    454                                     !is_member_function_pointer<_Tp>::value> {};
    455 
    456 // is_enum
    457 
    458 #if __has_feature(is_enum) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
    459 
    460 template <class _Tp> struct _LIBCPP_TYPE_VIS is_enum
    461     : public integral_constant<bool, __is_enum(_Tp)> {};
    462 
    463 #else
    464 
    465 template <class _Tp> struct _LIBCPP_TYPE_VIS is_enum
    466     : public integral_constant<bool, !is_void<_Tp>::value             &&
    467                                      !is_integral<_Tp>::value         &&
    468                                      !is_floating_point<_Tp>::value   &&
    469                                      !is_array<_Tp>::value            &&
    470                                      !is_pointer<_Tp>::value          &&
    471                                      !is_reference<_Tp>::value        &&
    472                                      !is_member_pointer<_Tp>::value   &&
    473                                      !is_union<_Tp>::value            &&
    474                                      !is_class<_Tp>::value            &&
    475                                      !is_function<_Tp>::value         > {};
    476 
    477 #endif
    478 
    479 // is_arithmetic
    480 
    481 template <class _Tp> struct _LIBCPP_TYPE_VIS is_arithmetic
    482     : public integral_constant<bool, is_integral<_Tp>::value      ||
    483                                      is_floating_point<_Tp>::value> {};
    484 
    485 // is_fundamental
    486 
    487 template <class _Tp> struct _LIBCPP_TYPE_VIS is_fundamental
    488     : public integral_constant<bool, is_void<_Tp>::value        ||
    489                                      __is_nullptr_t<_Tp>::value ||
    490                                      is_arithmetic<_Tp>::value> {};
    491 
    492 // is_scalar
    493 
    494 template <class _Tp> struct _LIBCPP_TYPE_VIS is_scalar
    495     : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
    496                                      is_member_pointer<_Tp>::value ||
    497                                      is_pointer<_Tp>::value        ||
    498                                      __is_nullptr_t<_Tp>::value    ||
    499                                      is_enum<_Tp>::value           > {};
    500 
    501 template <> struct _LIBCPP_TYPE_VIS is_scalar<nullptr_t> : public true_type {};
    502 
    503 // is_object
    504 
    505 template <class _Tp> struct _LIBCPP_TYPE_VIS is_object
    506     : public integral_constant<bool, is_scalar<_Tp>::value ||
    507                                      is_array<_Tp>::value  ||
    508                                      is_union<_Tp>::value  ||
    509                                      is_class<_Tp>::value  > {};
    510 
    511 // is_compound
    512 
    513 template <class _Tp> struct _LIBCPP_TYPE_VIS is_compound
    514     : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
    515 
    516 // add_const
    517 
    518 template <class _Tp, bool = is_reference<_Tp>::value ||
    519                             is_function<_Tp>::value  ||
    520                             is_const<_Tp>::value     >
    521 struct __add_const             {typedef _Tp type;};
    522 
    523 template <class _Tp>
    524 struct __add_const<_Tp, false> {typedef const _Tp type;};
    525 
    526 template <class _Tp> struct _LIBCPP_TYPE_VIS add_const
    527     {typedef typename __add_const<_Tp>::type type;};
    528 
    529 #if _LIBCPP_STD_VER > 11
    530 template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
    531 #endif
    532 
    533 // add_volatile
    534 
    535 template <class _Tp, bool = is_reference<_Tp>::value ||
    536                             is_function<_Tp>::value  ||
    537                             is_volatile<_Tp>::value  >
    538 struct __add_volatile             {typedef _Tp type;};
    539 
    540 template <class _Tp>
    541 struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
    542 
    543 template <class _Tp> struct _LIBCPP_TYPE_VIS add_volatile
    544     {typedef typename __add_volatile<_Tp>::type type;};
    545 
    546 #if _LIBCPP_STD_VER > 11
    547 template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
    548 #endif
    549 
    550 // add_cv
    551 
    552 template <class _Tp> struct _LIBCPP_TYPE_VIS add_cv
    553     {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;};
    554 
    555 #if _LIBCPP_STD_VER > 11
    556 template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
    557 #endif
    558 
    559 // remove_reference
    560 
    561 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference        {typedef _Tp type;};
    562 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference<_Tp&>  {typedef _Tp type;};
    563 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    564 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference<_Tp&&> {typedef _Tp type;};
    565 #endif
    566 
    567 #if _LIBCPP_STD_VER > 11
    568 template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
    569 #endif
    570 
    571 // add_lvalue_reference
    572 
    573 template <class _Tp> struct _LIBCPP_TYPE_VIS add_lvalue_reference                      {typedef _Tp& type;};
    574 template <class _Tp> struct _LIBCPP_TYPE_VIS add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
    575 template <>          struct _LIBCPP_TYPE_VIS add_lvalue_reference<void>                {typedef void type;};
    576 template <>          struct _LIBCPP_TYPE_VIS add_lvalue_reference<const void>          {typedef const void type;};
    577 template <>          struct _LIBCPP_TYPE_VIS add_lvalue_reference<volatile void>       {typedef volatile void type;};
    578 template <>          struct _LIBCPP_TYPE_VIS add_lvalue_reference<const volatile void> {typedef const volatile void type;};
    579 
    580 #if _LIBCPP_STD_VER > 11
    581 template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
    582 #endif
    583 
    584 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    585 
    586 template <class _Tp> struct _LIBCPP_TYPE_VIS  add_rvalue_reference                     {typedef _Tp&& type;};
    587 template <>          struct _LIBCPP_TYPE_VIS add_rvalue_reference<void>                {typedef void type;};
    588 template <>          struct _LIBCPP_TYPE_VIS add_rvalue_reference<const void>          {typedef const void type;};
    589 template <>          struct _LIBCPP_TYPE_VIS add_rvalue_reference<volatile void>       {typedef volatile void type;};
    590 template <>          struct _LIBCPP_TYPE_VIS add_rvalue_reference<const volatile void> {typedef const volatile void type;};
    591 
    592 #if _LIBCPP_STD_VER > 11
    593 template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
    594 #endif
    595 
    596 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    597 
    598 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    599 
    600 template <class _Tp>
    601 typename add_rvalue_reference<_Tp>::type
    602 declval() _NOEXCEPT;
    603 
    604 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    605 
    606 template <class _Tp>
    607 typename add_lvalue_reference<_Tp>::type
    608 declval();
    609 
    610 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    611 
    612 struct __any
    613 {
    614     __any(...);
    615 };
    616 
    617 // remove_pointer
    618 
    619 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer                      {typedef _Tp type;};
    620 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp*>                {typedef _Tp type;};
    621 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* const>          {typedef _Tp type;};
    622 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* volatile>       {typedef _Tp type;};
    623 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* const volatile> {typedef _Tp type;};
    624 
    625 #if _LIBCPP_STD_VER > 11
    626 template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
    627 #endif
    628 
    629 // add_pointer
    630 
    631 template <class _Tp> struct _LIBCPP_TYPE_VIS add_pointer
    632     {typedef typename remove_reference<_Tp>::type* type;};
    633 
    634 #if _LIBCPP_STD_VER > 11
    635 template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
    636 #endif
    637 
    638 // is_signed
    639 
    640 template <class _Tp, bool = is_integral<_Tp>::value>
    641 struct ___is_signed : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};
    642 
    643 template <class _Tp>
    644 struct ___is_signed<_Tp, false> : public true_type {};  // floating point
    645 
    646 template <class _Tp, bool = is_arithmetic<_Tp>::value>
    647 struct __is_signed : public ___is_signed<_Tp> {};
    648 
    649 template <class _Tp> struct __is_signed<_Tp, false> : public false_type {};
    650 
    651 template <class _Tp> struct _LIBCPP_TYPE_VIS is_signed : public __is_signed<_Tp> {};
    652 
    653 // is_unsigned
    654 
    655 template <class _Tp, bool = is_integral<_Tp>::value>
    656 struct ___is_unsigned : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};
    657 
    658 template <class _Tp>
    659 struct ___is_unsigned<_Tp, false> : public false_type {};  // floating point
    660 
    661 template <class _Tp, bool = is_arithmetic<_Tp>::value>
    662 struct __is_unsigned : public ___is_unsigned<_Tp> {};
    663 
    664 template <class _Tp> struct __is_unsigned<_Tp, false> : public false_type {};
    665 
    666 template <class _Tp> struct _LIBCPP_TYPE_VIS is_unsigned : public __is_unsigned<_Tp> {};
    667 
    668 // rank
    669 
    670 template <class _Tp> struct _LIBCPP_TYPE_VIS rank
    671     : public integral_constant<size_t, 0> {};
    672 template <class _Tp> struct _LIBCPP_TYPE_VIS rank<_Tp[]>
    673     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
    674 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS rank<_Tp[_Np]>
    675     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
    676 
    677 // extent
    678 
    679 template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TYPE_VIS extent
    680     : public integral_constant<size_t, 0> {};
    681 template <class _Tp> struct _LIBCPP_TYPE_VIS extent<_Tp[], 0>
    682     : public integral_constant<size_t, 0> {};
    683 template <class _Tp, unsigned _Ip> struct _LIBCPP_TYPE_VIS extent<_Tp[], _Ip>
    684     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
    685 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS extent<_Tp[_Np], 0>
    686     : public integral_constant<size_t, _Np> {};
    687 template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TYPE_VIS extent<_Tp[_Np], _Ip>
    688     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
    689 
    690 // remove_extent
    691 
    692 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_extent
    693     {typedef _Tp type;};
    694 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_extent<_Tp[]>
    695     {typedef _Tp type;};
    696 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS remove_extent<_Tp[_Np]>
    697     {typedef _Tp type;};
    698 
    699 #if _LIBCPP_STD_VER > 11
    700 template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
    701 #endif
    702 
    703 // remove_all_extents
    704 
    705 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_all_extents
    706     {typedef _Tp type;};
    707 template <class _Tp> struct _LIBCPP_TYPE_VIS remove_all_extents<_Tp[]>
    708     {typedef typename remove_all_extents<_Tp>::type type;};
    709 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS remove_all_extents<_Tp[_Np]>
    710     {typedef typename remove_all_extents<_Tp>::type type;};
    711 
    712 #if _LIBCPP_STD_VER > 11
    713 template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
    714 #endif
    715 
    716 // is_abstract
    717 
    718 namespace __is_abstract_imp
    719 {
    720 template <class _Tp> char  __test(_Tp (*)[1]);
    721 template <class _Tp> __two __test(...);
    722 }
    723 
    724 template <class _Tp, bool = is_class<_Tp>::value>
    725 struct __libcpp_abstract : public integral_constant<bool, sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
    726 
    727 template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {};
    728 
    729 template <class _Tp> struct _LIBCPP_TYPE_VIS is_abstract : public __libcpp_abstract<_Tp> {};
    730 
    731 // is_base_of
    732 
    733 #ifdef _LIBCP_HAS_IS_BASE_OF
    734 
    735 template <class _Bp, class _Dp>
    736 struct _LIBCPP_TYPE_VIS is_base_of
    737     : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
    738 
    739 #else  // __has_feature(is_base_of)
    740 
    741 namespace __is_base_of_imp
    742 {
    743 template <class _Tp>
    744 struct _Dst
    745 {
    746     _Dst(const volatile _Tp &);
    747 };
    748 template <class _Tp>
    749 struct _Src
    750 {
    751     operator const volatile _Tp &();
    752     template <class _Up> operator const _Dst<_Up> &();
    753 };
    754 template <size_t> struct __one { typedef char type; };
    755 template <class _Bp, class _Dp> typename __one<sizeof(_Dst<_Bp>(declval<_Src<_Dp> >()))>::type __test(int);
    756 template <class _Bp, class _Dp> __two __test(...);
    757 }
    758 
    759 template <class _Bp, class _Dp>
    760 struct _LIBCPP_TYPE_VIS is_base_of
    761     : public integral_constant<bool, is_class<_Bp>::value &&
    762                                      sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {};
    763 
    764 #endif  // __has_feature(is_base_of)
    765 
    766 // is_convertible
    767 
    768 #if __has_feature(is_convertible_to)
    769 
    770 template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS is_convertible
    771     : public integral_constant<bool, __is_convertible_to(_T1, _T2) &&
    772                                      !is_abstract<_T2>::value> {};
    773 
    774 #else  // __has_feature(is_convertible_to)
    775 
    776 namespace __is_convertible_imp
    777 {
    778 template <class _Tp> char  __test(_Tp);
    779 template <class _Tp> __two __test(...);
    780 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    781 template <class _Tp> _Tp&& __source();
    782 #else
    783 template <class _Tp> typename remove_reference<_Tp>::type& __source();
    784 #endif
    785 
    786 template <class _Tp, bool _IsArray =    is_array<_Tp>::value,
    787                      bool _IsFunction = is_function<_Tp>::value,
    788                      bool _IsVoid =     is_void<_Tp>::value>
    789                      struct __is_array_function_or_void                          {enum {value = 0};};
    790 template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
    791 template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
    792 template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
    793 }
    794 
    795 template <class _Tp,
    796     unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
    797 struct __is_convertible_check
    798 {
    799     static const size_t __v = 0;
    800 };
    801 
    802 template <class _Tp>
    803 struct __is_convertible_check<_Tp, 0>
    804 {
    805     static const size_t __v = sizeof(_Tp);
    806 };
    807 
    808 template <class _T1, class _T2,
    809     unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
    810     unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
    811 struct __is_convertible
    812     : public integral_constant<bool,
    813 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    814         sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
    815 #else
    816         sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
    817          && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value
    818               && (!is_const<typename remove_reference<_T2>::type>::value
    819                   || is_volatile<typename remove_reference<_T2>::type>::value)
    820                   && (is_same<typename remove_cv<_T1>::type,
    821                               typename remove_cv<typename remove_reference<_T2>::type>::type>::value
    822                       || is_base_of<typename remove_reference<_T2>::type, _T1>::value))
    823 #endif
    824     >
    825 {};
    826 
    827 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 0> : false_type {};
    828 
    829 template <class _T1> struct __is_convertible<_T1, const _T1&, 1, 0> : true_type {};
    830 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    831 template <class _T1> struct __is_convertible<_T1, _T1&&, 1, 0> : true_type {};
    832 template <class _T1> struct __is_convertible<_T1, const _T1&&, 1, 0> : true_type {};
    833 template <class _T1> struct __is_convertible<_T1, volatile _T1&&, 1, 0> : true_type {};
    834 template <class _T1> struct __is_convertible<_T1, const volatile _T1&&, 1, 0> : true_type {};
    835 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    836 
    837 template <class _T1, class _T2> struct __is_convertible<_T1, _T2*, 1, 0>
    838     : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*>::value> {};
    839 
    840 template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const, 1, 0>
    841     : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const>::value> {};
    842 
    843 template <class _T1, class _T2> struct __is_convertible<_T1, _T2* volatile, 1, 0>
    844     : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*volatile>::value> {};
    845 
    846 template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const volatile, 1, 0>
    847     : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const volatile>::value> {};
    848 
    849 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 0>                : public false_type {};
    850 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    851 template <class _T1>            struct __is_convertible<_T1, _T1&&, 2, 0>               : public true_type {};
    852 #endif
    853 template <class _T1>            struct __is_convertible<_T1, _T1&, 2, 0>               : public true_type {};
    854 template <class _T1>            struct __is_convertible<_T1, _T1*, 2, 0>               : public true_type {};
    855 template <class _T1>            struct __is_convertible<_T1, _T1*const, 2, 0>          : public true_type {};
    856 template <class _T1>            struct __is_convertible<_T1, _T1*volatile, 2, 0>       : public true_type {};
    857 template <class _T1>            struct __is_convertible<_T1, _T1*const volatile, 2, 0> : public true_type {};
    858 
    859 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 0> : public false_type {};
    860 
    861 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
    862 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
    863 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
    864 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
    865 
    866 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
    867 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
    868 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
    869 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
    870 
    871 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
    872 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
    873 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
    874 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
    875 
    876 template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS is_convertible
    877     : public __is_convertible<_T1, _T2>
    878 {
    879     static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
    880     static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
    881 };
    882 
    883 #endif  // __has_feature(is_convertible_to)
    884 
    885 // is_empty
    886 
    887 #if __has_feature(is_empty)
    888 
    889 template <class _Tp>
    890 struct _LIBCPP_TYPE_VIS is_empty
    891     : public integral_constant<bool, __is_empty(_Tp)> {};
    892 
    893 #else  // __has_feature(is_empty)
    894 
    895 template <class _Tp>
    896 struct __is_empty1
    897     : public _Tp
    898 {
    899     double __lx;
    900 };
    901 
    902 struct __is_empty2
    903 {
    904     double __lx;
    905 };
    906 
    907 template <class _Tp, bool = is_class<_Tp>::value>
    908 struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
    909 
    910 template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
    911 
    912 template <class _Tp> struct _LIBCPP_TYPE_VIS is_empty : public __libcpp_empty<_Tp> {};
    913 
    914 #endif  // __has_feature(is_empty)
    915 
    916 // is_polymorphic
    917 
    918 #if __has_feature(is_polymorphic)
    919 
    920 template <class _Tp>
    921 struct _LIBCPP_TYPE_VIS is_polymorphic
    922     : public integral_constant<bool, __is_polymorphic(_Tp)> {};
    923 
    924 #else
    925 
    926 template<typename _Tp> char &__is_polymorphic_impl(
    927     typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
    928                        int>::type);
    929 template<typename _Tp> __two &__is_polymorphic_impl(...);
    930 
    931 template <class _Tp> struct _LIBCPP_TYPE_VIS is_polymorphic
    932     : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
    933 
    934 #endif // __has_feature(is_polymorphic)
    935 
    936 // has_virtual_destructor
    937 
    938 #if __has_feature(has_virtual_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
    939 
    940 template <class _Tp> struct _LIBCPP_TYPE_VIS has_virtual_destructor
    941     : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
    942 
    943 #else  // _LIBCPP_HAS_TYPE_TRAITS
    944 
    945 template <class _Tp> struct _LIBCPP_TYPE_VIS has_virtual_destructor
    946     : public false_type {};
    947 
    948 #endif  // _LIBCPP_HAS_TYPE_TRAITS
    949 
    950 // alignment_of
    951 
    952 template <class _Tp> struct _LIBCPP_TYPE_VIS alignment_of
    953     : public integral_constant<size_t, __alignof__(_Tp)> {};
    954 
    955 // aligned_storage
    956 
    957 template <class _Hp, class _Tp>
    958 struct __type_list
    959 {
    960     typedef _Hp _Head;
    961     typedef _Tp _Tail;
    962 };
    963 
    964 struct __nat
    965 {
    966 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
    967     __nat() = delete;
    968     __nat(const __nat&) = delete;
    969     __nat& operator=(const __nat&) = delete;
    970     ~__nat() = delete;
    971 #endif
    972 };
    973 
    974 template <class _Tp>
    975 struct __align_type
    976 {
    977     static const size_t value = alignment_of<_Tp>::value;
    978     typedef _Tp type;
    979 };
    980 
    981 struct __struct_double {long double __lx;};
    982 struct __struct_double4 {double __lx[4];};
    983 
    984 typedef
    985     __type_list<__align_type<unsigned char>,
    986     __type_list<__align_type<unsigned short>,
    987     __type_list<__align_type<unsigned int>,
    988     __type_list<__align_type<unsigned long>,
    989     __type_list<__align_type<unsigned long long>,
    990     __type_list<__align_type<double>,
    991     __type_list<__align_type<long double>,
    992     __type_list<__align_type<__struct_double>,
    993     __type_list<__align_type<__struct_double4>,
    994     __type_list<__align_type<int*>,
    995     __nat
    996     > > > > > > > > > > __all_types;
    997 
    998 template <class _TL, size_t _Align> struct __find_pod;
    999 
   1000 template <class _Hp, size_t _Align>
   1001 struct __find_pod<__type_list<_Hp, __nat>, _Align>
   1002 {
   1003     typedef typename conditional<
   1004                              _Align == _Hp::value,
   1005                              typename _Hp::type,
   1006                              void
   1007                          >::type type;
   1008 };
   1009 
   1010 template <class _Hp, class _Tp, size_t _Align>
   1011 struct __find_pod<__type_list<_Hp, _Tp>, _Align>
   1012 {
   1013     typedef typename conditional<
   1014                              _Align == _Hp::value,
   1015                              typename _Hp::type,
   1016                              typename __find_pod<_Tp, _Align>::type
   1017                          >::type type;
   1018 };
   1019 
   1020 template <class _TL, size_t _Len> struct __find_max_align;
   1021 
   1022 template <class _Hp, size_t _Len>
   1023 struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
   1024 
   1025 template <size_t _Len, size_t _A1, size_t _A2>
   1026 struct __select_align
   1027 {
   1028 private:
   1029     static const size_t __min = _A2 < _A1 ? _A2 : _A1;
   1030     static const size_t __max = _A1 < _A2 ? _A2 : _A1;
   1031 public:
   1032     static const size_t value = _Len < __max ? __min : __max;
   1033 };
   1034 
   1035 template <class _Hp, class _Tp, size_t _Len>
   1036 struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
   1037     : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
   1038 
   1039 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
   1040 struct _LIBCPP_TYPE_VIS aligned_storage
   1041 {
   1042     typedef typename __find_pod<__all_types, _Align>::type _Aligner;
   1043     static_assert(!is_void<_Aligner>::value, "");
   1044     union type
   1045     {
   1046         _Aligner __align;
   1047         unsigned char __data[_Len];
   1048     };
   1049 };
   1050 
   1051 #if _LIBCPP_STD_VER > 11
   1052 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
   1053     using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
   1054 #endif
   1055 
   1056 #define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
   1057 template <size_t _Len>\
   1058 struct _LIBCPP_TYPE_VIS aligned_storage<_Len, n>\
   1059 {\
   1060     struct _ALIGNAS(n) type\
   1061     {\
   1062         unsigned char __lx[_Len];\
   1063     };\
   1064 }
   1065 
   1066 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
   1067 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
   1068 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
   1069 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
   1070 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
   1071 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
   1072 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
   1073 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
   1074 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
   1075 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
   1076 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
   1077 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
   1078 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
   1079 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
   1080 // MSDN says that MSVC does not support alignment beyond 8192 (=0x2000)
   1081 #if !defined(_MSC_VER)
   1082 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
   1083 #endif // !_MSC_VER
   1084 
   1085 #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
   1086 
   1087 #ifndef _LIBCPP_HAS_NO_VARIADICS
   1088 
   1089 // aligned_union
   1090 
   1091 template <size_t _I0, size_t ..._In>
   1092 struct __static_max;
   1093 
   1094 template <size_t _I0>
   1095 struct __static_max<_I0>
   1096 {
   1097     static const size_t value = _I0;
   1098 };
   1099 
   1100 template <size_t _I0, size_t _I1, size_t ..._In>
   1101 struct __static_max<_I0, _I1, _In...>
   1102 {
   1103     static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
   1104                                              __static_max<_I1, _In...>::value;
   1105 };
   1106 
   1107 template <size_t _Len, class _Type0, class ..._Types>
   1108 struct aligned_union
   1109 {
   1110     static const size_t alignment_value = __static_max<__alignof__(_Type0),
   1111                                                        __alignof__(_Types)...>::value;
   1112     static const size_t __len = __static_max<_Len, sizeof(_Type0),
   1113                                              sizeof(_Types)...>::value;
   1114     typedef typename aligned_storage<__len, alignment_value>::type type;
   1115 };
   1116 
   1117 #if _LIBCPP_STD_VER > 11
   1118 template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
   1119 #endif
   1120 
   1121 #endif  // _LIBCPP_HAS_NO_VARIADICS
   1122 
   1123 // __promote
   1124 
   1125 template <class _A1, class _A2 = void, class _A3 = void,
   1126           bool = (is_arithmetic<_A1>::value || is_void<_A1>::value) &&
   1127                  (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
   1128                  (is_arithmetic<_A3>::value || is_void<_A3>::value)>
   1129 class __promote {};
   1130 
   1131 template <class _A1, class _A2, class _A3>
   1132 class __promote<_A1, _A2, _A3, true>
   1133 {
   1134 private:
   1135     typedef typename __promote<_A1>::type __type1;
   1136     typedef typename __promote<_A2>::type __type2;
   1137     typedef typename __promote<_A3>::type __type3;
   1138 public:
   1139     typedef decltype(__type1() + __type2() + __type3()) type;
   1140 };
   1141 
   1142 template <class _A1, class _A2>
   1143 class __promote<_A1, _A2, void, true>
   1144 {
   1145 private:
   1146     typedef typename __promote<_A1>::type __type1;
   1147     typedef typename __promote<_A2>::type __type2;
   1148 public:
   1149     typedef decltype(__type1() + __type2()) type;
   1150 };
   1151 
   1152 template <class _A1>
   1153 class __promote<_A1, void, void, true>
   1154 {
   1155 public:
   1156     typedef typename conditional<is_arithmetic<_A1>::value,
   1157                      typename conditional<is_integral<_A1>::value, double, _A1>::type,
   1158                      void
   1159             >::type type;
   1160 };
   1161 
   1162 #ifdef _LIBCPP_STORE_AS_OPTIMIZATION
   1163 
   1164 // __transform
   1165 
   1166 template <class _Tp, size_t = sizeof(_Tp), bool = is_scalar<_Tp>::value> struct __transform {typedef _Tp type;};
   1167 template <class _Tp> struct __transform<_Tp, 1, true> {typedef unsigned char      type;};
   1168 template <class _Tp> struct __transform<_Tp, 2, true> {typedef unsigned short     type;};
   1169 template <class _Tp> struct __transform<_Tp, 4, true> {typedef unsigned int       type;};
   1170 template <class _Tp> struct __transform<_Tp, 8, true> {typedef unsigned long long type;};
   1171 
   1172 #endif  // _LIBCPP_STORE_AS_OPTIMIZATION
   1173 
   1174 // make_signed / make_unsigned
   1175 
   1176 typedef
   1177     __type_list<signed char,
   1178     __type_list<signed short,
   1179     __type_list<signed int,
   1180     __type_list<signed long,
   1181     __type_list<signed long long,
   1182     __nat
   1183     > > > > > __signed_types;
   1184 
   1185 typedef
   1186     __type_list<unsigned char,
   1187     __type_list<unsigned short,
   1188     __type_list<unsigned int,
   1189     __type_list<unsigned long,
   1190     __type_list<unsigned long long,
   1191     __nat
   1192     > > > > > __unsigned_types;
   1193 
   1194 template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
   1195 
   1196 template <class _Hp, class _Tp, size_t _Size>
   1197 struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
   1198 {
   1199     typedef _Hp type;
   1200 };
   1201 
   1202 template <class _Hp, class _Tp, size_t _Size>
   1203 struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
   1204 {
   1205     typedef typename __find_first<_Tp, _Size>::type type;
   1206 };
   1207 
   1208 template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
   1209                              bool = is_volatile<typename remove_reference<_Tp>::type>::value>
   1210 struct __apply_cv
   1211 {
   1212     typedef _Up type;
   1213 };
   1214 
   1215 template <class _Tp, class _Up>
   1216 struct __apply_cv<_Tp, _Up, true, false>
   1217 {
   1218     typedef const _Up type;
   1219 };
   1220 
   1221 template <class _Tp, class _Up>
   1222 struct __apply_cv<_Tp, _Up, false, true>
   1223 {
   1224     typedef volatile _Up type;
   1225 };
   1226 
   1227 template <class _Tp, class _Up>
   1228 struct __apply_cv<_Tp, _Up, true, true>
   1229 {
   1230     typedef const volatile _Up type;
   1231 };
   1232 
   1233 template <class _Tp, class _Up>
   1234 struct __apply_cv<_Tp&, _Up, false, false>
   1235 {
   1236     typedef _Up& type;
   1237 };
   1238 
   1239 template <class _Tp, class _Up>
   1240 struct __apply_cv<_Tp&, _Up, true, false>
   1241 {
   1242     typedef const _Up& type;
   1243 };
   1244 
   1245 template <class _Tp, class _Up>
   1246 struct __apply_cv<_Tp&, _Up, false, true>
   1247 {
   1248     typedef volatile _Up& type;
   1249 };
   1250 
   1251 template <class _Tp, class _Up>
   1252 struct __apply_cv<_Tp&, _Up, true, true>
   1253 {
   1254     typedef const volatile _Up& type;
   1255 };
   1256 
   1257 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
   1258 struct __make_signed {};
   1259 
   1260 template <class _Tp>
   1261 struct __make_signed<_Tp, true>
   1262 {
   1263     typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
   1264 };
   1265 
   1266 template <> struct __make_signed<bool,               true> {};
   1267 template <> struct __make_signed<  signed short,     true> {typedef short     type;};
   1268 template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
   1269 template <> struct __make_signed<  signed int,       true> {typedef int       type;};
   1270 template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
   1271 template <> struct __make_signed<  signed long,      true> {typedef long      type;};
   1272 template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
   1273 template <> struct __make_signed<  signed long long, true> {typedef long long type;};
   1274 template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
   1275 
   1276 template <class _Tp>
   1277 struct _LIBCPP_TYPE_VIS make_signed
   1278 {
   1279     typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
   1280 };
   1281 
   1282 #if _LIBCPP_STD_VER > 11
   1283 template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
   1284 #endif
   1285 
   1286 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
   1287 struct __make_unsigned {};
   1288 
   1289 template <class _Tp>
   1290 struct __make_unsigned<_Tp, true>
   1291 {
   1292     typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
   1293 };
   1294 
   1295 template <> struct __make_unsigned<bool,               true> {};
   1296 template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
   1297 template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
   1298 template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
   1299 template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
   1300 template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
   1301 template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
   1302 template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
   1303 template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
   1304 
   1305 template <class _Tp>
   1306 struct _LIBCPP_TYPE_VIS make_unsigned
   1307 {
   1308     typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
   1309 };
   1310 
   1311 #if _LIBCPP_STD_VER > 11
   1312 template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
   1313 #endif
   1314 
   1315 #ifdef _LIBCPP_HAS_NO_VARIADICS
   1316 
   1317 template <class _Tp, class _Up = void, class V = void>
   1318 struct _LIBCPP_TYPE_VIS common_type
   1319 {
   1320 public:
   1321     typedef typename common_type<typename common_type<_Tp, _Up>::type, V>::type type;
   1322 };
   1323 
   1324 template <class _Tp>
   1325 struct _LIBCPP_TYPE_VIS common_type<_Tp, void, void>
   1326 {
   1327 public:
   1328     typedef _Tp type;
   1329 };
   1330 
   1331 template <class _Tp, class _Up>
   1332 struct _LIBCPP_TYPE_VIS common_type<_Tp, _Up, void>
   1333 {
   1334 private:
   1335 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1336     static _Tp&& __t();
   1337     static _Up&& __u();
   1338 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1339     static _Tp __t();
   1340     static _Up __u();
   1341 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1342 public:
   1343     typedef typename remove_reference<decltype(true ? __t() : __u())>::type type;
   1344 };
   1345 
   1346 #else  // _LIBCPP_HAS_NO_VARIADICS
   1347 
   1348 template <class ..._Tp> struct common_type;
   1349 
   1350 template <class _Tp>
   1351 struct _LIBCPP_TYPE_VIS common_type<_Tp>
   1352 {
   1353     typedef _Tp type;
   1354 };
   1355 
   1356 template <class _Tp, class _Up>
   1357 struct _LIBCPP_TYPE_VIS common_type<_Tp, _Up>
   1358 {
   1359 private:
   1360     static _Tp&& __t();
   1361     static _Up&& __u();
   1362     static bool __f();
   1363 public:
   1364     typedef typename remove_reference<decltype(__f() ? __t() : __u())>::type type;
   1365 };
   1366 
   1367 template <class _Tp, class _Up, class ..._Vp>
   1368 struct _LIBCPP_TYPE_VIS common_type<_Tp, _Up, _Vp...>
   1369 {
   1370     typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
   1371 };
   1372 
   1373 #if _LIBCPP_STD_VER > 11
   1374 template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
   1375 #endif
   1376 
   1377 #endif  // _LIBCPP_HAS_NO_VARIADICS
   1378 
   1379 // is_assignable
   1380 
   1381 template <class _Tp, class _Arg>
   1382 decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>(), true_type()))
   1383 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1384 __is_assignable_test(_Tp&&, _Arg&&);
   1385 #else
   1386 __is_assignable_test(_Tp, _Arg&);
   1387 #endif
   1388 
   1389 template <class _Arg>
   1390 false_type
   1391 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1392 __is_assignable_test(__any, _Arg&&);
   1393 #else
   1394 __is_assignable_test(__any, _Arg&);
   1395 #endif
   1396 
   1397 template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
   1398 struct __is_assignable_imp
   1399     : public common_type
   1400         <
   1401             decltype(__is_assignable_test(declval<_Tp>(), declval<_Arg>()))
   1402         >::type {};
   1403 
   1404 template <class _Tp, class _Arg>
   1405 struct __is_assignable_imp<_Tp, _Arg, true>
   1406     : public false_type
   1407 {
   1408 };
   1409 
   1410 template <class _Tp, class _Arg>
   1411 struct is_assignable
   1412     : public __is_assignable_imp<_Tp, _Arg> {};
   1413 
   1414 // is_copy_assignable
   1415 
   1416 template <class _Tp> struct _LIBCPP_TYPE_VIS is_copy_assignable
   1417     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
   1418                      const typename add_lvalue_reference<_Tp>::type> {};
   1419 
   1420 // is_move_assignable
   1421 
   1422 template <class _Tp> struct _LIBCPP_TYPE_VIS is_move_assignable
   1423 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1424     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
   1425                      const typename add_rvalue_reference<_Tp>::type> {};
   1426 #else
   1427     : public is_copy_assignable<_Tp> {};
   1428 #endif
   1429 
   1430 // is_destructible
   1431 
   1432 template <class _Tp>
   1433 struct __destructible_test
   1434 {
   1435     _Tp __t;
   1436 };
   1437 
   1438 template <class _Tp>
   1439 decltype((_VSTD::declval<__destructible_test<_Tp> >().~__destructible_test<_Tp>(), true_type()))
   1440 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1441 __is_destructible_test(_Tp&&);
   1442 #else
   1443 __is_destructible_test(_Tp&);
   1444 #endif
   1445 
   1446 false_type
   1447 __is_destructible_test(__any);
   1448 
   1449 template <class _Tp, bool = is_void<_Tp>::value || is_abstract<_Tp>::value>
   1450 struct __destructible_imp
   1451     : public common_type
   1452         <
   1453             decltype(__is_destructible_test(declval<_Tp>()))
   1454         >::type {};
   1455 
   1456 template <class _Tp>
   1457 struct __destructible_imp<_Tp, true>
   1458     : public false_type {};
   1459 
   1460 template <class _Tp>
   1461 struct is_destructible
   1462     : public __destructible_imp<_Tp> {};
   1463 
   1464 // move
   1465 
   1466 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1467 
   1468 template <class _Tp>
   1469 inline _LIBCPP_INLINE_VISIBILITY
   1470 typename remove_reference<_Tp>::type&&
   1471 move(_Tp&& __t) _NOEXCEPT
   1472 {
   1473     typedef typename remove_reference<_Tp>::type _Up;
   1474     return static_cast<_Up&&>(__t);
   1475 }
   1476 
   1477 template <class _Tp>
   1478 inline _LIBCPP_INLINE_VISIBILITY
   1479 _Tp&&
   1480 forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
   1481 {
   1482     return static_cast<_Tp&&>(__t);
   1483 }
   1484 
   1485 template <class _Tp>
   1486 inline _LIBCPP_INLINE_VISIBILITY
   1487 _Tp&&
   1488 forward(typename std::remove_reference<_Tp>::type&& __t) _NOEXCEPT
   1489 {
   1490     static_assert(!std::is_lvalue_reference<_Tp>::value,
   1491                   "Can not forward an rvalue as an lvalue.");
   1492     return static_cast<_Tp&&>(__t);
   1493 }
   1494 
   1495 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1496 
   1497 template <class _Tp>
   1498 inline _LIBCPP_INLINE_VISIBILITY
   1499 _Tp&
   1500 move(_Tp& __t)
   1501 {
   1502     return __t;
   1503 }
   1504 
   1505 template <class _Tp>
   1506 inline _LIBCPP_INLINE_VISIBILITY
   1507 const _Tp&
   1508 move(const _Tp& __t)
   1509 {
   1510     return __t;
   1511 }
   1512 
   1513 template <class _Tp>
   1514 inline _LIBCPP_INLINE_VISIBILITY
   1515 _Tp&
   1516 forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
   1517 {
   1518     return __t;
   1519 }
   1520 
   1521 
   1522 template <class _Tp>
   1523 class __rv
   1524 {
   1525     typedef typename remove_reference<_Tp>::type _Trr;
   1526     _Trr& t_;
   1527 public:
   1528     _LIBCPP_INLINE_VISIBILITY
   1529     _Trr* operator->() {return &t_;}
   1530     _LIBCPP_INLINE_VISIBILITY
   1531     explicit __rv(_Trr& __t) : t_(__t) {}
   1532 };
   1533 
   1534 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1535 
   1536 template <class _Tp>
   1537 struct _LIBCPP_TYPE_VIS decay
   1538 {
   1539 private:
   1540     typedef typename remove_reference<_Tp>::type _Up;
   1541 public:
   1542     typedef typename conditional
   1543                      <
   1544                          is_array<_Up>::value,
   1545                          typename remove_extent<_Up>::type*,
   1546                          typename conditional
   1547                          <
   1548                               is_function<_Up>::value,
   1549                               typename add_pointer<_Up>::type,
   1550                               typename remove_cv<_Up>::type
   1551                          >::type
   1552                      >::type type;
   1553 };
   1554 
   1555 #if _LIBCPP_STD_VER > 11
   1556 template <class _Tp> using decay_t = typename decay<_Tp>::type;
   1557 #endif
   1558 
   1559 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   1560 
   1561 template <class _Tp>
   1562 inline _LIBCPP_INLINE_VISIBILITY
   1563 typename decay<_Tp>::type
   1564 __decay_copy(_Tp&& __t)
   1565 {
   1566     return _VSTD::forward<_Tp>(__t);
   1567 }
   1568 
   1569 #else
   1570 
   1571 template <class _Tp>
   1572 inline _LIBCPP_INLINE_VISIBILITY
   1573 typename decay<_Tp>::type
   1574 __decay_copy(const _Tp& __t)
   1575 {
   1576     return _VSTD::forward<_Tp>(__t);
   1577 }
   1578 
   1579 #endif
   1580 
   1581 template <class _MP, bool _IsMemberFuctionPtr, bool _IsMemberObjectPtr>
   1582 struct __member_pointer_traits_imp
   1583 {
   1584 };
   1585 
   1586 #ifndef _LIBCPP_HAS_NO_VARIADICS
   1587 
   1588 template <class _Rp, class _Class, class ..._Param>
   1589 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
   1590 {
   1591     typedef _Class _ClassType;
   1592     typedef _Rp _ReturnType;
   1593 };
   1594 
   1595 template <class _Rp, class _Class, class ..._Param>
   1596 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
   1597 {
   1598     typedef _Class const _ClassType;
   1599     typedef _Rp _ReturnType;
   1600 };
   1601 
   1602 template <class _Rp, class _Class, class ..._Param>
   1603 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
   1604 {
   1605     typedef _Class volatile _ClassType;
   1606     typedef _Rp _ReturnType;
   1607 };
   1608 
   1609 template <class _Rp, class _Class, class ..._Param>
   1610 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
   1611 {
   1612     typedef _Class const volatile _ClassType;
   1613     typedef _Rp _ReturnType;
   1614 };
   1615 
   1616 #if __has_feature(cxx_reference_qualified_functions)
   1617 
   1618 template <class _Rp, class _Class, class ..._Param>
   1619 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
   1620 {
   1621     typedef _Class& _ClassType;
   1622     typedef _Rp _ReturnType;
   1623 };
   1624 
   1625 template <class _Rp, class _Class, class ..._Param>
   1626 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
   1627 {
   1628     typedef _Class const& _ClassType;
   1629     typedef _Rp _ReturnType;
   1630 };
   1631 
   1632 template <class _Rp, class _Class, class ..._Param>
   1633 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
   1634 {
   1635     typedef _Class volatile& _ClassType;
   1636     typedef _Rp _ReturnType;
   1637 };
   1638 
   1639 template <class _Rp, class _Class, class ..._Param>
   1640 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
   1641 {
   1642     typedef _Class const volatile& _ClassType;
   1643     typedef _Rp _ReturnType;
   1644 };
   1645 
   1646 template <class _Rp, class _Class, class ..._Param>
   1647 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
   1648 {
   1649     typedef _Class&& _ClassType;
   1650     typedef _Rp _ReturnType;
   1651 };
   1652 
   1653 template <class _Rp, class _Class, class ..._Param>
   1654 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
   1655 {
   1656     typedef _Class const&& _ClassType;
   1657     typedef _Rp _ReturnType;
   1658 };
   1659 
   1660 template <class _Rp, class _Class, class ..._Param>
   1661 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
   1662 {
   1663     typedef _Class volatile&& _ClassType;
   1664     typedef _Rp _ReturnType;
   1665 };
   1666 
   1667 template <class _Rp, class _Class, class ..._Param>
   1668 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
   1669 {
   1670     typedef _Class const volatile&& _ClassType;
   1671     typedef _Rp _ReturnType;
   1672 };
   1673 
   1674 #endif  // __has_feature(cxx_reference_qualified_functions)
   1675 
   1676 #else  // _LIBCPP_HAS_NO_VARIADICS
   1677 
   1678 template <class _Rp, class _Class>
   1679 struct __member_pointer_traits_imp<_Rp (_Class::*)(), true, false>
   1680 {
   1681     typedef _Class _ClassType;
   1682     typedef _Rp _ReturnType;
   1683 };
   1684 
   1685 template <class _Rp, class _Class, class _P0>
   1686 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0), true, false>
   1687 {
   1688     typedef _Class _ClassType;
   1689     typedef _Rp _ReturnType;
   1690 };
   1691 
   1692 template <class _Rp, class _Class, class _P0, class _P1>
   1693 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1), true, false>
   1694 {
   1695     typedef _Class _ClassType;
   1696     typedef _Rp _ReturnType;
   1697 };
   1698 
   1699 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
   1700 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2), true, false>
   1701 {
   1702     typedef _Class _ClassType;
   1703     typedef _Rp _ReturnType;
   1704 };
   1705 
   1706 template <class _Rp, class _Class>
   1707 struct __member_pointer_traits_imp<_Rp (_Class::*)() const, true, false>
   1708 {
   1709     typedef _Class const _ClassType;
   1710     typedef _Rp _ReturnType;
   1711 };
   1712 
   1713 template <class _Rp, class _Class, class _P0>
   1714 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const, true, false>
   1715 {
   1716     typedef _Class const _ClassType;
   1717     typedef _Rp _ReturnType;
   1718 };
   1719 
   1720 template <class _Rp, class _Class, class _P0, class _P1>
   1721 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const, true, false>
   1722 {
   1723     typedef _Class const _ClassType;
   1724     typedef _Rp _ReturnType;
   1725 };
   1726 
   1727 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
   1728 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const, true, false>
   1729 {
   1730     typedef _Class const _ClassType;
   1731     typedef _Rp _ReturnType;
   1732 };
   1733 
   1734 template <class _Rp, class _Class>
   1735 struct __member_pointer_traits_imp<_Rp (_Class::*)() volatile, true, false>
   1736 {
   1737     typedef _Class volatile _ClassType;
   1738     typedef _Rp _ReturnType;
   1739 };
   1740 
   1741 template <class _Rp, class _Class, class _P0>
   1742 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) volatile, true, false>
   1743 {
   1744     typedef _Class volatile _ClassType;
   1745     typedef _Rp _ReturnType;
   1746 };
   1747 
   1748 template <class _Rp, class _Class, class _P0, class _P1>
   1749 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) volatile, true, false>
   1750 {
   1751     typedef _Class volatile _ClassType;
   1752     typedef _Rp _ReturnType;
   1753 };
   1754 
   1755 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
   1756 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) volatile, true, false>
   1757 {
   1758     typedef _Class volatile _ClassType;
   1759     typedef _Rp _ReturnType;
   1760 };
   1761 
   1762 template <class _Rp, class _Class>
   1763 struct __member_pointer_traits_imp<_Rp (_Class::*)() const volatile, true, false>
   1764 {
   1765     typedef _Class const volatile _ClassType;
   1766     typedef _Rp _ReturnType;
   1767 };
   1768 
   1769 template <class _Rp, class _Class, class _P0>
   1770 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const volatile, true, false>
   1771 {
   1772     typedef _Class const volatile _ClassType;
   1773     typedef _Rp _ReturnType;
   1774 };
   1775 
   1776 template <class _Rp, class _Class, class _P0, class _P1>
   1777 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const volatile, true, false>
   1778 {
   1779     typedef _Class const volatile _ClassType;
   1780     typedef _Rp _ReturnType;
   1781 };
   1782 
   1783 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
   1784 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const volatile, true, false>
   1785 {
   1786     typedef _Class const volatile _ClassType;
   1787     typedef _Rp _ReturnType;
   1788 };
   1789 
   1790 #endif  // _LIBCPP_HAS_NO_VARIADICS
   1791 
   1792 template <class _Rp, class _Class>
   1793 struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
   1794 {
   1795     typedef _Class _ClassType;
   1796     typedef _Rp _ReturnType;
   1797 };
   1798 
   1799 template <class _MP>
   1800 struct __member_pointer_traits
   1801     : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
   1802                     is_member_function_pointer<_MP>::value,
   1803                     is_member_object_pointer<_MP>::value>
   1804 {
   1805 //     typedef ... _ClassType;
   1806 //     typedef ... _ReturnType;
   1807 };
   1808 
   1809 // result_of
   1810 
   1811 template <class _Callable> class result_of;
   1812 
   1813 #ifdef _LIBCPP_HAS_NO_VARIADICS
   1814 
   1815 template <class _Fn, bool, bool>
   1816 class __result_of
   1817 {
   1818 };
   1819 
   1820 template <class _Fn>
   1821 class __result_of<_Fn(), true, false>
   1822 {
   1823 public:
   1824     typedef decltype(declval<_Fn>()()) type;
   1825 };
   1826 
   1827 template <class _Fn, class _A0>
   1828 class __result_of<_Fn(_A0), true, false>
   1829 {
   1830 public:
   1831     typedef decltype(declval<_Fn>()(declval<_A0>())) type;
   1832 };
   1833 
   1834 template <class _Fn, class _A0, class _A1>
   1835 class __result_of<_Fn(_A0, _A1), true, false>
   1836 {
   1837 public:
   1838     typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
   1839 };
   1840 
   1841 template <class _Fn, class _A0, class _A1, class _A2>
   1842 class __result_of<_Fn(_A0, _A1, _A2), true, false>
   1843 {
   1844 public:
   1845     typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
   1846 };
   1847 
   1848 template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
   1849 struct __result_of_mp;
   1850 
   1851 // member function pointer
   1852 
   1853 template <class _MP, class _Tp>
   1854 struct __result_of_mp<_MP, _Tp, true>
   1855     : public common_type<typename __member_pointer_traits<_MP>::_ReturnType>
   1856 {
   1857 };
   1858 
   1859 // member data pointer
   1860 
   1861 template <class _MP, class _Tp, bool>
   1862 struct __result_of_mdp;
   1863 
   1864 template <class _Rp, class _Class, class _Tp>
   1865 struct __result_of_mdp<_Rp _Class::*, _Tp, false>
   1866 {
   1867     typedef typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type& type;
   1868 };
   1869 
   1870 template <class _Rp, class _Class, class _Tp>
   1871 struct __result_of_mdp<_Rp _Class::*, _Tp, true>
   1872 {
   1873     typedef typename __apply_cv<_Tp, _Rp>::type& type;
   1874 };
   1875 
   1876 template <class _Rp, class _Class, class _Tp>
   1877 struct __result_of_mp<_Rp _Class::*, _Tp, false>
   1878     : public __result_of_mdp<_Rp _Class::*, _Tp,
   1879             is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
   1880 {
   1881 };
   1882 
   1883 
   1884 
   1885 template <class _Fn, class _Tp>
   1886 class __result_of<_Fn(_Tp), false, true>  // _Fn must be member pointer
   1887     : public __result_of_mp<typename remove_reference<_Fn>::type,
   1888                             _Tp,
   1889                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
   1890 {
   1891 };
   1892 
   1893 template <class _Fn, class _Tp, class _A0>
   1894 class __result_of<_Fn(_Tp, _A0), false, true>  // _Fn must be member pointer
   1895     : public __result_of_mp<typename remove_reference<_Fn>::type,
   1896                             _Tp,
   1897                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
   1898 {
   1899 };
   1900 
   1901 template <class _Fn, class _Tp, class _A0, class _A1>
   1902 class __result_of<_Fn(_Tp, _A0, _A1), false, true>  // _Fn must be member pointer
   1903     : public __result_of_mp<typename remove_reference<_Fn>::type,
   1904                             _Tp,
   1905                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
   1906 {
   1907 };
   1908 
   1909 template <class _Fn, class _Tp, class _A0, class _A1, class _A2>
   1910 class __result_of<_Fn(_Tp, _A0, _A1, _A2), false, true>  // _Fn must be member pointer
   1911     : public __result_of_mp<typename remove_reference<_Fn>::type,
   1912                             _Tp,
   1913                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
   1914 {
   1915 };
   1916 
   1917 // result_of
   1918 
   1919 template <class _Fn>
   1920 class _LIBCPP_TYPE_VIS result_of<_Fn()>
   1921     : public __result_of<_Fn(),
   1922                          is_class<typename remove_reference<_Fn>::type>::value ||
   1923                          is_function<typename remove_reference<_Fn>::type>::value,
   1924                          is_member_pointer<typename remove_reference<_Fn>::type>::value
   1925                         >
   1926 {
   1927 };
   1928 
   1929 template <class _Fn, class _A0>
   1930 class _LIBCPP_TYPE_VIS result_of<_Fn(_A0)>
   1931     : public __result_of<_Fn(_A0),
   1932                          is_class<typename remove_reference<_Fn>::type>::value ||
   1933                          is_function<typename remove_reference<_Fn>::type>::value,
   1934                          is_member_pointer<typename remove_reference<_Fn>::type>::value
   1935                         >
   1936 {
   1937 };
   1938 
   1939 template <class _Fn, class _A0, class _A1>
   1940 class _LIBCPP_TYPE_VIS result_of<_Fn(_A0, _A1)>
   1941     : public __result_of<_Fn(_A0, _A1),
   1942                          is_class<typename remove_reference<_Fn>::type>::value ||
   1943                          is_function<typename remove_reference<_Fn>::type>::value,
   1944                          is_member_pointer<typename remove_reference<_Fn>::type>::value
   1945                         >
   1946 {
   1947 };
   1948 
   1949 template <class _Fn, class _A0, class _A1, class _A2>
   1950 class _LIBCPP_TYPE_VIS result_of<_Fn(_A0, _A1, _A2)>
   1951     : public __result_of<_Fn(_A0, _A1, _A2),
   1952                          is_class<typename remove_reference<_Fn>::type>::value ||
   1953                          is_function<typename remove_reference<_Fn>::type>::value,
   1954                          is_member_pointer<typename remove_reference<_Fn>::type>::value
   1955                         >
   1956 {
   1957 };
   1958 
   1959 #endif  // _LIBCPP_HAS_NO_VARIADICS
   1960 
   1961 #ifndef _LIBCPP_HAS_NO_VARIADICS
   1962 
   1963 // template <class T, class... Args> struct is_constructible;
   1964 
   1965 //      main is_constructible test
   1966 
   1967 template<typename, typename T> struct __select_2nd { typedef T type; };
   1968 
   1969 template <class _Tp, class ..._Args>
   1970 typename __select_2nd<decltype(_VSTD::move(_Tp(_VSTD::declval<_Args>()...))), true_type>::type
   1971 __is_constructible_test(_Tp&&, _Args&& ...);
   1972 
   1973 template <class ..._Args>
   1974 false_type
   1975 __is_constructible_test(__any, _Args&& ...);
   1976 
   1977 template <bool, class _Tp, class... _Args>
   1978 struct __is_constructible // false, _Tp is not a scalar
   1979     : public common_type
   1980              <
   1981                  decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...))
   1982              >::type
   1983     {};
   1984 
   1985 //      function types are not constructible
   1986 
   1987 template <class _Rp, class... _A1, class... _A2>
   1988 struct __is_constructible<false, _Rp(_A1...), _A2...>
   1989     : public false_type
   1990     {};
   1991 
   1992 //      handle scalars and reference types
   1993 
   1994 //      Scalars are default constructible, references are not
   1995 
   1996 template <class _Tp>
   1997 struct __is_constructible<true, _Tp>
   1998     : public is_scalar<_Tp>
   1999     {};
   2000 
   2001 //      Scalars and references are constructible from one arg if that arg is
   2002 //          implicitly convertible to the scalar or reference.
   2003 
   2004 template <class _Tp>
   2005 struct __is_constructible_ref
   2006 {
   2007     true_type static __lxx(_Tp);
   2008     false_type static __lxx(...);
   2009 };
   2010 
   2011 template <class _Tp, class _A0>
   2012 struct __is_constructible<true, _Tp, _A0>
   2013     : public common_type
   2014              <
   2015                  decltype(__is_constructible_ref<_Tp>::__lxx(declval<_A0>()))
   2016              >::type
   2017     {};
   2018 
   2019 //      Scalars and references are not constructible from multiple args.
   2020 
   2021 template <class _Tp, class _A0, class ..._Args>
   2022 struct __is_constructible<true, _Tp, _A0, _Args...>
   2023     : public false_type
   2024     {};
   2025 
   2026 //      Treat scalars and reference types separately
   2027 
   2028 template <bool, class _Tp, class... _Args>
   2029 struct __is_constructible_void_check
   2030     : public __is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
   2031                                 _Tp, _Args...>
   2032     {};
   2033 
   2034 //      If any of T or Args is void, is_constructible should be false
   2035 
   2036 template <class _Tp, class... _Args>
   2037 struct __is_constructible_void_check<true, _Tp, _Args...>
   2038     : public false_type
   2039     {};
   2040 
   2041 template <class ..._Args> struct __contains_void;
   2042 
   2043 template <> struct __contains_void<> : false_type {};
   2044 
   2045 template <class _A0, class ..._Args>
   2046 struct __contains_void<_A0, _Args...>
   2047 {
   2048     static const bool value = is_void<_A0>::value ||
   2049                               __contains_void<_Args...>::value;
   2050 };
   2051 
   2052 //      is_constructible entry point
   2053 
   2054 template <class _Tp, class... _Args>
   2055 struct _LIBCPP_TYPE_VIS is_constructible
   2056     : public __is_constructible_void_check<__contains_void<_Tp, _Args...>::value
   2057                                         || is_abstract<_Tp>::value,
   2058                                            _Tp, _Args...>
   2059     {};
   2060 
   2061 //      Array types are default constructible if their element type
   2062 //      is default constructible
   2063 
   2064 template <class _Ap, size_t _Np>
   2065 struct __is_constructible<false, _Ap[_Np]>
   2066     : public is_constructible<typename remove_all_extents<_Ap>::type>
   2067     {};
   2068 
   2069 //      Otherwise array types are not constructible by this syntax
   2070 
   2071 template <class _Ap, size_t _Np, class ..._Args>
   2072 struct __is_constructible<false, _Ap[_Np], _Args...>
   2073     : public false_type
   2074     {};
   2075 
   2076 //      Incomplete array types are not constructible
   2077 
   2078 template <class _Ap, class ..._Args>
   2079 struct __is_constructible<false, _Ap[], _Args...>
   2080     : public false_type
   2081     {};
   2082 
   2083 #else  // _LIBCPP_HAS_NO_VARIADICS
   2084 
   2085 // template <class T> struct is_constructible0;
   2086 
   2087 //      main is_constructible0 test
   2088 
   2089 template <class _Tp>
   2090 decltype((_Tp(), true_type()))
   2091 __is_constructible0_test(_Tp&);
   2092 
   2093 false_type
   2094 __is_constructible0_test(__any);
   2095 
   2096 template <class _Tp, class _A0>
   2097 decltype((_Tp(_VSTD::declval<_A0>()), true_type()))
   2098 __is_constructible1_test(_Tp&, _A0&);
   2099 
   2100 template <class _A0>
   2101 false_type
   2102 __is_constructible1_test(__any, _A0&);
   2103 
   2104 template <class _Tp, class _A0, class _A1>
   2105 decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>()), true_type()))
   2106 __is_constructible2_test(_Tp&, _A0&, _A1&);
   2107 
   2108 template <class _A0, class _A1>
   2109 false_type
   2110 __is_constructible2_test(__any, _A0&, _A1&);
   2111 
   2112 template <bool, class _Tp>
   2113 struct __is_constructible0_imp // false, _Tp is not a scalar
   2114     : public common_type
   2115              <
   2116                  decltype(__is_constructible0_test(declval<_Tp&>()))
   2117              >::type
   2118     {};
   2119 
   2120 template <bool, class _Tp, class _A0>
   2121 struct __is_constructible1_imp // false, _Tp is not a scalar
   2122     : public common_type
   2123              <
   2124                  decltype(__is_constructible1_test(declval<_Tp&>(), declval<_A0&>()))
   2125              >::type
   2126     {};
   2127 
   2128 template <bool, class _Tp, class _A0, class _A1>
   2129 struct __is_constructible2_imp // false, _Tp is not a scalar
   2130     : public common_type
   2131              <
   2132                  decltype(__is_constructible2_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>()))
   2133              >::type
   2134     {};
   2135 
   2136 //      handle scalars and reference types
   2137 
   2138 //      Scalars are default constructible, references are not
   2139 
   2140 template <class _Tp>
   2141 struct __is_constructible0_imp<true, _Tp>
   2142     : public is_scalar<_Tp>
   2143     {};
   2144 
   2145 template <class _Tp, class _A0>
   2146 struct __is_constructible1_imp<true, _Tp, _A0>
   2147     : public is_convertible<_A0, _Tp>
   2148     {};
   2149 
   2150 template <class _Tp, class _A0, class _A1>
   2151 struct __is_constructible2_imp<true, _Tp, _A0, _A1>
   2152     : public false_type
   2153     {};
   2154 
   2155 //      Treat scalars and reference types separately
   2156 
   2157 template <bool, class _Tp>
   2158 struct __is_constructible0_void_check
   2159     : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
   2160                                 _Tp>
   2161     {};
   2162 
   2163 template <bool, class _Tp, class _A0>
   2164 struct __is_constructible1_void_check
   2165     : public __is_constructible1_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
   2166                                 _Tp, _A0>
   2167     {};
   2168 
   2169 template <bool, class _Tp, class _A0, class _A1>
   2170 struct __is_constructible2_void_check
   2171     : public __is_constructible2_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
   2172                                 _Tp, _A0, _A1>
   2173     {};
   2174 
   2175 //      If any of T or Args is void, is_constructible should be false
   2176 
   2177 template <class _Tp>
   2178 struct __is_constructible0_void_check<true, _Tp>
   2179     : public false_type
   2180     {};
   2181 
   2182 template <class _Tp, class _A0>
   2183 struct __is_constructible1_void_check<true, _Tp, _A0>
   2184     : public false_type
   2185     {};
   2186 
   2187 template <class _Tp, class _A0, class _A1>
   2188 struct __is_constructible2_void_check<true, _Tp, _A0, _A1>
   2189     : public false_type
   2190     {};
   2191 
   2192 //      is_constructible entry point
   2193 
   2194 namespace __is_construct
   2195 {
   2196 
   2197 struct __nat {};
   2198 
   2199 }
   2200 
   2201 template <class _Tp, class _A0 = __is_construct::__nat,
   2202                      class _A1 = __is_construct::__nat>
   2203 struct _LIBCPP_TYPE_VIS is_constructible
   2204     : public __is_constructible2_void_check<is_void<_Tp>::value
   2205                                         || is_abstract<_Tp>::value
   2206                                         || is_function<_Tp>::value
   2207                                         || is_void<_A0>::value
   2208                                         || is_void<_A1>::value,
   2209                                            _Tp, _A0, _A1>
   2210     {};
   2211 
   2212 template <class _Tp>
   2213 struct _LIBCPP_TYPE_VIS is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat>
   2214     : public __is_constructible0_void_check<is_void<_Tp>::value
   2215                                         || is_abstract<_Tp>::value
   2216                                         || is_function<_Tp>::value,
   2217                                            _Tp>
   2218     {};
   2219 
   2220 template <class _Tp, class _A0>
   2221 struct _LIBCPP_TYPE_VIS is_constructible<_Tp, _A0, __is_construct::__nat>
   2222     : public __is_constructible1_void_check<is_void<_Tp>::value
   2223                                         || is_abstract<_Tp>::value
   2224                                         || is_function<_Tp>::value
   2225                                         || is_void<_A0>::value,
   2226                                            _Tp, _A0>
   2227     {};
   2228 
   2229 //      Array types are default constructible if their element type
   2230 //      is default constructible
   2231 
   2232 template <class _Ap, size_t _Np>
   2233 struct __is_constructible0_imp<false, _Ap[_Np]>
   2234     : public is_constructible<typename remove_all_extents<_Ap>::type>
   2235     {};
   2236 
   2237 template <class _Ap, size_t _Np, class _A0>
   2238 struct __is_constructible1_imp<false, _Ap[_Np], _A0>
   2239     : public false_type
   2240     {};
   2241 
   2242 template <class _Ap, size_t _Np, class _A0, class _A1>
   2243 struct __is_constructible2_imp<false, _Ap[_Np], _A0, _A1>
   2244     : public false_type
   2245     {};
   2246 
   2247 //      Incomplete array types are not constructible
   2248 
   2249 template <class _Ap>
   2250 struct __is_constructible0_imp<false, _Ap[]>
   2251     : public false_type
   2252     {};
   2253 
   2254 template <class _Ap, class _A0>
   2255 struct __is_constructible1_imp<false, _Ap[], _A0>
   2256     : public false_type
   2257     {};
   2258 
   2259 template <class _Ap, class _A0, class _A1>
   2260 struct __is_constructible2_imp<false, _Ap[], _A0, _A1>
   2261     : public false_type
   2262     {};
   2263 
   2264 #endif  // _LIBCPP_HAS_NO_VARIADICS
   2265 
   2266 // is_default_constructible
   2267 
   2268 template <class _Tp>
   2269 struct _LIBCPP_TYPE_VIS is_default_constructible
   2270     : public is_constructible<_Tp>
   2271     {};
   2272 
   2273 // is_copy_constructible
   2274 
   2275 template <class _Tp>
   2276 struct _LIBCPP_TYPE_VIS is_copy_constructible
   2277     : public is_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
   2278     {};
   2279 
   2280 // is_move_constructible
   2281 
   2282 template <class _Tp>
   2283 struct _LIBCPP_TYPE_VIS is_move_constructible
   2284 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2285     : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
   2286 #else
   2287     : public is_copy_constructible<_Tp>
   2288 #endif
   2289     {};
   2290 
   2291 // is_trivially_constructible
   2292 
   2293 #ifndef _LIBCPP_HAS_NO_VARIADICS
   2294 
   2295 #if __has_feature(is_trivially_constructible)
   2296 
   2297 template <class _Tp, class... _Args>
   2298 struct _LIBCPP_TYPE_VIS is_trivially_constructible
   2299     : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
   2300 {
   2301 };
   2302 
   2303 #else  // !__has_feature(is_trivially_constructible)
   2304 
   2305 template <class _Tp, class... _Args>
   2306 struct _LIBCPP_TYPE_VIS is_trivially_constructible
   2307     : false_type
   2308 {
   2309 };
   2310 
   2311 template <class _Tp>
   2312 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp>
   2313 #if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2314     : integral_constant<bool, __has_trivial_constructor(_Tp)>
   2315 #else
   2316     : integral_constant<bool, is_scalar<_Tp>::value>
   2317 #endif
   2318 {
   2319 };
   2320 
   2321 template <class _Tp>
   2322 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2323 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp&&>
   2324 #else
   2325 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp>
   2326 #endif
   2327     : integral_constant<bool, is_scalar<_Tp>::value>
   2328 {
   2329 };
   2330 
   2331 template <class _Tp>
   2332 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, const _Tp&>
   2333     : integral_constant<bool, is_scalar<_Tp>::value>
   2334 {
   2335 };
   2336 
   2337 template <class _Tp>
   2338 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp&>
   2339     : integral_constant<bool, is_scalar<_Tp>::value>
   2340 {
   2341 };
   2342 
   2343 #endif  // !__has_feature(is_trivially_constructible)
   2344 
   2345 #else  // _LIBCPP_HAS_NO_VARIADICS
   2346 
   2347 template <class _Tp, class _A0 = __is_construct::__nat,
   2348                      class _A1 = __is_construct::__nat>
   2349 struct _LIBCPP_TYPE_VIS is_trivially_constructible
   2350     : false_type
   2351 {
   2352 };
   2353 
   2354 #if __has_feature(is_trivially_constructible)
   2355 
   2356 template <class _Tp>
   2357 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, __is_construct::__nat,
   2358                                                        __is_construct::__nat>
   2359     : integral_constant<bool, __is_trivially_constructible(_Tp)>
   2360 {
   2361 };
   2362 
   2363 template <class _Tp>
   2364 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp,
   2365                                                        __is_construct::__nat>
   2366     : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)>
   2367 {
   2368 };
   2369 
   2370 template <class _Tp>
   2371 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, const _Tp&,
   2372                                                        __is_construct::__nat>
   2373     : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)>
   2374 {
   2375 };
   2376 
   2377 template <class _Tp>
   2378 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp&,
   2379                                                        __is_construct::__nat>
   2380     : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)>
   2381 {
   2382 };
   2383 
   2384 #else  // !__has_feature(is_trivially_constructible)
   2385 
   2386 template <class _Tp>
   2387 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, __is_construct::__nat,
   2388                                                        __is_construct::__nat>
   2389     : integral_constant<bool, is_scalar<_Tp>::value>
   2390 {
   2391 };
   2392 
   2393 template <class _Tp>
   2394 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp,
   2395                                                        __is_construct::__nat>
   2396     : integral_constant<bool, is_scalar<_Tp>::value>
   2397 {
   2398 };
   2399 
   2400 template <class _Tp>
   2401 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, const _Tp&,
   2402                                                        __is_construct::__nat>
   2403     : integral_constant<bool, is_scalar<_Tp>::value>
   2404 {
   2405 };
   2406 
   2407 template <class _Tp>
   2408 struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp&,
   2409                                                        __is_construct::__nat>
   2410     : integral_constant<bool, is_scalar<_Tp>::value>
   2411 {
   2412 };
   2413 
   2414 #endif  // !__has_feature(is_trivially_constructible)
   2415 
   2416 #endif  // _LIBCPP_HAS_NO_VARIADICS
   2417 
   2418 // is_trivially_default_constructible
   2419 
   2420 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_default_constructible
   2421     : public is_trivially_constructible<_Tp>
   2422     {};
   2423 
   2424 // is_trivially_copy_constructible
   2425 
   2426 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_copy_constructible
   2427     : public is_trivially_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
   2428     {};
   2429 
   2430 // is_trivially_move_constructible
   2431 
   2432 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_move_constructible
   2433 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2434     : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
   2435 #else
   2436     : public is_trivially_copy_constructible<_Tp>
   2437 #endif
   2438     {};
   2439 
   2440 // is_trivially_assignable
   2441 
   2442 #if __has_feature(is_trivially_constructible)
   2443 
   2444 template <class _Tp, class _Arg>
   2445 struct is_trivially_assignable
   2446     : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
   2447 {
   2448 };
   2449 
   2450 #else  // !__has_feature(is_trivially_constructible)
   2451 
   2452 template <class _Tp, class _Arg>
   2453 struct is_trivially_assignable
   2454     : public false_type {};
   2455 
   2456 template <class _Tp>
   2457 struct is_trivially_assignable<_Tp&, _Tp>
   2458     : integral_constant<bool, is_scalar<_Tp>::value> {};
   2459 
   2460 template <class _Tp>
   2461 struct is_trivially_assignable<_Tp&, _Tp&>
   2462     : integral_constant<bool, is_scalar<_Tp>::value> {};
   2463 
   2464 template <class _Tp>
   2465 struct is_trivially_assignable<_Tp&, const _Tp&>
   2466     : integral_constant<bool, is_scalar<_Tp>::value> {};
   2467 
   2468 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2469 
   2470 template <class _Tp>
   2471 struct is_trivially_assignable<_Tp&, _Tp&&>
   2472     : integral_constant<bool, is_scalar<_Tp>::value> {};
   2473 
   2474 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2475 
   2476 #endif  // !__has_feature(is_trivially_constructible)
   2477 
   2478 // is_trivially_copy_assignable
   2479 
   2480 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_copy_assignable
   2481     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
   2482                                const typename add_lvalue_reference<_Tp>::type>
   2483     {};
   2484 
   2485 // is_trivially_move_assignable
   2486 
   2487 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_move_assignable
   2488     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
   2489 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2490                                      typename add_rvalue_reference<_Tp>::type>
   2491 #else
   2492                                      typename add_lvalue_reference<_Tp>::type>
   2493 #endif
   2494     {};
   2495 
   2496 // is_trivially_destructible
   2497 
   2498 #if __has_feature(has_trivial_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2499 
   2500 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_destructible
   2501     : public integral_constant<bool, __has_trivial_destructor(_Tp)> {};
   2502 
   2503 #else  // _LIBCPP_HAS_TYPE_TRAITS
   2504 
   2505 template <class _Tp> struct __libcpp_trivial_destructor
   2506     : public integral_constant<bool, is_scalar<_Tp>::value ||
   2507                                      is_reference<_Tp>::value> {};
   2508 
   2509 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_destructible
   2510     : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
   2511 
   2512 #endif  // _LIBCPP_HAS_TYPE_TRAITS
   2513 
   2514 // is_nothrow_constructible
   2515 
   2516 #ifndef _LIBCPP_HAS_NO_VARIADICS
   2517 
   2518 #if __has_feature(cxx_noexcept)
   2519 
   2520 template <bool, class _Tp, class... _Args> struct __is_nothrow_constructible;
   2521 
   2522 template <class _Tp, class... _Args>
   2523 struct __is_nothrow_constructible<true, _Tp, _Args...>
   2524     : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
   2525 {
   2526 };
   2527 
   2528 template <class _Tp, class... _Args>
   2529 struct __is_nothrow_constructible<false, _Tp, _Args...>
   2530     : public false_type
   2531 {
   2532 };
   2533 
   2534 template <class _Tp, class... _Args>
   2535 struct _LIBCPP_TYPE_VIS is_nothrow_constructible
   2536     : __is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, _Tp, _Args...>
   2537 {
   2538 };
   2539 
   2540 template <class _Tp, size_t _Ns>
   2541 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp[_Ns]>
   2542     : __is_nothrow_constructible<is_constructible<_Tp>::value, _Tp>
   2543 {
   2544 };
   2545 
   2546 #else  // __has_feature(cxx_noexcept)
   2547 
   2548 template <class _Tp, class... _Args>
   2549 struct _LIBCPP_TYPE_VIS is_nothrow_constructible
   2550     : false_type
   2551 {
   2552 };
   2553 
   2554 template <class _Tp>
   2555 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp>
   2556 #if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2557     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
   2558 #else
   2559     : integral_constant<bool, is_scalar<_Tp>::value>
   2560 #endif
   2561 {
   2562 };
   2563 
   2564 template <class _Tp>
   2565 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2566 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp&&>
   2567 #else
   2568 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp>
   2569 #endif
   2570 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2571     : integral_constant<bool, __has_nothrow_copy(_Tp)>
   2572 #else
   2573     : integral_constant<bool, is_scalar<_Tp>::value>
   2574 #endif
   2575 {
   2576 };
   2577 
   2578 template <class _Tp>
   2579 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, const _Tp&>
   2580 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2581     : integral_constant<bool, __has_nothrow_copy(_Tp)>
   2582 #else
   2583     : integral_constant<bool, is_scalar<_Tp>::value>
   2584 #endif
   2585 {
   2586 };
   2587 
   2588 template <class _Tp>
   2589 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp&>
   2590 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2591     : integral_constant<bool, __has_nothrow_copy(_Tp)>
   2592 #else
   2593     : integral_constant<bool, is_scalar<_Tp>::value>
   2594 #endif
   2595 {
   2596 };
   2597 
   2598 #endif  // __has_feature(cxx_noexcept)
   2599 
   2600 #else  // _LIBCPP_HAS_NO_VARIADICS
   2601 
   2602 template <class _Tp, class _A0 = __is_construct::__nat,
   2603                      class _A1 = __is_construct::__nat>
   2604 struct _LIBCPP_TYPE_VIS is_nothrow_constructible
   2605     : false_type
   2606 {
   2607 };
   2608 
   2609 template <class _Tp>
   2610 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, __is_construct::__nat,
   2611                                                        __is_construct::__nat>
   2612 #if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2613     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
   2614 #else
   2615     : integral_constant<bool, is_scalar<_Tp>::value>
   2616 #endif
   2617 {
   2618 };
   2619 
   2620 template <class _Tp>
   2621 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp,
   2622                                                        __is_construct::__nat>
   2623 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2624     : integral_constant<bool, __has_nothrow_copy(_Tp)>
   2625 #else
   2626     : integral_constant<bool, is_scalar<_Tp>::value>
   2627 #endif
   2628 {
   2629 };
   2630 
   2631 template <class _Tp>
   2632 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, const _Tp&,
   2633                                                        __is_construct::__nat>
   2634 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2635     : integral_constant<bool, __has_nothrow_copy(_Tp)>
   2636 #else
   2637     : integral_constant<bool, is_scalar<_Tp>::value>
   2638 #endif
   2639 {
   2640 };
   2641 
   2642 template <class _Tp>
   2643 struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp&,
   2644                                                        __is_construct::__nat>
   2645 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2646     : integral_constant<bool, __has_nothrow_copy(_Tp)>
   2647 #else
   2648     : integral_constant<bool, is_scalar<_Tp>::value>
   2649 #endif
   2650 {
   2651 };
   2652 
   2653 #endif  // _LIBCPP_HAS_NO_VARIADICS
   2654 
   2655 // is_nothrow_default_constructible
   2656 
   2657 template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_default_constructible
   2658     : public is_nothrow_constructible<_Tp>
   2659     {};
   2660 
   2661 // is_nothrow_copy_constructible
   2662 
   2663 template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_copy_constructible
   2664     : public is_nothrow_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
   2665     {};
   2666 
   2667 // is_nothrow_move_constructible
   2668 
   2669 template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_move_constructible
   2670 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2671     : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
   2672 #else
   2673     : public is_nothrow_copy_constructible<_Tp>
   2674 #endif
   2675     {};
   2676 
   2677 // is_nothrow_assignable
   2678 
   2679 #if __has_feature(cxx_noexcept)
   2680 
   2681 template <bool, class _Tp, class _Arg> struct __is_nothrow_assignable;
   2682 
   2683 template <class _Tp, class _Arg>
   2684 struct __is_nothrow_assignable<false, _Tp, _Arg>
   2685     : public false_type
   2686 {
   2687 };
   2688 
   2689 template <class _Tp, class _Arg>
   2690 struct __is_nothrow_assignable<true, _Tp, _Arg>
   2691     : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>()) >
   2692 {
   2693 };
   2694 
   2695 template <class _Tp, class _Arg>
   2696 struct _LIBCPP_TYPE_VIS is_nothrow_assignable
   2697     : public __is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
   2698 {
   2699 };
   2700 
   2701 #else  // __has_feature(cxx_noexcept)
   2702 
   2703 template <class _Tp, class _Arg>
   2704 struct _LIBCPP_TYPE_VIS is_nothrow_assignable
   2705     : public false_type {};
   2706 
   2707 template <class _Tp>
   2708 struct _LIBCPP_TYPE_VIS is_nothrow_assignable<_Tp&, _Tp>
   2709 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2710     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
   2711 #else
   2712     : integral_constant<bool, is_scalar<_Tp>::value> {};
   2713 #endif
   2714 
   2715 template <class _Tp>
   2716 struct _LIBCPP_TYPE_VIS is_nothrow_assignable<_Tp&, _Tp&>
   2717 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2718     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
   2719 #else
   2720     : integral_constant<bool, is_scalar<_Tp>::value> {};
   2721 #endif
   2722 
   2723 template <class _Tp>
   2724 struct _LIBCPP_TYPE_VIS is_nothrow_assignable<_Tp&, const _Tp&>
   2725 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2726     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
   2727 #else
   2728     : integral_constant<bool, is_scalar<_Tp>::value> {};
   2729 #endif
   2730 
   2731 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2732 
   2733 template <class _Tp>
   2734 struct is_nothrow_assignable<_Tp&, _Tp&&>
   2735 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2736     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
   2737 #else
   2738     : integral_constant<bool, is_scalar<_Tp>::value> {};
   2739 #endif
   2740 
   2741 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2742 
   2743 #endif  // __has_feature(cxx_noexcept)
   2744 
   2745 // is_nothrow_copy_assignable
   2746 
   2747 template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_copy_assignable
   2748     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
   2749                                const typename add_lvalue_reference<_Tp>::type>
   2750     {};
   2751 
   2752 // is_nothrow_move_assignable
   2753 
   2754 template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_move_assignable
   2755     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
   2756 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2757                                      typename add_rvalue_reference<_Tp>::type>
   2758 #else
   2759                                      typename add_lvalue_reference<_Tp>::type>
   2760 #endif
   2761     {};
   2762 
   2763 // is_nothrow_destructible
   2764 
   2765 #if __has_feature(cxx_noexcept)
   2766 
   2767 template <bool, class _Tp> struct __is_nothrow_destructible;
   2768 
   2769 template <class _Tp>
   2770 struct __is_nothrow_destructible<false, _Tp>
   2771     : public false_type
   2772 {
   2773 };
   2774 
   2775 template <class _Tp>
   2776 struct __is_nothrow_destructible<true, _Tp>
   2777     : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>().~_Tp()) >
   2778 {
   2779 };
   2780 
   2781 template <class _Tp>
   2782 struct _LIBCPP_TYPE_VIS is_nothrow_destructible
   2783     : public __is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
   2784 {
   2785 };
   2786 
   2787 template <class _Tp, size_t _Ns>
   2788 struct _LIBCPP_TYPE_VIS is_nothrow_destructible<_Tp[_Ns]>
   2789     : public is_nothrow_destructible<_Tp>
   2790 {
   2791 };
   2792 
   2793 template <class _Tp>
   2794 struct _LIBCPP_TYPE_VIS is_nothrow_destructible<_Tp&>
   2795     : public true_type
   2796 {
   2797 };
   2798 
   2799 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
   2800 
   2801 template <class _Tp>
   2802 struct _LIBCPP_TYPE_VIS is_nothrow_destructible<_Tp&&>
   2803     : public true_type
   2804 {
   2805 };
   2806 
   2807 #endif
   2808 
   2809 #else
   2810 
   2811 template <class _Tp> struct __libcpp_nothrow_destructor
   2812     : public integral_constant<bool, is_scalar<_Tp>::value ||
   2813                                      is_reference<_Tp>::value> {};
   2814 
   2815 template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_destructible
   2816     : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
   2817 
   2818 #endif
   2819 
   2820 // is_pod
   2821 
   2822 #if __has_feature(is_pod) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
   2823 
   2824 template <class _Tp> struct _LIBCPP_TYPE_VIS is_pod
   2825     : public integral_constant<bool, __is_pod(_Tp)> {};
   2826 
   2827 #else  // _LIBCPP_HAS_TYPE_TRAITS
   2828 
   2829 template <class _Tp> struct _LIBCPP_TYPE_VIS is_pod
   2830     : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
   2831                                      is_trivially_copy_constructible<_Tp>::value      &&
   2832                                      is_trivially_copy_assignable<_Tp>::value    &&
   2833                                      is_trivially_destructible<_Tp>::value> {};
   2834 
   2835 #endif  // _LIBCPP_HAS_TYPE_TRAITS
   2836 
   2837 // is_literal_type;
   2838 
   2839 template <class _Tp> struct _LIBCPP_TYPE_VIS is_literal_type
   2840 #if __has_feature(is_literal)
   2841     : public integral_constant<bool, __is_literal(_Tp)>
   2842 #else
   2843     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value ||
   2844                               is_reference<typename remove_all_extents<_Tp>::type>::value>
   2845 #endif
   2846     {};
   2847     
   2848 // is_standard_layout;
   2849 
   2850 template <class _Tp> struct _LIBCPP_TYPE_VIS is_standard_layout
   2851 #if __has_feature(is_standard_layout)
   2852     : public integral_constant<bool, __is_standard_layout(_Tp)>
   2853 #else
   2854     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
   2855 #endif
   2856     {};
   2857     
   2858 // is_trivially_copyable;
   2859 
   2860 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_copyable
   2861 #if __has_feature(is_trivially_copyable)
   2862     : public integral_constant<bool, __is_trivially_copyable(_Tp)>
   2863 #else
   2864     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
   2865 #endif
   2866     {};
   2867     
   2868 // is_trivial;
   2869 
   2870 template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivial
   2871 #if __has_feature(is_trivial)
   2872     : public integral_constant<bool, __is_trivial(_Tp)>
   2873 #else
   2874     : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
   2875                                  is_trivially_default_constructible<_Tp>::value>
   2876 #endif
   2877     {};
   2878 
   2879 #ifndef _LIBCPP_HAS_NO_VARIADICS
   2880 
   2881 // Check for complete types
   2882 
   2883 template <class ..._Tp> struct __check_complete;
   2884 
   2885 template <>
   2886 struct __check_complete<>
   2887 {
   2888 };
   2889 
   2890 template <class _Hp, class _T0, class ..._Tp>
   2891 struct __check_complete<_Hp, _T0, _Tp...>
   2892     : private __check_complete<_Hp>,
   2893       private __check_complete<_T0, _Tp...>
   2894 {
   2895 };
   2896 
   2897 template <class _Hp>
   2898 struct __check_complete<_Hp, _Hp>
   2899     : private __check_complete<_Hp>
   2900 {
   2901 };
   2902 
   2903 template <class _Tp>
   2904 struct __check_complete<_Tp>
   2905 {
   2906     static_assert(sizeof(_Tp) > 0, "Type must be complete.");
   2907 };
   2908 
   2909 template <class _Tp>
   2910 struct __check_complete<_Tp&>
   2911     : private __check_complete<_Tp>
   2912 {
   2913 };
   2914 
   2915 template <class _Tp>
   2916 struct __check_complete<_Tp&&>
   2917     : private __check_complete<_Tp>
   2918 {
   2919 };
   2920 
   2921 template <class _Rp, class ..._Param>
   2922 struct __check_complete<_Rp (*)(_Param...)>
   2923     : private __check_complete<_Rp>
   2924 {
   2925 };
   2926 
   2927 template <class _Rp, class ..._Param>
   2928 struct __check_complete<_Rp (_Param...)>
   2929     : private __check_complete<_Rp>
   2930 {
   2931 };
   2932 
   2933 template <class _Rp, class _Class, class ..._Param>
   2934 struct __check_complete<_Rp (_Class::*)(_Param...)>
   2935     : private __check_complete<_Class>
   2936 {
   2937 };
   2938 
   2939 template <class _Rp, class _Class, class ..._Param>
   2940 struct __check_complete<_Rp (_Class::*)(_Param...) const>
   2941     : private __check_complete<_Class>
   2942 {
   2943 };
   2944 
   2945 template <class _Rp, class _Class, class ..._Param>
   2946 struct __check_complete<_Rp (_Class::*)(_Param...) volatile>
   2947     : private __check_complete<_Class>
   2948 {
   2949 };
   2950 
   2951 template <class _Rp, class _Class, class ..._Param>
   2952 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile>
   2953     : private __check_complete<_Class>
   2954 {
   2955 };
   2956 
   2957 #if __has_feature(cxx_reference_qualified_functions)
   2958 
   2959 template <class _Rp, class _Class, class ..._Param>
   2960 struct __check_complete<_Rp (_Class::*)(_Param...) &>
   2961     : private __check_complete<_Class>
   2962 {
   2963 };
   2964 
   2965 template <class _Rp, class _Class, class ..._Param>
   2966 struct __check_complete<_Rp (_Class::*)(_Param...) const&>
   2967     : private __check_complete<_Class>
   2968 {
   2969 };
   2970 
   2971 template <class _Rp, class _Class, class ..._Param>
   2972 struct __check_complete<_Rp (_Class::*)(_Param...) volatile&>
   2973     : private __check_complete<_Class>
   2974 {
   2975 };
   2976 
   2977 template <class _Rp, class _Class, class ..._Param>
   2978 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&>
   2979     : private __check_complete<_Class>
   2980 {
   2981 };
   2982 
   2983 template <class _Rp, class _Class, class ..._Param>
   2984 struct __check_complete<_Rp (_Class::*)(_Param...) &&>
   2985     : private __check_complete<_Class>
   2986 {
   2987 };
   2988 
   2989 template <class _Rp, class _Class, class ..._Param>
   2990 struct __check_complete<_Rp (_Class::*)(_Param...) const&&>
   2991     : private __check_complete<_Class>
   2992 {
   2993 };
   2994 
   2995 template <class _Rp, class _Class, class ..._Param>
   2996 struct __check_complete<_Rp (_Class::*)(_Param...) volatile&&>
   2997     : private __check_complete<_Class>
   2998 {
   2999 };
   3000 
   3001 template <class _Rp, class _Class, class ..._Param>
   3002 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&&>
   3003     : private __check_complete<_Class>
   3004 {
   3005 };
   3006 
   3007 #endif
   3008 
   3009 template <class _Rp, class _Class>
   3010 struct __check_complete<_Rp _Class::*>
   3011     : private __check_complete<_Class>
   3012 {
   3013 };
   3014 
   3015 // __invoke forward declarations
   3016 
   3017 // fall back - none of the bullets
   3018 
   3019 template <class ..._Args>
   3020 auto
   3021 __invoke(__any, _Args&& ...__args)
   3022     -> __nat;
   3023 
   3024 // bullets 1 and 2
   3025 
   3026 template <class _Fp, class _A0, class ..._Args,
   3027             class = typename enable_if
   3028             <
   3029                 is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
   3030                 is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
   3031                            typename remove_reference<_A0>::type>::value
   3032             >::type
   3033          >
   3034 _LIBCPP_INLINE_VISIBILITY
   3035 auto
   3036 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
   3037     -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...));
   3038 
   3039 template <class _Fp, class _A0, class ..._Args,
   3040             class = typename enable_if
   3041             <
   3042                 is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
   3043                 !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
   3044                            typename remove_reference<_A0>::type>::value
   3045             >::type
   3046          >
   3047 _LIBCPP_INLINE_VISIBILITY
   3048 auto
   3049 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
   3050     -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...));
   3051 
   3052 // bullets 3 and 4
   3053 
   3054 template <class _Fp, class _A0,
   3055             class = typename enable_if
   3056             <
   3057                 is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
   3058                 is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
   3059                            typename remove_reference<_A0>::type>::value
   3060             >::type
   3061          >
   3062 _LIBCPP_INLINE_VISIBILITY
   3063 auto
   3064 __invoke(_Fp&& __f, _A0&& __a0)
   3065     -> decltype(_VSTD::forward<_A0>(__a0).*__f);
   3066 
   3067 template <class _Fp, class _A0,
   3068             class = typename enable_if
   3069             <
   3070                 is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
   3071                 !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
   3072                            typename remove_reference<_A0>::type>::value
   3073             >::type
   3074          >
   3075 _LIBCPP_INLINE_VISIBILITY
   3076 auto
   3077 __invoke(_Fp&& __f, _A0&& __a0)
   3078     -> decltype((*_VSTD::forward<_A0>(__a0)).*__f);
   3079 
   3080 // bullet 5
   3081 
   3082 template <class _Fp, class ..._Args>
   3083 _LIBCPP_INLINE_VISIBILITY
   3084 auto
   3085 __invoke(_Fp&& __f, _Args&& ...__args)
   3086     -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...));
   3087 
   3088 // __invokable
   3089 
   3090 template <class _Fp, class ..._Args>
   3091 struct __invokable_imp
   3092     : private __check_complete<_Fp>
   3093 {
   3094     typedef decltype(
   3095             __invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)
   3096                     ) type;
   3097     static const bool value = !is_same<type, __nat>::value;
   3098 };
   3099 
   3100 template <class _Fp, class ..._Args>
   3101 struct __invokable
   3102     : public integral_constant<bool,
   3103           __invokable_imp<_Fp, _Args...>::value>
   3104 {
   3105 };
   3106 
   3107 // __invoke_of
   3108 
   3109 template <bool _Invokable, class _Fp, class ..._Args>
   3110 struct __invoke_of_imp  // false
   3111 {
   3112 };
   3113 
   3114 template <class _Fp, class ..._Args>
   3115 struct __invoke_of_imp<true, _Fp, _Args...>
   3116 {
   3117     typedef typename __invokable_imp<_Fp, _Args...>::type type;
   3118 };
   3119 
   3120 template <class _Fp, class ..._Args>
   3121 struct __invoke_of
   3122     : public __invoke_of_imp<__invokable<_Fp, _Args...>::value, _Fp, _Args...>
   3123 {
   3124 };
   3125 
   3126 template <class _Fp, class ..._Args>
   3127 class _LIBCPP_TYPE_VIS result_of<_Fp(_Args...)>
   3128     : public __invoke_of<_Fp, _Args...>
   3129 {
   3130 };
   3131 
   3132 #if _LIBCPP_STD_VER > 11
   3133 template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
   3134 #endif
   3135 
   3136 #endif  // _LIBCPP_HAS_NO_VARIADICS
   3137 
   3138 template <class _Tp>
   3139 inline _LIBCPP_INLINE_VISIBILITY
   3140 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
   3141 typename enable_if
   3142 <
   3143     is_move_constructible<_Tp>::value &&
   3144     is_move_assignable<_Tp>::value
   3145 >::type
   3146 #else
   3147 void
   3148 #endif
   3149 swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
   3150                                     is_nothrow_move_assignable<_Tp>::value)
   3151 {
   3152     _Tp __t(_VSTD::move(__x));
   3153     __x = _VSTD::move(__y);
   3154     __y = _VSTD::move(__t);
   3155 }
   3156 
   3157 template <class _ForwardIterator1, class _ForwardIterator2>
   3158 inline _LIBCPP_INLINE_VISIBILITY
   3159 void
   3160 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
   3161     //                                  _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
   3162                _NOEXCEPT_(_NOEXCEPT_(swap(*_VSTD::declval<_ForwardIterator1>(),
   3163                                           *_VSTD::declval<_ForwardIterator2>())))
   3164 {
   3165     swap(*__a, *__b);
   3166 }
   3167 
   3168 // __swappable
   3169 
   3170 namespace __detail
   3171 {
   3172 
   3173 using _VSTD::swap;
   3174 __nat swap(__any, __any);
   3175 
   3176 template <class _Tp>
   3177 struct __swappable
   3178 {
   3179     typedef decltype(swap(_VSTD::declval<_Tp&>(), _VSTD::declval<_Tp&>())) type;
   3180     static const bool value = !is_same<type, __nat>::value;
   3181 };
   3182 
   3183 }  // __detail
   3184 
   3185 template <class _Tp>
   3186 struct __is_swappable
   3187     : public integral_constant<bool, __detail::__swappable<_Tp>::value>
   3188 {
   3189 };
   3190 
   3191 #if __has_feature(cxx_noexcept)
   3192 
   3193 template <bool, class _Tp>
   3194 struct __is_nothrow_swappable_imp
   3195     : public integral_constant<bool, noexcept(swap(_VSTD::declval<_Tp&>(),
   3196                                                    _VSTD::declval<_Tp&>()))>
   3197 {
   3198 };
   3199 
   3200 template <class _Tp>
   3201 struct __is_nothrow_swappable_imp<false, _Tp>
   3202     : public false_type
   3203 {
   3204 };
   3205 
   3206 template <class _Tp>
   3207 struct __is_nothrow_swappable
   3208     : public __is_nothrow_swappable_imp<__is_swappable<_Tp>::value, _Tp>
   3209 {
   3210 };
   3211 
   3212 #else  // __has_feature(cxx_noexcept)
   3213 
   3214 template <class _Tp>
   3215 struct __is_nothrow_swappable
   3216     : public false_type
   3217 {
   3218 };
   3219 
   3220 #endif  // __has_feature(cxx_noexcept)
   3221 
   3222 #ifdef _LIBCXX_UNDERLYING_TYPE
   3223 
   3224 template <class _Tp>
   3225 struct underlying_type
   3226 {
   3227     typedef _LIBCXX_UNDERLYING_TYPE(_Tp) type;
   3228 };
   3229 
   3230 #if _LIBCPP_STD_VER > 11
   3231 template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
   3232 #endif
   3233 
   3234 #else  // _LIBCXX_UNDERLYING_TYPE
   3235 
   3236 template <class _Tp, bool _Support = false>
   3237 struct underlying_type
   3238 {
   3239     static_assert(_Support, "The underyling_type trait requires compiler "
   3240                             "support. Either no such support exists or "
   3241                             "libc++ does not know how to use it.");
   3242 };
   3243 
   3244 #endif // _LIBCXX_UNDERLYING_TYPE
   3245 
   3246 _LIBCPP_END_NAMESPACE_STD
   3247 
   3248 #endif  // _LIBCPP_TYPE_TRAITS
   3249