]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libc++/include/type_traits
MFV r323530,r323533,r323534: 7431 ZFS Channel Programs, and followups
[FreeBSD/FreeBSD.git] / contrib / libc++ / include / type_traits
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
17 namespace std
18 {
19
20     // helper class:
21     template <class T, T v> struct integral_constant;
22     typedef integral_constant<bool, true>  true_type;   // C++11
23     typedef integral_constant<bool, false> false_type;  // C++11
24     
25     template <bool B>                                   // C++14
26     using bool_constant = integral_constant<bool, B>;   // C++14
27     typedef bool_constant<true> true_type;              // C++14
28     typedef bool_constant<false> false_type;            // C++14
29
30     // helper traits
31     template <bool, class T = void> struct enable_if;
32     template <bool, class T, class F> struct conditional;
33
34     // Primary classification traits:
35     template <class T> struct is_void;
36     template <class T> struct is_null_pointer;  // C++14
37     template <class T> struct is_integral;
38     template <class T> struct is_floating_point;
39     template <class T> struct is_array;
40     template <class T> struct is_pointer;
41     template <class T> struct is_lvalue_reference;
42     template <class T> struct is_rvalue_reference;
43     template <class T> struct is_member_object_pointer;
44     template <class T> struct is_member_function_pointer;
45     template <class T> struct is_enum;
46     template <class T> struct is_union;
47     template <class T> struct is_class;
48     template <class T> struct is_function;
49
50     // Secondary classification traits:
51     template <class T> struct is_reference;
52     template <class T> struct is_arithmetic;
53     template <class T> struct is_fundamental;
54     template <class T> struct is_member_pointer;
55     template <class T> struct is_scalar;
56     template <class T> struct is_object;
57     template <class T> struct is_compound;
58
59     // Const-volatile properties and transformations:
60     template <class T> struct is_const;
61     template <class T> struct is_volatile;
62     template <class T> struct remove_const;
63     template <class T> struct remove_volatile;
64     template <class T> struct remove_cv;
65     template <class T> struct add_const;
66     template <class T> struct add_volatile;
67     template <class T> struct add_cv;
68
69     // Reference transformations:
70     template <class T> struct remove_reference;
71     template <class T> struct add_lvalue_reference;
72     template <class T> struct add_rvalue_reference;
73
74     // Pointer transformations:
75     template <class T> struct remove_pointer;
76     template <class T> struct add_pointer;
77
78     // Integral properties:
79     template <class T> struct is_signed;
80     template <class T> struct is_unsigned;
81     template <class T> struct make_signed;
82     template <class T> struct make_unsigned;
83
84     // Array properties and transformations:
85     template <class T> struct rank;
86     template <class T, unsigned I = 0> struct extent;
87     template <class T> struct remove_extent;
88     template <class T> struct remove_all_extents;
89
90     // Member introspection:
91     template <class T> struct is_pod;
92     template <class T> struct is_trivial;
93     template <class T> struct is_trivially_copyable;
94     template <class T> struct is_standard_layout;
95     template <class T> struct is_literal_type;
96     template <class T> struct is_empty;
97     template <class T> struct is_polymorphic;
98     template <class T> struct is_abstract;
99     template <class T> struct is_final; // C++14
100     template <class T> struct is_aggregate; // C++17
101
102     template <class T, class... Args> struct is_constructible;
103     template <class T>                struct is_default_constructible;
104     template <class T>                struct is_copy_constructible;
105     template <class T>                struct is_move_constructible;
106     template <class T, class U>       struct is_assignable;
107     template <class T>                struct is_copy_assignable;
108     template <class T>                struct is_move_assignable;
109     template <class T, class U>       struct is_swappable_with;       // C++17
110     template <class T>                struct is_swappable;            // C++17
111     template <class T>                struct is_destructible;
112
113     template <class T, class... Args> struct is_trivially_constructible;
114     template <class T>                struct is_trivially_default_constructible;
115     template <class T>                struct is_trivially_copy_constructible;
116     template <class T>                struct is_trivially_move_constructible;
117     template <class T, class U>       struct is_trivially_assignable;
118     template <class T>                struct is_trivially_copy_assignable;
119     template <class T>                struct is_trivially_move_assignable;
120     template <class T>                struct is_trivially_destructible;
121
122     template <class T, class... Args> struct is_nothrow_constructible;
123     template <class T>                struct is_nothrow_default_constructible;
124     template <class T>                struct is_nothrow_copy_constructible;
125     template <class T>                struct is_nothrow_move_constructible;
126     template <class T, class U>       struct is_nothrow_assignable;
127     template <class T>                struct is_nothrow_copy_assignable;
128     template <class T>                struct is_nothrow_move_assignable;
129     template <class T, class U>       struct is_nothrow_swappable_with; // C++17
130     template <class T>                struct is_nothrow_swappable;      // C++17
131     template <class T>                struct is_nothrow_destructible;
132
133     template <class T> struct has_virtual_destructor;
134
135     // Relationships between types:
136     template <class T, class U> struct is_same;
137     template <class Base, class Derived> struct is_base_of;
138     template <class From, class To> struct is_convertible;
139
140     template <class, class R = void> struct is_callable; // not defined
141     template <class Fn, class... ArgTypes, class R>
142       struct is_callable<Fn(ArgTypes...), R>;
143
144     template <class, class R = void> struct is_nothrow_callable; // not defined
145     template <class Fn, class... ArgTypes, class R>
146       struct is_nothrow_callable<Fn(ArgTypes...), R>;
147
148     // Alignment properties and transformations:
149     template <class T> struct alignment_of;
150     template <size_t Len, size_t Align = most_stringent_alignment_requirement>
151         struct aligned_storage;
152     template <size_t Len, class... Types> struct aligned_union;
153
154     template <class T> struct decay;
155     template <class... T> struct common_type;
156     template <class T> struct underlying_type;
157     template <class> class result_of; // undefined
158     template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
159
160     // const-volatile modifications:
161     template <class T>
162       using remove_const_t    = typename remove_const<T>::type;  // C++14
163     template <class T>
164       using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
165     template <class T>
166       using remove_cv_t       = typename remove_cv<T>::type;  // C++14
167     template <class T>
168       using add_const_t       = typename add_const<T>::type;  // C++14
169     template <class T>
170       using add_volatile_t    = typename add_volatile<T>::type;  // C++14
171     template <class T>
172       using add_cv_t          = typename add_cv<T>::type;  // C++14
173   
174     // reference modifications:
175     template <class T>
176       using remove_reference_t     = typename remove_reference<T>::type;  // C++14
177     template <class T>
178       using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
179     template <class T>
180       using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
181   
182     // sign modifications:
183     template <class T>
184       using make_signed_t   = typename make_signed<T>::type;  // C++14
185     template <class T>
186       using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
187   
188     // array modifications:
189     template <class T>
190       using remove_extent_t      = typename remove_extent<T>::type;  // C++14
191     template <class T>
192       using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
193
194     // pointer modifications:
195     template <class T>
196       using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
197     template <class T>
198       using add_pointer_t    = typename add_pointer<T>::type;  // C++14
199
200     // other transformations:
201     template <size_t Len, std::size_t Align=default-alignment>
202       using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
203     template <std::size_t Len, class... Types>
204       using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
205     template <class T>
206       using decay_t           = typename decay<T>::type;  // C++14
207     template <bool b, class T=void>
208       using enable_if_t       = typename enable_if<b,T>::type;  // C++14
209     template <bool b, class T, class F>
210       using conditional_t     = typename conditional<b,T,F>::type;  // C++14
211     template <class... T>
212       using common_type_t     = typename common_type<T...>::type;  // C++14
213     template <class T>
214       using underlying_type_t = typename underlying_type<T>::type;  // C++14
215     template <class F, class... ArgTypes>
216       using result_of_t       = typename result_of<F(ArgTypes...)>::type;  // C++14
217
218     template <class...>
219       using void_t = void;   // C++17
220       
221       // See C++14 20.10.4.1, primary type categories
222       template <class T> constexpr bool is_void_v
223         = is_void<T>::value;                                             // C++17
224       template <class T> constexpr bool is_null_pointer_v
225         = is_null_pointer<T>::value;                                     // C++17
226       template <class T> constexpr bool is_integral_v
227         = is_integral<T>::value;                                         // C++17
228       template <class T> constexpr bool is_floating_point_v
229         = is_floating_point<T>::value;                                   // C++17
230       template <class T> constexpr bool is_array_v
231         = is_array<T>::value;                                            // C++17
232       template <class T> constexpr bool is_pointer_v
233         = is_pointer<T>::value;                                          // C++17
234       template <class T> constexpr bool is_lvalue_reference_v
235         = is_lvalue_reference<T>::value;                                 // C++17
236       template <class T> constexpr bool is_rvalue_reference_v
237         = is_rvalue_reference<T>::value;                                 // C++17
238       template <class T> constexpr bool is_member_object_pointer_v
239         = is_member_object_pointer<T>::value;                            // C++17
240       template <class T> constexpr bool is_member_function_pointer_v
241         = is_member_function_pointer<T>::value;                          // C++17
242       template <class T> constexpr bool is_enum_v
243         = is_enum<T>::value;                                             // C++17
244       template <class T> constexpr bool is_union_v
245         = is_union<T>::value;                                            // C++17
246       template <class T> constexpr bool is_class_v
247         = is_class<T>::value;                                            // C++17
248       template <class T> constexpr bool is_function_v
249         = is_function<T>::value;                                         // C++17
250
251       // See C++14 20.10.4.2, composite type categories
252       template <class T> constexpr bool is_reference_v
253         = is_reference<T>::value;                                        // C++17
254       template <class T> constexpr bool is_arithmetic_v
255         = is_arithmetic<T>::value;                                       // C++17
256       template <class T> constexpr bool is_fundamental_v
257         = is_fundamental<T>::value;                                      // C++17
258       template <class T> constexpr bool is_object_v
259         = is_object<T>::value;                                           // C++17
260       template <class T> constexpr bool is_scalar_v
261         = is_scalar<T>::value;                                           // C++17
262       template <class T> constexpr bool is_compound_v
263         = is_compound<T>::value;                                         // C++17
264       template <class T> constexpr bool is_member_pointer_v
265         = is_member_pointer<T>::value;                                   // C++17
266
267       // See C++14 20.10.4.3, type properties
268       template <class T> constexpr bool is_const_v
269         = is_const<T>::value;                                            // C++17
270       template <class T> constexpr bool is_volatile_v
271         = is_volatile<T>::value;                                         // C++17
272       template <class T> constexpr bool is_trivial_v
273         = is_trivial<T>::value;                                          // C++17
274       template <class T> constexpr bool is_trivially_copyable_v
275         = is_trivially_copyable<T>::value;                               // C++17
276       template <class T> constexpr bool is_standard_layout_v
277         = is_standard_layout<T>::value;                                  // C++17
278       template <class T> constexpr bool is_pod_v
279         = is_pod<T>::value;                                              // C++17
280       template <class T> constexpr bool is_literal_type_v
281         = is_literal_type<T>::value;                                     // C++17
282       template <class T> constexpr bool is_empty_v
283         = is_empty<T>::value;                                            // C++17
284       template <class T> constexpr bool is_polymorphic_v
285         = is_polymorphic<T>::value;                                      // C++17
286       template <class T> constexpr bool is_abstract_v
287         = is_abstract<T>::value;                                         // C++17
288       template <class T> constexpr bool is_final_v
289         = is_final<T>::value;                                            // C++17
290       template <class T> constexpr bool is_aggregate_v
291         = is_aggregate<T>::value;                                        // C++17
292       template <class T> constexpr bool is_signed_v
293         = is_signed<T>::value;                                           // C++17
294       template <class T> constexpr bool is_unsigned_v
295         = is_unsigned<T>::value;                                         // C++17
296       template <class T, class... Args> constexpr bool is_constructible_v
297         = is_constructible<T, Args...>::value;                           // C++17
298       template <class T> constexpr bool is_default_constructible_v
299         = is_default_constructible<T>::value;                            // C++17
300       template <class T> constexpr bool is_copy_constructible_v
301         = is_copy_constructible<T>::value;                               // C++17
302       template <class T> constexpr bool is_move_constructible_v
303         = is_move_constructible<T>::value;                               // C++17
304       template <class T, class U> constexpr bool is_assignable_v
305         = is_assignable<T, U>::value;                                    // C++17
306       template <class T> constexpr bool is_copy_assignable_v
307         = is_copy_assignable<T>::value;                                  // C++17
308       template <class T> constexpr bool is_move_assignable_v
309         = is_move_assignable<T>::value;                                  // C++17
310       template <class T, class U> constexpr bool is_swappable_with_v
311         = is_swappable_with<T, U>::value;                                // C++17
312       template <class T> constexpr bool is_swappable_v
313         = is_swappable<T>::value;                                        // C++17
314       template <class T> constexpr bool is_destructible_v
315         = is_destructible<T>::value;                                     // C++17
316       template <class T, class... Args> constexpr bool is_trivially_constructible_v
317         = is_trivially_constructible<T, Args...>::value;                 // C++17
318       template <class T> constexpr bool is_trivially_default_constructible_v
319         = is_trivially_default_constructible<T>::value;                  // C++17
320       template <class T> constexpr bool is_trivially_copy_constructible_v
321         = is_trivially_copy_constructible<T>::value;                     // C++17
322       template <class T> constexpr bool is_trivially_move_constructible_v
323         = is_trivially_move_constructible<T>::value;                     // C++17
324       template <class T, class U> constexpr bool is_trivially_assignable_v
325         = is_trivially_assignable<T, U>::value;                          // C++17
326       template <class T> constexpr bool is_trivially_copy_assignable_v
327         = is_trivially_copy_assignable<T>::value;                        // C++17
328       template <class T> constexpr bool is_trivially_move_assignable_v
329         = is_trivially_move_assignable<T>::value;                        // C++17
330       template <class T> constexpr bool is_trivially_destructible_v
331         = is_trivially_destructible<T>::value;                           // C++17
332       template <class T, class... Args> constexpr bool is_nothrow_constructible_v
333         = is_nothrow_constructible<T, Args...>::value;                   // C++17
334       template <class T> constexpr bool is_nothrow_default_constructible_v
335         = is_nothrow_default_constructible<T>::value;                    // C++17
336       template <class T> constexpr bool is_nothrow_copy_constructible_v
337         = is_nothrow_copy_constructible<T>::value;                       // C++17
338       template <class T> constexpr bool is_nothrow_move_constructible_v
339         = is_nothrow_move_constructible<T>::value;                       // C++17
340       template <class T, class U> constexpr bool is_nothrow_assignable_v
341         = is_nothrow_assignable<T, U>::value;                            // C++17
342       template <class T> constexpr bool is_nothrow_copy_assignable_v
343         = is_nothrow_copy_assignable<T>::value;                          // C++17
344       template <class T> constexpr bool is_nothrow_move_assignable_v
345         = is_nothrow_move_assignable<T>::value;                          // C++17
346       template <class T, class U> constexpr bool is_nothrow_swappable_with_v
347         = is_nothrow_swappable_with<T, U>::value;                       // C++17
348       template <class T> constexpr bool is_nothrow_swappable_v
349         = is_nothrow_swappable<T>::value;                               // C++17
350       template <class T> constexpr bool is_nothrow_destructible_v
351         = is_nothrow_destructible<T>::value;                             // C++17
352       template <class T> constexpr bool has_virtual_destructor_v
353         = has_virtual_destructor<T>::value;                              // C++17
354
355       // See C++14 20.10.5, type property queries
356       template <class T> constexpr size_t alignment_of_v
357         = alignment_of<T>::value;                                        // C++17
358       template <class T> constexpr size_t rank_v
359         = rank<T>::value;                                                // C++17
360       template <class T, unsigned I = 0> constexpr size_t extent_v
361         = extent<T, I>::value;                                           // C++17
362
363       // See C++14 20.10.6, type relations
364       template <class T, class U> constexpr bool is_same_v
365         = is_same<T, U>::value;                                          // C++17
366       template <class Base, class Derived> constexpr bool is_base_of_v
367         = is_base_of<Base, Derived>::value;                              // C++17
368       template <class From, class To> constexpr bool is_convertible_v
369         = is_convertible<From, To>::value;                               // C++17
370       template <class T, class R = void> constexpr bool is_callable_v
371         = is_callable<T, R>::value;                                      // C++17
372       template <class T, class R = void> constexpr bool is_nothrow_callable_v
373         = is_nothrow_callable<T, R>::value;                              // C++17
374
375       // [meta.logical], logical operator traits:
376       template<class... B> struct conjunction;                           // C++17
377       template<class... B> 
378         constexpr bool conjunction_v = conjunction<B...>::value;         // C++17
379       template<class... B> struct disjunction;                           // C++17
380       template<class... B>
381         constexpr bool disjunction_v = disjunction<B...>::value;         // C++17
382       template<class B> struct negation;                                 // C++17
383       template<class B> 
384         constexpr bool negation_v = negation<B>::value;                  // C++17
385
386 }
387
388 */
389 #include <__config>
390 #include <cstddef>
391
392 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
393 #pragma GCC system_header
394 #endif
395
396 _LIBCPP_BEGIN_NAMESPACE_STD
397
398 template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair;
399 template <class _Tp> class _LIBCPP_TEMPLATE_VIS reference_wrapper;
400 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
401
402 template <class>
403 struct __void_t { typedef void type; };
404
405 template <class _Tp>
406 struct __identity { typedef _Tp type; };
407
408 template <class _Tp, bool>
409 struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
410
411 template <bool _Bp, class _If, class _Then>
412     struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;};
413 template <class _If, class _Then>
414     struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {typedef _Then type;};
415
416 #if _LIBCPP_STD_VER > 11
417 template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
418 #endif
419
420 template <bool, class _Tp> struct _LIBCPP_TEMPLATE_VIS __lazy_enable_if {};
421 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __lazy_enable_if<true, _Tp> {typedef typename _Tp::type type;};
422
423 template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
424 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;};
425
426 #if _LIBCPP_STD_VER > 11
427 template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
428 #endif
429
430 // addressof
431 #ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
432
433 template <class _Tp>
434 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
435 _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
436 _Tp*
437 addressof(_Tp& __x) _NOEXCEPT
438 {
439     return __builtin_addressof(__x);
440 }
441
442 #else
443
444 template <class _Tp>
445 inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
446 _Tp*
447 addressof(_Tp& __x) _NOEXCEPT
448 {
449   return reinterpret_cast<_Tp *>(
450       const_cast<char *>(&reinterpret_cast<const volatile char &>(__x)));
451 }
452
453 #endif // _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
454
455 #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
456 // Objective-C++ Automatic Reference Counting uses qualified pointers
457 // that require special addressof() signatures. When
458 // _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
459 // itself is providing these definitions. Otherwise, we provide them.
460 template <class _Tp>
461 inline _LIBCPP_INLINE_VISIBILITY
462 __strong _Tp*
463 addressof(__strong _Tp& __x) _NOEXCEPT
464 {
465   return &__x;
466 }
467
468 #ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
469 template <class _Tp>
470 inline _LIBCPP_INLINE_VISIBILITY
471 __weak _Tp*
472 addressof(__weak _Tp& __x) _NOEXCEPT
473 {
474   return &__x;
475 }
476 #endif
477
478 template <class _Tp>
479 inline _LIBCPP_INLINE_VISIBILITY
480 __autoreleasing _Tp*
481 addressof(__autoreleasing _Tp& __x) _NOEXCEPT
482 {
483   return &__x;
484 }
485
486 template <class _Tp>
487 inline _LIBCPP_INLINE_VISIBILITY
488 __unsafe_unretained _Tp*
489 addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
490 {
491   return &__x;
492 }
493 #endif
494
495 #if !defined(_LIBCPP_CXX03_LANG)
496 template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete;
497 #endif
498
499 struct __two {char __lx[2];};
500
501 // helper class:
502
503 template <class _Tp, _Tp __v>
504 struct _LIBCPP_TEMPLATE_VIS integral_constant
505 {
506     static _LIBCPP_CONSTEXPR const _Tp      value = __v;
507     typedef _Tp               value_type;
508     typedef integral_constant type;
509     _LIBCPP_INLINE_VISIBILITY
510         _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;}
511 #if _LIBCPP_STD_VER > 11
512     _LIBCPP_INLINE_VISIBILITY
513          constexpr value_type operator ()() const _NOEXCEPT {return value;}
514 #endif
515 };
516
517 template <class _Tp, _Tp __v>
518 _LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
519
520 #if _LIBCPP_STD_VER > 14
521 template <bool __b>
522 using bool_constant = integral_constant<bool, __b>;
523 #define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)>
524 #else
525 #define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>
526 #endif
527
528 typedef _LIBCPP_BOOL_CONSTANT(true)  true_type;
529 typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
530
531 #if !defined(_LIBCPP_CXX03_LANG)
532
533 // __lazy_and
534
535 template <bool _Last, class ..._Preds>
536 struct __lazy_and_impl;
537
538 template <class ..._Preds>
539 struct __lazy_and_impl<false, _Preds...> : false_type {};
540
541 template <>
542 struct __lazy_and_impl<true> : true_type {};
543
544 template <class _Pred>
545 struct __lazy_and_impl<true, _Pred> : integral_constant<bool, _Pred::type::value> {};
546
547 template <class _Hp, class ..._Tp>
548 struct __lazy_and_impl<true, _Hp, _Tp...> : __lazy_and_impl<_Hp::type::value, _Tp...> {};
549
550 template <class _P1, class ..._Pr>
551 struct __lazy_and : __lazy_and_impl<_P1::type::value, _Pr...> {};
552
553 // __lazy_or
554
555 template <bool _List, class ..._Preds>
556 struct __lazy_or_impl;
557
558 template <class ..._Preds>
559 struct __lazy_or_impl<true, _Preds...> : true_type {};
560
561 template <>
562 struct __lazy_or_impl<false> : false_type {};
563
564 template <class _Hp, class ..._Tp>
565 struct __lazy_or_impl<false, _Hp, _Tp...>
566         : __lazy_or_impl<_Hp::type::value, _Tp...> {};
567
568 template <class _P1, class ..._Pr>
569 struct __lazy_or : __lazy_or_impl<_P1::type::value, _Pr...> {};
570
571 // __lazy_not
572
573 template <class _Pred>
574 struct __lazy_not : integral_constant<bool, !_Pred::type::value> {};
575
576 // __and_
577 template<class...> struct __and_;
578 template<> struct __and_<> : true_type {};
579
580 template<class _B0> struct __and_<_B0> : _B0 {};
581
582 template<class _B0, class _B1>
583 struct __and_<_B0, _B1> : conditional<_B0::value, _B1, _B0>::type {};
584
585 template<class _B0, class _B1, class _B2, class... _Bn>
586 struct __and_<_B0, _B1, _B2, _Bn...> 
587         : conditional<_B0::value, __and_<_B1, _B2, _Bn...>, _B0>::type {};
588
589 // __or_
590 template<class...> struct __or_;
591 template<> struct __or_<> : false_type {};
592
593 template<class _B0> struct __or_<_B0> : _B0 {};
594
595 template<class _B0, class _B1>
596 struct __or_<_B0, _B1> : conditional<_B0::value, _B0, _B1>::type {};
597
598 template<class _B0, class _B1, class _B2, class... _Bn>
599 struct __or_<_B0, _B1, _B2, _Bn...> 
600         : conditional<_B0::value, _B0, __or_<_B1, _B2, _Bn...> >::type {};
601
602 // __not_
603 template<class _Tp> 
604 struct __not_ : conditional<_Tp::value, false_type, true_type>::type {};
605
606 #endif // !defined(_LIBCPP_CXX03_LANG)
607
608 // is_const
609
610 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const            : public false_type {};
611 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
612
613 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
614 template <class _Tp> _LIBCPP_CONSTEXPR bool is_const_v
615     = is_const<_Tp>::value;
616 #endif
617
618 // is_volatile
619
620 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile               : public false_type {};
621 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
622
623 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
624 template <class _Tp> _LIBCPP_CONSTEXPR bool is_volatile_v
625     = is_volatile<_Tp>::value;
626 #endif
627
628 // remove_const
629
630 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const            {typedef _Tp type;};
631 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const<const _Tp> {typedef _Tp type;};
632 #if _LIBCPP_STD_VER > 11
633 template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
634 #endif
635
636 // remove_volatile
637
638 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile               {typedef _Tp type;};
639 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;};
640 #if _LIBCPP_STD_VER > 11
641 template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
642 #endif
643
644 // remove_cv
645
646 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
647 {typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
648 #if _LIBCPP_STD_VER > 11
649 template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
650 #endif
651
652 // is_void
653
654 template <class _Tp> struct __libcpp_is_void       : public false_type {};
655 template <>          struct __libcpp_is_void<void> : public true_type {};
656
657 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void
658     : public __libcpp_is_void<typename remove_cv<_Tp>::type> {};
659
660 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
661 template <class _Tp> _LIBCPP_CONSTEXPR bool is_void_v
662     = is_void<_Tp>::value;
663 #endif
664
665 // __is_nullptr_t
666
667 template <class _Tp> struct __is_nullptr_t_impl       : public false_type {};
668 template <>          struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
669
670 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t
671     : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
672
673 #if _LIBCPP_STD_VER > 11
674 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer
675     : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
676
677 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
678 template <class _Tp> _LIBCPP_CONSTEXPR bool is_null_pointer_v
679     = is_null_pointer<_Tp>::value;
680 #endif
681 #endif
682
683 // is_integral
684
685 template <class _Tp> struct __libcpp_is_integral                     : public false_type {};
686 template <>          struct __libcpp_is_integral<bool>               : public true_type {};
687 template <>          struct __libcpp_is_integral<char>               : public true_type {};
688 template <>          struct __libcpp_is_integral<signed char>        : public true_type {};
689 template <>          struct __libcpp_is_integral<unsigned char>      : public true_type {};
690 template <>          struct __libcpp_is_integral<wchar_t>            : public true_type {};
691 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
692 template <>          struct __libcpp_is_integral<char16_t>           : public true_type {};
693 template <>          struct __libcpp_is_integral<char32_t>           : public true_type {};
694 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
695 template <>          struct __libcpp_is_integral<short>              : public true_type {};
696 template <>          struct __libcpp_is_integral<unsigned short>     : public true_type {};
697 template <>          struct __libcpp_is_integral<int>                : public true_type {};
698 template <>          struct __libcpp_is_integral<unsigned int>       : public true_type {};
699 template <>          struct __libcpp_is_integral<long>               : public true_type {};
700 template <>          struct __libcpp_is_integral<unsigned long>      : public true_type {};
701 template <>          struct __libcpp_is_integral<long long>          : public true_type {};
702 template <>          struct __libcpp_is_integral<unsigned long long> : public true_type {};
703 #ifndef _LIBCPP_HAS_NO_INT128
704 template <>          struct __libcpp_is_integral<__int128_t>         : public true_type {};
705 template <>          struct __libcpp_is_integral<__uint128_t>        : public true_type {};
706 #endif
707
708 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
709     : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
710
711 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
712 template <class _Tp> _LIBCPP_CONSTEXPR bool is_integral_v
713     = is_integral<_Tp>::value;
714 #endif
715
716 // is_floating_point
717
718 template <class _Tp> struct __libcpp_is_floating_point              : public false_type {};
719 template <>          struct __libcpp_is_floating_point<float>       : public true_type {};
720 template <>          struct __libcpp_is_floating_point<double>      : public true_type {};
721 template <>          struct __libcpp_is_floating_point<long double> : public true_type {};
722
723 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point
724     : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
725
726 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
727 template <class _Tp> _LIBCPP_CONSTEXPR bool is_floating_point_v
728     = is_floating_point<_Tp>::value;
729 #endif
730
731 // is_array
732
733 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array
734     : public false_type {};
735 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]>
736     : public true_type {};
737 template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]>
738     : public true_type {};
739
740 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
741 template <class _Tp> _LIBCPP_CONSTEXPR bool is_array_v
742     = is_array<_Tp>::value;
743 #endif
744
745 // is_pointer
746
747 template <class _Tp> struct __libcpp_is_pointer       : public false_type {};
748 template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
749
750 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer
751     : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> {};
752
753 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
754 template <class _Tp> _LIBCPP_CONSTEXPR bool is_pointer_v
755     = is_pointer<_Tp>::value;
756 #endif
757
758 // is_reference
759
760 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference       : public false_type {};
761 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {};
762
763 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference        : public false_type {};
764 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
765 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {};
766 #endif
767
768 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference        : public false_type {};
769 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&>  : public true_type {};
770 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
771 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {};
772 #endif
773
774 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
775 template <class _Tp> _LIBCPP_CONSTEXPR bool is_reference_v
776     = is_reference<_Tp>::value;
777
778 template <class _Tp> _LIBCPP_CONSTEXPR bool is_lvalue_reference_v
779     = is_lvalue_reference<_Tp>::value;
780
781 template <class _Tp> _LIBCPP_CONSTEXPR bool is_rvalue_reference_v
782     = is_rvalue_reference<_Tp>::value;
783 #endif
784 // is_union
785
786 #if __has_feature(is_union) || (_GNUC_VER >= 403)
787
788 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
789     : public integral_constant<bool, __is_union(_Tp)> {};
790
791 #else
792
793 template <class _Tp> struct __libcpp_union : public false_type {};
794 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
795     : public __libcpp_union<typename remove_cv<_Tp>::type> {};
796
797 #endif
798
799 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
800 template <class _Tp> _LIBCPP_CONSTEXPR bool is_union_v
801     = is_union<_Tp>::value;
802 #endif
803
804 // is_class
805
806 #if __has_feature(is_class) || (_GNUC_VER >= 403)
807
808 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
809     : public integral_constant<bool, __is_class(_Tp)> {};
810
811 #else
812
813 namespace __is_class_imp
814 {
815 template <class _Tp> char  __test(int _Tp::*);
816 template <class _Tp> __two __test(...);
817 }
818
819 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
820     : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
821
822 #endif
823
824 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
825 template <class _Tp> _LIBCPP_CONSTEXPR bool is_class_v
826     = is_class<_Tp>::value;
827 #endif
828
829 // is_same
830
831 template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same           : public false_type {};
832 template <class _Tp>            struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {};
833
834 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
835 template <class _Tp, class _Up> _LIBCPP_CONSTEXPR bool is_same_v
836     = is_same<_Tp, _Up>::value;
837 #endif
838
839 // is_function
840
841 namespace __libcpp_is_function_imp
842 {
843 struct __dummy_type {};
844 template <class _Tp> char  __test(_Tp*);
845 template <class _Tp> char __test(__dummy_type);
846 template <class _Tp> __two __test(...);
847 template <class _Tp> _Tp&  __source(int);
848 template <class _Tp> __dummy_type __source(...);
849 }
850
851 template <class _Tp, bool = is_class<_Tp>::value ||
852                             is_union<_Tp>::value ||
853                             is_void<_Tp>::value  ||
854                             is_reference<_Tp>::value ||
855                             __is_nullptr_t<_Tp>::value >
856 struct __libcpp_is_function
857     : public integral_constant<bool, sizeof(__libcpp_is_function_imp::__test<_Tp>(__libcpp_is_function_imp::__source<_Tp>(0))) == 1>
858     {};
859 template <class _Tp> struct __libcpp_is_function<_Tp, true> : public false_type {};
860
861 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function
862     : public __libcpp_is_function<_Tp> {};
863
864 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
865 template <class _Tp> _LIBCPP_CONSTEXPR bool is_function_v
866     = is_function<_Tp>::value;
867 #endif
868
869 // is_member_function_pointer
870
871 // template <class _Tp> struct            __libcpp_is_member_function_pointer             : public false_type {};
872 // template <class _Tp, class _Up> struct __libcpp_is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
873 // 
874
875 template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
876 struct __member_pointer_traits_imp
877 {  // forward declaration; specializations later
878 };
879
880
881 template <class _Tp> struct __libcpp_is_member_function_pointer
882     : public false_type {};
883
884 template <class _Ret, class _Class>
885 struct __libcpp_is_member_function_pointer<_Ret _Class::*>
886     : public is_function<_Ret> {};
887
888 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
889     : public __libcpp_is_member_function_pointer<typename remove_cv<_Tp>::type>::type {};
890
891 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
892 template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
893     = is_member_function_pointer<_Tp>::value;
894 #endif
895
896 // is_member_pointer
897
898 template <class _Tp>            struct __libcpp_is_member_pointer             : public false_type {};
899 template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> : public true_type {};
900
901 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
902     : public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {};
903
904 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
905 template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_pointer_v
906     = is_member_pointer<_Tp>::value;
907 #endif
908
909 // is_member_object_pointer
910
911 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
912     : public integral_constant<bool, is_member_pointer<_Tp>::value &&
913                                     !is_member_function_pointer<_Tp>::value> {};
914
915 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
916 template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
917     = is_member_object_pointer<_Tp>::value;
918 #endif
919
920 // is_enum
921
922 #if __has_feature(is_enum) || (_GNUC_VER >= 403)
923
924 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
925     : public integral_constant<bool, __is_enum(_Tp)> {};
926
927 #else
928
929 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
930     : public integral_constant<bool, !is_void<_Tp>::value             &&
931                                      !is_integral<_Tp>::value         &&
932                                      !is_floating_point<_Tp>::value   &&
933                                      !is_array<_Tp>::value            &&
934                                      !is_pointer<_Tp>::value          &&
935                                      !is_reference<_Tp>::value        &&
936                                      !is_member_pointer<_Tp>::value   &&
937                                      !is_union<_Tp>::value            &&
938                                      !is_class<_Tp>::value            &&
939                                      !is_function<_Tp>::value         > {};
940
941 #endif
942
943 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
944 template <class _Tp> _LIBCPP_CONSTEXPR bool is_enum_v
945     = is_enum<_Tp>::value;
946 #endif
947
948 // is_arithmetic
949
950 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
951     : public integral_constant<bool, is_integral<_Tp>::value      ||
952                                      is_floating_point<_Tp>::value> {};
953
954 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
955 template <class _Tp> _LIBCPP_CONSTEXPR bool is_arithmetic_v
956     = is_arithmetic<_Tp>::value;
957 #endif
958
959 // is_fundamental
960
961 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
962     : public integral_constant<bool, is_void<_Tp>::value        ||
963                                      __is_nullptr_t<_Tp>::value ||
964                                      is_arithmetic<_Tp>::value> {};
965
966 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
967 template <class _Tp> _LIBCPP_CONSTEXPR bool is_fundamental_v
968     = is_fundamental<_Tp>::value;
969 #endif
970
971 // is_scalar
972
973 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
974     : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
975                                      is_member_pointer<_Tp>::value ||
976                                      is_pointer<_Tp>::value        ||
977                                      __is_nullptr_t<_Tp>::value    ||
978                                      is_enum<_Tp>::value           > {};
979
980 template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
981
982 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
983 template <class _Tp> _LIBCPP_CONSTEXPR bool is_scalar_v
984     = is_scalar<_Tp>::value;
985 #endif
986
987 // is_object
988
989 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
990     : public integral_constant<bool, is_scalar<_Tp>::value ||
991                                      is_array<_Tp>::value  ||
992                                      is_union<_Tp>::value  ||
993                                      is_class<_Tp>::value  > {};
994
995 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
996 template <class _Tp> _LIBCPP_CONSTEXPR bool is_object_v
997     = is_object<_Tp>::value;
998 #endif
999
1000 // is_compound
1001
1002 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
1003     : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
1004
1005 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1006 template <class _Tp> _LIBCPP_CONSTEXPR bool is_compound_v
1007     = is_compound<_Tp>::value;
1008 #endif
1009
1010
1011 // __is_referenceable  [defns.referenceable]
1012
1013 struct __is_referenceable_impl {
1014     template <class _Tp> static _Tp& __test(int);
1015     template <class _Tp> static __two __test(...);
1016 };
1017
1018 template <class _Tp>
1019 struct __is_referenceable : integral_constant<bool,
1020     !is_same<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {};
1021
1022
1023 // add_const
1024
1025 template <class _Tp, bool = is_reference<_Tp>::value ||
1026                             is_function<_Tp>::value  ||
1027                             is_const<_Tp>::value     >
1028 struct __add_const             {typedef _Tp type;};
1029
1030 template <class _Tp>
1031 struct __add_const<_Tp, false> {typedef const _Tp type;};
1032
1033 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const
1034     {typedef typename __add_const<_Tp>::type type;};
1035
1036 #if _LIBCPP_STD_VER > 11
1037 template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
1038 #endif
1039
1040 // add_volatile
1041
1042 template <class _Tp, bool = is_reference<_Tp>::value ||
1043                             is_function<_Tp>::value  ||
1044                             is_volatile<_Tp>::value  >
1045 struct __add_volatile             {typedef _Tp type;};
1046
1047 template <class _Tp>
1048 struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
1049
1050 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile
1051     {typedef typename __add_volatile<_Tp>::type type;};
1052
1053 #if _LIBCPP_STD_VER > 11
1054 template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
1055 #endif
1056
1057 // add_cv
1058
1059 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv
1060     {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;};
1061
1062 #if _LIBCPP_STD_VER > 11
1063 template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
1064 #endif
1065
1066 // remove_reference
1067
1068 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference        {typedef _Tp type;};
1069 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&>  {typedef _Tp type;};
1070 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1071 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _Tp type;};
1072 #endif
1073
1074 #if _LIBCPP_STD_VER > 11
1075 template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
1076 #endif
1077
1078 // add_lvalue_reference
1079
1080 template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl            { typedef _Tp  type; };
1081 template <class _Tp                                       > struct __add_lvalue_reference_impl<_Tp, true> { typedef _Tp& type; };
1082
1083 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference
1084 {typedef typename __add_lvalue_reference_impl<_Tp>::type type;};
1085
1086 #if _LIBCPP_STD_VER > 11
1087 template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1088 #endif
1089
1090 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1091
1092 template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl            { typedef _Tp   type; };
1093 template <class _Tp                                       > struct __add_rvalue_reference_impl<_Tp, true> { typedef _Tp&& type; };
1094
1095 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference
1096 {typedef typename __add_rvalue_reference_impl<_Tp>::type type;};
1097
1098 #if _LIBCPP_STD_VER > 11
1099 template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1100 #endif
1101
1102 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1103
1104 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1105
1106 template <class _Tp> _Tp&& __declval(int);
1107 template <class _Tp> _Tp   __declval(long);
1108
1109 template <class _Tp>
1110 decltype(_VSTD::__declval<_Tp>(0))
1111 declval() _NOEXCEPT;
1112
1113 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1114
1115 template <class _Tp>
1116 typename add_lvalue_reference<_Tp>::type
1117 declval();
1118
1119 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1120
1121 // __uncvref
1122
1123 template <class _Tp>
1124 struct __uncvref  {
1125     typedef typename remove_cv<typename remove_reference<_Tp>::type>::type type;
1126 };
1127
1128 template <class _Tp>
1129 struct __unconstref {
1130     typedef typename remove_const<typename remove_reference<_Tp>::type>::type type;
1131 };
1132
1133 #ifndef _LIBCPP_CXX03_LANG
1134 template <class _Tp>
1135 using __uncvref_t = typename __uncvref<_Tp>::type;
1136 #endif
1137
1138 // __is_same_uncvref
1139
1140 template <class _Tp, class _Up>
1141 struct __is_same_uncvref : is_same<typename __uncvref<_Tp>::type,
1142                                    typename __uncvref<_Up>::type> {};
1143
1144 struct __any
1145 {
1146     __any(...);
1147 };
1148
1149 // remove_pointer
1150
1151 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer                      {typedef _Tp type;};
1152 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*>                {typedef _Tp type;};
1153 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const>          {typedef _Tp type;};
1154 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile>       {typedef _Tp type;};
1155 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _Tp type;};
1156
1157 #if _LIBCPP_STD_VER > 11
1158 template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
1159 #endif
1160
1161 // add_pointer
1162
1163 template <class _Tp, 
1164         bool = __is_referenceable<_Tp>::value || 
1165                 is_same<typename remove_cv<_Tp>::type, void>::value>
1166 struct __add_pointer_impl
1167     {typedef typename remove_reference<_Tp>::type* type;};
1168 template <class _Tp> struct __add_pointer_impl<_Tp, false> 
1169     {typedef _Tp type;};
1170
1171 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer
1172     {typedef typename __add_pointer_impl<_Tp>::type type;};
1173
1174 #if _LIBCPP_STD_VER > 11
1175 template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
1176 #endif
1177
1178 // is_signed
1179
1180 template <class _Tp, bool = is_integral<_Tp>::value>
1181 struct __libcpp_is_signed_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(-1) < _Tp(0)) {};
1182
1183 template <class _Tp>
1184 struct __libcpp_is_signed_impl<_Tp, false> : public true_type {};  // floating point
1185
1186 template <class _Tp, bool = is_arithmetic<_Tp>::value>
1187 struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
1188
1189 template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
1190
1191 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {};
1192
1193 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1194 template <class _Tp> _LIBCPP_CONSTEXPR bool is_signed_v
1195     = is_signed<_Tp>::value;
1196 #endif
1197
1198 // is_unsigned
1199
1200 template <class _Tp, bool = is_integral<_Tp>::value>
1201 struct __libcpp_is_unsigned_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(0) < _Tp(-1)) {};
1202
1203 template <class _Tp>
1204 struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {};  // floating point
1205
1206 template <class _Tp, bool = is_arithmetic<_Tp>::value>
1207 struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
1208
1209 template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
1210
1211 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {};
1212
1213 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1214 template <class _Tp> _LIBCPP_CONSTEXPR bool is_unsigned_v
1215     = is_unsigned<_Tp>::value;
1216 #endif
1217
1218 // rank
1219
1220 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank
1221     : public integral_constant<size_t, 0> {};
1222 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]>
1223     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
1224 template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]>
1225     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
1226
1227 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1228 template <class _Tp> _LIBCPP_CONSTEXPR size_t rank_v
1229     = rank<_Tp>::value;
1230 #endif
1231
1232 // extent
1233
1234 template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent
1235     : public integral_constant<size_t, 0> {};
1236 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0>
1237     : public integral_constant<size_t, 0> {};
1238 template <class _Tp, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip>
1239     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
1240 template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0>
1241     : public integral_constant<size_t, _Np> {};
1242 template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip>
1243     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
1244
1245 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1246 template <class _Tp, unsigned _Ip = 0> _LIBCPP_CONSTEXPR size_t extent_v
1247     = extent<_Tp, _Ip>::value;
1248 #endif
1249
1250 // remove_extent
1251
1252 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent
1253     {typedef _Tp type;};
1254 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[]>
1255     {typedef _Tp type;};
1256 template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[_Np]>
1257     {typedef _Tp type;};
1258
1259 #if _LIBCPP_STD_VER > 11
1260 template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
1261 #endif
1262
1263 // remove_all_extents
1264
1265 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents
1266     {typedef _Tp type;};
1267 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[]>
1268     {typedef typename remove_all_extents<_Tp>::type type;};
1269 template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[_Np]>
1270     {typedef typename remove_all_extents<_Tp>::type type;};
1271
1272 #if _LIBCPP_STD_VER > 11
1273 template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1274 #endif
1275
1276 // decay
1277
1278 template <class _Up, bool>
1279 struct __decay {
1280     typedef typename remove_cv<_Up>::type type;
1281 };
1282
1283 template <class _Up>
1284 struct __decay<_Up, true> {
1285 public:
1286     typedef typename conditional
1287                      <
1288                          is_array<_Up>::value,
1289                          typename remove_extent<_Up>::type*,
1290                          typename conditional
1291                          <
1292                               is_function<_Up>::value,
1293                               typename add_pointer<_Up>::type,
1294                               typename remove_cv<_Up>::type
1295                          >::type
1296                      >::type type;
1297 };
1298
1299 template <class _Tp>
1300 struct _LIBCPP_TEMPLATE_VIS decay
1301 {
1302 private:
1303     typedef typename remove_reference<_Tp>::type _Up;
1304 public:
1305     typedef typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
1306 };
1307
1308 #if _LIBCPP_STD_VER > 11
1309 template <class _Tp> using decay_t = typename decay<_Tp>::type;
1310 #endif
1311
1312 // is_abstract
1313
1314 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract
1315     : public integral_constant<bool, __is_abstract(_Tp)> {};
1316
1317 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1318 template <class _Tp> _LIBCPP_CONSTEXPR bool is_abstract_v
1319     = is_abstract<_Tp>::value;
1320 #endif
1321
1322 // is_final
1323
1324 #if defined(_LIBCPP_HAS_IS_FINAL)
1325 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1326 __libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {};
1327 #else
1328 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1329 __libcpp_is_final : public false_type {};
1330 #endif
1331
1332 #if defined(_LIBCPP_HAS_IS_FINAL) && _LIBCPP_STD_VER > 11
1333 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1334 is_final : public integral_constant<bool, __is_final(_Tp)> {};
1335 #endif
1336
1337 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1338 template <class _Tp> _LIBCPP_CONSTEXPR bool is_final_v
1339     = is_final<_Tp>::value;
1340 #endif
1341
1342 // is_aggregate
1343 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
1344
1345 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1346 is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
1347
1348 #if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1349 template <class _Tp>
1350 constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
1351 #endif
1352
1353 #endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
1354
1355 // is_base_of
1356
1357 #ifdef _LIBCPP_HAS_IS_BASE_OF
1358
1359 template <class _Bp, class _Dp>
1360 struct _LIBCPP_TEMPLATE_VIS is_base_of
1361     : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
1362
1363 #else  // _LIBCPP_HAS_IS_BASE_OF
1364
1365 namespace __is_base_of_imp
1366 {
1367 template <class _Tp>
1368 struct _Dst
1369 {
1370     _Dst(const volatile _Tp &);
1371 };
1372 template <class _Tp>
1373 struct _Src
1374 {
1375     operator const volatile _Tp &();
1376     template <class _Up> operator const _Dst<_Up> &();
1377 };
1378 template <size_t> struct __one { typedef char type; };
1379 template <class _Bp, class _Dp> typename __one<sizeof(_Dst<_Bp>(declval<_Src<_Dp> >()))>::type __test(int);
1380 template <class _Bp, class _Dp> __two __test(...);
1381 }
1382
1383 template <class _Bp, class _Dp>
1384 struct _LIBCPP_TEMPLATE_VIS is_base_of
1385     : public integral_constant<bool, is_class<_Bp>::value &&
1386                                      sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {};
1387
1388 #endif  // _LIBCPP_HAS_IS_BASE_OF
1389
1390 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1391 template <class _Bp, class _Dp> _LIBCPP_CONSTEXPR bool is_base_of_v
1392     = is_base_of<_Bp, _Dp>::value;
1393 #endif
1394
1395 // is_convertible
1396
1397 #if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
1398
1399 template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
1400     : public integral_constant<bool, __is_convertible_to(_T1, _T2) &&
1401                                      !is_abstract<_T2>::value> {};
1402
1403 #else  // __has_feature(is_convertible_to)
1404
1405 namespace __is_convertible_imp
1406 {
1407 template <class _Tp> void  __test_convert(_Tp);
1408
1409 template <class _From, class _To, class = void>
1410 struct __is_convertible_test : public false_type {};
1411
1412 template <class _From, class _To>
1413 struct __is_convertible_test<_From, _To,
1414     decltype(_VSTD::__is_convertible_imp::__test_convert<_To>(_VSTD::declval<_From>()))> : public true_type
1415 {};
1416
1417 template <class _Tp, bool _IsArray =    is_array<_Tp>::value,
1418                      bool _IsFunction = is_function<_Tp>::value,
1419                      bool _IsVoid =     is_void<_Tp>::value>
1420                      struct __is_array_function_or_void                          {enum {value = 0};};
1421 template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
1422 template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
1423 template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
1424 }
1425
1426 template <class _Tp,
1427     unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
1428 struct __is_convertible_check
1429 {
1430     static const size_t __v = 0;
1431 };
1432
1433 template <class _Tp>
1434 struct __is_convertible_check<_Tp, 0>
1435 {
1436     static const size_t __v = sizeof(_Tp);
1437 };
1438
1439 template <class _T1, class _T2,
1440     unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
1441     unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
1442 struct __is_convertible
1443     : public integral_constant<bool,
1444         __is_convertible_imp::__is_convertible_test<_T1, _T2>::value
1445 #if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1446          && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value
1447               && (!is_const<typename remove_reference<_T2>::type>::value
1448                   || is_volatile<typename remove_reference<_T2>::type>::value)
1449                   && (is_same<typename remove_cv<_T1>::type,
1450                               typename remove_cv<typename remove_reference<_T2>::type>::type>::value
1451                       || is_base_of<typename remove_reference<_T2>::type, _T1>::value))
1452 #endif
1453     >
1454 {};
1455
1456 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
1457 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
1458 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
1459 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
1460
1461 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
1462 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
1463 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
1464 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
1465
1466 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
1467 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
1468 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
1469 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
1470
1471 template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
1472     : public __is_convertible<_T1, _T2>
1473 {
1474     static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
1475     static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
1476 };
1477
1478 #endif  // __has_feature(is_convertible_to)
1479
1480 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1481 template <class _From, class _To> _LIBCPP_CONSTEXPR bool is_convertible_v
1482     = is_convertible<_From, _To>::value;
1483 #endif
1484
1485 // is_empty
1486
1487 #if __has_feature(is_empty) || (_GNUC_VER >= 407)
1488
1489 template <class _Tp>
1490 struct _LIBCPP_TEMPLATE_VIS is_empty
1491     : public integral_constant<bool, __is_empty(_Tp)> {};
1492
1493 #else  // __has_feature(is_empty)
1494
1495 template <class _Tp>
1496 struct __is_empty1
1497     : public _Tp
1498 {
1499     double __lx;
1500 };
1501
1502 struct __is_empty2
1503 {
1504     double __lx;
1505 };
1506
1507 template <class _Tp, bool = is_class<_Tp>::value>
1508 struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
1509
1510 template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
1511
1512 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empty<_Tp> {};
1513
1514 #endif  // __has_feature(is_empty)
1515
1516 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1517 template <class _Tp> _LIBCPP_CONSTEXPR bool is_empty_v
1518     = is_empty<_Tp>::value;
1519 #endif
1520
1521 // is_polymorphic
1522
1523 #if __has_feature(is_polymorphic) || defined(_LIBCPP_COMPILER_MSVC)
1524
1525 template <class _Tp>
1526 struct _LIBCPP_TEMPLATE_VIS is_polymorphic
1527     : public integral_constant<bool, __is_polymorphic(_Tp)> {};
1528
1529 #else
1530
1531 template<typename _Tp> char &__is_polymorphic_impl(
1532     typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
1533                        int>::type);
1534 template<typename _Tp> __two &__is_polymorphic_impl(...);
1535
1536 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic
1537     : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
1538
1539 #endif // __has_feature(is_polymorphic)
1540
1541 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1542 template <class _Tp> _LIBCPP_CONSTEXPR bool is_polymorphic_v
1543     = is_polymorphic<_Tp>::value;
1544 #endif
1545
1546 // has_virtual_destructor
1547
1548 #if __has_feature(has_virtual_destructor) || (_GNUC_VER >= 403)
1549
1550 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
1551     : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
1552
1553 #else
1554
1555 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
1556     : public false_type {};
1557
1558 #endif
1559
1560 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1561 template <class _Tp> _LIBCPP_CONSTEXPR bool has_virtual_destructor_v
1562     = has_virtual_destructor<_Tp>::value;
1563 #endif
1564
1565 // alignment_of
1566
1567 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
1568     : public integral_constant<size_t, __alignof__(_Tp)> {};
1569
1570 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1571 template <class _Tp> _LIBCPP_CONSTEXPR size_t alignment_of_v
1572     = alignment_of<_Tp>::value;
1573 #endif
1574
1575 // aligned_storage
1576
1577 template <class _Hp, class _Tp>
1578 struct __type_list
1579 {
1580     typedef _Hp _Head;
1581     typedef _Tp _Tail;
1582 };
1583
1584 struct __nat
1585 {
1586 #ifndef _LIBCPP_CXX03_LANG
1587     __nat() = delete;
1588     __nat(const __nat&) = delete;
1589     __nat& operator=(const __nat&) = delete;
1590     ~__nat() = delete;
1591 #endif
1592 };
1593
1594 template <class _Tp>
1595 struct __align_type
1596 {
1597     static const size_t value = alignment_of<_Tp>::value;
1598     typedef _Tp type;
1599 };
1600
1601 struct __struct_double {long double __lx;};
1602 struct __struct_double4 {double __lx[4];};
1603
1604 typedef
1605     __type_list<__align_type<unsigned char>,
1606     __type_list<__align_type<unsigned short>,
1607     __type_list<__align_type<unsigned int>,
1608     __type_list<__align_type<unsigned long>,
1609     __type_list<__align_type<unsigned long long>,
1610     __type_list<__align_type<double>,
1611     __type_list<__align_type<long double>,
1612     __type_list<__align_type<__struct_double>,
1613     __type_list<__align_type<__struct_double4>,
1614     __type_list<__align_type<int*>,
1615     __nat
1616     > > > > > > > > > > __all_types;
1617
1618 template <class _TL, size_t _Align> struct __find_pod;
1619
1620 template <class _Hp, size_t _Align>
1621 struct __find_pod<__type_list<_Hp, __nat>, _Align>
1622 {
1623     typedef typename conditional<
1624                              _Align == _Hp::value,
1625                              typename _Hp::type,
1626                              void
1627                          >::type type;
1628 };
1629
1630 template <class _Hp, class _Tp, size_t _Align>
1631 struct __find_pod<__type_list<_Hp, _Tp>, _Align>
1632 {
1633     typedef typename conditional<
1634                              _Align == _Hp::value,
1635                              typename _Hp::type,
1636                              typename __find_pod<_Tp, _Align>::type
1637                          >::type type;
1638 };
1639
1640 template <class _TL, size_t _Len> struct __find_max_align;
1641
1642 template <class _Hp, size_t _Len>
1643 struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
1644
1645 template <size_t _Len, size_t _A1, size_t _A2>
1646 struct __select_align
1647 {
1648 private:
1649     static const size_t __min = _A2 < _A1 ? _A2 : _A1;
1650     static const size_t __max = _A1 < _A2 ? _A2 : _A1;
1651 public:
1652     static const size_t value = _Len < __max ? __min : __max;
1653 };
1654
1655 template <class _Hp, class _Tp, size_t _Len>
1656 struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
1657     : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
1658
1659 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1660 struct _LIBCPP_TEMPLATE_VIS aligned_storage
1661 {
1662     typedef typename __find_pod<__all_types, _Align>::type _Aligner;
1663     static_assert(!is_void<_Aligner>::value, "");
1664     union type
1665     {
1666         _Aligner __align;
1667         unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
1668     };
1669 };
1670
1671 #if _LIBCPP_STD_VER > 11
1672 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1673     using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
1674 #endif
1675
1676 #define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
1677 template <size_t _Len>\
1678 struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
1679 {\
1680     struct _ALIGNAS(n) type\
1681     {\
1682         unsigned char __lx[(_Len + n - 1)/n * n];\
1683     };\
1684 }
1685
1686 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
1687 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
1688 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
1689 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
1690 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
1691 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
1692 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
1693 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
1694 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
1695 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
1696 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
1697 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
1698 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
1699 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
1700 // PE/COFF does not support alignment beyond 8192 (=0x2000)
1701 #if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1702 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
1703 #endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1704
1705 #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
1706
1707 #ifndef _LIBCPP_HAS_NO_VARIADICS
1708
1709 // aligned_union
1710
1711 template <size_t _I0, size_t ..._In>
1712 struct __static_max;
1713
1714 template <size_t _I0>
1715 struct __static_max<_I0>
1716 {
1717     static const size_t value = _I0;
1718 };
1719
1720 template <size_t _I0, size_t _I1, size_t ..._In>
1721 struct __static_max<_I0, _I1, _In...>
1722 {
1723     static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
1724                                              __static_max<_I1, _In...>::value;
1725 };
1726
1727 template <size_t _Len, class _Type0, class ..._Types>
1728 struct aligned_union
1729 {
1730     static const size_t alignment_value = __static_max<__alignof__(_Type0),
1731                                                        __alignof__(_Types)...>::value;
1732     static const size_t __len = __static_max<_Len, sizeof(_Type0),
1733                                              sizeof(_Types)...>::value;
1734     typedef typename aligned_storage<__len, alignment_value>::type type;
1735 };
1736
1737 #if _LIBCPP_STD_VER > 11
1738 template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
1739 #endif
1740
1741 #endif  // _LIBCPP_HAS_NO_VARIADICS
1742
1743 template <class _Tp>
1744 struct __numeric_type
1745 {
1746    static void __test(...);
1747    static float __test(float);
1748    static double __test(char);
1749    static double __test(int);
1750    static double __test(unsigned);
1751    static double __test(long);
1752    static double __test(unsigned long);
1753    static double __test(long long);
1754    static double __test(unsigned long long);
1755    static double __test(double);
1756    static long double __test(long double);
1757
1758    typedef decltype(__test(declval<_Tp>())) type;
1759    static const bool value = !is_same<type, void>::value;
1760 };
1761
1762 template <>
1763 struct __numeric_type<void>
1764 {
1765    static const bool value = true;
1766 };
1767
1768 // __promote
1769
1770 template <class _A1, class _A2 = void, class _A3 = void,
1771           bool = __numeric_type<_A1>::value &&
1772                  __numeric_type<_A2>::value &&
1773                  __numeric_type<_A3>::value>
1774 class __promote_imp
1775 {
1776 public:
1777     static const bool value = false;
1778 };
1779
1780 template <class _A1, class _A2, class _A3>
1781 class __promote_imp<_A1, _A2, _A3, true>
1782 {
1783 private:
1784     typedef typename __promote_imp<_A1>::type __type1;
1785     typedef typename __promote_imp<_A2>::type __type2;
1786     typedef typename __promote_imp<_A3>::type __type3;
1787 public:
1788     typedef decltype(__type1() + __type2() + __type3()) type;
1789     static const bool value = true;
1790 };
1791
1792 template <class _A1, class _A2>
1793 class __promote_imp<_A1, _A2, void, true>
1794 {
1795 private:
1796     typedef typename __promote_imp<_A1>::type __type1;
1797     typedef typename __promote_imp<_A2>::type __type2;
1798 public:
1799     typedef decltype(__type1() + __type2()) type;
1800     static const bool value = true;
1801 };
1802
1803 template <class _A1>
1804 class __promote_imp<_A1, void, void, true>
1805 {
1806 public:
1807     typedef typename __numeric_type<_A1>::type type;
1808     static const bool value = true;
1809 };
1810
1811 template <class _A1, class _A2 = void, class _A3 = void>
1812 class __promote : public __promote_imp<_A1, _A2, _A3> {};
1813
1814 // make_signed / make_unsigned
1815
1816 typedef
1817     __type_list<signed char,
1818     __type_list<signed short,
1819     __type_list<signed int,
1820     __type_list<signed long,
1821     __type_list<signed long long,
1822 #ifndef _LIBCPP_HAS_NO_INT128
1823     __type_list<__int128_t,
1824 #endif
1825     __nat
1826 #ifndef _LIBCPP_HAS_NO_INT128
1827     >
1828 #endif
1829     > > > > > __signed_types;
1830
1831 typedef
1832     __type_list<unsigned char,
1833     __type_list<unsigned short,
1834     __type_list<unsigned int,
1835     __type_list<unsigned long,
1836     __type_list<unsigned long long,
1837 #ifndef _LIBCPP_HAS_NO_INT128
1838     __type_list<__uint128_t,
1839 #endif
1840     __nat
1841 #ifndef _LIBCPP_HAS_NO_INT128
1842     >
1843 #endif
1844     > > > > > __unsigned_types;
1845
1846 template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
1847
1848 template <class _Hp, class _Tp, size_t _Size>
1849 struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
1850 {
1851     typedef _Hp type;
1852 };
1853
1854 template <class _Hp, class _Tp, size_t _Size>
1855 struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
1856 {
1857     typedef typename __find_first<_Tp, _Size>::type type;
1858 };
1859
1860 template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
1861                              bool = is_volatile<typename remove_reference<_Tp>::type>::value>
1862 struct __apply_cv
1863 {
1864     typedef _Up type;
1865 };
1866
1867 template <class _Tp, class _Up>
1868 struct __apply_cv<_Tp, _Up, true, false>
1869 {
1870     typedef const _Up type;
1871 };
1872
1873 template <class _Tp, class _Up>
1874 struct __apply_cv<_Tp, _Up, false, true>
1875 {
1876     typedef volatile _Up type;
1877 };
1878
1879 template <class _Tp, class _Up>
1880 struct __apply_cv<_Tp, _Up, true, true>
1881 {
1882     typedef const volatile _Up type;
1883 };
1884
1885 template <class _Tp, class _Up>
1886 struct __apply_cv<_Tp&, _Up, false, false>
1887 {
1888     typedef _Up& type;
1889 };
1890
1891 template <class _Tp, class _Up>
1892 struct __apply_cv<_Tp&, _Up, true, false>
1893 {
1894     typedef const _Up& type;
1895 };
1896
1897 template <class _Tp, class _Up>
1898 struct __apply_cv<_Tp&, _Up, false, true>
1899 {
1900     typedef volatile _Up& type;
1901 };
1902
1903 template <class _Tp, class _Up>
1904 struct __apply_cv<_Tp&, _Up, true, true>
1905 {
1906     typedef const volatile _Up& type;
1907 };
1908
1909 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1910 struct __make_signed {};
1911
1912 template <class _Tp>
1913 struct __make_signed<_Tp, true>
1914 {
1915     typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
1916 };
1917
1918 template <> struct __make_signed<bool,               true> {};
1919 template <> struct __make_signed<  signed short,     true> {typedef short     type;};
1920 template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
1921 template <> struct __make_signed<  signed int,       true> {typedef int       type;};
1922 template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
1923 template <> struct __make_signed<  signed long,      true> {typedef long      type;};
1924 template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
1925 template <> struct __make_signed<  signed long long, true> {typedef long long type;};
1926 template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
1927 #ifndef _LIBCPP_HAS_NO_INT128
1928 template <> struct __make_signed<__int128_t,         true> {typedef __int128_t type;};
1929 template <> struct __make_signed<__uint128_t,        true> {typedef __int128_t type;};
1930 #endif
1931
1932 template <class _Tp>
1933 struct _LIBCPP_TEMPLATE_VIS make_signed
1934 {
1935     typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
1936 };
1937
1938 #if _LIBCPP_STD_VER > 11
1939 template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
1940 #endif
1941
1942 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1943 struct __make_unsigned {};
1944
1945 template <class _Tp>
1946 struct __make_unsigned<_Tp, true>
1947 {
1948     typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
1949 };
1950
1951 template <> struct __make_unsigned<bool,               true> {};
1952 template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
1953 template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
1954 template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
1955 template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
1956 template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
1957 template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
1958 template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
1959 template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
1960 #ifndef _LIBCPP_HAS_NO_INT128
1961 template <> struct __make_unsigned<__int128_t,         true> {typedef __uint128_t        type;};
1962 template <> struct __make_unsigned<__uint128_t,        true> {typedef __uint128_t        type;};
1963 #endif
1964
1965 template <class _Tp>
1966 struct _LIBCPP_TEMPLATE_VIS make_unsigned
1967 {
1968     typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
1969 };
1970
1971 #if _LIBCPP_STD_VER > 11
1972 template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
1973 #endif
1974
1975 #ifdef _LIBCPP_HAS_NO_VARIADICS
1976
1977 template <class _Tp, class _Up = void, class _Vp = void>
1978 struct _LIBCPP_TEMPLATE_VIS common_type
1979 {
1980 public:
1981     typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp>::type type;
1982 };
1983
1984 template <>
1985 struct _LIBCPP_TEMPLATE_VIS common_type<void, void, void>
1986 {
1987 public:
1988     typedef void type;
1989 };
1990
1991 template <class _Tp>
1992 struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, void, void>
1993 {
1994 public:
1995     typedef typename common_type<_Tp, _Tp>::type type;
1996 };
1997
1998 template <class _Tp, class _Up>
1999 struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up, void>
2000 {
2001     typedef typename decay<decltype(
2002         true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>()
2003       )>::type type;
2004 };
2005
2006 #else  // _LIBCPP_HAS_NO_VARIADICS
2007
2008 // bullet 1 - sizeof...(Tp) == 0
2009
2010 template <class ..._Tp>
2011 struct _LIBCPP_TEMPLATE_VIS common_type {};
2012
2013 // bullet 2 - sizeof...(Tp) == 1
2014
2015 template <class _Tp>
2016 struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
2017     : public common_type<_Tp, _Tp> {};
2018
2019 // bullet 3 - sizeof...(Tp) == 2
2020
2021 template <class _Tp, class _Up, class = void>
2022 struct __common_type2_imp {};
2023
2024 template <class _Tp, class _Up>
2025 struct __common_type2_imp<_Tp, _Up,
2026     typename __void_t<decltype(
2027         true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>()
2028     )>::type>
2029 {
2030     typedef typename decay<decltype(
2031         true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>()
2032     )>::type type;
2033 };
2034
2035 template <class _Tp, class _Up,
2036           class _DTp = typename decay<_Tp>::type,
2037           class _DUp = typename decay<_Up>::type>
2038 using __common_type2 =
2039   typename conditional<
2040     is_same<_Tp, _DTp>::value && is_same<_Up, _DUp>::value,
2041     __common_type2_imp<_Tp, _Up>,
2042     common_type<_DTp, _DUp>
2043   >::type;
2044
2045 template <class _Tp, class _Up>
2046 struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
2047     : __common_type2<_Tp, _Up> {};
2048
2049 // bullet 4 - sizeof...(Tp) > 2
2050
2051 template <class ...Tp> struct __common_types;
2052
2053 template <class, class = void>
2054 struct __common_type_impl {};
2055
2056 template <class _Tp, class _Up>
2057 struct __common_type_impl<
2058     __common_types<_Tp, _Up>,
2059     typename __void_t<typename common_type<_Tp, _Up>::type>::type>
2060 {
2061   typedef typename common_type<_Tp, _Up>::type type;
2062 };
2063
2064 template <class _Tp, class _Up, class ..._Vp>
2065 struct __common_type_impl<__common_types<_Tp, _Up, _Vp...>,
2066     typename __void_t<typename common_type<_Tp, _Up>::type>::type>
2067   : __common_type_impl<
2068       __common_types<typename common_type<_Tp, _Up>::type, _Vp...> >
2069 {
2070
2071 };
2072
2073 template <class _Tp, class _Up, class ..._Vp>
2074 struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up, _Vp...>
2075     : __common_type_impl<__common_types<_Tp, _Up, _Vp...> > {};
2076
2077 #if _LIBCPP_STD_VER > 11
2078 template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
2079 #endif
2080
2081 #endif  // _LIBCPP_HAS_NO_VARIADICS
2082
2083 // is_assignable
2084
2085 template<typename, typename _Tp> struct __select_2nd { typedef _Tp type; };
2086
2087 template <class _Tp, class _Arg>
2088 typename __select_2nd<decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>())), true_type>::type
2089 __is_assignable_test(int);
2090
2091 template <class, class>
2092 false_type __is_assignable_test(...);
2093
2094
2095 template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
2096 struct __is_assignable_imp
2097     : public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {};
2098
2099 template <class _Tp, class _Arg>
2100 struct __is_assignable_imp<_Tp, _Arg, true>
2101     : public false_type
2102 {
2103 };
2104
2105 template <class _Tp, class _Arg>
2106 struct is_assignable
2107     : public __is_assignable_imp<_Tp, _Arg> {};
2108
2109 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2110 template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_assignable_v
2111     = is_assignable<_Tp, _Arg>::value;
2112 #endif
2113
2114 // is_copy_assignable
2115
2116 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
2117     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
2118                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2119
2120 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2121 template <class _Tp> _LIBCPP_CONSTEXPR bool is_copy_assignable_v
2122     = is_copy_assignable<_Tp>::value;
2123 #endif
2124
2125 // is_move_assignable
2126
2127 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable
2128 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2129     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
2130                            typename add_rvalue_reference<_Tp>::type> {};
2131 #else
2132     : public is_copy_assignable<_Tp> {};
2133 #endif
2134
2135 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2136 template <class _Tp> _LIBCPP_CONSTEXPR bool is_move_assignable_v
2137     = is_move_assignable<_Tp>::value;
2138 #endif
2139
2140 // is_destructible
2141
2142 //  if it's a reference, return true
2143 //  if it's a function, return false
2144 //  if it's   void,     return false
2145 //  if it's an array of unknown bound, return false
2146 //  Otherwise, return "std::declval<_Up&>().~_Up()" is well-formed
2147 //    where _Up is remove_all_extents<_Tp>::type
2148
2149 template <class>
2150 struct __is_destructible_apply { typedef int type; };
2151
2152 template <typename _Tp>
2153 struct __is_destructor_wellformed {
2154     template <typename _Tp1>
2155     static char  __test (
2156         typename __is_destructible_apply<decltype(_VSTD::declval<_Tp1&>().~_Tp1())>::type
2157     );
2158
2159     template <typename _Tp1>
2160     static __two __test (...);
2161     
2162     static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
2163 };
2164
2165 template <class _Tp, bool>
2166 struct __destructible_imp;
2167
2168 template <class _Tp>
2169 struct __destructible_imp<_Tp, false> 
2170    : public _VSTD::integral_constant<bool, 
2171         __is_destructor_wellformed<typename _VSTD::remove_all_extents<_Tp>::type>::value> {};
2172
2173 template <class _Tp>
2174 struct __destructible_imp<_Tp, true>
2175     : public _VSTD::true_type {};
2176
2177 template <class _Tp, bool>
2178 struct __destructible_false;
2179
2180 template <class _Tp>
2181 struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, _VSTD::is_reference<_Tp>::value> {};
2182
2183 template <class _Tp>
2184 struct __destructible_false<_Tp, true> : public _VSTD::false_type {};
2185
2186 template <class _Tp>
2187 struct is_destructible
2188     : public __destructible_false<_Tp, _VSTD::is_function<_Tp>::value> {};
2189
2190 template <class _Tp>
2191 struct is_destructible<_Tp[]>
2192     : public _VSTD::false_type {};
2193
2194 template <>
2195 struct is_destructible<void>
2196     : public _VSTD::false_type {};
2197
2198 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2199 template <class _Tp> _LIBCPP_CONSTEXPR bool is_destructible_v
2200     = is_destructible<_Tp>::value;
2201 #endif
2202
2203 // move
2204
2205 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2206
2207 template <class _Tp>
2208 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2209 typename remove_reference<_Tp>::type&&
2210 move(_Tp&& __t) _NOEXCEPT
2211 {
2212     typedef typename remove_reference<_Tp>::type _Up;
2213     return static_cast<_Up&&>(__t);
2214 }
2215
2216 template <class _Tp>
2217 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2218 _Tp&&
2219 forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT
2220 {
2221     return static_cast<_Tp&&>(__t);
2222 }
2223
2224 template <class _Tp>
2225 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2226 _Tp&&
2227 forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT
2228 {
2229     static_assert(!is_lvalue_reference<_Tp>::value,
2230                   "can not forward an rvalue as an lvalue");
2231     return static_cast<_Tp&&>(__t);
2232 }
2233
2234 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2235
2236 template <class _Tp>
2237 inline _LIBCPP_INLINE_VISIBILITY
2238 _Tp&
2239 move(_Tp& __t)
2240 {
2241     return __t;
2242 }
2243
2244 template <class _Tp>
2245 inline _LIBCPP_INLINE_VISIBILITY
2246 const _Tp&
2247 move(const _Tp& __t)
2248 {
2249     return __t;
2250 }
2251
2252 template <class _Tp>
2253 inline _LIBCPP_INLINE_VISIBILITY
2254 _Tp&
2255 forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT
2256 {
2257     return __t;
2258 }
2259
2260
2261 template <class _Tp>
2262 class __rv
2263 {
2264     typedef typename remove_reference<_Tp>::type _Trr;
2265     _Trr& t_;
2266 public:
2267     _LIBCPP_INLINE_VISIBILITY
2268     _Trr* operator->() {return &t_;}
2269     _LIBCPP_INLINE_VISIBILITY
2270     explicit __rv(_Trr& __t) : t_(__t) {}
2271 };
2272
2273 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2274
2275 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2276
2277 template <class _Tp>
2278 inline _LIBCPP_INLINE_VISIBILITY
2279 typename decay<_Tp>::type
2280 __decay_copy(_Tp&& __t)
2281 {
2282     return _VSTD::forward<_Tp>(__t);
2283 }
2284
2285 #else
2286
2287 template <class _Tp>
2288 inline _LIBCPP_INLINE_VISIBILITY
2289 typename decay<_Tp>::type
2290 __decay_copy(const _Tp& __t)
2291 {
2292     return _VSTD::forward<_Tp>(__t);
2293 }
2294
2295 #endif
2296
2297 #ifndef _LIBCPP_HAS_NO_VARIADICS
2298
2299 template <class _Rp, class _Class, class ..._Param>
2300 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
2301 {
2302     typedef _Class _ClassType;
2303     typedef _Rp _ReturnType;
2304     typedef _Rp (_FnType) (_Param...);
2305 };
2306
2307 template <class _Rp, class _Class, class ..._Param>
2308 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
2309 {
2310     typedef _Class _ClassType;
2311     typedef _Rp _ReturnType;
2312     typedef _Rp (_FnType) (_Param..., ...);
2313 };
2314
2315 template <class _Rp, class _Class, class ..._Param>
2316 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
2317 {
2318     typedef _Class const _ClassType;
2319     typedef _Rp _ReturnType;
2320     typedef _Rp (_FnType) (_Param...);
2321 };
2322
2323 template <class _Rp, class _Class, class ..._Param>
2324 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
2325 {
2326     typedef _Class const _ClassType;
2327     typedef _Rp _ReturnType;
2328     typedef _Rp (_FnType) (_Param..., ...);
2329 };
2330
2331 template <class _Rp, class _Class, class ..._Param>
2332 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
2333 {
2334     typedef _Class volatile _ClassType;
2335     typedef _Rp _ReturnType;
2336     typedef _Rp (_FnType) (_Param...);
2337 };
2338
2339 template <class _Rp, class _Class, class ..._Param>
2340 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
2341 {
2342     typedef _Class volatile _ClassType;
2343     typedef _Rp _ReturnType;
2344     typedef _Rp (_FnType) (_Param..., ...);
2345 };
2346
2347 template <class _Rp, class _Class, class ..._Param>
2348 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
2349 {
2350     typedef _Class const volatile _ClassType;
2351     typedef _Rp _ReturnType;
2352     typedef _Rp (_FnType) (_Param...);
2353 };
2354
2355 template <class _Rp, class _Class, class ..._Param>
2356 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
2357 {
2358     typedef _Class const volatile _ClassType;
2359     typedef _Rp _ReturnType;
2360     typedef _Rp (_FnType) (_Param..., ...);
2361 };
2362
2363 #if __has_feature(cxx_reference_qualified_functions) || \
2364     (defined(_GNUC_VER) && _GNUC_VER >= 409)
2365
2366 template <class _Rp, class _Class, class ..._Param>
2367 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
2368 {
2369     typedef _Class& _ClassType;
2370     typedef _Rp _ReturnType;
2371     typedef _Rp (_FnType) (_Param...);
2372 };
2373
2374 template <class _Rp, class _Class, class ..._Param>
2375 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
2376 {
2377     typedef _Class& _ClassType;
2378     typedef _Rp _ReturnType;
2379     typedef _Rp (_FnType) (_Param..., ...);
2380 };
2381
2382 template <class _Rp, class _Class, class ..._Param>
2383 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
2384 {
2385     typedef _Class const& _ClassType;
2386     typedef _Rp _ReturnType;
2387     typedef _Rp (_FnType) (_Param...);
2388 };
2389
2390 template <class _Rp, class _Class, class ..._Param>
2391 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
2392 {
2393     typedef _Class const& _ClassType;
2394     typedef _Rp _ReturnType;
2395     typedef _Rp (_FnType) (_Param..., ...);
2396 };
2397
2398 template <class _Rp, class _Class, class ..._Param>
2399 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
2400 {
2401     typedef _Class volatile& _ClassType;
2402     typedef _Rp _ReturnType;
2403     typedef _Rp (_FnType) (_Param...);
2404 };
2405
2406 template <class _Rp, class _Class, class ..._Param>
2407 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
2408 {
2409     typedef _Class volatile& _ClassType;
2410     typedef _Rp _ReturnType;
2411     typedef _Rp (_FnType) (_Param..., ...);
2412 };
2413
2414 template <class _Rp, class _Class, class ..._Param>
2415 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
2416 {
2417     typedef _Class const volatile& _ClassType;
2418     typedef _Rp _ReturnType;
2419     typedef _Rp (_FnType) (_Param...);
2420 };
2421
2422 template <class _Rp, class _Class, class ..._Param>
2423 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
2424 {
2425     typedef _Class const volatile& _ClassType;
2426     typedef _Rp _ReturnType;
2427     typedef _Rp (_FnType) (_Param..., ...);
2428 };
2429
2430 template <class _Rp, class _Class, class ..._Param>
2431 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
2432 {
2433     typedef _Class&& _ClassType;
2434     typedef _Rp _ReturnType;
2435     typedef _Rp (_FnType) (_Param...);
2436 };
2437
2438 template <class _Rp, class _Class, class ..._Param>
2439 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
2440 {
2441     typedef _Class&& _ClassType;
2442     typedef _Rp _ReturnType;
2443     typedef _Rp (_FnType) (_Param..., ...);
2444 };
2445
2446 template <class _Rp, class _Class, class ..._Param>
2447 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
2448 {
2449     typedef _Class const&& _ClassType;
2450     typedef _Rp _ReturnType;
2451     typedef _Rp (_FnType) (_Param...);
2452 };
2453
2454 template <class _Rp, class _Class, class ..._Param>
2455 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
2456 {
2457     typedef _Class const&& _ClassType;
2458     typedef _Rp _ReturnType;
2459     typedef _Rp (_FnType) (_Param..., ...);
2460 };
2461
2462 template <class _Rp, class _Class, class ..._Param>
2463 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
2464 {
2465     typedef _Class volatile&& _ClassType;
2466     typedef _Rp _ReturnType;
2467     typedef _Rp (_FnType) (_Param...);
2468 };
2469
2470 template <class _Rp, class _Class, class ..._Param>
2471 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
2472 {
2473     typedef _Class volatile&& _ClassType;
2474     typedef _Rp _ReturnType;
2475     typedef _Rp (_FnType) (_Param..., ...);
2476 };
2477
2478 template <class _Rp, class _Class, class ..._Param>
2479 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
2480 {
2481     typedef _Class const volatile&& _ClassType;
2482     typedef _Rp _ReturnType;
2483     typedef _Rp (_FnType) (_Param...);
2484 };
2485
2486 template <class _Rp, class _Class, class ..._Param>
2487 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
2488 {
2489     typedef _Class const volatile&& _ClassType;
2490     typedef _Rp _ReturnType;
2491     typedef _Rp (_FnType) (_Param..., ...);
2492 };
2493
2494 #endif  // __has_feature(cxx_reference_qualified_functions) || _GNUC_VER >= 409
2495
2496 #else  // _LIBCPP_HAS_NO_VARIADICS
2497
2498 template <class _Rp, class _Class>
2499 struct __member_pointer_traits_imp<_Rp (_Class::*)(), true, false>
2500 {
2501     typedef _Class _ClassType;
2502     typedef _Rp _ReturnType;
2503     typedef _Rp (_FnType) ();
2504 };
2505
2506 template <class _Rp, class _Class>
2507 struct __member_pointer_traits_imp<_Rp (_Class::*)(...), true, false>
2508 {
2509     typedef _Class _ClassType;
2510     typedef _Rp _ReturnType;
2511     typedef _Rp (_FnType) (...);
2512 };
2513
2514 template <class _Rp, class _Class, class _P0>
2515 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0), true, false>
2516 {
2517     typedef _Class _ClassType;
2518     typedef _Rp _ReturnType;
2519     typedef _Rp (_FnType) (_P0);
2520 };
2521
2522 template <class _Rp, class _Class, class _P0>
2523 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...), true, false>
2524 {
2525     typedef _Class _ClassType;
2526     typedef _Rp _ReturnType;
2527     typedef _Rp (_FnType) (_P0, ...);
2528 };
2529
2530 template <class _Rp, class _Class, class _P0, class _P1>
2531 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1), true, false>
2532 {
2533     typedef _Class _ClassType;
2534     typedef _Rp _ReturnType;
2535     typedef _Rp (_FnType) (_P0, _P1);
2536 };
2537
2538 template <class _Rp, class _Class, class _P0, class _P1>
2539 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...), true, false>
2540 {
2541     typedef _Class _ClassType;
2542     typedef _Rp _ReturnType;
2543     typedef _Rp (_FnType) (_P0, _P1, ...);
2544 };
2545
2546 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
2547 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2), true, false>
2548 {
2549     typedef _Class _ClassType;
2550     typedef _Rp _ReturnType;
2551     typedef _Rp (_FnType) (_P0, _P1, _P2);
2552 };
2553
2554 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
2555 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...), true, false>
2556 {
2557     typedef _Class _ClassType;
2558     typedef _Rp _ReturnType;
2559     typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
2560 };
2561
2562 template <class _Rp, class _Class>
2563 struct __member_pointer_traits_imp<_Rp (_Class::*)() const, true, false>
2564 {
2565     typedef _Class const _ClassType;
2566     typedef _Rp _ReturnType;
2567     typedef _Rp (_FnType) ();
2568 };
2569
2570 template <class _Rp, class _Class>
2571 struct __member_pointer_traits_imp<_Rp (_Class::*)(...) const, true, false>
2572 {
2573     typedef _Class const _ClassType;
2574     typedef _Rp _ReturnType;
2575     typedef _Rp (_FnType) (...);
2576 };
2577
2578 template <class _Rp, class _Class, class _P0>
2579 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const, true, false>
2580 {
2581     typedef _Class const _ClassType;
2582     typedef _Rp _ReturnType;
2583     typedef _Rp (_FnType) (_P0);
2584 };
2585
2586 template <class _Rp, class _Class, class _P0>
2587 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const, true, false>
2588 {
2589     typedef _Class const _ClassType;
2590     typedef _Rp _ReturnType;
2591     typedef _Rp (_FnType) (_P0, ...);
2592 };
2593
2594 template <class _Rp, class _Class, class _P0, class _P1>
2595 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const, true, false>
2596 {
2597     typedef _Class const _ClassType;
2598     typedef _Rp _ReturnType;
2599     typedef _Rp (_FnType) (_P0, _P1);
2600 };
2601
2602 template <class _Rp, class _Class, class _P0, class _P1>
2603 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const, true, false>
2604 {
2605     typedef _Class const _ClassType;
2606     typedef _Rp _ReturnType;
2607     typedef _Rp (_FnType) (_P0, _P1, ...);
2608 };
2609
2610 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
2611 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const, true, false>
2612 {
2613     typedef _Class const _ClassType;
2614     typedef _Rp _ReturnType;
2615     typedef _Rp (_FnType) (_P0, _P1, _P2);
2616 };
2617
2618 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
2619 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const, true, false>
2620 {
2621     typedef _Class const _ClassType;
2622     typedef _Rp _ReturnType;
2623     typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
2624 };
2625
2626 template <class _Rp, class _Class>
2627 struct __member_pointer_traits_imp<_Rp (_Class::*)() volatile, true, false>
2628 {
2629     typedef _Class volatile _ClassType;
2630     typedef _Rp _ReturnType;
2631     typedef _Rp (_FnType) ();
2632 };
2633
2634 template <class _Rp, class _Class>
2635 struct __member_pointer_traits_imp<_Rp (_Class::*)(...) volatile, true, false>
2636 {
2637     typedef _Class volatile _ClassType;
2638     typedef _Rp _ReturnType;
2639     typedef _Rp (_FnType) (...);
2640 };
2641
2642 template <class _Rp, class _Class, class _P0>
2643 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) volatile, true, false>
2644 {
2645     typedef _Class volatile _ClassType;
2646     typedef _Rp _ReturnType;
2647     typedef _Rp (_FnType) (_P0);
2648 };
2649
2650 template <class _Rp, class _Class, class _P0>
2651 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) volatile, true, false>
2652 {
2653     typedef _Class volatile _ClassType;
2654     typedef _Rp _ReturnType;
2655     typedef _Rp (_FnType) (_P0, ...);
2656 };
2657
2658 template <class _Rp, class _Class, class _P0, class _P1>
2659 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) volatile, true, false>
2660 {
2661     typedef _Class volatile _ClassType;
2662     typedef _Rp _ReturnType;
2663     typedef _Rp (_FnType) (_P0, _P1);
2664 };
2665
2666 template <class _Rp, class _Class, class _P0, class _P1>
2667 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) volatile, true, false>
2668 {
2669     typedef _Class volatile _ClassType;
2670     typedef _Rp _ReturnType;
2671     typedef _Rp (_FnType) (_P0, _P1, ...);
2672 };
2673
2674 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
2675 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) volatile, true, false>
2676 {
2677     typedef _Class volatile _ClassType;
2678     typedef _Rp _ReturnType;
2679     typedef _Rp (_FnType) (_P0, _P1, _P2);
2680 };
2681
2682 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
2683 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) volatile, true, false>
2684 {
2685     typedef _Class volatile _ClassType;
2686     typedef _Rp _ReturnType;
2687     typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
2688 };
2689
2690 template <class _Rp, class _Class>
2691 struct __member_pointer_traits_imp<_Rp (_Class::*)() const volatile, true, false>
2692 {
2693     typedef _Class const volatile _ClassType;
2694     typedef _Rp _ReturnType;
2695     typedef _Rp (_FnType) ();
2696 };
2697
2698 template <class _Rp, class _Class>
2699 struct __member_pointer_traits_imp<_Rp (_Class::*)(...) const volatile, true, false>
2700 {
2701     typedef _Class const volatile _ClassType;
2702     typedef _Rp _ReturnType;
2703     typedef _Rp (_FnType) (...);
2704 };
2705
2706 template <class _Rp, class _Class, class _P0>
2707 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const volatile, true, false>
2708 {
2709     typedef _Class const volatile _ClassType;
2710     typedef _Rp _ReturnType;
2711     typedef _Rp (_FnType) (_P0);
2712 };
2713
2714 template <class _Rp, class _Class, class _P0>
2715 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const volatile, true, false>
2716 {
2717     typedef _Class const volatile _ClassType;
2718     typedef _Rp _ReturnType;
2719     typedef _Rp (_FnType) (_P0, ...);
2720 };
2721
2722 template <class _Rp, class _Class, class _P0, class _P1>
2723 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const volatile, true, false>
2724 {
2725     typedef _Class const volatile _ClassType;
2726     typedef _Rp _ReturnType;
2727     typedef _Rp (_FnType) (_P0, _P1);
2728 };
2729
2730 template <class _Rp, class _Class, class _P0, class _P1>
2731 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const volatile, true, false>
2732 {
2733     typedef _Class const volatile _ClassType;
2734     typedef _Rp _ReturnType;
2735     typedef _Rp (_FnType) (_P0, _P1, ...);
2736 };
2737
2738 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
2739 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const volatile, true, false>
2740 {
2741     typedef _Class const volatile _ClassType;
2742     typedef _Rp _ReturnType;
2743     typedef _Rp (_FnType) (_P0, _P1, _P2);
2744 };
2745
2746 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
2747 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const volatile, true, false>
2748 {
2749     typedef _Class const volatile _ClassType;
2750     typedef _Rp _ReturnType;
2751     typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
2752 };
2753
2754 #endif  // _LIBCPP_HAS_NO_VARIADICS
2755
2756 template <class _Rp, class _Class>
2757 struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
2758 {
2759     typedef _Class _ClassType;
2760     typedef _Rp _ReturnType;
2761 };
2762
2763 template <class _MP>
2764 struct __member_pointer_traits
2765     : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
2766                     is_member_function_pointer<_MP>::value,
2767                     is_member_object_pointer<_MP>::value>
2768 {
2769 //     typedef ... _ClassType;
2770 //     typedef ... _ReturnType;
2771 //     typedef ... _FnType;
2772 };
2773
2774
2775 template <class _DecayedFp>
2776 struct __member_pointer_class_type {};
2777
2778 template <class _Ret, class _ClassType>
2779 struct __member_pointer_class_type<_Ret _ClassType::*> {
2780   typedef _ClassType type;
2781 };
2782
2783 // result_of
2784
2785 template <class _Callable> class result_of;
2786
2787 #ifdef _LIBCPP_HAS_NO_VARIADICS
2788
2789 template <class _Fn, bool, bool>
2790 class __result_of
2791 {
2792 };
2793
2794 template <class _Fn>
2795 class __result_of<_Fn(), true, false>
2796 {
2797 public:
2798     typedef decltype(declval<_Fn>()()) type;
2799 };
2800
2801 template <class _Fn, class _A0>
2802 class __result_of<_Fn(_A0), true, false>
2803 {
2804 public:
2805     typedef decltype(declval<_Fn>()(declval<_A0>())) type;
2806 };
2807
2808 template <class _Fn, class _A0, class _A1>
2809 class __result_of<_Fn(_A0, _A1), true, false>
2810 {
2811 public:
2812     typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
2813 };
2814
2815 template <class _Fn, class _A0, class _A1, class _A2>
2816 class __result_of<_Fn(_A0, _A1, _A2), true, false>
2817 {
2818 public:
2819     typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
2820 };
2821
2822 template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
2823 struct __result_of_mp;
2824
2825 // member function pointer
2826
2827 template <class _MP, class _Tp>
2828 struct __result_of_mp<_MP, _Tp, true>
2829     : public __identity<typename __member_pointer_traits<_MP>::_ReturnType>
2830 {
2831 };
2832
2833 // member data pointer
2834
2835 template <class _MP, class _Tp, bool>
2836 struct __result_of_mdp;
2837
2838 template <class _Rp, class _Class, class _Tp>
2839 struct __result_of_mdp<_Rp _Class::*, _Tp, false>
2840 {
2841     typedef typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type& type;
2842 };
2843
2844 template <class _Rp, class _Class, class _Tp>
2845 struct __result_of_mdp<_Rp _Class::*, _Tp, true>
2846 {
2847     typedef typename __apply_cv<_Tp, _Rp>::type& type;
2848 };
2849
2850 template <class _Rp, class _Class, class _Tp>
2851 struct __result_of_mp<_Rp _Class::*, _Tp, false>
2852     : public __result_of_mdp<_Rp _Class::*, _Tp,
2853             is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
2854 {
2855 };
2856
2857
2858
2859 template <class _Fn, class _Tp>
2860 class __result_of<_Fn(_Tp), false, true>  // _Fn must be member pointer
2861     : public __result_of_mp<typename remove_reference<_Fn>::type,
2862                             _Tp,
2863                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2864 {
2865 };
2866
2867 template <class _Fn, class _Tp, class _A0>
2868 class __result_of<_Fn(_Tp, _A0), false, true>  // _Fn must be member pointer
2869     : public __result_of_mp<typename remove_reference<_Fn>::type,
2870                             _Tp,
2871                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2872 {
2873 };
2874
2875 template <class _Fn, class _Tp, class _A0, class _A1>
2876 class __result_of<_Fn(_Tp, _A0, _A1), false, true>  // _Fn must be member pointer
2877     : public __result_of_mp<typename remove_reference<_Fn>::type,
2878                             _Tp,
2879                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2880 {
2881 };
2882
2883 template <class _Fn, class _Tp, class _A0, class _A1, class _A2>
2884 class __result_of<_Fn(_Tp, _A0, _A1, _A2), false, true>  // _Fn must be member pointer
2885     : public __result_of_mp<typename remove_reference<_Fn>::type,
2886                             _Tp,
2887                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2888 {
2889 };
2890
2891 // result_of
2892
2893 template <class _Fn>
2894 class _LIBCPP_TEMPLATE_VIS result_of<_Fn()>
2895     : public __result_of<_Fn(),
2896                          is_class<typename remove_reference<_Fn>::type>::value ||
2897                          is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
2898                          is_member_pointer<typename remove_reference<_Fn>::type>::value
2899                         >
2900 {
2901 };
2902
2903 template <class _Fn, class _A0>
2904 class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0)>
2905     : public __result_of<_Fn(_A0),
2906                          is_class<typename remove_reference<_Fn>::type>::value ||
2907                          is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
2908                          is_member_pointer<typename remove_reference<_Fn>::type>::value
2909                         >
2910 {
2911 };
2912
2913 template <class _Fn, class _A0, class _A1>
2914 class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0, _A1)>
2915     : public __result_of<_Fn(_A0, _A1),
2916                          is_class<typename remove_reference<_Fn>::type>::value ||
2917                          is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
2918                          is_member_pointer<typename remove_reference<_Fn>::type>::value
2919                         >
2920 {
2921 };
2922
2923 template <class _Fn, class _A0, class _A1, class _A2>
2924 class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0, _A1, _A2)>
2925     : public __result_of<_Fn(_A0, _A1, _A2),
2926                          is_class<typename remove_reference<_Fn>::type>::value ||
2927                          is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
2928                          is_member_pointer<typename remove_reference<_Fn>::type>::value
2929                         >
2930 {
2931 };
2932
2933 #endif  // _LIBCPP_HAS_NO_VARIADICS
2934
2935 // template <class T, class... Args> struct is_constructible;
2936
2937 namespace __is_construct
2938 {
2939 struct __nat {};
2940 }
2941
2942 #if !defined(_LIBCPP_CXX03_LANG) && (!__has_feature(is_constructible) || \
2943     defined(_LIBCPP_TESTING_FALLBACK_IS_CONSTRUCTIBLE))
2944
2945 template <class _Tp, class... _Args>
2946 struct __libcpp_is_constructible;
2947
2948 template <class _To, class _From>
2949 struct __is_invalid_base_to_derived_cast {
2950   static_assert(is_reference<_To>::value, "Wrong specialization");
2951   using _RawFrom = __uncvref_t<_From>;
2952   using _RawTo = __uncvref_t<_To>;
2953   static const bool value = __lazy_and<
2954         __lazy_not<is_same<_RawFrom, _RawTo>>,
2955         is_base_of<_RawFrom, _RawTo>,
2956         __lazy_not<__libcpp_is_constructible<_RawTo, _From>>
2957   >::value;
2958 };
2959
2960 template <class _To, class _From>
2961 struct __is_invalid_lvalue_to_rvalue_cast : false_type {
2962   static_assert(is_reference<_To>::value, "Wrong specialization");
2963 };
2964
2965 template <class _ToRef, class _FromRef>
2966 struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> {
2967   using _RawFrom = __uncvref_t<_FromRef>;
2968   using _RawTo = __uncvref_t<_ToRef>;
2969   static const bool value = __lazy_and<
2970       __lazy_not<is_function<_RawTo>>,
2971       __lazy_or<
2972         is_same<_RawFrom, _RawTo>,
2973         is_base_of<_RawTo, _RawFrom>>
2974     >::value;
2975 };
2976
2977 struct __is_constructible_helper
2978 {
2979     template <class _To>
2980     static void __eat(_To);
2981
2982     // This overload is needed to work around a Clang bug that disallows
2983     // static_cast<T&&>(e) for non-reference-compatible types.
2984     // Example: static_cast<int&&>(declval<double>());
2985     // NOTE: The static_cast implementation below is required to support
2986     //  classes with explicit conversion operators.
2987     template <class _To, class _From,
2988               class = decltype(__eat<_To>(_VSTD::declval<_From>()))>
2989     static true_type __test_cast(int);
2990
2991     template <class _To, class _From,
2992               class = decltype(static_cast<_To>(_VSTD::declval<_From>()))>
2993     static integral_constant<bool,
2994         !__is_invalid_base_to_derived_cast<_To, _From>::value &&
2995         !__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value
2996     > __test_cast(long);
2997
2998     template <class, class>
2999     static false_type __test_cast(...);
3000
3001     template <class _Tp, class ..._Args,
3002         class = decltype(_Tp(_VSTD::declval<_Args>()...))>
3003     static true_type __test_nary(int);
3004     template <class _Tp, class...>
3005     static false_type __test_nary(...);
3006
3007     template <class _Tp, class _A0, class = decltype(::new _Tp(_VSTD::declval<_A0>()))>
3008     static is_destructible<_Tp> __test_unary(int);
3009     template <class, class>
3010     static false_type __test_unary(...);
3011 };
3012
3013 template <class _Tp, bool = is_void<_Tp>::value>
3014 struct __is_default_constructible
3015     : decltype(__is_constructible_helper::__test_nary<_Tp>(0))
3016 {};
3017
3018 template <class _Tp>
3019 struct __is_default_constructible<_Tp, true> : false_type {};
3020
3021 template <class _Tp>
3022 struct __is_default_constructible<_Tp[], false> : false_type {};
3023
3024 template <class _Tp, size_t _Nx>
3025 struct __is_default_constructible<_Tp[_Nx], false>
3026     : __is_default_constructible<typename remove_all_extents<_Tp>::type>  {};
3027
3028 template <class _Tp, class... _Args>
3029 struct __libcpp_is_constructible
3030 {
3031   static_assert(sizeof...(_Args) > 1, "Wrong specialization");
3032   typedef decltype(__is_constructible_helper::__test_nary<_Tp, _Args...>(0))
3033       type;
3034 };
3035
3036 template <class _Tp>
3037 struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {};
3038
3039 template <class _Tp, class _A0>
3040 struct __libcpp_is_constructible<_Tp, _A0>
3041     : public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0))
3042 {};
3043
3044 template <class _Tp, class _A0>
3045 struct __libcpp_is_constructible<_Tp&, _A0>
3046     : public decltype(__is_constructible_helper::
3047     __test_cast<_Tp&, _A0>(0))
3048 {};
3049
3050 template <class _Tp, class _A0>
3051 struct __libcpp_is_constructible<_Tp&&, _A0>
3052     : public decltype(__is_constructible_helper::
3053     __test_cast<_Tp&&, _A0>(0))
3054 {};
3055
3056 #endif
3057
3058 #if __has_feature(is_constructible)
3059 template <class _Tp, class ..._Args>
3060 struct _LIBCPP_TEMPLATE_VIS is_constructible
3061     : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
3062     {};
3063 #elif !defined(_LIBCPP_CXX03_LANG)
3064 template <class _Tp, class... _Args>
3065 struct _LIBCPP_TEMPLATE_VIS is_constructible
3066     : public __libcpp_is_constructible<_Tp, _Args...>::type {};
3067 #else
3068 // template <class T> struct is_constructible0;
3069
3070 //      main is_constructible0 test
3071
3072 template <class _Tp>
3073 decltype((_Tp(), true_type()))
3074 __is_constructible0_test(_Tp&);
3075
3076 false_type
3077 __is_constructible0_test(__any);
3078
3079 template <class _Tp, class _A0>
3080 decltype((_Tp(_VSTD::declval<_A0>()), true_type()))
3081 __is_constructible1_test(_Tp&, _A0&);
3082
3083 template <class _A0>
3084 false_type
3085 __is_constructible1_test(__any, _A0&);
3086
3087 template <class _Tp, class _A0, class _A1>
3088 decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>()), true_type()))
3089 __is_constructible2_test(_Tp&, _A0&, _A1&);
3090
3091 template <class _A0, class _A1>
3092 false_type
3093 __is_constructible2_test(__any, _A0&, _A1&);
3094
3095 template <bool, class _Tp>
3096 struct __is_constructible0_imp // false, _Tp is not a scalar
3097     : public common_type
3098              <
3099                  decltype(__is_constructible0_test(declval<_Tp&>()))
3100              >::type
3101     {};
3102
3103 template <bool, class _Tp, class _A0>
3104 struct __is_constructible1_imp // false, _Tp is not a scalar
3105     : public common_type
3106              <
3107                  decltype(__is_constructible1_test(declval<_Tp&>(), declval<_A0&>()))
3108              >::type
3109     {};
3110
3111 template <bool, class _Tp, class _A0, class _A1>
3112 struct __is_constructible2_imp // false, _Tp is not a scalar
3113     : public common_type
3114              <
3115                  decltype(__is_constructible2_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>()))
3116              >::type
3117     {};
3118
3119 //      handle scalars and reference types
3120
3121 //      Scalars are default constructible, references are not
3122
3123 template <class _Tp>
3124 struct __is_constructible0_imp<true, _Tp>
3125     : public is_scalar<_Tp>
3126     {};
3127
3128 template <class _Tp, class _A0>
3129 struct __is_constructible1_imp<true, _Tp, _A0>
3130     : public is_convertible<_A0, _Tp>
3131     {};
3132
3133 template <class _Tp, class _A0, class _A1>
3134 struct __is_constructible2_imp<true, _Tp, _A0, _A1>
3135     : public false_type
3136     {};
3137
3138 //      Treat scalars and reference types separately
3139
3140 template <bool, class _Tp>
3141 struct __is_constructible0_void_check
3142     : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
3143                                 _Tp>
3144     {};
3145
3146 template <bool, class _Tp, class _A0>
3147 struct __is_constructible1_void_check
3148     : public __is_constructible1_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
3149                                 _Tp, _A0>
3150     {};
3151
3152 template <bool, class _Tp, class _A0, class _A1>
3153 struct __is_constructible2_void_check
3154     : public __is_constructible2_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
3155                                 _Tp, _A0, _A1>
3156     {};
3157
3158 //      If any of T or Args is void, is_constructible should be false
3159
3160 template <class _Tp>
3161 struct __is_constructible0_void_check<true, _Tp>
3162     : public false_type
3163     {};
3164
3165 template <class _Tp, class _A0>
3166 struct __is_constructible1_void_check<true, _Tp, _A0>
3167     : public false_type
3168     {};
3169
3170 template <class _Tp, class _A0, class _A1>
3171 struct __is_constructible2_void_check<true, _Tp, _A0, _A1>
3172     : public false_type
3173     {};
3174
3175 //      is_constructible entry point
3176
3177 template <class _Tp, class _A0 = __is_construct::__nat,
3178                      class _A1 = __is_construct::__nat>
3179 struct _LIBCPP_TEMPLATE_VIS is_constructible
3180     : public __is_constructible2_void_check<is_void<_Tp>::value
3181                                         || is_abstract<_Tp>::value
3182                                         || is_function<_Tp>::value
3183                                         || is_void<_A0>::value
3184                                         || is_void<_A1>::value,
3185                                            _Tp, _A0, _A1>
3186     {};
3187
3188 template <class _Tp>
3189 struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat>
3190     : public __is_constructible0_void_check<is_void<_Tp>::value
3191                                         || is_abstract<_Tp>::value
3192                                         || is_function<_Tp>::value,
3193                                            _Tp>
3194     {};
3195
3196 template <class _Tp, class _A0>
3197 struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, _A0, __is_construct::__nat>
3198     : public __is_constructible1_void_check<is_void<_Tp>::value
3199                                         || is_abstract<_Tp>::value
3200                                         || is_function<_Tp>::value
3201                                         || is_void<_A0>::value,
3202                                            _Tp, _A0>
3203     {};
3204
3205 //      Array types are default constructible if their element type
3206 //      is default constructible
3207
3208 template <class _Ap, size_t _Np>
3209 struct __is_constructible0_imp<false, _Ap[_Np]>
3210     : public is_constructible<typename remove_all_extents<_Ap>::type>
3211     {};
3212
3213 template <class _Ap, size_t _Np, class _A0>
3214 struct __is_constructible1_imp<false, _Ap[_Np], _A0>
3215     : public false_type
3216     {};
3217
3218 template <class _Ap, size_t _Np, class _A0, class _A1>
3219 struct __is_constructible2_imp<false, _Ap[_Np], _A0, _A1>
3220     : public false_type
3221     {};
3222
3223 //      Incomplete array types are not constructible
3224
3225 template <class _Ap>
3226 struct __is_constructible0_imp<false, _Ap[]>
3227     : public false_type
3228     {};
3229
3230 template <class _Ap, class _A0>
3231 struct __is_constructible1_imp<false, _Ap[], _A0>
3232     : public false_type
3233     {};
3234
3235 template <class _Ap, class _A0, class _A1>
3236 struct __is_constructible2_imp<false, _Ap[], _A0, _A1>
3237     : public false_type
3238     {};
3239
3240 #endif // __has_feature(is_constructible)
3241
3242
3243 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
3244 template <class _Tp, class ..._Args> _LIBCPP_CONSTEXPR bool is_constructible_v
3245     = is_constructible<_Tp, _Args...>::value;
3246 #endif
3247
3248 // is_default_constructible
3249
3250 template <class _Tp>
3251 struct _LIBCPP_TEMPLATE_VIS is_default_constructible
3252     : public is_constructible<_Tp>
3253     {};
3254
3255 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3256 template <class _Tp> _LIBCPP_CONSTEXPR bool is_default_constructible_v
3257     = is_default_constructible<_Tp>::value;
3258 #endif
3259
3260 // is_copy_constructible
3261
3262 template <class _Tp>
3263 struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
3264     : public is_constructible<_Tp, 
3265                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3266
3267 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3268 template <class _Tp> _LIBCPP_CONSTEXPR bool is_copy_constructible_v
3269     = is_copy_constructible<_Tp>::value;
3270 #endif
3271
3272 // is_move_constructible
3273
3274 template <class _Tp>
3275 struct _LIBCPP_TEMPLATE_VIS is_move_constructible
3276 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3277     : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3278 #else
3279     : public is_copy_constructible<_Tp>
3280 #endif
3281     {};
3282
3283 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3284 template <class _Tp> _LIBCPP_CONSTEXPR bool is_move_constructible_v
3285     = is_move_constructible<_Tp>::value;
3286 #endif
3287
3288 // is_trivially_constructible
3289
3290 #ifndef _LIBCPP_HAS_NO_VARIADICS
3291
3292 #if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501
3293
3294 template <class _Tp, class... _Args>
3295 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
3296     : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
3297 {
3298 };
3299
3300 #else  // !__has_feature(is_trivially_constructible)
3301
3302 template <class _Tp, class... _Args>
3303 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
3304     : false_type
3305 {
3306 };
3307
3308 template <class _Tp>
3309 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp>
3310 #if __has_feature(has_trivial_constructor) || (_GNUC_VER >= 403)
3311     : integral_constant<bool, __has_trivial_constructor(_Tp)>
3312 #else
3313     : integral_constant<bool, is_scalar<_Tp>::value>
3314 #endif
3315 {
3316 };
3317
3318 template <class _Tp>
3319 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3320 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&>
3321 #else
3322 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp>
3323 #endif
3324     : integral_constant<bool, is_scalar<_Tp>::value>
3325 {
3326 };
3327
3328 template <class _Tp>
3329 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&>
3330     : integral_constant<bool, is_scalar<_Tp>::value>
3331 {
3332 };
3333
3334 template <class _Tp>
3335 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&>
3336     : integral_constant<bool, is_scalar<_Tp>::value>
3337 {
3338 };
3339
3340 #endif  // !__has_feature(is_trivially_constructible)
3341
3342 #else  // _LIBCPP_HAS_NO_VARIADICS
3343
3344 template <class _Tp, class _A0 = __is_construct::__nat,
3345                      class _A1 = __is_construct::__nat>
3346 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
3347     : false_type
3348 {
3349 };
3350
3351 #if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501
3352
3353 template <class _Tp>
3354 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, __is_construct::__nat,
3355                                                        __is_construct::__nat>
3356     : integral_constant<bool, __is_trivially_constructible(_Tp)>
3357 {
3358 };
3359
3360 template <class _Tp>
3361 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp,
3362                                                        __is_construct::__nat>
3363     : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)>
3364 {
3365 };
3366
3367 template <class _Tp>
3368 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&,
3369                                                        __is_construct::__nat>
3370     : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)>
3371 {
3372 };
3373
3374 template <class _Tp>
3375 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&,
3376                                                        __is_construct::__nat>
3377     : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)>
3378 {
3379 };
3380
3381 #else  // !__has_feature(is_trivially_constructible)
3382
3383 template <class _Tp>
3384 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, __is_construct::__nat,
3385                                                        __is_construct::__nat>
3386     : integral_constant<bool, is_scalar<_Tp>::value>
3387 {
3388 };
3389
3390 template <class _Tp>
3391 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp,
3392                                                        __is_construct::__nat>
3393     : integral_constant<bool, is_scalar<_Tp>::value>
3394 {
3395 };
3396
3397 template <class _Tp>
3398 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&,
3399                                                        __is_construct::__nat>
3400     : integral_constant<bool, is_scalar<_Tp>::value>
3401 {
3402 };
3403
3404 template <class _Tp>
3405 struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&,
3406                                                        __is_construct::__nat>
3407     : integral_constant<bool, is_scalar<_Tp>::value>
3408 {
3409 };
3410
3411 #endif  // !__has_feature(is_trivially_constructible)
3412
3413 #endif  // _LIBCPP_HAS_NO_VARIADICS
3414
3415 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
3416 template <class _Tp, class... _Args> _LIBCPP_CONSTEXPR bool is_trivially_constructible_v
3417     = is_trivially_constructible<_Tp, _Args...>::value;
3418 #endif
3419
3420 // is_trivially_default_constructible
3421
3422 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
3423     : public is_trivially_constructible<_Tp>
3424     {};
3425
3426 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3427 template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v
3428     = is_trivially_default_constructible<_Tp>::value;
3429 #endif
3430
3431 // is_trivially_copy_constructible
3432
3433 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
3434     : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
3435     {};
3436
3437 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3438 template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v
3439     = is_trivially_copy_constructible<_Tp>::value;
3440 #endif
3441
3442 // is_trivially_move_constructible
3443
3444 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
3445 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3446     : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3447 #else
3448     : public is_trivially_copy_constructible<_Tp>
3449 #endif
3450     {};
3451
3452 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3453 template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v
3454     = is_trivially_move_constructible<_Tp>::value;
3455 #endif
3456
3457 // is_trivially_assignable
3458
3459 #if __has_feature(is_trivially_assignable) || _GNUC_VER >= 501
3460
3461 template <class _Tp, class _Arg>
3462 struct is_trivially_assignable
3463     : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
3464 {
3465 };
3466
3467 #else  // !__has_feature(is_trivially_assignable)
3468
3469 template <class _Tp, class _Arg>
3470 struct is_trivially_assignable
3471     : public false_type {};
3472
3473 template <class _Tp>
3474 struct is_trivially_assignable<_Tp&, _Tp>
3475     : integral_constant<bool, is_scalar<_Tp>::value> {};
3476
3477 template <class _Tp>
3478 struct is_trivially_assignable<_Tp&, _Tp&>
3479     : integral_constant<bool, is_scalar<_Tp>::value> {};
3480
3481 template <class _Tp>
3482 struct is_trivially_assignable<_Tp&, const _Tp&>
3483     : integral_constant<bool, is_scalar<_Tp>::value> {};
3484
3485 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3486
3487 template <class _Tp>
3488 struct is_trivially_assignable<_Tp&, _Tp&&>
3489     : integral_constant<bool, is_scalar<_Tp>::value> {};
3490
3491 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3492
3493 #endif  // !__has_feature(is_trivially_assignable)
3494
3495 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3496 template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_trivially_assignable_v
3497     = is_trivially_assignable<_Tp, _Arg>::value;
3498 #endif
3499
3500 // is_trivially_copy_assignable
3501
3502 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
3503     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
3504                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3505
3506 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3507 template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v
3508     = is_trivially_copy_assignable<_Tp>::value;
3509 #endif
3510
3511 // is_trivially_move_assignable
3512
3513 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
3514     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
3515 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3516                                      typename add_rvalue_reference<_Tp>::type>
3517 #else
3518                                      typename add_lvalue_reference<_Tp>::type>
3519 #endif
3520     {};
3521
3522 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3523 template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v
3524     = is_trivially_move_assignable<_Tp>::value;
3525 #endif
3526
3527 // is_trivially_destructible
3528
3529 #if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403)
3530
3531 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3532     : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
3533
3534 #else
3535
3536 template <class _Tp> struct __libcpp_trivial_destructor
3537     : public integral_constant<bool, is_scalar<_Tp>::value ||
3538                                      is_reference<_Tp>::value> {};
3539
3540 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3541     : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
3542
3543 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]>
3544     : public false_type {};
3545
3546 #endif
3547
3548 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3549 template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_destructible_v
3550     = is_trivially_destructible<_Tp>::value;
3551 #endif
3552
3553 // is_nothrow_constructible
3554
3555 #if 0
3556 template <class _Tp, class... _Args>
3557 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3558     : public integral_constant<bool, __is_nothrow_constructible(_Tp(_Args...))>
3559 {
3560 };
3561
3562 #else
3563
3564 #ifndef _LIBCPP_HAS_NO_VARIADICS
3565
3566 #if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
3567
3568 template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
3569
3570 template <class _Tp, class... _Args>
3571 struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
3572     : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
3573 {
3574 };
3575
3576 template <class _Tp>
3577 void __implicit_conversion_to(_Tp) noexcept { }
3578
3579 template <class _Tp, class _Arg>
3580 struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
3581     : public integral_constant<bool, noexcept(__implicit_conversion_to<_Tp>(declval<_Arg>()))>
3582 {
3583 };
3584
3585 template <class _Tp, bool _IsReference, class... _Args>
3586 struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
3587     : public false_type
3588 {
3589 };
3590
3591 template <class _Tp, class... _Args>
3592 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3593     : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
3594 {
3595 };
3596
3597 template <class _Tp, size_t _Ns>
3598 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
3599     : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
3600 {
3601 };
3602
3603 #else  // __has_feature(cxx_noexcept)
3604
3605 template <class _Tp, class... _Args>
3606 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3607     : false_type
3608 {
3609 };
3610
3611 template <class _Tp>
3612 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp>
3613 #if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403)
3614     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
3615 #else
3616     : integral_constant<bool, is_scalar<_Tp>::value>
3617 #endif
3618 {
3619 };
3620
3621 template <class _Tp>
3622 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3623 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&&>
3624 #else
3625 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp>
3626 #endif
3627 #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3628     : integral_constant<bool, __has_nothrow_copy(_Tp)>
3629 #else
3630     : integral_constant<bool, is_scalar<_Tp>::value>
3631 #endif
3632 {
3633 };
3634
3635 template <class _Tp>
3636 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, const _Tp&>
3637 #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3638     : integral_constant<bool, __has_nothrow_copy(_Tp)>
3639 #else
3640     : integral_constant<bool, is_scalar<_Tp>::value>
3641 #endif
3642 {
3643 };
3644
3645 template <class _Tp>
3646 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&>
3647 #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3648     : integral_constant<bool, __has_nothrow_copy(_Tp)>
3649 #else
3650     : integral_constant<bool, is_scalar<_Tp>::value>
3651 #endif
3652 {
3653 };
3654
3655 #endif  // __has_feature(cxx_noexcept)
3656
3657 #else  // _LIBCPP_HAS_NO_VARIADICS
3658
3659 template <class _Tp, class _A0 = __is_construct::__nat,
3660                      class _A1 = __is_construct::__nat>
3661 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3662     : false_type
3663 {
3664 };
3665
3666 template <class _Tp>
3667 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, __is_construct::__nat,
3668                                                        __is_construct::__nat>
3669 #if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403)
3670     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
3671 #else
3672     : integral_constant<bool, is_scalar<_Tp>::value>
3673 #endif
3674 {
3675 };
3676
3677 template <class _Tp>
3678 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp,
3679                                                        __is_construct::__nat>
3680 #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3681     : integral_constant<bool, __has_nothrow_copy(_Tp)>
3682 #else
3683     : integral_constant<bool, is_scalar<_Tp>::value>
3684 #endif
3685 {
3686 };
3687
3688 template <class _Tp>
3689 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, const _Tp&,
3690                                                        __is_construct::__nat>
3691 #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3692     : integral_constant<bool, __has_nothrow_copy(_Tp)>
3693 #else
3694     : integral_constant<bool, is_scalar<_Tp>::value>
3695 #endif
3696 {
3697 };
3698
3699 template <class _Tp>
3700 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&,
3701                                                        __is_construct::__nat>
3702 #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3703     : integral_constant<bool, __has_nothrow_copy(_Tp)>
3704 #else
3705     : integral_constant<bool, is_scalar<_Tp>::value>
3706 #endif
3707 {
3708 };
3709
3710 #endif  // _LIBCPP_HAS_NO_VARIADICS
3711 #endif  // __has_feature(is_nothrow_constructible)
3712
3713 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
3714 template <class _Tp, class ..._Args> _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v
3715     = is_nothrow_constructible<_Tp, _Args...>::value;
3716 #endif
3717
3718 // is_nothrow_default_constructible
3719
3720 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
3721     : public is_nothrow_constructible<_Tp>
3722     {};
3723
3724 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3725 template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v
3726     = is_nothrow_default_constructible<_Tp>::value;
3727 #endif
3728
3729 // is_nothrow_copy_constructible
3730
3731 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
3732     : public is_nothrow_constructible<_Tp,
3733                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3734
3735 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3736 template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v
3737     = is_nothrow_copy_constructible<_Tp>::value;
3738 #endif
3739
3740 // is_nothrow_move_constructible
3741
3742 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
3743 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3744     : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3745 #else
3746     : public is_nothrow_copy_constructible<_Tp>
3747 #endif
3748     {};
3749
3750 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3751 template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v
3752     = is_nothrow_move_constructible<_Tp>::value;
3753 #endif
3754
3755 // is_nothrow_assignable
3756
3757 #if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
3758
3759 template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
3760
3761 template <class _Tp, class _Arg>
3762 struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
3763     : public false_type
3764 {
3765 };
3766
3767 template <class _Tp, class _Arg>
3768 struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
3769     : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>()) >
3770 {
3771 };
3772
3773 template <class _Tp, class _Arg>
3774 struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
3775     : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
3776 {
3777 };
3778
3779 #else  // __has_feature(cxx_noexcept)
3780
3781 template <class _Tp, class _Arg>
3782 struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
3783     : public false_type {};
3784
3785 template <class _Tp>
3786 struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, _Tp>
3787 #if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
3788     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
3789 #else
3790     : integral_constant<bool, is_scalar<_Tp>::value> {};
3791 #endif
3792
3793 template <class _Tp>
3794 struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, _Tp&>
3795 #if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
3796     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
3797 #else
3798     : integral_constant<bool, is_scalar<_Tp>::value> {};
3799 #endif
3800
3801 template <class _Tp>
3802 struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, const _Tp&>
3803 #if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
3804     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
3805 #else
3806     : integral_constant<bool, is_scalar<_Tp>::value> {};
3807 #endif
3808
3809 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3810
3811 template <class _Tp>
3812 struct is_nothrow_assignable<_Tp&, _Tp&&>
3813 #if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
3814     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
3815 #else
3816     : integral_constant<bool, is_scalar<_Tp>::value> {};
3817 #endif
3818
3819 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3820
3821 #endif  // __has_feature(cxx_noexcept)
3822
3823 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3824 template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v
3825     = is_nothrow_assignable<_Tp, _Arg>::value;
3826 #endif
3827
3828 // is_nothrow_copy_assignable
3829
3830 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
3831     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3832                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3833
3834 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3835 template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v
3836     = is_nothrow_copy_assignable<_Tp>::value;
3837 #endif
3838
3839 // is_nothrow_move_assignable
3840
3841 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
3842     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3843 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3844                                      typename add_rvalue_reference<_Tp>::type>
3845 #else
3846                                      typename add_lvalue_reference<_Tp>::type>
3847 #endif
3848     {};
3849
3850 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3851 template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v
3852     = is_nothrow_move_assignable<_Tp>::value;
3853 #endif
3854
3855 // is_nothrow_destructible
3856
3857 #if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
3858
3859 template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
3860
3861 template <class _Tp>
3862 struct __libcpp_is_nothrow_destructible<false, _Tp>
3863     : public false_type
3864 {
3865 };
3866
3867 template <class _Tp>
3868 struct __libcpp_is_nothrow_destructible<true, _Tp>
3869     : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>().~_Tp()) >
3870 {
3871 };
3872
3873 template <class _Tp>
3874 struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
3875     : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
3876 {
3877 };
3878
3879 template <class _Tp, size_t _Ns>
3880 struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
3881     : public is_nothrow_destructible<_Tp>
3882 {
3883 };
3884
3885 template <class _Tp>
3886 struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
3887     : public true_type
3888 {
3889 };
3890
3891 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3892
3893 template <class _Tp>
3894 struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
3895     : public true_type
3896 {
3897 };
3898
3899 #endif
3900
3901 #else
3902
3903 template <class _Tp> struct __libcpp_nothrow_destructor
3904     : public integral_constant<bool, is_scalar<_Tp>::value ||
3905                                      is_reference<_Tp>::value> {};
3906
3907 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
3908     : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
3909
3910 template <class _Tp>
3911 struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
3912     : public false_type {};
3913
3914 #endif
3915
3916 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3917 template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v
3918     = is_nothrow_destructible<_Tp>::value;
3919 #endif
3920
3921 // is_pod
3922
3923 #if __has_feature(is_pod) || (_GNUC_VER >= 403)
3924
3925 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
3926     : public integral_constant<bool, __is_pod(_Tp)> {};
3927
3928 #else
3929
3930 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
3931     : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
3932                                      is_trivially_copy_constructible<_Tp>::value      &&
3933                                      is_trivially_copy_assignable<_Tp>::value    &&
3934                                      is_trivially_destructible<_Tp>::value> {};
3935
3936 #endif
3937
3938 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3939 template <class _Tp> _LIBCPP_CONSTEXPR bool is_pod_v
3940     = is_pod<_Tp>::value;
3941 #endif
3942
3943 // is_literal_type;
3944
3945 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_literal_type
3946 #ifdef _LIBCPP_IS_LITERAL
3947     : public integral_constant<bool, _LIBCPP_IS_LITERAL(_Tp)>
3948 #else
3949     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value ||
3950                               is_reference<typename remove_all_extents<_Tp>::type>::value>
3951 #endif
3952     {};
3953     
3954 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3955 template <class _Tp> _LIBCPP_CONSTEXPR bool is_literal_type_v
3956     = is_literal_type<_Tp>::value;
3957 #endif
3958
3959 // is_standard_layout;
3960
3961 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
3962 #if __has_feature(is_standard_layout) || (_GNUC_VER >= 407)
3963     : public integral_constant<bool, __is_standard_layout(_Tp)>
3964 #else
3965     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3966 #endif
3967     {};
3968     
3969 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3970 template <class _Tp> _LIBCPP_CONSTEXPR bool is_standard_layout_v
3971     = is_standard_layout<_Tp>::value;
3972 #endif
3973
3974 // is_trivially_copyable;
3975
3976 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
3977 #if __has_feature(is_trivially_copyable)
3978     : public integral_constant<bool, __is_trivially_copyable(_Tp)>
3979 #elif _GNUC_VER >= 501
3980     : public integral_constant<bool, !is_volatile<_Tp>::value && __is_trivially_copyable(_Tp)>
3981 #else
3982     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3983 #endif
3984     {};
3985     
3986 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3987 template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copyable_v
3988     = is_trivially_copyable<_Tp>::value;
3989 #endif
3990
3991 // is_trivial;
3992
3993 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
3994 #if __has_feature(is_trivial) || _GNUC_VER >= 407
3995     : public integral_constant<bool, __is_trivial(_Tp)>
3996 #else
3997     : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
3998                                  is_trivially_default_constructible<_Tp>::value>
3999 #endif
4000     {};
4001
4002 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
4003 template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivial_v
4004     = is_trivial<_Tp>::value;
4005 #endif
4006
4007 template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
4008 template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
4009 template <class _Tp> struct __is_reference_wrapper
4010     : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
4011
4012 #ifndef _LIBCPP_CXX03_LANG
4013
4014 // Check for complete types
4015
4016 template <class ..._Tp> struct __check_complete;
4017
4018 template <>
4019 struct __check_complete<>
4020 {
4021 };
4022
4023 template <class _Hp, class _T0, class ..._Tp>
4024 struct __check_complete<_Hp, _T0, _Tp...>
4025     : private __check_complete<_Hp>,
4026       private __check_complete<_T0, _Tp...>
4027 {
4028 };
4029
4030 template <class _Hp>
4031 struct __check_complete<_Hp, _Hp>
4032     : private __check_complete<_Hp>
4033 {
4034 };
4035
4036 template <class _Tp>
4037 struct __check_complete<_Tp>
4038 {
4039     static_assert(sizeof(_Tp) > 0, "Type must be complete.");
4040 };
4041
4042 template <class _Tp>
4043 struct __check_complete<_Tp&>
4044     : private __check_complete<_Tp>
4045 {
4046 };
4047
4048 template <class _Tp>
4049 struct __check_complete<_Tp&&>
4050     : private __check_complete<_Tp>
4051 {
4052 };
4053
4054 template <class _Rp, class ..._Param>
4055 struct __check_complete<_Rp (*)(_Param...)>
4056     : private __check_complete<_Rp>
4057 {
4058 };
4059
4060 template <class ..._Param>
4061 struct __check_complete<void (*)(_Param...)>
4062 {
4063 };
4064
4065 template <class _Rp, class ..._Param>
4066 struct __check_complete<_Rp (_Param...)>
4067     : private __check_complete<_Rp>
4068 {
4069 };
4070
4071 template <class ..._Param>
4072 struct __check_complete<void (_Param...)>
4073 {
4074 };
4075
4076 template <class _Rp, class _Class, class ..._Param>
4077 struct __check_complete<_Rp (_Class::*)(_Param...)>
4078     : private __check_complete<_Class>
4079 {
4080 };
4081
4082 template <class _Rp, class _Class, class ..._Param>
4083 struct __check_complete<_Rp (_Class::*)(_Param...) const>
4084     : private __check_complete<_Class>
4085 {
4086 };
4087
4088 template <class _Rp, class _Class, class ..._Param>
4089 struct __check_complete<_Rp (_Class::*)(_Param...) volatile>
4090     : private __check_complete<_Class>
4091 {
4092 };
4093
4094 template <class _Rp, class _Class, class ..._Param>
4095 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile>
4096     : private __check_complete<_Class>
4097 {
4098 };
4099
4100 template <class _Rp, class _Class, class ..._Param>
4101 struct __check_complete<_Rp (_Class::*)(_Param...) &>
4102     : private __check_complete<_Class>
4103 {
4104 };
4105
4106 template <class _Rp, class _Class, class ..._Param>
4107 struct __check_complete<_Rp (_Class::*)(_Param...) const&>
4108     : private __check_complete<_Class>
4109 {
4110 };
4111
4112 template <class _Rp, class _Class, class ..._Param>
4113 struct __check_complete<_Rp (_Class::*)(_Param...) volatile&>
4114     : private __check_complete<_Class>
4115 {
4116 };
4117
4118 template <class _Rp, class _Class, class ..._Param>
4119 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&>
4120     : private __check_complete<_Class>
4121 {
4122 };
4123
4124 template <class _Rp, class _Class, class ..._Param>
4125 struct __check_complete<_Rp (_Class::*)(_Param...) &&>
4126     : private __check_complete<_Class>
4127 {
4128 };
4129
4130 template <class _Rp, class _Class, class ..._Param>
4131 struct __check_complete<_Rp (_Class::*)(_Param...) const&&>
4132     : private __check_complete<_Class>
4133 {
4134 };
4135
4136 template <class _Rp, class _Class, class ..._Param>
4137 struct __check_complete<_Rp (_Class::*)(_Param...) volatile&&>
4138     : private __check_complete<_Class>
4139 {
4140 };
4141
4142 template <class _Rp, class _Class, class ..._Param>
4143 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&&>
4144     : private __check_complete<_Class>
4145 {
4146 };
4147
4148 template <class _Rp, class _Class>
4149 struct __check_complete<_Rp _Class::*>
4150     : private __check_complete<_Class>
4151 {
4152 };
4153
4154
4155 template <class _Fp, class _A0,
4156          class _DecayFp = typename decay<_Fp>::type,
4157          class _DecayA0 = typename decay<_A0>::type,
4158          class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
4159 using __enable_if_bullet1 = typename enable_if
4160     <
4161         is_member_function_pointer<_DecayFp>::value
4162         && is_base_of<_ClassT, _DecayA0>::value
4163     >::type;
4164
4165 template <class _Fp, class _A0,
4166          class _DecayFp = typename decay<_Fp>::type,
4167          class _DecayA0 = typename decay<_A0>::type>
4168 using __enable_if_bullet2 = typename enable_if
4169     <
4170         is_member_function_pointer<_DecayFp>::value
4171         && __is_reference_wrapper<_DecayA0>::value
4172     >::type;
4173
4174 template <class _Fp, class _A0,
4175          class _DecayFp = typename decay<_Fp>::type,
4176          class _DecayA0 = typename decay<_A0>::type,
4177          class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
4178 using __enable_if_bullet3 = typename enable_if
4179     <
4180         is_member_function_pointer<_DecayFp>::value
4181         && !is_base_of<_ClassT, _DecayA0>::value
4182         && !__is_reference_wrapper<_DecayA0>::value
4183     >::type;
4184
4185 template <class _Fp, class _A0,
4186          class _DecayFp = typename decay<_Fp>::type,
4187          class _DecayA0 = typename decay<_A0>::type,
4188          class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
4189 using __enable_if_bullet4 = typename enable_if
4190     <
4191         is_member_object_pointer<_DecayFp>::value
4192         && is_base_of<_ClassT, _DecayA0>::value
4193     >::type;
4194
4195 template <class _Fp, class _A0,
4196          class _DecayFp = typename decay<_Fp>::type,
4197          class _DecayA0 = typename decay<_A0>::type>
4198 using __enable_if_bullet5 = typename enable_if
4199     <
4200         is_member_object_pointer<_DecayFp>::value
4201         && __is_reference_wrapper<_DecayA0>::value
4202     >::type;
4203
4204 template <class _Fp, class _A0,
4205          class _DecayFp = typename decay<_Fp>::type,
4206          class _DecayA0 = typename decay<_A0>::type,
4207          class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
4208 using __enable_if_bullet6 = typename enable_if
4209     <
4210         is_member_object_pointer<_DecayFp>::value
4211         && !is_base_of<_ClassT, _DecayA0>::value
4212         && !__is_reference_wrapper<_DecayA0>::value
4213     >::type;
4214
4215 // __invoke forward declarations
4216
4217 // fall back - none of the bullets
4218
4219 #define _LIBCPP_INVOKE_RETURN(...) \
4220     noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \
4221     { return __VA_ARGS__; }
4222
4223 template <class ..._Args>
4224 auto __invoke(__any, _Args&& ...__args) -> __nat;
4225
4226 template <class ..._Args>
4227 auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
4228
4229 // bullets 1, 2 and 3
4230
4231 template <class _Fp, class _A0, class ..._Args,
4232           class = __enable_if_bullet1<_Fp, _A0>>
4233 inline _LIBCPP_INLINE_VISIBILITY
4234 auto
4235 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
4236 _LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
4237
4238 template <class _Fp, class _A0, class ..._Args,
4239           class = __enable_if_bullet1<_Fp, _A0>>
4240 inline _LIBCPP_INLINE_VISIBILITY
4241 _LIBCPP_CONSTEXPR auto
4242 __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
4243 _LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
4244
4245 template <class _Fp, class _A0, class ..._Args,
4246           class = __enable_if_bullet2<_Fp, _A0>>
4247 inline _LIBCPP_INLINE_VISIBILITY
4248 auto
4249 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
4250 _LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...))
4251
4252 template <class _Fp, class _A0, class ..._Args,
4253           class = __enable_if_bullet2<_Fp, _A0>>
4254 inline _LIBCPP_INLINE_VISIBILITY
4255 _LIBCPP_CONSTEXPR auto
4256 __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
4257 _LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...))
4258
4259 template <class _Fp, class _A0, class ..._Args,
4260           class = __enable_if_bullet3<_Fp, _A0>>
4261 inline _LIBCPP_INLINE_VISIBILITY
4262 auto
4263 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
4264 _LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
4265
4266 template <class _Fp, class _A0, class ..._Args,
4267           class = __enable_if_bullet3<_Fp, _A0>>
4268 inline _LIBCPP_INLINE_VISIBILITY
4269 _LIBCPP_CONSTEXPR auto
4270 __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
4271 _LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
4272
4273 // bullets 4, 5 and 6
4274
4275 template <class _Fp, class _A0,
4276           class = __enable_if_bullet4<_Fp, _A0>>
4277 inline _LIBCPP_INLINE_VISIBILITY
4278 auto
4279 __invoke(_Fp&& __f, _A0&& __a0)
4280 _LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f)
4281
4282 template <class _Fp, class _A0,
4283           class = __enable_if_bullet4<_Fp, _A0>>
4284 inline _LIBCPP_INLINE_VISIBILITY
4285 _LIBCPP_CONSTEXPR auto
4286 __invoke_constexpr(_Fp&& __f, _A0&& __a0)
4287 _LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f)
4288
4289 template <class _Fp, class _A0,
4290           class = __enable_if_bullet5<_Fp, _A0>>
4291 inline _LIBCPP_INLINE_VISIBILITY
4292 auto
4293 __invoke(_Fp&& __f, _A0&& __a0)
4294 _LIBCPP_INVOKE_RETURN(__a0.get().*__f)
4295
4296 template <class _Fp, class _A0,
4297           class = __enable_if_bullet5<_Fp, _A0>>
4298 inline _LIBCPP_INLINE_VISIBILITY
4299 _LIBCPP_CONSTEXPR auto
4300 __invoke_constexpr(_Fp&& __f, _A0&& __a0)
4301 _LIBCPP_INVOKE_RETURN(__a0.get().*__f)
4302
4303 template <class _Fp, class _A0,
4304           class = __enable_if_bullet6<_Fp, _A0>>
4305 inline _LIBCPP_INLINE_VISIBILITY
4306 auto
4307 __invoke(_Fp&& __f, _A0&& __a0)
4308 _LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f)
4309
4310 template <class _Fp, class _A0,
4311           class = __enable_if_bullet6<_Fp, _A0>>
4312 inline _LIBCPP_INLINE_VISIBILITY
4313 _LIBCPP_CONSTEXPR auto
4314 __invoke_constexpr(_Fp&& __f, _A0&& __a0)
4315 _LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f)
4316
4317 // bullet 7
4318
4319 template <class _Fp, class ..._Args>
4320 inline _LIBCPP_INLINE_VISIBILITY
4321 auto
4322 __invoke(_Fp&& __f, _Args&& ...__args)
4323 _LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
4324
4325 template <class _Fp, class ..._Args>
4326 inline _LIBCPP_INLINE_VISIBILITY
4327 _LIBCPP_CONSTEXPR auto
4328 __invoke_constexpr(_Fp&& __f, _Args&& ...__args)
4329 _LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
4330
4331 #undef _LIBCPP_INVOKE_RETURN
4332
4333 // __invokable
4334
4335 template <class _Ret, class _Fp, class ..._Args>
4336 struct __invokable_r
4337     : private __check_complete<_Fp>
4338 {
4339     using _Result = decltype(
4340         _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
4341
4342     static const bool value =
4343         conditional<
4344             !is_same<_Result, __nat>::value,
4345             typename conditional<
4346                 is_void<_Ret>::value,
4347                 true_type,
4348                 is_convertible<_Result, _Ret>
4349             >::type,
4350             false_type
4351         >::type::value;
4352 };
4353
4354 template <class _Fp, class ..._Args>
4355 using __invokable = __invokable_r<void, _Fp, _Args...>;
4356
4357 template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
4358 struct __nothrow_invokable_r_imp {
4359   static const bool value = false;
4360 };
4361
4362 template <class _Ret, class _Fp, class ..._Args>
4363 struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
4364 {
4365     typedef __nothrow_invokable_r_imp _ThisT;
4366
4367     template <class _Tp>
4368     static void __test_noexcept(_Tp) noexcept;
4369
4370     static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
4371         _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)));
4372 };
4373
4374 template <class _Ret, class _Fp, class ..._Args>
4375 struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
4376 {
4377     static const bool value = noexcept(
4378         _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
4379 };
4380
4381 template <class _Ret, class _Fp, class ..._Args>
4382 using __nothrow_invokable_r =
4383     __nothrow_invokable_r_imp<
4384             __invokable_r<_Ret, _Fp, _Args...>::value,
4385             is_void<_Ret>::value,
4386             _Ret, _Fp, _Args...
4387     >;
4388
4389 template <class _Fp, class ..._Args>
4390 struct __invoke_of
4391     : public enable_if<
4392         __invokable<_Fp, _Args...>::value,
4393         typename __invokable_r<void, _Fp, _Args...>::_Result>
4394 {
4395 };
4396
4397 // result_of
4398
4399 template <class _Fp, class ..._Args>
4400 class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)>
4401     : public __invoke_of<_Fp, _Args...>
4402 {
4403 };
4404
4405 #if _LIBCPP_STD_VER > 11
4406 template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
4407 #endif
4408
4409 #if _LIBCPP_STD_VER > 14
4410
4411 // is_callable
4412
4413 template <class _Fn, class _Ret = void>
4414 struct _LIBCPP_TEMPLATE_VIS is_callable;
4415
4416 template <class _Fn, class ..._Args, class _Ret>
4417 struct _LIBCPP_TEMPLATE_VIS is_callable<_Fn(_Args...), _Ret>
4418     : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
4419
4420 template <class _Fn, class _Ret = void>
4421 constexpr bool is_callable_v = is_callable<_Fn, _Ret>::value;
4422
4423 // is_nothrow_callable
4424
4425 template <class _Fn, class _Ret = void>
4426 struct _LIBCPP_TEMPLATE_VIS is_nothrow_callable;
4427
4428 template <class _Fn, class ..._Args, class _Ret>
4429 struct _LIBCPP_TEMPLATE_VIS is_nothrow_callable<_Fn(_Args...), _Ret>
4430     : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value>
4431 {};
4432
4433 template <class _Fn, class _Ret = void>
4434 constexpr bool is_nothrow_callable_v = is_nothrow_callable<_Fn, _Ret>::value;
4435
4436 #endif // _LIBCPP_STD_VER > 14
4437
4438 #endif  // !defined(_LIBCPP_CXX03_LANG)
4439
4440 template <class _Tp> struct __is_swappable;
4441 template <class _Tp> struct __is_nothrow_swappable;
4442
4443 template <class _Tp>
4444 inline _LIBCPP_INLINE_VISIBILITY
4445 #ifndef _LIBCPP_CXX03_LANG
4446 typename enable_if
4447 <
4448     is_move_constructible<_Tp>::value &&
4449     is_move_assignable<_Tp>::value
4450 >::type
4451 #else
4452 void
4453 #endif
4454 swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
4455                                     is_nothrow_move_assignable<_Tp>::value)
4456 {
4457     _Tp __t(_VSTD::move(__x));
4458     __x = _VSTD::move(__y);
4459     __y = _VSTD::move(__t);
4460 }
4461
4462 template<class _Tp, size_t _Np>
4463 inline _LIBCPP_INLINE_VISIBILITY
4464 typename enable_if<
4465     __is_swappable<_Tp>::value
4466 >::type
4467 swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
4468
4469 template <class _ForwardIterator1, class _ForwardIterator2>
4470 inline _LIBCPP_INLINE_VISIBILITY
4471 void
4472 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
4473     //                                  _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
4474                _NOEXCEPT_(_NOEXCEPT_(swap(*_VSTD::declval<_ForwardIterator1>(),
4475                                           *_VSTD::declval<_ForwardIterator2>())))
4476 {
4477     swap(*__a, *__b);
4478 }
4479
4480 // __swappable
4481
4482 namespace __detail
4483 {
4484 // ALL generic swap overloads MUST already have a declaration available at this point.
4485
4486 template <class _Tp, class _Up = _Tp,
4487           bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value>
4488 struct __swappable_with
4489 {
4490     template <class _LHS, class _RHS>
4491     static decltype(swap(_VSTD::declval<_LHS>(), _VSTD::declval<_RHS>()))
4492     __test_swap(int);
4493     template <class, class>
4494     static __nat __test_swap(long);
4495
4496     // Extra parens are needed for the C++03 definition of decltype.
4497     typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1;
4498     typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2;
4499
4500     static const bool value = !is_same<__swap1, __nat>::value
4501                            && !is_same<__swap2, __nat>::value;
4502 };
4503
4504 template <class _Tp, class _Up>
4505 struct __swappable_with<_Tp, _Up,  false> : false_type {};
4506
4507 template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value>
4508 struct __nothrow_swappable_with {
4509   static const bool value =
4510 #ifndef _LIBCPP_HAS_NO_NOEXCEPT
4511       noexcept(swap(_VSTD::declval<_Tp>(), _VSTD::declval<_Up>()))
4512   &&  noexcept(swap(_VSTD::declval<_Up>(), _VSTD::declval<_Tp>()));
4513 #else
4514       false;
4515 #endif
4516 };
4517
4518 template <class _Tp, class _Up>
4519 struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
4520
4521 }  // __detail
4522
4523 template <class _Tp>
4524 struct __is_swappable
4525     : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value>
4526 {
4527 };
4528
4529 template <class _Tp>
4530 struct __is_nothrow_swappable
4531     : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value>
4532 {
4533 };
4534
4535 #if _LIBCPP_STD_VER > 14
4536
4537 template <class _Tp, class _Up>
4538 struct _LIBCPP_TEMPLATE_VIS is_swappable_with
4539     : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value>
4540 {
4541 };
4542
4543 template <class _Tp>
4544 struct _LIBCPP_TEMPLATE_VIS is_swappable
4545     : public conditional<
4546         __is_referenceable<_Tp>::value,
4547         is_swappable_with<
4548             typename add_lvalue_reference<_Tp>::type,
4549             typename add_lvalue_reference<_Tp>::type>,
4550         false_type
4551     >::type
4552 {
4553 };
4554
4555 template <class _Tp, class _Up>
4556 struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with
4557     : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value>
4558 {
4559 };
4560
4561 template <class _Tp>
4562 struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable
4563     : public conditional<
4564         __is_referenceable<_Tp>::value,
4565         is_nothrow_swappable_with<
4566             typename add_lvalue_reference<_Tp>::type,
4567             typename add_lvalue_reference<_Tp>::type>,
4568         false_type
4569     >::type
4570 {
4571 };
4572
4573 template <class _Tp, class _Up>
4574 constexpr bool is_swappable_with_v = is_swappable_with<_Tp, _Up>::value;
4575
4576 template <class _Tp>
4577 constexpr bool is_swappable_v = is_swappable<_Tp>::value;
4578
4579 template <class _Tp, class _Up>
4580 constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<_Tp, _Up>::value;
4581
4582 template <class _Tp>
4583 constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value;
4584
4585 #endif // _LIBCPP_STD_VER > 14
4586
4587 #ifdef _LIBCPP_UNDERLYING_TYPE
4588
4589 template <class _Tp>
4590 struct underlying_type
4591 {
4592     typedef _LIBCPP_UNDERLYING_TYPE(_Tp) type;
4593 };
4594
4595 #if _LIBCPP_STD_VER > 11
4596 template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
4597 #endif
4598
4599 #else  // _LIBCPP_UNDERLYING_TYPE
4600
4601 template <class _Tp, bool _Support = false>
4602 struct underlying_type
4603 {
4604     static_assert(_Support, "The underyling_type trait requires compiler "
4605                             "support. Either no such support exists or "
4606                             "libc++ does not know how to use it.");
4607 };
4608
4609 #endif // _LIBCPP_UNDERLYING_TYPE
4610
4611
4612 template <class _Tp, bool = is_enum<_Tp>::value>
4613 struct __sfinae_underlying_type
4614 {
4615     typedef typename underlying_type<_Tp>::type type;
4616     typedef decltype(((type)1) + 0) __promoted_type;
4617 };
4618
4619 template <class _Tp>
4620 struct __sfinae_underlying_type<_Tp, false> {};
4621
4622 inline _LIBCPP_INLINE_VISIBILITY
4623 int __convert_to_integral(int __val) { return __val; }
4624
4625 inline _LIBCPP_INLINE_VISIBILITY
4626 unsigned __convert_to_integral(unsigned __val) { return __val; }
4627
4628 inline _LIBCPP_INLINE_VISIBILITY
4629 long __convert_to_integral(long __val) { return __val; }
4630
4631 inline _LIBCPP_INLINE_VISIBILITY
4632 unsigned long __convert_to_integral(unsigned long __val) { return __val; }
4633
4634 inline _LIBCPP_INLINE_VISIBILITY
4635 long long __convert_to_integral(long long __val) { return __val; }
4636
4637 inline _LIBCPP_INLINE_VISIBILITY
4638 unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
4639
4640 #ifndef _LIBCPP_HAS_NO_INT128
4641 inline _LIBCPP_INLINE_VISIBILITY
4642 __int128_t __convert_to_integral(__int128_t __val) { return __val; }
4643
4644 inline _LIBCPP_INLINE_VISIBILITY
4645 __uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
4646 #endif
4647
4648 template <class _Tp>
4649 inline _LIBCPP_INLINE_VISIBILITY
4650 typename __sfinae_underlying_type<_Tp>::__promoted_type
4651 __convert_to_integral(_Tp __val) { return __val; }
4652
4653 #ifndef _LIBCPP_CXX03_LANG
4654
4655 template <class _Tp>
4656 struct __has_operator_addressof_member_imp
4657 {
4658     template <class _Up>
4659         static auto __test(int)
4660             -> typename __select_2nd<decltype(_VSTD::declval<_Up>().operator&()), true_type>::type;
4661     template <class>
4662         static auto __test(long) -> false_type;
4663
4664     static const bool value = decltype(__test<_Tp>(0))::value;
4665 };
4666
4667 template <class _Tp>
4668 struct __has_operator_addressof_free_imp
4669 {
4670     template <class _Up>
4671         static auto __test(int)
4672             -> typename __select_2nd<decltype(operator&(_VSTD::declval<_Up>())), true_type>::type;
4673     template <class>
4674         static auto __test(long) -> false_type;
4675
4676     static const bool value = decltype(__test<_Tp>(0))::value;
4677 };
4678
4679 template <class _Tp>
4680 struct __has_operator_addressof
4681     : public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
4682                                   || __has_operator_addressof_free_imp<_Tp>::value>
4683 {};
4684
4685 #endif  // _LIBCPP_CXX03_LANG
4686
4687 #if _LIBCPP_STD_VER > 14
4688
4689 #define __cpp_lib_void_t 201411
4690 template <class...> using void_t = void;
4691
4692 # ifndef _LIBCPP_HAS_NO_VARIADICS
4693 template <class... _Args>
4694 struct conjunction : __and_<_Args...> {};
4695 template<class... _Args> constexpr bool conjunction_v = conjunction<_Args...>::value;
4696
4697 template <class... _Args>
4698 struct disjunction : __or_<_Args...> {};
4699 template<class... _Args> constexpr bool disjunction_v = disjunction<_Args...>::value;
4700
4701 template <class _Tp>
4702 struct negation : __not_<_Tp> {};
4703 template<class _Tp> constexpr bool negation_v = negation<_Tp>::value;
4704 # endif // _LIBCPP_HAS_NO_VARIADICS
4705 #endif  // _LIBCPP_STD_VER > 14
4706
4707 // These traits are used in __tree and __hash_table
4708 #ifndef _LIBCPP_CXX03_LANG
4709 struct __extract_key_fail_tag {};
4710 struct __extract_key_self_tag {};
4711 struct __extract_key_first_tag {};
4712
4713 template <class _ValTy, class _Key,
4714           class _RawValTy = typename __unconstref<_ValTy>::type>
4715 struct __can_extract_key
4716     : conditional<is_same<_RawValTy, _Key>::value, __extract_key_self_tag,
4717                   __extract_key_fail_tag>::type {};
4718
4719 template <class _Pair, class _Key, class _First, class _Second>
4720 struct __can_extract_key<_Pair, _Key, pair<_First, _Second>>
4721     : conditional<is_same<typename remove_const<_First>::type, _Key>::value,
4722                   __extract_key_first_tag, __extract_key_fail_tag>::type {};
4723
4724 // __can_extract_map_key uses true_type/false_type instead of the tags.
4725 // It returns true if _Key != _ContainerValueTy (the container is a map not a set)
4726 // and _ValTy == _Key.
4727 template <class _ValTy, class _Key, class _ContainerValueTy,
4728           class _RawValTy = typename __unconstref<_ValTy>::type>
4729 struct __can_extract_map_key
4730     : integral_constant<bool, is_same<_RawValTy, _Key>::value> {};
4731
4732 // This specialization returns __extract_key_fail_tag for non-map containers
4733 // because _Key == _ContainerValueTy
4734 template <class _ValTy, class _Key, class _RawValTy>
4735 struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
4736     : false_type {};
4737
4738 #endif
4739
4740 _LIBCPP_END_NAMESPACE_STD
4741
4742 #if _LIBCPP_STD_VER > 14
4743 // std::byte
4744 namespace std  // purposefully not versioned
4745 {
4746 template <class _Integer>
4747   constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
4748   operator<<=(byte& __lhs, _Integer __shift) noexcept
4749   { return __lhs = byte(static_cast<unsigned char>(__lhs) << __shift); }
4750   
4751 template <class _Integer>
4752   constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
4753   operator<< (byte  __lhs, _Integer __shift) noexcept
4754   { return         byte(static_cast<unsigned char>(__lhs) << __shift); }
4755
4756 template <class _Integer>
4757   constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
4758   operator>>=(byte& __lhs, _Integer __shift) noexcept
4759   { return __lhs = byte(static_cast<unsigned char>(__lhs) >> __shift); }
4760
4761 template <class _Integer>
4762   constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
4763   operator>> (byte  __lhs, _Integer __shift) noexcept
4764   { return         byte(static_cast<unsigned char>(__lhs) >> __shift); }
4765   
4766 template <class _Integer>
4767   constexpr typename enable_if<is_integral_v<_Integer>, _Integer>::type
4768   to_integer(byte __b) noexcept { return _Integer(__b); }
4769
4770 }
4771 #endif
4772
4773 #endif  // _LIBCPP_TYPE_TRAITS