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