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