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