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