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