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