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