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