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