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