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