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