1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
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_scoped_enum; // C++2b
55    template <class T> struct is_scalar;
56    template <class T> struct is_object;
57    template <class T> struct is_compound;
58
59    // Const-volatile properties and transformations:
60    template <class T> struct is_const;
61    template <class T> struct is_volatile;
62    template <class T> struct remove_const;
63    template <class T> struct remove_volatile;
64    template <class T> struct remove_cv;
65    template <class T> struct add_const;
66    template <class T> struct add_volatile;
67    template <class T> struct add_cv;
68
69    // Reference transformations:
70    template <class T> struct remove_reference;
71    template <class T> struct add_lvalue_reference;
72    template <class T> struct add_rvalue_reference;
73
74    // Pointer transformations:
75    template <class T> struct remove_pointer;
76    template <class T> struct add_pointer;
77
78    template<class T> struct type_identity;                     // C++20
79    template<class T>
80      using type_identity_t = typename type_identity<T>::type;  // C++20
81
82    // Integral properties:
83    template <class T> struct is_signed;
84    template <class T> struct is_unsigned;
85    template <class T> struct make_signed;
86    template <class T> struct make_unsigned;
87
88    // Array properties and transformations:
89    template <class T> struct rank;
90    template <class T, unsigned I = 0> struct extent;
91    template <class T> struct remove_extent;
92    template <class T> struct remove_all_extents;
93
94    template <class T> struct is_bounded_array;                 // C++20
95    template <class T> struct is_unbounded_array;               // C++20
96
97    // Member introspection:
98    template <class T> struct is_pod;
99    template <class T> struct is_trivial;
100    template <class T> struct is_trivially_copyable;
101    template <class T> struct is_standard_layout;
102    template <class T> struct is_literal_type; // Deprecated in C++17; removed in C++20
103    template <class T> struct is_empty;
104    template <class T> struct is_polymorphic;
105    template <class T> struct is_abstract;
106    template <class T> struct is_final; // C++14
107    template <class T> struct is_aggregate; // C++17
108
109    template <class T, class... Args> struct is_constructible;
110    template <class T>                struct is_default_constructible;
111    template <class T>                struct is_copy_constructible;
112    template <class T>                struct is_move_constructible;
113    template <class T, class U>       struct is_assignable;
114    template <class T>                struct is_copy_assignable;
115    template <class T>                struct is_move_assignable;
116    template <class T, class U>       struct is_swappable_with;       // C++17
117    template <class T>                struct is_swappable;            // C++17
118    template <class T>                struct is_destructible;
119
120    template <class T, class... Args> struct is_trivially_constructible;
121    template <class T>                struct is_trivially_default_constructible;
122    template <class T>                struct is_trivially_copy_constructible;
123    template <class T>                struct is_trivially_move_constructible;
124    template <class T, class U>       struct is_trivially_assignable;
125    template <class T>                struct is_trivially_copy_assignable;
126    template <class T>                struct is_trivially_move_assignable;
127    template <class T>                struct is_trivially_destructible;
128
129    template <class T, class... Args> struct is_nothrow_constructible;
130    template <class T>                struct is_nothrow_default_constructible;
131    template <class T>                struct is_nothrow_copy_constructible;
132    template <class T>                struct is_nothrow_move_constructible;
133    template <class T, class U>       struct is_nothrow_assignable;
134    template <class T>                struct is_nothrow_copy_assignable;
135    template <class T>                struct is_nothrow_move_assignable;
136    template <class T, class U>       struct is_nothrow_swappable_with; // C++17
137    template <class T>                struct is_nothrow_swappable;      // C++17
138    template <class T>                struct is_nothrow_destructible;
139
140    template <class T> struct has_virtual_destructor;
141
142    template<class T> struct has_unique_object_representations;         // C++17
143
144    // Relationships between types:
145    template <class T, class U> struct is_same;
146    template <class Base, class Derived> struct is_base_of;
147
148    template <class From, class To> struct is_convertible;
149    template <typename From, typename To> struct is_nothrow_convertible;                  // C++20
150    template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20
151
152    template <class Fn, class... ArgTypes> struct is_invocable;
153    template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
154
155    template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
156    template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
157
158    // Alignment properties and transformations:
159    template <class T> struct alignment_of;
160    template <size_t Len, size_t Align = most_stringent_alignment_requirement>
161        struct aligned_storage;
162    template <size_t Len, class... Types> struct aligned_union;
163    template <class T> struct remove_cvref; // C++20
164
165    template <class T> struct decay;
166    template <class... T> struct common_type;
167    template <class T> struct underlying_type;
168    template <class> class result_of; // undefined; deprecated in C++17; removed in C++20
169    template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20
170    template <class Fn, class... ArgTypes> struct invoke_result;  // C++17
171
172    // const-volatile modifications:
173    template <class T>
174      using remove_const_t    = typename remove_const<T>::type;  // C++14
175    template <class T>
176      using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
177    template <class T>
178      using remove_cv_t       = typename remove_cv<T>::type;  // C++14
179    template <class T>
180      using add_const_t       = typename add_const<T>::type;  // C++14
181    template <class T>
182      using add_volatile_t    = typename add_volatile<T>::type;  // C++14
183    template <class T>
184      using add_cv_t          = typename add_cv<T>::type;  // C++14
185
186    // reference modifications:
187    template <class T>
188      using remove_reference_t     = typename remove_reference<T>::type;  // C++14
189    template <class T>
190      using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
191    template <class T>
192      using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
193
194    // sign modifications:
195    template <class T>
196      using make_signed_t   = typename make_signed<T>::type;  // C++14
197    template <class T>
198      using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
199
200    // array modifications:
201    template <class T>
202      using remove_extent_t      = typename remove_extent<T>::type;  // C++14
203    template <class T>
204      using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
205
206    template <class T>
207      inline constexpr bool is_bounded_array_v
208        = is_bounded_array<T>::value;                                     // C++20
209      inline constexpr bool is_unbounded_array_v
210        = is_unbounded_array<T>::value;                                   // C++20
211
212    // pointer modifications:
213    template <class T>
214      using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
215    template <class T>
216      using add_pointer_t    = typename add_pointer<T>::type;  // C++14
217
218    // other transformations:
219    template <size_t Len, size_t Align=default-alignment>
220      using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
221    template <size_t Len, class... Types>
222      using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
223    template <class T>
224      using remove_cvref_t    = typename remove_cvref<T>::type;  // C++20
225    template <class T>
226      using decay_t           = typename decay<T>::type;  // C++14
227    template <bool b, class T=void>
228      using enable_if_t       = typename enable_if<b,T>::type;  // C++14
229    template <bool b, class T, class F>
230      using conditional_t     = typename conditional<b,T,F>::type;  // C++14
231    template <class... T>
232      using common_type_t     = typename common_type<T...>::type;  // C++14
233    template <class T>
234      using underlying_type_t = typename underlying_type<T>::type;  // C++14
235    template <class T>
236      using result_of_t       = typename result_of<T>::type;  // C++14; deprecated in C++17; removed in C++20
237    template <class Fn, class... ArgTypes>
238      using invoke_result_t   = typename invoke_result<Fn, ArgTypes...>::type;  // C++17
239
240    template <class...>
241      using void_t = void;   // C++17
242
243      // See C++14 20.10.4.1, primary type categories
244      template <class T> inline constexpr bool is_void_v
245        = is_void<T>::value;                                             // C++17
246      template <class T> inline constexpr bool is_null_pointer_v
247        = is_null_pointer<T>::value;                                     // C++17
248      template <class T> inline constexpr bool is_integral_v
249        = is_integral<T>::value;                                         // C++17
250      template <class T> inline constexpr bool is_floating_point_v
251        = is_floating_point<T>::value;                                   // C++17
252      template <class T> inline constexpr bool is_array_v
253        = is_array<T>::value;                                            // C++17
254      template <class T> inline constexpr bool is_pointer_v
255        = is_pointer<T>::value;                                          // C++17
256      template <class T> inline constexpr bool is_lvalue_reference_v
257        = is_lvalue_reference<T>::value;                                 // C++17
258      template <class T> inline constexpr bool is_rvalue_reference_v
259        = is_rvalue_reference<T>::value;                                 // C++17
260      template <class T> inline constexpr bool is_member_object_pointer_v
261        = is_member_object_pointer<T>::value;                            // C++17
262      template <class T> inline constexpr bool is_member_function_pointer_v
263        = is_member_function_pointer<T>::value;                          // C++17
264      template <class T> inline constexpr bool is_enum_v
265        = is_enum<T>::value;                                             // C++17
266      template <class T> inline constexpr bool is_union_v
267        = is_union<T>::value;                                            // C++17
268      template <class T> inline constexpr bool is_class_v
269        = is_class<T>::value;                                            // C++17
270      template <class T> inline constexpr bool is_function_v
271        = is_function<T>::value;                                         // C++17
272
273      // See C++14 20.10.4.2, composite type categories
274      template <class T> inline constexpr bool is_reference_v
275        = is_reference<T>::value;                                        // C++17
276      template <class T> inline constexpr bool is_arithmetic_v
277        = is_arithmetic<T>::value;                                       // C++17
278      template <class T> inline constexpr bool is_fundamental_v
279        = is_fundamental<T>::value;                                      // C++17
280      template <class T> inline constexpr bool is_object_v
281        = is_object<T>::value;                                           // C++17
282      template <class T> inline constexpr bool is_scalar_v
283        = is_scalar<T>::value;                                           // C++17
284      template <class T> inline constexpr bool is_compound_v
285        = is_compound<T>::value;                                         // C++17
286      template <class T> inline constexpr bool is_member_pointer_v
287        = is_member_pointer<T>::value;                                   // C++17
288      template <class T> inline constexpr bool is_scoped_enum_v
289        = is_scoped_enum<T>::value;                                      // C++2b
290
291      // See C++14 20.10.4.3, type properties
292      template <class T> inline constexpr bool is_const_v
293        = is_const<T>::value;                                            // C++17
294      template <class T> inline constexpr bool is_volatile_v
295        = is_volatile<T>::value;                                         // C++17
296      template <class T> inline constexpr bool is_trivial_v
297        = is_trivial<T>::value;                                          // C++17
298      template <class T> inline constexpr bool is_trivially_copyable_v
299        = is_trivially_copyable<T>::value;                               // C++17
300      template <class T> inline constexpr bool is_standard_layout_v
301        = is_standard_layout<T>::value;                                  // C++17
302      template <class T> inline constexpr bool is_pod_v
303        = is_pod<T>::value;                                              // C++17
304      template <class T> inline constexpr bool is_literal_type_v
305        = is_literal_type<T>::value;                                     // C++17; deprecated in C++17; removed in C++20
306      template <class T> inline constexpr bool is_empty_v
307        = is_empty<T>::value;                                            // C++17
308      template <class T> inline constexpr bool is_polymorphic_v
309        = is_polymorphic<T>::value;                                      // C++17
310      template <class T> inline constexpr bool is_abstract_v
311        = is_abstract<T>::value;                                         // C++17
312      template <class T> inline constexpr bool is_final_v
313        = is_final<T>::value;                                            // C++17
314      template <class T> inline constexpr bool is_aggregate_v
315        = is_aggregate<T>::value;                                        // C++17
316      template <class T> inline constexpr bool is_signed_v
317        = is_signed<T>::value;                                           // C++17
318      template <class T> inline constexpr bool is_unsigned_v
319        = is_unsigned<T>::value;                                         // C++17
320      template <class T, class... Args> inline constexpr bool is_constructible_v
321        = is_constructible<T, Args...>::value;                           // C++17
322      template <class T> inline constexpr bool is_default_constructible_v
323        = is_default_constructible<T>::value;                            // C++17
324      template <class T> inline constexpr bool is_copy_constructible_v
325        = is_copy_constructible<T>::value;                               // C++17
326      template <class T> inline constexpr bool is_move_constructible_v
327        = is_move_constructible<T>::value;                               // C++17
328      template <class T, class U> inline constexpr bool is_assignable_v
329        = is_assignable<T, U>::value;                                    // C++17
330      template <class T> inline constexpr bool is_copy_assignable_v
331        = is_copy_assignable<T>::value;                                  // C++17
332      template <class T> inline constexpr bool is_move_assignable_v
333        = is_move_assignable<T>::value;                                  // C++17
334      template <class T, class U> inline constexpr bool is_swappable_with_v
335        = is_swappable_with<T, U>::value;                                // C++17
336      template <class T> inline constexpr bool is_swappable_v
337        = is_swappable<T>::value;                                        // C++17
338      template <class T> inline constexpr bool is_destructible_v
339        = is_destructible<T>::value;                                     // C++17
340      template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
341        = is_trivially_constructible<T, Args...>::value;                 // C++17
342      template <class T> inline constexpr bool is_trivially_default_constructible_v
343        = is_trivially_default_constructible<T>::value;                  // C++17
344      template <class T> inline constexpr bool is_trivially_copy_constructible_v
345        = is_trivially_copy_constructible<T>::value;                     // C++17
346      template <class T> inline constexpr bool is_trivially_move_constructible_v
347        = is_trivially_move_constructible<T>::value;                     // C++17
348      template <class T, class U> inline constexpr bool is_trivially_assignable_v
349        = is_trivially_assignable<T, U>::value;                          // C++17
350      template <class T> inline constexpr bool is_trivially_copy_assignable_v
351        = is_trivially_copy_assignable<T>::value;                        // C++17
352      template <class T> inline constexpr bool is_trivially_move_assignable_v
353        = is_trivially_move_assignable<T>::value;                        // C++17
354      template <class T> inline constexpr bool is_trivially_destructible_v
355        = is_trivially_destructible<T>::value;                           // C++17
356      template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
357        = is_nothrow_constructible<T, Args...>::value;                   // C++17
358      template <class T> inline constexpr bool is_nothrow_default_constructible_v
359        = is_nothrow_default_constructible<T>::value;                    // C++17
360      template <class T> inline constexpr bool is_nothrow_copy_constructible_v
361        = is_nothrow_copy_constructible<T>::value;                       // C++17
362      template <class T> inline constexpr bool is_nothrow_move_constructible_v
363        = is_nothrow_move_constructible<T>::value;                       // C++17
364      template <class T, class U> inline constexpr bool is_nothrow_assignable_v
365        = is_nothrow_assignable<T, U>::value;                            // C++17
366      template <class T> inline constexpr bool is_nothrow_copy_assignable_v
367        = is_nothrow_copy_assignable<T>::value;                          // C++17
368      template <class T> inline constexpr bool is_nothrow_move_assignable_v
369        = is_nothrow_move_assignable<T>::value;                          // C++17
370      template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
371        = is_nothrow_swappable_with<T, U>::value;                       // C++17
372      template <class T> inline constexpr bool is_nothrow_swappable_v
373        = is_nothrow_swappable<T>::value;                               // C++17
374      template <class T> inline constexpr bool is_nothrow_destructible_v
375        = is_nothrow_destructible<T>::value;                             // C++17
376      template <class T> inline constexpr bool has_virtual_destructor_v
377        = has_virtual_destructor<T>::value;                              // C++17
378      template<class T> inline constexpr bool has_unique_object_representations_v // C++17
379        = has_unique_object_representations<T>::value;
380
381      // See C++14 20.10.5, type property queries
382      template <class T> inline constexpr size_t alignment_of_v
383        = alignment_of<T>::value;                                        // C++17
384      template <class T> inline constexpr size_t rank_v
385        = rank<T>::value;                                                // C++17
386      template <class T, unsigned I = 0> inline constexpr size_t extent_v
387        = extent<T, I>::value;                                           // C++17
388
389      // See C++14 20.10.6, type relations
390      template <class T, class U> inline constexpr bool is_same_v
391        = is_same<T, U>::value;                                          // C++17
392      template <class Base, class Derived> inline constexpr bool is_base_of_v
393        = is_base_of<Base, Derived>::value;                              // C++17
394      template <class From, class To> inline constexpr bool is_convertible_v
395        = is_convertible<From, To>::value;                               // C++17
396      template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
397        = is_invocable<Fn, ArgTypes...>::value;                          // C++17
398      template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
399        = is_invocable_r<R, Fn, ArgTypes...>::value;                     // C++17
400      template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
401        = is_nothrow_invocable<Fn, ArgTypes...>::value;                  // C++17
402      template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
403        = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;             // C++17
404
405      // [meta.logical], logical operator traits:
406      template<class... B> struct conjunction;                           // C++17
407      template<class... B>
408        inline constexpr bool conjunction_v = conjunction<B...>::value;  // C++17
409      template<class... B> struct disjunction;                           // C++17
410      template<class... B>
411        inline constexpr bool disjunction_v = disjunction<B...>::value;  // C++17
412      template<class B> struct negation;                                 // C++17
413      template<class B>
414        inline constexpr bool negation_v = negation<B>::value;           // C++17
415
416}
417
418*/
419#include <__config>
420#include <cstddef>
421#include <version>
422
423#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
424#  pragma GCC system_header
425#endif
426
427_LIBCPP_BEGIN_NAMESPACE_STD
428
429template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair;
430template <class _Tp> class _LIBCPP_TEMPLATE_VIS reference_wrapper;
431template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
432
433template <class _Tp, _Tp __v>
434struct _LIBCPP_TEMPLATE_VIS integral_constant
435{
436  static _LIBCPP_CONSTEXPR const _Tp      value = __v;
437  typedef _Tp               value_type;
438  typedef integral_constant type;
439  _LIBCPP_INLINE_VISIBILITY
440  _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;}
441#if _LIBCPP_STD_VER > 11
442  _LIBCPP_INLINE_VISIBILITY
443  constexpr value_type operator ()() const _NOEXCEPT {return value;}
444#endif
445};
446
447template <class _Tp, _Tp __v>
448_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
449
450#if _LIBCPP_STD_VER > 14
451template <bool __b>
452using bool_constant = integral_constant<bool, __b>;
453#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)>
454#else
455#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>
456#endif
457
458template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
459template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;};
460
461template <bool _Bp, class _Tp = void> using __enable_if_t _LIBCPP_NODEBUG = typename enable_if<_Bp, _Tp>::type;
462
463#if _LIBCPP_STD_VER > 11
464template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
465#endif
466
467typedef _LIBCPP_BOOL_CONSTANT(true)  true_type;
468typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
469
470template <bool _Val>
471using _BoolConstant _LIBCPP_NODEBUG = integral_constant<bool, _Val>;
472
473template <bool> struct _MetaBase;
474template <>
475struct _MetaBase<true> {
476  template <class _Tp, class _Up>
477  using _SelectImpl _LIBCPP_NODEBUG = _Tp;
478  template <template <class...> class _FirstFn, template <class...> class, class ..._Args>
479  using _SelectApplyImpl _LIBCPP_NODEBUG = _FirstFn<_Args...>;
480  template <class _First, class...>
481  using _FirstImpl _LIBCPP_NODEBUG = _First;
482  template <class, class _Second, class...>
483  using _SecondImpl _LIBCPP_NODEBUG = _Second;
484  template <class _Result, class _First, class ..._Rest>
485  using _OrImpl _LIBCPP_NODEBUG = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
486};
487
488template <>
489struct _MetaBase<false> {
490  template <class _Tp, class _Up>
491  using _SelectImpl _LIBCPP_NODEBUG = _Up;
492  template <template <class...> class, template <class...> class _SecondFn, class ..._Args>
493  using _SelectApplyImpl _LIBCPP_NODEBUG = _SecondFn<_Args...>;
494  template <class _Result, class ...>
495  using _OrImpl _LIBCPP_NODEBUG = _Result;
496};
497template <bool _Cond, class _IfRes, class _ElseRes>
498using _If _LIBCPP_NODEBUG = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
499template <class ..._Rest>
500using _Or _LIBCPP_NODEBUG = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
501template <class _Pred>
502struct _Not : _BoolConstant<!_Pred::value> {};
503template <class ..._Args>
504using _FirstType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
505template <class ..._Args>
506using _SecondType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
507
508template <class ...> using __expand_to_true = true_type;
509template <class ..._Pred>
510__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
511template <class ...>
512false_type __and_helper(...);
513template <class ..._Pred>
514using _And _LIBCPP_NODEBUG = decltype(__and_helper<_Pred...>(0));
515
516template <template <class...> class _Func, class ..._Args>
517struct _Lazy : _Func<_Args...> {};
518
519// Member detector base
520
521template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> >
522true_type __sfinae_test_impl(int);
523template <template <class...> class, class ...>
524false_type __sfinae_test_impl(...);
525
526template <template <class ...> class _Templ, class ..._Args>
527using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
528
529template <class>
530struct __void_t { typedef void type; };
531
532template <class _Tp>
533struct __identity { typedef _Tp type; };
534
535template <class _Tp>
536using __identity_t _LIBCPP_NODEBUG = typename __identity<_Tp>::type;
537
538template <class _Tp, bool>
539struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
540
541
542template <bool _Bp, class _If, class _Then>
543    struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;};
544template <class _If, class _Then>
545    struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {typedef _Then type;};
546
547#if _LIBCPP_STD_VER > 11
548template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
549#endif
550
551// is_same
552
553template <class _Tp, class _Up>
554struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> { };
555
556#if _LIBCPP_STD_VER > 14
557template <class _Tp, class _Up>
558inline constexpr bool is_same_v = __is_same(_Tp, _Up);
559#endif
560
561// _IsSame<T,U> has the same effect as is_same<T,U> but instantiates fewer types:
562// is_same<A,B> and is_same<C,D> are guaranteed to be different types, but
563// _IsSame<A,B> and _IsSame<C,D> are the same type (namely, false_type).
564// Neither GCC nor Clang can mangle the __is_same builtin, so _IsSame
565// mustn't be directly used anywhere that contributes to name-mangling
566// (such as in a dependent return type).
567
568template <class _Tp, class _Up>
569using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
570
571template <class _Tp, class _Up>
572using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;
573
574template <class _Tp>
575using __test_for_primary_template = __enable_if_t<
576    _IsSame<_Tp, typename _Tp::__primary_template>::value
577  >;
578template <class _Tp>
579using __is_primary_template = _IsValidExpansion<
580    __test_for_primary_template, _Tp
581  >;
582
583// helper class
584
585struct __two {char __lx[2];};
586
587// is_const
588
589#if __has_keyword(__is_const)
590
591template <class _Tp>
592struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { };
593
594#if _LIBCPP_STD_VER > 14
595template <class _Tp>
596inline constexpr bool is_const_v = __is_const(_Tp);
597#endif
598
599#else
600
601template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const            : public false_type {};
602template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
603
604#if _LIBCPP_STD_VER > 14
605template <class _Tp>
606inline constexpr bool is_const_v = is_const<_Tp>::value;
607#endif
608
609#endif // __has_keyword(__is_const)
610
611// is_volatile
612
613#if __has_keyword(__is_volatile)
614
615template <class _Tp>
616struct _LIBCPP_TEMPLATE_VIS is_volatile : _BoolConstant<__is_volatile(_Tp)> { };
617
618#if _LIBCPP_STD_VER > 14
619template <class _Tp>
620inline constexpr bool is_volatile_v = __is_volatile(_Tp);
621#endif
622
623#else
624
625template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile               : public false_type {};
626template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
627
628#if _LIBCPP_STD_VER > 14
629template <class _Tp>
630inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
631#endif
632
633#endif // __has_keyword(__is_volatile)
634
635// remove_const
636
637template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const            {typedef _Tp type;};
638template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const<const _Tp> {typedef _Tp type;};
639#if _LIBCPP_STD_VER > 11
640template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
641#endif
642
643// remove_volatile
644
645template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile               {typedef _Tp type;};
646template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;};
647#if _LIBCPP_STD_VER > 11
648template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
649#endif
650
651// remove_cv
652
653template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
654{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
655#if _LIBCPP_STD_VER > 11
656template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
657#endif
658
659// is_void
660
661#if __has_keyword(__is_void)
662
663template <class _Tp>
664struct _LIBCPP_TEMPLATE_VIS is_void : _BoolConstant<__is_void(_Tp)> { };
665
666#if _LIBCPP_STD_VER > 14
667template <class _Tp>
668inline constexpr bool is_void_v = __is_void(_Tp);
669#endif
670
671#else
672
673template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void
674    : public is_same<typename remove_cv<_Tp>::type, void> {};
675
676#if _LIBCPP_STD_VER > 14
677template <class _Tp>
678inline constexpr bool is_void_v = is_void<_Tp>::value;
679#endif
680
681#endif // __has_keyword(__is_void)
682
683// __is_nullptr_t
684
685template <class _Tp> struct __is_nullptr_t_impl       : public false_type {};
686template <>          struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
687
688template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t
689    : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
690
691#if _LIBCPP_STD_VER > 11
692template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer
693    : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
694
695#if _LIBCPP_STD_VER > 14
696template <class _Tp>
697inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
698#endif
699#endif // _LIBCPP_STD_VER > 11
700
701// is_integral
702
703#if __has_keyword(__is_integral)
704
705template <class _Tp>
706struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> { };
707
708#if _LIBCPP_STD_VER > 14
709template <class _Tp>
710inline constexpr bool is_integral_v = __is_integral(_Tp);
711#endif
712
713#else
714
715template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
716    : public _BoolConstant<__libcpp_is_integral<typename remove_cv<_Tp>::type>::value> {};
717
718#if _LIBCPP_STD_VER > 14
719template <class _Tp>
720inline constexpr bool is_integral_v = is_integral<_Tp>::value;
721#endif
722
723#endif // __has_keyword(__is_integral)
724
725// [basic.fundamental] defines five standard signed integer types;
726// __int128_t is an extended signed integer type.
727// The signed and unsigned integer types, plus bool and the
728// five types with "char" in their name, compose the "integral" types.
729
730template <class _Tp> struct __libcpp_is_signed_integer : public false_type {};
731template <> struct __libcpp_is_signed_integer<signed char>      : public true_type {};
732template <> struct __libcpp_is_signed_integer<signed short>     : public true_type {};
733template <> struct __libcpp_is_signed_integer<signed int>       : public true_type {};
734template <> struct __libcpp_is_signed_integer<signed long>      : public true_type {};
735template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
736#ifndef _LIBCPP_HAS_NO_INT128
737template <> struct __libcpp_is_signed_integer<__int128_t>       : public true_type {};
738#endif
739
740template <class _Tp> struct __libcpp_is_unsigned_integer : public false_type {};
741template <> struct __libcpp_is_unsigned_integer<unsigned char>      : public true_type {};
742template <> struct __libcpp_is_unsigned_integer<unsigned short>     : public true_type {};
743template <> struct __libcpp_is_unsigned_integer<unsigned int>       : public true_type {};
744template <> struct __libcpp_is_unsigned_integer<unsigned long>      : public true_type {};
745template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
746#ifndef _LIBCPP_HAS_NO_INT128
747template <> struct __libcpp_is_unsigned_integer<__uint128_t>        : public true_type {};
748#endif
749
750// is_floating_point
751// <concepts> implements __libcpp_floating_point
752
753template <class _Tp> struct __libcpp_is_floating_point              : public false_type {};
754template <>          struct __libcpp_is_floating_point<float>       : public true_type {};
755template <>          struct __libcpp_is_floating_point<double>      : public true_type {};
756template <>          struct __libcpp_is_floating_point<long double> : public true_type {};
757
758template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point
759    : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
760
761#if _LIBCPP_STD_VER > 14
762template <class _Tp>
763inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
764#endif
765
766// is_array
767
768#if __has_keyword(__is_array)
769
770template <class _Tp>
771struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> { };
772
773#if _LIBCPP_STD_VER > 14
774template <class _Tp>
775inline constexpr bool is_array_v = __is_array(_Tp);
776#endif
777
778#else
779
780template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array
781    : public false_type {};
782template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]>
783    : public true_type {};
784template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]>
785    : public true_type {};
786
787#if _LIBCPP_STD_VER > 14
788template <class _Tp>
789inline constexpr bool is_array_v = is_array<_Tp>::value;
790#endif
791
792#endif // __has_keyword(__is_array)
793
794// is_pointer
795
796// Before AppleClang 12.0.5, __is_pointer didn't work for Objective-C types.
797#if __has_keyword(__is_pointer) &&                                             \
798    !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1205)
799
800template<class _Tp>
801struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
802
803#if _LIBCPP_STD_VER > 14
804template <class _Tp>
805inline constexpr bool is_pointer_v = __is_pointer(_Tp);
806#endif
807
808#else // __has_keyword(__is_pointer)
809
810template <class _Tp> struct __libcpp_is_pointer       : public false_type {};
811template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
812
813template <class _Tp> struct __libcpp_remove_objc_qualifiers { typedef _Tp type; };
814#if defined(_LIBCPP_HAS_OBJC_ARC)
815template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
816template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };
817template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; };
818template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; };
819#endif
820
821template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer
822    : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {};
823
824#if _LIBCPP_STD_VER > 14
825template <class _Tp>
826inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
827#endif
828
829#endif // __has_keyword(__is_pointer)
830
831// is_reference
832
833#if __has_keyword(__is_lvalue_reference) && \
834    __has_keyword(__is_rvalue_reference) && \
835    __has_keyword(__is_reference)
836
837template<class _Tp>
838struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> { };
839
840template<class _Tp>
841struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> { };
842
843template<class _Tp>
844struct _LIBCPP_TEMPLATE_VIS is_reference : _BoolConstant<__is_reference(_Tp)> { };
845
846#if _LIBCPP_STD_VER > 14
847template <class _Tp>
848inline constexpr bool is_reference_v = __is_reference(_Tp);
849template <class _Tp>
850inline constexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
851template <class _Tp>
852inline constexpr bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
853#endif
854
855#else // __has_keyword(__is_lvalue_reference) && etc...
856
857template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference       : public false_type {};
858template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {};
859
860template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference        : public false_type {};
861template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {};
862
863template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference        : public false_type {};
864template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&>  : public true_type {};
865template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {};
866
867#if _LIBCPP_STD_VER > 14
868template <class _Tp>
869inline constexpr bool is_reference_v = is_reference<_Tp>::value;
870
871template <class _Tp>
872inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value;
873
874template <class _Tp>
875inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value;
876#endif
877
878#endif // __has_keyword(__is_lvalue_reference) && etc...
879
880// is_union
881
882#if __has_feature(is_union) || defined(_LIBCPP_COMPILER_GCC)
883
884template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
885    : public integral_constant<bool, __is_union(_Tp)> {};
886
887#else
888
889template <class _Tp> struct __libcpp_union : public false_type {};
890template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
891    : public __libcpp_union<typename remove_cv<_Tp>::type> {};
892
893#endif
894
895#if _LIBCPP_STD_VER > 14
896template <class _Tp>
897inline constexpr bool is_union_v = is_union<_Tp>::value;
898#endif
899
900// is_class
901
902#if __has_feature(is_class) || defined(_LIBCPP_COMPILER_GCC)
903
904template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
905    : public integral_constant<bool, __is_class(_Tp)> {};
906
907#else
908
909namespace __is_class_imp
910{
911template <class _Tp> char  __test(int _Tp::*);
912template <class _Tp> __two __test(...);
913}
914
915template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
916    : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
917
918#endif
919
920#if _LIBCPP_STD_VER > 14
921template <class _Tp>
922inline constexpr bool is_class_v = is_class<_Tp>::value;
923#endif
924
925// is_function
926
927template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function
928    : public _BoolConstant<
929#ifdef __clang__
930    __is_function(_Tp)
931#else
932 !(is_reference<_Tp>::value || is_const<const _Tp>::value)
933#endif
934    > {};
935
936
937#if _LIBCPP_STD_VER > 14
938template <class _Tp>
939inline constexpr bool is_function_v = is_function<_Tp>::value;
940#endif
941
942template <class _Tp> struct __libcpp_is_member_pointer {
943  enum {
944    __is_member = false,
945    __is_func = false,
946    __is_obj = false
947  };
948};
949template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> {
950  enum {
951    __is_member = true,
952    __is_func = is_function<_Tp>::value,
953    __is_obj = !__is_func,
954  };
955};
956
957#if __has_keyword(__is_member_function_pointer)
958
959template<class _Tp>
960struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
961    : _BoolConstant<__is_member_function_pointer(_Tp)> { };
962
963#if _LIBCPP_STD_VER > 14
964template <class _Tp>
965inline constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Tp);
966#endif
967
968#else // __has_keyword(__is_member_function_pointer)
969
970template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
971    : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
972
973#if _LIBCPP_STD_VER > 14
974template <class _Tp>
975inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value;
976#endif
977
978#endif // __has_keyword(__is_member_function_pointer)
979
980// is_member_pointer
981
982#if __has_keyword(__is_member_pointer)
983
984template<class _Tp>
985struct _LIBCPP_TEMPLATE_VIS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> { };
986
987#if _LIBCPP_STD_VER > 14
988template <class _Tp>
989inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
990#endif
991
992#else // __has_keyword(__is_member_pointer)
993
994template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
995 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
996
997#if _LIBCPP_STD_VER > 14
998template <class _Tp>
999inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
1000#endif
1001
1002#endif // __has_keyword(__is_member_pointer)
1003
1004// is_member_object_pointer
1005
1006#if __has_keyword(__is_member_object_pointer)
1007
1008template<class _Tp>
1009struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
1010    : _BoolConstant<__is_member_object_pointer(_Tp)> { };
1011
1012#if _LIBCPP_STD_VER > 14
1013template <class _Tp>
1014inline constexpr bool is_member_object_pointer_v = __is_member_object_pointer(_Tp);
1015#endif
1016
1017#else // __has_keyword(__is_member_object_pointer)
1018
1019template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
1020    : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj >  {};
1021
1022#if _LIBCPP_STD_VER > 14
1023template <class _Tp>
1024inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value;
1025#endif
1026
1027#endif // __has_keyword(__is_member_object_pointer)
1028
1029// is_enum
1030
1031#if __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
1032
1033template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
1034    : public integral_constant<bool, __is_enum(_Tp)> {};
1035
1036#if _LIBCPP_STD_VER > 14
1037template <class _Tp>
1038inline constexpr bool is_enum_v = __is_enum(_Tp);
1039#endif
1040
1041#else
1042
1043template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
1044    : public integral_constant<bool, !is_void<_Tp>::value             &&
1045                                     !is_integral<_Tp>::value         &&
1046                                     !is_floating_point<_Tp>::value   &&
1047                                     !is_array<_Tp>::value            &&
1048                                     !is_pointer<_Tp>::value          &&
1049                                     !is_reference<_Tp>::value        &&
1050                                     !is_member_pointer<_Tp>::value   &&
1051                                     !is_union<_Tp>::value            &&
1052                                     !is_class<_Tp>::value            &&
1053                                     !is_function<_Tp>::value         > {};
1054
1055#if _LIBCPP_STD_VER > 14
1056template <class _Tp>
1057inline constexpr bool is_enum_v = is_enum<_Tp>::value;
1058#endif
1059
1060#endif // __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
1061
1062// is_arithmetic
1063
1064
1065template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
1066    : public integral_constant<bool, is_integral<_Tp>::value      ||
1067                                     is_floating_point<_Tp>::value> {};
1068
1069#if _LIBCPP_STD_VER > 14
1070template <class _Tp>
1071inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
1072#endif
1073
1074// is_fundamental
1075
1076// Before Clang 10, __is_fundamental didn't work for nullptr_t.
1077// In C++03 nullptr_t is library-provided but must still count as "fundamental."
1078#if __has_keyword(__is_fundamental) &&                                         \
1079    !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1000) &&               \
1080    !defined(_LIBCPP_CXX03_LANG)
1081
1082template<class _Tp>
1083struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
1084
1085#if _LIBCPP_STD_VER > 14
1086template <class _Tp>
1087inline constexpr bool is_fundamental_v = __is_fundamental(_Tp);
1088#endif
1089
1090#else // __has_keyword(__is_fundamental)
1091
1092template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
1093    : public integral_constant<bool, is_void<_Tp>::value        ||
1094                                     __is_nullptr_t<_Tp>::value ||
1095                                     is_arithmetic<_Tp>::value> {};
1096
1097#if _LIBCPP_STD_VER > 14
1098template <class _Tp>
1099inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
1100#endif
1101
1102#endif // __has_keyword(__is_fundamental)
1103
1104// is_scalar
1105
1106// In C++03 nullptr_t is library-provided but must still count as "scalar."
1107#if __has_keyword(__is_scalar) && !defined(_LIBCPP_CXX03_LANG)
1108
1109template<class _Tp>
1110struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
1111
1112#if _LIBCPP_STD_VER > 14
1113template <class _Tp>
1114inline constexpr bool is_scalar_v = __is_scalar(_Tp);
1115#endif
1116
1117#else // __has_keyword(__is_scalar)
1118
1119template <class _Tp> struct __is_block : false_type {};
1120#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS)
1121template <class _Rp, class ..._Args> struct __is_block<_Rp (^)(_Args...)> : true_type {};
1122#endif
1123
1124template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
1125    : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
1126                                     is_member_pointer<_Tp>::value ||
1127                                     is_pointer<_Tp>::value        ||
1128                                     __is_nullptr_t<_Tp>::value    ||
1129                                     __is_block<_Tp>::value        ||
1130                                     is_enum<_Tp>::value           > {};
1131
1132template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
1133
1134#if _LIBCPP_STD_VER > 14
1135template <class _Tp>
1136inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
1137#endif
1138
1139#endif // __has_keyword(__is_scalar)
1140
1141// is_object
1142
1143#if __has_keyword(__is_object)
1144
1145template<class _Tp>
1146struct _LIBCPP_TEMPLATE_VIS is_object : _BoolConstant<__is_object(_Tp)> { };
1147
1148#if _LIBCPP_STD_VER > 14
1149template <class _Tp>
1150inline constexpr bool is_object_v = __is_object(_Tp);
1151#endif
1152
1153#else // __has_keyword(__is_object)
1154
1155template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
1156    : public integral_constant<bool, is_scalar<_Tp>::value ||
1157                                     is_array<_Tp>::value  ||
1158                                     is_union<_Tp>::value  ||
1159                                     is_class<_Tp>::value  > {};
1160
1161#if _LIBCPP_STD_VER > 14
1162template <class _Tp>
1163inline constexpr bool is_object_v = is_object<_Tp>::value;
1164#endif
1165
1166#endif // __has_keyword(__is_object)
1167
1168// is_compound
1169
1170// >= 11 because in C++03 nullptr isn't actually nullptr
1171#if __has_keyword(__is_compound) && !defined(_LIBCPP_CXX03_LANG)
1172
1173template<class _Tp>
1174struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> { };
1175
1176#if _LIBCPP_STD_VER > 14
1177template <class _Tp>
1178inline constexpr bool is_compound_v = __is_compound(_Tp);
1179#endif
1180
1181#else // __has_keyword(__is_compound)
1182
1183template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
1184    : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
1185
1186#if _LIBCPP_STD_VER > 14
1187template <class _Tp>
1188inline constexpr bool is_compound_v = is_compound<_Tp>::value;
1189#endif
1190
1191#endif // __has_keyword(__is_compound)
1192
1193// __is_referenceable  [defns.referenceable]
1194
1195struct __is_referenceable_impl {
1196    template <class _Tp> static _Tp& __test(int);
1197    template <class _Tp> static __two __test(...);
1198};
1199
1200template <class _Tp>
1201struct __is_referenceable : integral_constant<bool,
1202    _IsNotSame<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {};
1203
1204
1205// add_const
1206
1207template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const {
1208  typedef _LIBCPP_NODEBUG const _Tp type;
1209};
1210
1211#if _LIBCPP_STD_VER > 11
1212template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
1213#endif
1214
1215// add_volatile
1216
1217template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile {
1218  typedef _LIBCPP_NODEBUG volatile _Tp type;
1219};
1220
1221#if _LIBCPP_STD_VER > 11
1222template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
1223#endif
1224
1225// add_cv
1226template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv {
1227  typedef _LIBCPP_NODEBUG const volatile _Tp type;
1228};
1229
1230#if _LIBCPP_STD_VER > 11
1231template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
1232#endif
1233
1234// remove_reference
1235
1236template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference        {typedef _LIBCPP_NODEBUG _Tp type;};
1237template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&>  {typedef _LIBCPP_NODEBUG _Tp type;};
1238template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG _Tp type;};
1239
1240#if _LIBCPP_STD_VER > 11
1241template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
1242#endif
1243
1244// add_lvalue_reference
1245
1246template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl            { typedef _LIBCPP_NODEBUG _Tp  type; };
1247template <class _Tp                                       > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG _Tp& type; };
1248
1249template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference
1250{typedef _LIBCPP_NODEBUG typename  __add_lvalue_reference_impl<_Tp>::type type;};
1251
1252#if _LIBCPP_STD_VER > 11
1253template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1254#endif
1255
1256template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl            { typedef _LIBCPP_NODEBUG _Tp   type; };
1257template <class _Tp                                       > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG _Tp&& type; };
1258
1259template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference
1260{typedef _LIBCPP_NODEBUG typename __add_rvalue_reference_impl<_Tp>::type type;};
1261
1262#if _LIBCPP_STD_VER > 11
1263template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1264#endif
1265
1266// Suppress deprecation notice for volatile-qualified return type resulting
1267// from volatile-qualified types _Tp.
1268_LIBCPP_SUPPRESS_DEPRECATED_PUSH
1269template <class _Tp> _Tp&& __declval(int);
1270template <class _Tp> _Tp   __declval(long);
1271_LIBCPP_SUPPRESS_DEPRECATED_POP
1272
1273template <class _Tp>
1274decltype(__declval<_Tp>(0))
1275declval() _NOEXCEPT;
1276
1277// __uncvref
1278
1279template <class _Tp>
1280struct __uncvref  {
1281    typedef _LIBCPP_NODEBUG typename remove_cv<typename remove_reference<_Tp>::type>::type type;
1282};
1283
1284template <class _Tp>
1285struct __unconstref {
1286    typedef _LIBCPP_NODEBUG typename remove_const<typename remove_reference<_Tp>::type>::type type;
1287};
1288
1289#ifndef _LIBCPP_CXX03_LANG
1290template <class _Tp>
1291using __uncvref_t _LIBCPP_NODEBUG = typename __uncvref<_Tp>::type;
1292#endif
1293
1294// __is_same_uncvref
1295
1296template <class _Tp, class _Up>
1297struct __is_same_uncvref : _IsSame<typename __uncvref<_Tp>::type,
1298                                   typename __uncvref<_Up>::type> {};
1299
1300#if _LIBCPP_STD_VER > 17
1301// remove_cvref - same as __uncvref
1302template <class _Tp>
1303struct remove_cvref : public __uncvref<_Tp> {};
1304
1305template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type;
1306#endif
1307
1308
1309struct __any
1310{
1311    __any(...);
1312};
1313
1314// remove_pointer
1315
1316template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer                      {typedef _LIBCPP_NODEBUG _Tp type;};
1317template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*>                {typedef _LIBCPP_NODEBUG _Tp type;};
1318template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const>          {typedef _LIBCPP_NODEBUG _Tp type;};
1319template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile>       {typedef _LIBCPP_NODEBUG _Tp type;};
1320template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG _Tp type;};
1321
1322#if _LIBCPP_STD_VER > 11
1323template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
1324#endif
1325
1326// add_pointer
1327
1328template <class _Tp,
1329        bool = __is_referenceable<_Tp>::value ||
1330                _IsSame<typename remove_cv<_Tp>::type, void>::value>
1331struct __add_pointer_impl
1332    {typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type* type;};
1333template <class _Tp> struct __add_pointer_impl<_Tp, false>
1334    {typedef _LIBCPP_NODEBUG _Tp type;};
1335
1336template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer
1337    {typedef _LIBCPP_NODEBUG typename __add_pointer_impl<_Tp>::type type;};
1338
1339#if _LIBCPP_STD_VER > 11
1340template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
1341#endif
1342
1343// type_identity
1344#if _LIBCPP_STD_VER > 17
1345template<class _Tp> struct type_identity { typedef _Tp type; };
1346template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
1347#endif
1348
1349// is_signed
1350
1351#if __has_keyword(__is_signed)
1352
1353template<class _Tp>
1354struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { };
1355
1356#if _LIBCPP_STD_VER > 14
1357template <class _Tp>
1358inline constexpr bool is_signed_v = __is_signed(_Tp);
1359#endif
1360
1361#else // __has_keyword(__is_signed)
1362
1363template <class _Tp, bool = is_integral<_Tp>::value>
1364struct __libcpp_is_signed_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(-1) < _Tp(0)) {};
1365
1366template <class _Tp>
1367struct __libcpp_is_signed_impl<_Tp, false> : public true_type {};  // floating point
1368
1369template <class _Tp, bool = is_arithmetic<_Tp>::value>
1370struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
1371
1372template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
1373
1374template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {};
1375
1376#if _LIBCPP_STD_VER > 14
1377template <class _Tp>
1378inline constexpr bool is_signed_v = is_signed<_Tp>::value;
1379#endif
1380
1381#endif // __has_keyword(__is_signed)
1382
1383// is_unsigned
1384
1385// Before Clang 13, __is_unsigned returned true for enums with signed underlying type.
1386// No currently-released version of AppleClang contains the fixed intrinsic.
1387#if __has_keyword(__is_unsigned) &&                                            \
1388    !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1300) &&               \
1389    !defined(_LIBCPP_APPLE_CLANG_VER)
1390
1391template<class _Tp>
1392struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };
1393
1394#if _LIBCPP_STD_VER > 14
1395template <class _Tp>
1396inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
1397#endif
1398
1399#else // __has_keyword(__is_unsigned)
1400
1401template <class _Tp, bool = is_integral<_Tp>::value>
1402struct __libcpp_is_unsigned_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(0) < _Tp(-1)) {};
1403
1404template <class _Tp>
1405struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {};  // floating point
1406
1407template <class _Tp, bool = is_arithmetic<_Tp>::value>
1408struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
1409
1410template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
1411
1412template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {};
1413
1414#if _LIBCPP_STD_VER > 14
1415template <class _Tp>
1416inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
1417#endif
1418
1419#endif // __has_keyword(__is_unsigned)
1420
1421// rank
1422
1423template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank
1424    : public integral_constant<size_t, 0> {};
1425template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]>
1426    : public integral_constant<size_t, rank<_Tp>::value + 1> {};
1427template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]>
1428    : public integral_constant<size_t, rank<_Tp>::value + 1> {};
1429
1430#if _LIBCPP_STD_VER > 14
1431template <class _Tp>
1432inline constexpr size_t rank_v = rank<_Tp>::value;
1433#endif
1434
1435// extent
1436
1437#if __has_keyword(__array_extent)
1438
1439template<class _Tp, size_t _Dim = 0>
1440struct _LIBCPP_TEMPLATE_VIS extent
1441    : integral_constant<size_t, __array_extent(_Tp, _Dim)> { };
1442
1443#if _LIBCPP_STD_VER > 14
1444template <class _Tp, unsigned _Ip = 0>
1445inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
1446#endif
1447
1448#else // __has_keyword(__array_extent)
1449
1450template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent
1451    : public integral_constant<size_t, 0> {};
1452template <class _Tp> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0>
1453    : public integral_constant<size_t, 0> {};
1454template <class _Tp, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip>
1455    : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
1456template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0>
1457    : public integral_constant<size_t, _Np> {};
1458template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip>
1459    : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
1460
1461#if _LIBCPP_STD_VER > 14
1462template <class _Tp, unsigned _Ip = 0>
1463inline constexpr size_t extent_v = extent<_Tp, _Ip>::value;
1464#endif
1465
1466#endif // __has_keyword(__array_extent)
1467
1468// remove_extent
1469
1470template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent
1471    {typedef _Tp type;};
1472template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[]>
1473    {typedef _Tp type;};
1474template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[_Np]>
1475    {typedef _Tp type;};
1476
1477#if _LIBCPP_STD_VER > 11
1478template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
1479#endif
1480
1481// remove_all_extents
1482
1483template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents
1484    {typedef _Tp type;};
1485template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[]>
1486    {typedef typename remove_all_extents<_Tp>::type type;};
1487template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[_Np]>
1488    {typedef typename remove_all_extents<_Tp>::type type;};
1489
1490#if _LIBCPP_STD_VER > 11
1491template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1492#endif
1493
1494#if _LIBCPP_STD_VER > 17
1495// is_bounded_array
1496
1497template <class>                 struct _LIBCPP_TEMPLATE_VIS is_bounded_array           : false_type {};
1498template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {};
1499
1500template <class _Tp>
1501inline constexpr
1502bool is_bounded_array_v  = is_bounded_array<_Tp>::value;
1503
1504// is_unbounded_array
1505
1506template <class>     struct _LIBCPP_TEMPLATE_VIS is_unbounded_array        : false_type {};
1507template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {};
1508
1509template <class _Tp>
1510inline constexpr
1511bool is_unbounded_array_v  = is_unbounded_array<_Tp>::value;
1512#endif
1513
1514// decay
1515
1516template <class _Up, bool>
1517struct __decay {
1518    typedef _LIBCPP_NODEBUG typename remove_cv<_Up>::type type;
1519};
1520
1521template <class _Up>
1522struct __decay<_Up, true> {
1523public:
1524    typedef _LIBCPP_NODEBUG typename conditional
1525                     <
1526                         is_array<_Up>::value,
1527                         typename remove_extent<_Up>::type*,
1528                         typename conditional
1529                         <
1530                              is_function<_Up>::value,
1531                              typename add_pointer<_Up>::type,
1532                              typename remove_cv<_Up>::type
1533                         >::type
1534                     >::type type;
1535};
1536
1537template <class _Tp>
1538struct _LIBCPP_TEMPLATE_VIS decay
1539{
1540private:
1541    typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up;
1542public:
1543    typedef _LIBCPP_NODEBUG typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
1544};
1545
1546#if _LIBCPP_STD_VER > 11
1547template <class _Tp> using decay_t = typename decay<_Tp>::type;
1548#endif
1549
1550// is_abstract
1551
1552template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract
1553    : public integral_constant<bool, __is_abstract(_Tp)> {};
1554
1555#if _LIBCPP_STD_VER > 14
1556template <class _Tp>
1557inline constexpr bool is_abstract_v = is_abstract<_Tp>::value;
1558#endif
1559
1560// is_final
1561
1562template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1563__libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {};
1564
1565#if _LIBCPP_STD_VER > 11
1566template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1567is_final : public integral_constant<bool, __is_final(_Tp)> {};
1568#endif
1569
1570#if _LIBCPP_STD_VER > 14
1571template <class _Tp>
1572inline constexpr bool is_final_v = is_final<_Tp>::value;
1573#endif
1574
1575// is_aggregate
1576#if _LIBCPP_STD_VER > 14
1577
1578template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
1579is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
1580
1581template <class _Tp>
1582inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
1583
1584#endif // _LIBCPP_STD_VER > 14
1585
1586// is_base_of
1587
1588template <class _Bp, class _Dp>
1589struct _LIBCPP_TEMPLATE_VIS is_base_of
1590    : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
1591
1592#if _LIBCPP_STD_VER > 14
1593template <class _Bp, class _Dp>
1594inline constexpr bool is_base_of_v = is_base_of<_Bp, _Dp>::value;
1595#endif
1596
1597// __is_core_convertible
1598
1599// [conv.general]/3 says "E is convertible to T" whenever "T t=E;" is well-formed.
1600// We can't test for that, but we can test implicit convertibility by passing it
1601// to a function. Notice that __is_core_convertible<void,void> is false,
1602// and __is_core_convertible<immovable-type,immovable-type> is true in C++17 and later.
1603
1604template <class _Tp, class _Up, class = void>
1605struct __is_core_convertible : public false_type {};
1606
1607template <class _Tp, class _Up>
1608struct __is_core_convertible<_Tp, _Up, decltype(
1609    static_cast<void(*)(_Up)>(0) ( static_cast<_Tp(*)()>(0)() )
1610)> : public true_type {};
1611
1612// is_convertible
1613
1614#if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
1615
1616template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
1617    : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
1618
1619#else  // __has_feature(is_convertible_to)
1620
1621namespace __is_convertible_imp
1622{
1623template <class _Tp> void  __test_convert(_Tp);
1624
1625template <class _From, class _To, class = void>
1626struct __is_convertible_test : public false_type {};
1627
1628template <class _From, class _To>
1629struct __is_convertible_test<_From, _To,
1630    decltype(__is_convertible_imp::__test_convert<_To>(declval<_From>()))> : public true_type
1631{};
1632
1633template <class _Tp, bool _IsArray =    is_array<_Tp>::value,
1634                     bool _IsFunction = is_function<_Tp>::value,
1635                     bool _IsVoid =     is_void<_Tp>::value>
1636                     struct __is_array_function_or_void                          {enum {value = 0};};
1637template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
1638template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
1639template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
1640}
1641
1642template <class _Tp,
1643    unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
1644struct __is_convertible_check
1645{
1646    static const size_t __v = 0;
1647};
1648
1649template <class _Tp>
1650struct __is_convertible_check<_Tp, 0>
1651{
1652    static const size_t __v = sizeof(_Tp);
1653};
1654
1655template <class _T1, class _T2,
1656    unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
1657    unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
1658struct __is_convertible
1659    : public integral_constant<bool,
1660        __is_convertible_imp::__is_convertible_test<_T1, _T2>::value
1661    >
1662{};
1663
1664template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
1665template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
1666template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
1667template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
1668
1669template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
1670template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
1671template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
1672template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
1673
1674template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
1675template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
1676template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
1677template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
1678
1679template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
1680    : public __is_convertible<_T1, _T2>
1681{
1682    static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
1683    static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
1684};
1685
1686#endif // __has_feature(is_convertible_to)
1687
1688#if _LIBCPP_STD_VER > 14
1689template <class _From, class _To>
1690inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
1691#endif
1692
1693// is_nothrow_convertible
1694
1695#if _LIBCPP_STD_VER > 17
1696
1697template <typename _Tp>
1698static void __test_noexcept(_Tp) noexcept;
1699
1700template<typename _Fm, typename _To>
1701static bool_constant<noexcept(_VSTD::__test_noexcept<_To>(declval<_Fm>()))>
1702__is_nothrow_convertible_test();
1703
1704template <typename _Fm, typename _To>
1705struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>())
1706{ };
1707
1708template <typename _Fm, typename _To>
1709struct is_nothrow_convertible : _Or<
1710    _And<is_void<_To>, is_void<_Fm>>,
1711    _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>>
1712>::type { };
1713
1714template <typename _Fm, typename _To>
1715inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
1716
1717#endif // _LIBCPP_STD_VER > 17
1718
1719// is_empty
1720
1721#if __has_feature(is_empty) || defined(_LIBCPP_COMPILER_GCC)
1722
1723template <class _Tp>
1724struct _LIBCPP_TEMPLATE_VIS is_empty
1725    : public integral_constant<bool, __is_empty(_Tp)> {};
1726
1727#else  // __has_feature(is_empty)
1728
1729template <class _Tp>
1730struct __is_empty1
1731    : public _Tp
1732{
1733    double __lx;
1734};
1735
1736struct __is_empty2
1737{
1738    double __lx;
1739};
1740
1741template <class _Tp, bool = is_class<_Tp>::value>
1742struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
1743
1744template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
1745
1746template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empty<_Tp> {};
1747
1748#endif // __has_feature(is_empty)
1749
1750#if _LIBCPP_STD_VER > 14
1751template <class _Tp>
1752inline constexpr bool is_empty_v = is_empty<_Tp>::value;
1753#endif
1754
1755// is_polymorphic
1756
1757#if __has_feature(is_polymorphic) || defined(_LIBCPP_COMPILER_MSVC)
1758
1759template <class _Tp>
1760struct _LIBCPP_TEMPLATE_VIS is_polymorphic
1761    : public integral_constant<bool, __is_polymorphic(_Tp)> {};
1762
1763#else
1764
1765template<typename _Tp> char &__is_polymorphic_impl(
1766    typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
1767                       int>::type);
1768template<typename _Tp> __two &__is_polymorphic_impl(...);
1769
1770template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic
1771    : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
1772
1773#endif // __has_feature(is_polymorphic)
1774
1775#if _LIBCPP_STD_VER > 14
1776template <class _Tp>
1777inline constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value;
1778#endif
1779
1780// has_virtual_destructor
1781
1782#if __has_feature(has_virtual_destructor) || defined(_LIBCPP_COMPILER_GCC)
1783
1784template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
1785    : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
1786
1787#else
1788
1789template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
1790    : public false_type {};
1791
1792#endif
1793
1794#if _LIBCPP_STD_VER > 14
1795template <class _Tp>
1796inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<_Tp>::value;
1797#endif
1798
1799// has_unique_object_representations
1800
1801#if _LIBCPP_STD_VER > 14
1802
1803template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
1804    : public integral_constant<bool,
1805       __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
1806
1807template <class _Tp>
1808inline constexpr bool has_unique_object_representations_v = has_unique_object_representations<_Tp>::value;
1809
1810#endif
1811
1812// alignment_of
1813
1814template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
1815    : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
1816
1817#if _LIBCPP_STD_VER > 14
1818template <class _Tp>
1819inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
1820#endif
1821
1822// aligned_storage
1823
1824template <class _Hp, class _Tp>
1825struct __type_list
1826{
1827    typedef _Hp _Head;
1828    typedef _Tp _Tail;
1829};
1830
1831struct __nat
1832{
1833#ifndef _LIBCPP_CXX03_LANG
1834    __nat() = delete;
1835    __nat(const __nat&) = delete;
1836    __nat& operator=(const __nat&) = delete;
1837    ~__nat() = delete;
1838#endif
1839};
1840
1841template <class _Tp>
1842struct __align_type
1843{
1844    static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp);
1845    typedef _Tp type;
1846};
1847
1848struct __struct_double {long double __lx;};
1849struct __struct_double4 {double __lx[4];};
1850
1851typedef
1852    __type_list<__align_type<unsigned char>,
1853    __type_list<__align_type<unsigned short>,
1854    __type_list<__align_type<unsigned int>,
1855    __type_list<__align_type<unsigned long>,
1856    __type_list<__align_type<unsigned long long>,
1857    __type_list<__align_type<double>,
1858    __type_list<__align_type<long double>,
1859    __type_list<__align_type<__struct_double>,
1860    __type_list<__align_type<__struct_double4>,
1861    __type_list<__align_type<int*>,
1862    __nat
1863    > > > > > > > > > > __all_types;
1864
1865template <size_t _Align>
1866struct _ALIGNAS(_Align) __fallback_overaligned {};
1867
1868template <class _TL, size_t _Align> struct __find_pod;
1869
1870template <class _Hp, size_t _Align>
1871struct __find_pod<__type_list<_Hp, __nat>, _Align>
1872{
1873    typedef typename conditional<
1874                             _Align == _Hp::value,
1875                             typename _Hp::type,
1876                             __fallback_overaligned<_Align>
1877                         >::type type;
1878};
1879
1880template <class _Hp, class _Tp, size_t _Align>
1881struct __find_pod<__type_list<_Hp, _Tp>, _Align>
1882{
1883    typedef typename conditional<
1884                             _Align == _Hp::value,
1885                             typename _Hp::type,
1886                             typename __find_pod<_Tp, _Align>::type
1887                         >::type type;
1888};
1889
1890template <class _TL, size_t _Len> struct __find_max_align;
1891
1892template <class _Hp, size_t _Len>
1893struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
1894
1895template <size_t _Len, size_t _A1, size_t _A2>
1896struct __select_align
1897{
1898private:
1899    static const size_t __min = _A2 < _A1 ? _A2 : _A1;
1900    static const size_t __max = _A1 < _A2 ? _A2 : _A1;
1901public:
1902    static const size_t value = _Len < __max ? __min : __max;
1903};
1904
1905template <class _Hp, class _Tp, size_t _Len>
1906struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
1907    : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
1908
1909template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1910struct _LIBCPP_TEMPLATE_VIS aligned_storage
1911{
1912    typedef typename __find_pod<__all_types, _Align>::type _Aligner;
1913    union type
1914    {
1915        _Aligner __align;
1916        unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
1917    };
1918};
1919
1920#if _LIBCPP_STD_VER > 11
1921template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1922    using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
1923#endif
1924
1925#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
1926template <size_t _Len>\
1927struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
1928{\
1929    struct _ALIGNAS(n) type\
1930    {\
1931        unsigned char __lx[(_Len + n - 1)/n * n];\
1932    };\
1933}
1934
1935_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
1936_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
1937_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
1938_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
1939_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
1940_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
1941_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
1942_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
1943_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
1944_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
1945_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
1946_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
1947_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
1948_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
1949// PE/COFF does not support alignment beyond 8192 (=0x2000)
1950#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1951_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
1952#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1953
1954#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
1955
1956
1957// aligned_union
1958
1959template <size_t _I0, size_t ..._In>
1960struct __static_max;
1961
1962template <size_t _I0>
1963struct __static_max<_I0>
1964{
1965    static const size_t value = _I0;
1966};
1967
1968template <size_t _I0, size_t _I1, size_t ..._In>
1969struct __static_max<_I0, _I1, _In...>
1970{
1971    static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
1972                                             __static_max<_I1, _In...>::value;
1973};
1974
1975template <size_t _Len, class _Type0, class ..._Types>
1976struct aligned_union
1977{
1978    static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0),
1979                                                       _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
1980    static const size_t __len = __static_max<_Len, sizeof(_Type0),
1981                                             sizeof(_Types)...>::value;
1982    typedef typename aligned_storage<__len, alignment_value>::type type;
1983};
1984
1985#if _LIBCPP_STD_VER > 11
1986template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
1987#endif
1988
1989template <class _Tp>
1990struct __numeric_type
1991{
1992   static void __test(...);
1993   static float __test(float);
1994   static double __test(char);
1995   static double __test(int);
1996   static double __test(unsigned);
1997   static double __test(long);
1998   static double __test(unsigned long);
1999   static double __test(long long);
2000   static double __test(unsigned long long);
2001   static double __test(double);
2002   static long double __test(long double);
2003
2004   typedef decltype(__test(declval<_Tp>())) type;
2005   static const bool value = _IsNotSame<type, void>::value;
2006};
2007
2008template <>
2009struct __numeric_type<void>
2010{
2011   static const bool value = true;
2012};
2013
2014// __promote
2015
2016template <class _A1, class _A2 = void, class _A3 = void,
2017          bool = __numeric_type<_A1>::value &&
2018                 __numeric_type<_A2>::value &&
2019                 __numeric_type<_A3>::value>
2020class __promote_imp
2021{
2022public:
2023    static const bool value = false;
2024};
2025
2026template <class _A1, class _A2, class _A3>
2027class __promote_imp<_A1, _A2, _A3, true>
2028{
2029private:
2030    typedef typename __promote_imp<_A1>::type __type1;
2031    typedef typename __promote_imp<_A2>::type __type2;
2032    typedef typename __promote_imp<_A3>::type __type3;
2033public:
2034    typedef decltype(__type1() + __type2() + __type3()) type;
2035    static const bool value = true;
2036};
2037
2038template <class _A1, class _A2>
2039class __promote_imp<_A1, _A2, void, true>
2040{
2041private:
2042    typedef typename __promote_imp<_A1>::type __type1;
2043    typedef typename __promote_imp<_A2>::type __type2;
2044public:
2045    typedef decltype(__type1() + __type2()) type;
2046    static const bool value = true;
2047};
2048
2049template <class _A1>
2050class __promote_imp<_A1, void, void, true>
2051{
2052public:
2053    typedef typename __numeric_type<_A1>::type type;
2054    static const bool value = true;
2055};
2056
2057template <class _A1, class _A2 = void, class _A3 = void>
2058class __promote : public __promote_imp<_A1, _A2, _A3> {};
2059
2060// make_signed / make_unsigned
2061
2062typedef
2063    __type_list<signed char,
2064    __type_list<signed short,
2065    __type_list<signed int,
2066    __type_list<signed long,
2067    __type_list<signed long long,
2068#ifndef _LIBCPP_HAS_NO_INT128
2069    __type_list<__int128_t,
2070#endif
2071    __nat
2072#ifndef _LIBCPP_HAS_NO_INT128
2073    >
2074#endif
2075    > > > > > __signed_types;
2076
2077typedef
2078    __type_list<unsigned char,
2079    __type_list<unsigned short,
2080    __type_list<unsigned int,
2081    __type_list<unsigned long,
2082    __type_list<unsigned long long,
2083#ifndef _LIBCPP_HAS_NO_INT128
2084    __type_list<__uint128_t,
2085#endif
2086    __nat
2087#ifndef _LIBCPP_HAS_NO_INT128
2088    >
2089#endif
2090    > > > > > __unsigned_types;
2091
2092template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
2093
2094template <class _Hp, class _Tp, size_t _Size>
2095struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
2096{
2097    typedef _LIBCPP_NODEBUG _Hp type;
2098};
2099
2100template <class _Hp, class _Tp, size_t _Size>
2101struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
2102{
2103    typedef _LIBCPP_NODEBUG typename __find_first<_Tp, _Size>::type type;
2104};
2105
2106template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
2107                             bool = is_volatile<typename remove_reference<_Tp>::type>::value>
2108struct __apply_cv
2109{
2110    typedef _LIBCPP_NODEBUG _Up type;
2111};
2112
2113template <class _Tp, class _Up>
2114struct __apply_cv<_Tp, _Up, true, false>
2115{
2116    typedef _LIBCPP_NODEBUG const _Up type;
2117};
2118
2119template <class _Tp, class _Up>
2120struct __apply_cv<_Tp, _Up, false, true>
2121{
2122    typedef volatile _Up type;
2123};
2124
2125template <class _Tp, class _Up>
2126struct __apply_cv<_Tp, _Up, true, true>
2127{
2128    typedef const volatile _Up type;
2129};
2130
2131template <class _Tp, class _Up>
2132struct __apply_cv<_Tp&, _Up, false, false>
2133{
2134    typedef _Up& type;
2135};
2136
2137template <class _Tp, class _Up>
2138struct __apply_cv<_Tp&, _Up, true, false>
2139{
2140    typedef const _Up& type;
2141};
2142
2143template <class _Tp, class _Up>
2144struct __apply_cv<_Tp&, _Up, false, true>
2145{
2146    typedef volatile _Up& type;
2147};
2148
2149template <class _Tp, class _Up>
2150struct __apply_cv<_Tp&, _Up, true, true>
2151{
2152    typedef const volatile _Up& type;
2153};
2154
2155template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
2156struct __make_signed {};
2157
2158template <class _Tp>
2159struct __make_signed<_Tp, true>
2160{
2161    typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
2162};
2163
2164template <> struct __make_signed<bool,               true> {};
2165template <> struct __make_signed<  signed short,     true> {typedef short     type;};
2166template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
2167template <> struct __make_signed<  signed int,       true> {typedef int       type;};
2168template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
2169template <> struct __make_signed<  signed long,      true> {typedef long      type;};
2170template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
2171template <> struct __make_signed<  signed long long, true> {typedef long long type;};
2172template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
2173#ifndef _LIBCPP_HAS_NO_INT128
2174template <> struct __make_signed<__int128_t,         true> {typedef __int128_t type;};
2175template <> struct __make_signed<__uint128_t,        true> {typedef __int128_t type;};
2176#endif
2177
2178template <class _Tp>
2179struct _LIBCPP_TEMPLATE_VIS make_signed
2180{
2181    typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
2182};
2183
2184#if _LIBCPP_STD_VER > 11
2185template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
2186#endif
2187
2188template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
2189struct __make_unsigned {};
2190
2191template <class _Tp>
2192struct __make_unsigned<_Tp, true>
2193{
2194    typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
2195};
2196
2197template <> struct __make_unsigned<bool,               true> {};
2198template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
2199template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
2200template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
2201template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
2202template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
2203template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
2204template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
2205template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
2206#ifndef _LIBCPP_HAS_NO_INT128
2207template <> struct __make_unsigned<__int128_t,         true> {typedef __uint128_t        type;};
2208template <> struct __make_unsigned<__uint128_t,        true> {typedef __uint128_t        type;};
2209#endif
2210
2211template <class _Tp>
2212struct _LIBCPP_TEMPLATE_VIS make_unsigned
2213{
2214    typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
2215};
2216
2217#if _LIBCPP_STD_VER > 11
2218template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
2219#endif
2220
2221#ifndef _LIBCPP_CXX03_LANG
2222template <class _Tp>
2223_LIBCPP_HIDE_FROM_ABI constexpr
2224typename make_unsigned<_Tp>::type __to_unsigned_like(_Tp __x) noexcept {
2225    return static_cast<typename make_unsigned<_Tp>::type>(__x);
2226}
2227#endif
2228
2229#if _LIBCPP_STD_VER > 14
2230template <class...> using void_t = void;
2231#endif
2232
2233#if _LIBCPP_STD_VER > 17
2234// Let COND_RES(X, Y) be:
2235template <class _Tp, class _Up>
2236using __cond_type = decltype(false ? declval<_Tp>() : declval<_Up>());
2237
2238template <class _Tp, class _Up, class = void>
2239struct __common_type3 {};
2240
2241// sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
2242template <class _Tp, class _Up>
2243struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>>
2244{
2245    using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
2246};
2247
2248template <class _Tp, class _Up, class = void>
2249struct __common_type2_imp : __common_type3<_Tp, _Up> {};
2250#else
2251template <class _Tp, class _Up, class = void>
2252struct __common_type2_imp {};
2253#endif
2254
2255// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
2256template <class _Tp, class _Up>
2257struct __common_type2_imp<_Tp, _Up,
2258                          typename __void_t<decltype(
2259                                            true ? declval<_Tp>() : declval<_Up>()
2260                                            )>::type>
2261{
2262  typedef _LIBCPP_NODEBUG typename decay<decltype(
2263                         true ? declval<_Tp>() : declval<_Up>()
2264                         )>::type type;
2265};
2266
2267template <class, class = void>
2268struct __common_type_impl {};
2269
2270// Clang provides variadic templates in C++03 as an extension.
2271#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__)
2272# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
2273template <class... _Tp>
2274struct __common_types;
2275template <class... _Tp>
2276struct _LIBCPP_TEMPLATE_VIS common_type;
2277#else
2278# define _LIBCPP_OPTIONAL_PACK(...)
2279struct __no_arg;
2280template <class _Tp, class _Up, class = __no_arg>
2281struct __common_types;
2282template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg,
2283          class _Unused = __no_arg>
2284struct common_type {
2285  static_assert(sizeof(_Unused) == 0,
2286                "common_type accepts at most 3 arguments in C++03");
2287};
2288#endif // _LIBCPP_CXX03_LANG
2289
2290template <class _Tp, class _Up>
2291struct __common_type_impl<
2292    __common_types<_Tp, _Up>,
2293    typename __void_t<typename common_type<_Tp, _Up>::type>::type>
2294{
2295  typedef typename common_type<_Tp, _Up>::type type;
2296};
2297
2298template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
2299struct __common_type_impl<
2300    __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>,
2301    typename __void_t<typename common_type<_Tp, _Up>::type>::type>
2302    : __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type,
2303                                        _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {
2304};
2305
2306// bullet 1 - sizeof...(Tp) == 0
2307
2308template <>
2309struct _LIBCPP_TEMPLATE_VIS common_type<> {};
2310
2311// bullet 2 - sizeof...(Tp) == 1
2312
2313template <class _Tp>
2314struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
2315    : public common_type<_Tp, _Tp> {};
2316
2317// bullet 3 - sizeof...(Tp) == 2
2318
2319// sub-bullet 1 - "If is_same_v<T1, D1> is false or ..."
2320template <class _Tp, class _Up>
2321struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
2322    : conditional<
2323        _IsSame<_Tp, typename decay<_Tp>::type>::value && _IsSame<_Up, typename decay<_Up>::type>::value,
2324        __common_type2_imp<_Tp, _Up>,
2325        common_type<typename decay<_Tp>::type, typename decay<_Up>::type>
2326    >::type
2327{};
2328
2329// bullet 4 - sizeof...(Tp) > 2
2330
2331template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
2332struct _LIBCPP_TEMPLATE_VIS
2333    common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>
2334    : __common_type_impl<
2335          __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {};
2336
2337#undef _LIBCPP_OPTIONAL_PACK
2338
2339#if _LIBCPP_STD_VER > 11
2340template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
2341#endif
2342
2343#if _LIBCPP_STD_VER > 11
2344// Let COPYCV(FROM, TO) be an alias for type TO with the addition of FROM's
2345// top-level cv-qualifiers.
2346template <class _From, class _To>
2347struct __copy_cv
2348{
2349    using type = _To;
2350};
2351
2352template <class _From, class _To>
2353struct __copy_cv<const _From, _To>
2354{
2355    using type = add_const_t<_To>;
2356};
2357
2358template <class _From, class _To>
2359struct __copy_cv<volatile _From, _To>
2360{
2361    using type = add_volatile_t<_To>;
2362};
2363
2364template <class _From, class _To>
2365struct __copy_cv<const volatile _From, _To>
2366{
2367    using type = add_cv_t<_To>;
2368};
2369
2370template <class _From, class _To>
2371using __copy_cv_t = typename __copy_cv<_From, _To>::type;
2372
2373template <class _From, class _To>
2374struct __copy_cvref
2375{
2376    using type = __copy_cv_t<_From, _To>;
2377};
2378
2379template <class _From, class _To>
2380struct __copy_cvref<_From&, _To>
2381{
2382    using type = add_lvalue_reference_t<__copy_cv_t<_From, _To>>;
2383};
2384
2385template <class _From, class _To>
2386struct __copy_cvref<_From&&, _To>
2387{
2388    using type = add_rvalue_reference_t<__copy_cv_t<_From, _To>>;
2389};
2390
2391template <class _From, class _To>
2392using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
2393
2394#endif // _LIBCPP_STD_VER > 11
2395
2396// common_reference
2397#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
2398// Let COND_RES(X, Y) be:
2399template <class _Xp, class _Yp>
2400using __cond_res =
2401    decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
2402
2403// Let `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes the same type as `U`
2404// with the addition of `A`'s cv and reference qualifiers, for a non-reference cv-unqualified type
2405// `U`.
2406// [Note: `XREF(A)` is `__xref<A>::template __apply`]
2407template <class _Tp>
2408struct __xref {
2409  template<class _Up>
2410  using __apply = __copy_cvref_t<_Tp, _Up>;
2411};
2412
2413// Given types A and B, let X be remove_reference_t<A>, let Y be remove_reference_t<B>,
2414// and let COMMON-REF(A, B) be:
2415template<class _Ap, class _Bp, class _Xp = remove_reference_t<_Ap>, class _Yp = remove_reference_t<_Bp>>
2416struct __common_ref;
2417
2418template<class _Xp, class _Yp>
2419using __common_ref_t = typename __common_ref<_Xp, _Yp>::__type;
2420
2421template<class _Xp, class _Yp>
2422using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>;
2423
2424
2425//    If A and B are both lvalue reference types, COMMON-REF(A, B) is
2426//    COND-RES(COPYCV(X, Y)&, COPYCV(Y, X)&) if that type exists and is a reference type.
2427template<class _Ap, class _Bp, class _Xp, class _Yp>
2428requires requires { typename __cv_cond_res<_Xp, _Yp>; } && is_reference_v<__cv_cond_res<_Xp, _Yp>>
2429struct __common_ref<_Ap&, _Bp&, _Xp, _Yp>
2430{
2431    using __type = __cv_cond_res<_Xp, _Yp>;
2432};
2433
2434//    Otherwise, let C be remove_reference_t<COMMON-REF(X&, Y&)>&&. ...
2435template <class _Xp, class _Yp>
2436using __common_ref_C = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
2437
2438
2439//    .... If A and B are both rvalue reference types, C is well-formed, and
2440//    is_convertible_v<A, C> && is_convertible_v<B, C> is true, then COMMON-REF(A, B) is C.
2441template<class _Ap, class _Bp, class _Xp, class _Yp>
2442requires
2443  requires { typename __common_ref_C<_Xp, _Yp>; } &&
2444  is_convertible_v<_Ap&&, __common_ref_C<_Xp, _Yp>> &&
2445  is_convertible_v<_Bp&&, __common_ref_C<_Xp, _Yp>>
2446struct __common_ref<_Ap&&, _Bp&&, _Xp, _Yp>
2447{
2448    using __type = __common_ref_C<_Xp, _Yp>;
2449};
2450
2451//    Otherwise, let D be COMMON-REF(const X&, Y&). ...
2452template <class _Tp, class _Up>
2453using __common_ref_D = __common_ref_t<const _Tp&, _Up&>;
2454
2455//    ... If A is an rvalue reference and B is an lvalue reference and D is well-formed and
2456//    is_convertible_v<A, D> is true, then COMMON-REF(A, B) is D.
2457template<class _Ap, class _Bp, class _Xp, class _Yp>
2458requires requires { typename __common_ref_D<_Xp, _Yp>; } &&
2459         is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>>
2460struct __common_ref<_Ap&&, _Bp&, _Xp, _Yp>
2461{
2462    using __type = __common_ref_D<_Xp, _Yp>;
2463};
2464
2465//    Otherwise, if A is an lvalue reference and B is an rvalue reference, then
2466//    COMMON-REF(A, B) is COMMON-REF(B, A).
2467template<class _Ap, class _Bp, class _Xp, class _Yp>
2468struct __common_ref<_Ap&, _Bp&&, _Xp, _Yp> : __common_ref<_Bp&&, _Ap&> {};
2469
2470//    Otherwise, COMMON-REF(A, B) is ill-formed.
2471template<class _Ap, class _Bp, class _Xp, class _Yp>
2472struct __common_ref {};
2473
2474// Note C: For the common_reference trait applied to a parameter pack [...]
2475
2476template <class...>
2477struct common_reference;
2478
2479template <class... _Types>
2480using common_reference_t = typename common_reference<_Types...>::type;
2481
2482// bullet 1 - sizeof...(T) == 0
2483template<>
2484struct common_reference<> {};
2485
2486// bullet 2 - sizeof...(T) == 1
2487template <class _Tp>
2488struct common_reference<_Tp>
2489{
2490    using type = _Tp;
2491};
2492
2493// bullet 3 - sizeof...(T) == 2
2494template <class _Tp, class _Up> struct __common_reference_sub_bullet3;
2495template <class _Tp, class _Up> struct __common_reference_sub_bullet2 : __common_reference_sub_bullet3<_Tp, _Up> {};
2496template <class _Tp, class _Up> struct __common_reference_sub_bullet1 : __common_reference_sub_bullet2<_Tp, _Up> {};
2497
2498// sub-bullet 1 - If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, then
2499// the member typedef `type` denotes that type.
2500template <class _Tp, class _Up> struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
2501
2502template <class _Tp, class _Up>
2503requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
2504struct __common_reference_sub_bullet1<_Tp, _Up>
2505{
2506    using type = __common_ref_t<_Tp, _Up>;
2507};
2508
2509// sub-bullet 2 - Otherwise, if basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>, XREF(T1), XREF(T2)>::type
2510// is well-formed, then the member typedef `type` denotes that type.
2511template <class, class, template <class> class, template <class> class> struct basic_common_reference {};
2512
2513template <class _Tp, class _Up>
2514using __basic_common_reference_t = typename basic_common_reference<
2515    remove_cvref_t<_Tp>, remove_cvref_t<_Up>,
2516    __xref<_Tp>::template __apply, __xref<_Up>::template __apply>::type;
2517
2518template <class _Tp, class _Up>
2519requires requires { typename __basic_common_reference_t<_Tp, _Up>; }
2520struct __common_reference_sub_bullet2<_Tp, _Up>
2521{
2522    using type = __basic_common_reference_t<_Tp, _Up>;
2523};
2524
2525// sub-bullet 3 - Otherwise, if COND-RES(T1, T2) is well-formed,
2526// then the member typedef `type` denotes that type.
2527template <class _Tp, class _Up>
2528requires requires { typename __cond_res<_Tp, _Up>; }
2529struct __common_reference_sub_bullet3<_Tp, _Up>
2530{
2531    using type = __cond_res<_Tp, _Up>;
2532};
2533
2534
2535// sub-bullet 4 & 5 - Otherwise, if common_type_t<T1, T2> is well-formed,
2536//                    then the member typedef `type` denotes that type.
2537//                  - Otherwise, there shall be no member `type`.
2538template <class _Tp, class _Up> struct __common_reference_sub_bullet3 : common_type<_Tp, _Up> {};
2539
2540// bullet 4 - If there is such a type `C`, the member typedef type shall denote the same type, if
2541//            any, as `common_reference_t<C, Rest...>`.
2542template <class _Tp, class _Up, class _Vp, class... _Rest>
2543requires requires { typename common_reference_t<_Tp, _Up>; }
2544struct common_reference<_Tp, _Up, _Vp, _Rest...>
2545    : common_reference<common_reference_t<_Tp, _Up>, _Vp, _Rest...>
2546{};
2547
2548// bullet 5 - Otherwise, there shall be no member `type`.
2549template <class...> struct common_reference {};
2550
2551#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
2552
2553// is_assignable
2554
2555template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG _Tp type; };
2556
2557#if __has_keyword(__is_assignable)
2558
2559template<class _Tp, class _Up>
2560struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
2561
2562#if _LIBCPP_STD_VER > 14
2563template <class _Tp, class _Arg>
2564inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
2565#endif
2566
2567#else // __has_keyword(__is_assignable)
2568
2569template <class _Tp, class _Arg>
2570typename __select_2nd<decltype((declval<_Tp>() = declval<_Arg>())), true_type>::type
2571__is_assignable_test(int);
2572
2573template <class, class>
2574false_type __is_assignable_test(...);
2575
2576
2577template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
2578struct __is_assignable_imp
2579    : public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {};
2580
2581template <class _Tp, class _Arg>
2582struct __is_assignable_imp<_Tp, _Arg, true>
2583    : public false_type
2584{
2585};
2586
2587template <class _Tp, class _Arg>
2588struct is_assignable
2589    : public __is_assignable_imp<_Tp, _Arg> {};
2590
2591#if _LIBCPP_STD_VER > 14
2592template <class _Tp, class _Arg>
2593inline constexpr bool is_assignable_v = is_assignable<_Tp, _Arg>::value;
2594#endif
2595
2596#endif // __has_keyword(__is_assignable)
2597
2598// is_copy_assignable
2599
2600template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
2601    : public is_assignable<typename add_lvalue_reference<_Tp>::type,
2602                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2603
2604#if _LIBCPP_STD_VER > 14
2605template <class _Tp>
2606inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
2607#endif
2608
2609// is_move_assignable
2610
2611template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable
2612    : public is_assignable<typename add_lvalue_reference<_Tp>::type,
2613                           typename add_rvalue_reference<_Tp>::type> {};
2614
2615#if _LIBCPP_STD_VER > 14
2616template <class _Tp>
2617inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
2618#endif
2619
2620// is_destructible
2621
2622#if __has_keyword(__is_destructible)
2623
2624template<class _Tp>
2625struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
2626
2627#if _LIBCPP_STD_VER > 14
2628template <class _Tp>
2629inline constexpr bool is_destructible_v = __is_destructible(_Tp);
2630#endif
2631
2632#else // __has_keyword(__is_destructible)
2633
2634//  if it's a reference, return true
2635//  if it's a function, return false
2636//  if it's   void,     return false
2637//  if it's an array of unknown bound, return false
2638//  Otherwise, return "declval<_Up&>().~_Up()" is well-formed
2639//    where _Up is remove_all_extents<_Tp>::type
2640
2641template <class>
2642struct __is_destructible_apply { typedef int type; };
2643
2644template <typename _Tp>
2645struct __is_destructor_wellformed {
2646    template <typename _Tp1>
2647    static char  __test (
2648        typename __is_destructible_apply<decltype(declval<_Tp1&>().~_Tp1())>::type
2649    );
2650
2651    template <typename _Tp1>
2652    static __two __test (...);
2653
2654    static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
2655};
2656
2657template <class _Tp, bool>
2658struct __destructible_imp;
2659
2660template <class _Tp>
2661struct __destructible_imp<_Tp, false>
2662   : public integral_constant<bool,
2663        __is_destructor_wellformed<typename remove_all_extents<_Tp>::type>::value> {};
2664
2665template <class _Tp>
2666struct __destructible_imp<_Tp, true>
2667    : public true_type {};
2668
2669template <class _Tp, bool>
2670struct __destructible_false;
2671
2672template <class _Tp>
2673struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, is_reference<_Tp>::value> {};
2674
2675template <class _Tp>
2676struct __destructible_false<_Tp, true> : public false_type {};
2677
2678template <class _Tp>
2679struct is_destructible
2680    : public __destructible_false<_Tp, is_function<_Tp>::value> {};
2681
2682template <class _Tp>
2683struct is_destructible<_Tp[]>
2684    : public false_type {};
2685
2686template <>
2687struct is_destructible<void>
2688    : public false_type {};
2689
2690#if _LIBCPP_STD_VER > 14
2691template <class _Tp>
2692inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
2693#endif
2694
2695#endif // __has_keyword(__is_destructible)
2696
2697template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
2698struct __member_pointer_traits_imp
2699{
2700};
2701
2702template <class _Rp, class _Class, class ..._Param>
2703struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
2704{
2705    typedef _Class _ClassType;
2706    typedef _Rp _ReturnType;
2707    typedef _Rp (_FnType) (_Param...);
2708};
2709
2710template <class _Rp, class _Class, class ..._Param>
2711struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
2712{
2713    typedef _Class _ClassType;
2714    typedef _Rp _ReturnType;
2715    typedef _Rp (_FnType) (_Param..., ...);
2716};
2717
2718template <class _Rp, class _Class, class ..._Param>
2719struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
2720{
2721    typedef _Class const _ClassType;
2722    typedef _Rp _ReturnType;
2723    typedef _Rp (_FnType) (_Param...);
2724};
2725
2726template <class _Rp, class _Class, class ..._Param>
2727struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
2728{
2729    typedef _Class const _ClassType;
2730    typedef _Rp _ReturnType;
2731    typedef _Rp (_FnType) (_Param..., ...);
2732};
2733
2734template <class _Rp, class _Class, class ..._Param>
2735struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
2736{
2737    typedef _Class volatile _ClassType;
2738    typedef _Rp _ReturnType;
2739    typedef _Rp (_FnType) (_Param...);
2740};
2741
2742template <class _Rp, class _Class, class ..._Param>
2743struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
2744{
2745    typedef _Class volatile _ClassType;
2746    typedef _Rp _ReturnType;
2747    typedef _Rp (_FnType) (_Param..., ...);
2748};
2749
2750template <class _Rp, class _Class, class ..._Param>
2751struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
2752{
2753    typedef _Class const volatile _ClassType;
2754    typedef _Rp _ReturnType;
2755    typedef _Rp (_FnType) (_Param...);
2756};
2757
2758template <class _Rp, class _Class, class ..._Param>
2759struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
2760{
2761    typedef _Class const volatile _ClassType;
2762    typedef _Rp _ReturnType;
2763    typedef _Rp (_FnType) (_Param..., ...);
2764};
2765
2766#if __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
2767
2768template <class _Rp, class _Class, class ..._Param>
2769struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
2770{
2771    typedef _Class& _ClassType;
2772    typedef _Rp _ReturnType;
2773    typedef _Rp (_FnType) (_Param...);
2774};
2775
2776template <class _Rp, class _Class, class ..._Param>
2777struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
2778{
2779    typedef _Class& _ClassType;
2780    typedef _Rp _ReturnType;
2781    typedef _Rp (_FnType) (_Param..., ...);
2782};
2783
2784template <class _Rp, class _Class, class ..._Param>
2785struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
2786{
2787    typedef _Class const& _ClassType;
2788    typedef _Rp _ReturnType;
2789    typedef _Rp (_FnType) (_Param...);
2790};
2791
2792template <class _Rp, class _Class, class ..._Param>
2793struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
2794{
2795    typedef _Class const& _ClassType;
2796    typedef _Rp _ReturnType;
2797    typedef _Rp (_FnType) (_Param..., ...);
2798};
2799
2800template <class _Rp, class _Class, class ..._Param>
2801struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
2802{
2803    typedef _Class volatile& _ClassType;
2804    typedef _Rp _ReturnType;
2805    typedef _Rp (_FnType) (_Param...);
2806};
2807
2808template <class _Rp, class _Class, class ..._Param>
2809struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
2810{
2811    typedef _Class volatile& _ClassType;
2812    typedef _Rp _ReturnType;
2813    typedef _Rp (_FnType) (_Param..., ...);
2814};
2815
2816template <class _Rp, class _Class, class ..._Param>
2817struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
2818{
2819    typedef _Class const volatile& _ClassType;
2820    typedef _Rp _ReturnType;
2821    typedef _Rp (_FnType) (_Param...);
2822};
2823
2824template <class _Rp, class _Class, class ..._Param>
2825struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
2826{
2827    typedef _Class const volatile& _ClassType;
2828    typedef _Rp _ReturnType;
2829    typedef _Rp (_FnType) (_Param..., ...);
2830};
2831
2832template <class _Rp, class _Class, class ..._Param>
2833struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
2834{
2835    typedef _Class&& _ClassType;
2836    typedef _Rp _ReturnType;
2837    typedef _Rp (_FnType) (_Param...);
2838};
2839
2840template <class _Rp, class _Class, class ..._Param>
2841struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
2842{
2843    typedef _Class&& _ClassType;
2844    typedef _Rp _ReturnType;
2845    typedef _Rp (_FnType) (_Param..., ...);
2846};
2847
2848template <class _Rp, class _Class, class ..._Param>
2849struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
2850{
2851    typedef _Class const&& _ClassType;
2852    typedef _Rp _ReturnType;
2853    typedef _Rp (_FnType) (_Param...);
2854};
2855
2856template <class _Rp, class _Class, class ..._Param>
2857struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
2858{
2859    typedef _Class const&& _ClassType;
2860    typedef _Rp _ReturnType;
2861    typedef _Rp (_FnType) (_Param..., ...);
2862};
2863
2864template <class _Rp, class _Class, class ..._Param>
2865struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
2866{
2867    typedef _Class volatile&& _ClassType;
2868    typedef _Rp _ReturnType;
2869    typedef _Rp (_FnType) (_Param...);
2870};
2871
2872template <class _Rp, class _Class, class ..._Param>
2873struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
2874{
2875    typedef _Class volatile&& _ClassType;
2876    typedef _Rp _ReturnType;
2877    typedef _Rp (_FnType) (_Param..., ...);
2878};
2879
2880template <class _Rp, class _Class, class ..._Param>
2881struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
2882{
2883    typedef _Class const volatile&& _ClassType;
2884    typedef _Rp _ReturnType;
2885    typedef _Rp (_FnType) (_Param...);
2886};
2887
2888template <class _Rp, class _Class, class ..._Param>
2889struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
2890{
2891    typedef _Class const volatile&& _ClassType;
2892    typedef _Rp _ReturnType;
2893    typedef _Rp (_FnType) (_Param..., ...);
2894};
2895
2896#endif // __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
2897
2898
2899template <class _Rp, class _Class>
2900struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
2901{
2902    typedef _Class _ClassType;
2903    typedef _Rp _ReturnType;
2904};
2905
2906template <class _MP>
2907struct __member_pointer_traits
2908    : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
2909                    is_member_function_pointer<_MP>::value,
2910                    is_member_object_pointer<_MP>::value>
2911{
2912//     typedef ... _ClassType;
2913//     typedef ... _ReturnType;
2914//     typedef ... _FnType;
2915};
2916
2917
2918template <class _DecayedFp>
2919struct __member_pointer_class_type {};
2920
2921template <class _Ret, class _ClassType>
2922struct __member_pointer_class_type<_Ret _ClassType::*> {
2923  typedef _ClassType type;
2924};
2925
2926// template <class T, class... Args> struct is_constructible;
2927
2928template <class _Tp, class ..._Args>
2929struct _LIBCPP_TEMPLATE_VIS is_constructible
2930    : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
2931{ };
2932
2933#if _LIBCPP_STD_VER > 14
2934template <class _Tp, class ..._Args>
2935inline constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value;
2936#endif
2937
2938// is_default_constructible
2939
2940template <class _Tp>
2941struct _LIBCPP_TEMPLATE_VIS is_default_constructible
2942    : public is_constructible<_Tp>
2943    {};
2944
2945#if _LIBCPP_STD_VER > 14
2946template <class _Tp>
2947inline constexpr bool is_default_constructible_v = is_default_constructible<_Tp>::value;
2948#endif
2949
2950#ifndef _LIBCPP_CXX03_LANG
2951// First of all, we can't implement this check in C++03 mode because the {}
2952// default initialization syntax isn't valid.
2953// Second, we implement the trait in a funny manner with two defaulted template
2954// arguments to workaround Clang's PR43454.
2955template <class _Tp>
2956void __test_implicit_default_constructible(_Tp);
2957
2958template <class _Tp, class = void, class = typename is_default_constructible<_Tp>::type>
2959struct __is_implicitly_default_constructible
2960    : false_type
2961{ };
2962
2963template <class _Tp>
2964struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true_type>
2965    : true_type
2966{ };
2967
2968template <class _Tp>
2969struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), false_type>
2970    : false_type
2971{ };
2972#endif // !C++03
2973
2974// is_copy_constructible
2975
2976template <class _Tp>
2977struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
2978    : public is_constructible<_Tp,
2979                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2980
2981#if _LIBCPP_STD_VER > 14
2982template <class _Tp>
2983inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
2984#endif
2985
2986// is_move_constructible
2987
2988template <class _Tp>
2989struct _LIBCPP_TEMPLATE_VIS is_move_constructible
2990    : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2991    {};
2992
2993#if _LIBCPP_STD_VER > 14
2994template <class _Tp>
2995inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
2996#endif
2997
2998// is_trivially_constructible
2999
3000template <class _Tp, class... _Args>
3001struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
3002    : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
3003{
3004};
3005
3006#if _LIBCPP_STD_VER > 14
3007template <class _Tp, class... _Args>
3008inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value;
3009#endif
3010
3011// is_trivially_default_constructible
3012
3013template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
3014    : public is_trivially_constructible<_Tp>
3015    {};
3016
3017#if _LIBCPP_STD_VER > 14
3018template <class _Tp>
3019inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<_Tp>::value;
3020#endif
3021
3022// is_trivially_copy_constructible
3023
3024template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
3025    : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
3026    {};
3027
3028#if _LIBCPP_STD_VER > 14
3029template <class _Tp>
3030inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value;
3031#endif
3032
3033// is_trivially_move_constructible
3034
3035template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
3036    : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3037    {};
3038
3039#if _LIBCPP_STD_VER > 14
3040template <class _Tp>
3041inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value;
3042#endif
3043
3044// is_trivially_assignable
3045
3046template <class _Tp, class _Arg>
3047struct is_trivially_assignable
3048    : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
3049{ };
3050
3051#if _LIBCPP_STD_VER > 14
3052template <class _Tp, class _Arg>
3053inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<_Tp, _Arg>::value;
3054#endif
3055
3056// is_trivially_copy_assignable
3057
3058template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
3059    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
3060                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3061
3062#if _LIBCPP_STD_VER > 14
3063template <class _Tp>
3064inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value;
3065#endif
3066
3067// is_trivially_move_assignable
3068
3069template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
3070    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
3071                                     typename add_rvalue_reference<_Tp>::type>
3072    {};
3073
3074#if _LIBCPP_STD_VER > 14
3075template <class _Tp>
3076inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value;
3077#endif
3078
3079// is_trivially_destructible
3080
3081#if __has_keyword(__is_trivially_destructible)
3082
3083template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3084    : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
3085
3086#elif __has_feature(has_trivial_destructor) || defined(_LIBCPP_COMPILER_GCC)
3087
3088template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3089    : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
3090
3091#else
3092
3093template <class _Tp> struct __libcpp_trivial_destructor
3094    : public integral_constant<bool, is_scalar<_Tp>::value ||
3095                                     is_reference<_Tp>::value> {};
3096
3097template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3098    : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
3099
3100template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]>
3101    : public false_type {};
3102
3103#endif
3104
3105#if _LIBCPP_STD_VER > 14
3106template <class _Tp>
3107inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
3108#endif
3109
3110// is_nothrow_constructible
3111
3112#if __has_keyword(__is_nothrow_constructible)
3113
3114template <class _Tp, class... _Args>
3115struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3116    : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
3117
3118#else
3119
3120template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
3121
3122template <class _Tp, class... _Args>
3123struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
3124    : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
3125{
3126};
3127
3128template <class _Tp>
3129void __implicit_conversion_to(_Tp) noexcept { }
3130
3131template <class _Tp, class _Arg>
3132struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
3133    : public integral_constant<bool, noexcept(_VSTD::__implicit_conversion_to<_Tp>(declval<_Arg>()))>
3134{
3135};
3136
3137template <class _Tp, bool _IsReference, class... _Args>
3138struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
3139    : public false_type
3140{
3141};
3142
3143template <class _Tp, class... _Args>
3144struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3145    : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
3146{
3147};
3148
3149template <class _Tp, size_t _Ns>
3150struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
3151    : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
3152{
3153};
3154
3155#endif // _LIBCPP_HAS_NO_NOEXCEPT
3156
3157
3158#if _LIBCPP_STD_VER > 14
3159template <class _Tp, class ..._Args>
3160inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
3161#endif
3162
3163// is_nothrow_default_constructible
3164
3165template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
3166    : public is_nothrow_constructible<_Tp>
3167    {};
3168
3169#if _LIBCPP_STD_VER > 14
3170template <class _Tp>
3171inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value;
3172#endif
3173
3174// is_nothrow_copy_constructible
3175
3176template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
3177    : public is_nothrow_constructible<_Tp,
3178                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3179
3180#if _LIBCPP_STD_VER > 14
3181template <class _Tp>
3182inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value;
3183#endif
3184
3185// is_nothrow_move_constructible
3186
3187template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
3188    : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3189    {};
3190
3191#if _LIBCPP_STD_VER > 14
3192template <class _Tp>
3193inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value;
3194#endif
3195
3196// is_nothrow_assignable
3197
3198#if __has_keyword(__is_nothrow_assignable)
3199
3200template <class _Tp, class _Arg>
3201struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
3202    : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
3203
3204#else
3205
3206template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
3207
3208template <class _Tp, class _Arg>
3209struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
3210    : public false_type
3211{
3212};
3213
3214template <class _Tp, class _Arg>
3215struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
3216    : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Arg>()) >
3217{
3218};
3219
3220template <class _Tp, class _Arg>
3221struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
3222    : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
3223{
3224};
3225
3226#endif // _LIBCPP_HAS_NO_NOEXCEPT
3227
3228#if _LIBCPP_STD_VER > 14
3229template <class _Tp, class _Arg>
3230inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value;
3231#endif
3232
3233// is_nothrow_copy_assignable
3234
3235template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
3236    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3237                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3238
3239#if _LIBCPP_STD_VER > 14
3240template <class _Tp>
3241inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
3242#endif
3243
3244// is_nothrow_move_assignable
3245
3246template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
3247    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3248                                     typename add_rvalue_reference<_Tp>::type>
3249    {};
3250
3251#if _LIBCPP_STD_VER > 14
3252template <class _Tp>
3253inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
3254#endif
3255
3256// is_nothrow_destructible
3257
3258#if !defined(_LIBCPP_CXX03_LANG)
3259
3260template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
3261
3262template <class _Tp>
3263struct __libcpp_is_nothrow_destructible<false, _Tp>
3264    : public false_type
3265{
3266};
3267
3268template <class _Tp>
3269struct __libcpp_is_nothrow_destructible<true, _Tp>
3270    : public integral_constant<bool, noexcept(declval<_Tp>().~_Tp()) >
3271{
3272};
3273
3274template <class _Tp>
3275struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
3276    : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
3277{
3278};
3279
3280template <class _Tp, size_t _Ns>
3281struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
3282    : public is_nothrow_destructible<_Tp>
3283{
3284};
3285
3286template <class _Tp>
3287struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
3288    : public true_type
3289{
3290};
3291
3292template <class _Tp>
3293struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
3294    : public true_type
3295{
3296};
3297
3298#else
3299
3300template <class _Tp> struct __libcpp_nothrow_destructor
3301    : public integral_constant<bool, is_scalar<_Tp>::value ||
3302                                     is_reference<_Tp>::value> {};
3303
3304template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
3305    : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
3306
3307template <class _Tp>
3308struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
3309    : public false_type {};
3310
3311#endif
3312
3313#if _LIBCPP_STD_VER > 14
3314template <class _Tp>
3315inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
3316#endif
3317
3318// is_pod
3319
3320#if __has_feature(is_pod) || defined(_LIBCPP_COMPILER_GCC)
3321
3322template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
3323    : public integral_constant<bool, __is_pod(_Tp)> {};
3324
3325#else
3326
3327template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
3328    : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
3329                                     is_trivially_copy_constructible<_Tp>::value      &&
3330                                     is_trivially_copy_assignable<_Tp>::value    &&
3331                                     is_trivially_destructible<_Tp>::value> {};
3332
3333#endif
3334
3335#if _LIBCPP_STD_VER > 14
3336template <class _Tp>
3337inline constexpr bool is_pod_v = is_pod<_Tp>::value;
3338#endif
3339
3340// is_literal_type;
3341
3342#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3343template <class _Tp> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 is_literal_type
3344    : public integral_constant<bool, __is_literal_type(_Tp)>
3345    {};
3346
3347#if _LIBCPP_STD_VER > 14
3348template <class _Tp>
3349_LIBCPP_DEPRECATED_IN_CXX17 inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
3350#endif // _LIBCPP_STD_VER > 14
3351#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3352
3353// is_standard_layout;
3354
3355template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
3356#if __has_feature(is_standard_layout) || defined(_LIBCPP_COMPILER_GCC)
3357    : public integral_constant<bool, __is_standard_layout(_Tp)>
3358#else
3359    : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3360#endif
3361    {};
3362
3363#if _LIBCPP_STD_VER > 14
3364template <class _Tp>
3365inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
3366#endif
3367
3368// is_trivially_copyable;
3369
3370template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
3371    : public integral_constant<bool, __is_trivially_copyable(_Tp)>
3372    {};
3373
3374#if _LIBCPP_STD_VER > 14
3375template <class _Tp>
3376inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value;
3377#endif
3378
3379// is_trivial;
3380
3381template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
3382#if __has_feature(is_trivial) || defined(_LIBCPP_COMPILER_GCC)
3383    : public integral_constant<bool, __is_trivial(_Tp)>
3384#else
3385    : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
3386                                 is_trivially_default_constructible<_Tp>::value>
3387#endif
3388    {};
3389
3390#if _LIBCPP_STD_VER > 14
3391template <class _Tp>
3392inline constexpr bool is_trivial_v = is_trivial<_Tp>::value;
3393#endif
3394
3395template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
3396template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
3397template <class _Tp> struct __is_reference_wrapper
3398    : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
3399
3400#ifndef _LIBCPP_CXX03_LANG
3401
3402template <class _Fp, class _A0,
3403         class _DecayFp = typename decay<_Fp>::type,
3404         class _DecayA0 = typename decay<_A0>::type,
3405         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3406using __enable_if_bullet1 = typename enable_if
3407    <
3408        is_member_function_pointer<_DecayFp>::value
3409        && is_base_of<_ClassT, _DecayA0>::value
3410    >::type;
3411
3412template <class _Fp, class _A0,
3413         class _DecayFp = typename decay<_Fp>::type,
3414         class _DecayA0 = typename decay<_A0>::type>
3415using __enable_if_bullet2 = typename enable_if
3416    <
3417        is_member_function_pointer<_DecayFp>::value
3418        && __is_reference_wrapper<_DecayA0>::value
3419    >::type;
3420
3421template <class _Fp, class _A0,
3422         class _DecayFp = typename decay<_Fp>::type,
3423         class _DecayA0 = typename decay<_A0>::type,
3424         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3425using __enable_if_bullet3 = typename enable_if
3426    <
3427        is_member_function_pointer<_DecayFp>::value
3428        && !is_base_of<_ClassT, _DecayA0>::value
3429        && !__is_reference_wrapper<_DecayA0>::value
3430    >::type;
3431
3432template <class _Fp, class _A0,
3433         class _DecayFp = typename decay<_Fp>::type,
3434         class _DecayA0 = typename decay<_A0>::type,
3435         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3436using __enable_if_bullet4 = typename enable_if
3437    <
3438        is_member_object_pointer<_DecayFp>::value
3439        && is_base_of<_ClassT, _DecayA0>::value
3440    >::type;
3441
3442template <class _Fp, class _A0,
3443         class _DecayFp = typename decay<_Fp>::type,
3444         class _DecayA0 = typename decay<_A0>::type>
3445using __enable_if_bullet5 = typename enable_if
3446    <
3447        is_member_object_pointer<_DecayFp>::value
3448        && __is_reference_wrapper<_DecayA0>::value
3449    >::type;
3450
3451template <class _Fp, class _A0,
3452         class _DecayFp = typename decay<_Fp>::type,
3453         class _DecayA0 = typename decay<_A0>::type,
3454         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3455using __enable_if_bullet6 = typename enable_if
3456    <
3457        is_member_object_pointer<_DecayFp>::value
3458        && !is_base_of<_ClassT, _DecayA0>::value
3459        && !__is_reference_wrapper<_DecayA0>::value
3460    >::type;
3461
3462// __invoke forward declarations
3463
3464// fall back - none of the bullets
3465
3466template <class ..._Args>
3467auto __invoke(__any, _Args&& ...__args) -> __nat;
3468
3469template <class ..._Args>
3470auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
3471
3472// bullets 1, 2 and 3
3473
3474template <class _Fp, class _A0, class ..._Args,
3475          class = __enable_if_bullet1<_Fp, _A0>>
3476inline _LIBCPP_INLINE_VISIBILITY
3477_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3478__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3479    noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
3480    -> decltype(      (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
3481    { return          (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
3482
3483template <class _Fp, class _A0, class ..._Args,
3484          class = __enable_if_bullet1<_Fp, _A0>>
3485inline _LIBCPP_INLINE_VISIBILITY
3486_LIBCPP_CONSTEXPR auto
3487__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3488    noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
3489    -> decltype(      (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
3490    { return          (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
3491
3492template <class _Fp, class _A0, class ..._Args,
3493          class = __enable_if_bullet2<_Fp, _A0>>
3494inline _LIBCPP_INLINE_VISIBILITY
3495_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3496__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3497    noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
3498    -> decltype(      (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
3499    { return          (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
3500
3501template <class _Fp, class _A0, class ..._Args,
3502          class = __enable_if_bullet2<_Fp, _A0>>
3503inline _LIBCPP_INLINE_VISIBILITY
3504_LIBCPP_CONSTEXPR auto
3505__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3506    noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
3507    -> decltype(      (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
3508    { return          (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
3509
3510template <class _Fp, class _A0, class ..._Args,
3511          class = __enable_if_bullet3<_Fp, _A0>>
3512inline _LIBCPP_INLINE_VISIBILITY
3513_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3514__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3515    noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
3516    -> decltype(      ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
3517    { return          ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
3518
3519template <class _Fp, class _A0, class ..._Args,
3520          class = __enable_if_bullet3<_Fp, _A0>>
3521inline _LIBCPP_INLINE_VISIBILITY
3522_LIBCPP_CONSTEXPR auto
3523__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3524    noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
3525    -> decltype(      ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
3526    { return          ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
3527
3528// bullets 4, 5 and 6
3529
3530template <class _Fp, class _A0,
3531          class = __enable_if_bullet4<_Fp, _A0>>
3532inline _LIBCPP_INLINE_VISIBILITY
3533_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3534__invoke(_Fp&& __f, _A0&& __a0)
3535    noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
3536    -> decltype(      static_cast<_A0&&>(__a0).*__f)
3537    { return          static_cast<_A0&&>(__a0).*__f; }
3538
3539template <class _Fp, class _A0,
3540          class = __enable_if_bullet4<_Fp, _A0>>
3541inline _LIBCPP_INLINE_VISIBILITY
3542_LIBCPP_CONSTEXPR auto
3543__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3544    noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
3545    -> decltype(      static_cast<_A0&&>(__a0).*__f)
3546    { return          static_cast<_A0&&>(__a0).*__f; }
3547
3548template <class _Fp, class _A0,
3549          class = __enable_if_bullet5<_Fp, _A0>>
3550inline _LIBCPP_INLINE_VISIBILITY
3551_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3552__invoke(_Fp&& __f, _A0&& __a0)
3553    noexcept(noexcept(__a0.get().*__f))
3554    -> decltype(      __a0.get().*__f)
3555    { return          __a0.get().*__f; }
3556
3557template <class _Fp, class _A0,
3558          class = __enable_if_bullet5<_Fp, _A0>>
3559inline _LIBCPP_INLINE_VISIBILITY
3560_LIBCPP_CONSTEXPR auto
3561__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3562    noexcept(noexcept(__a0.get().*__f))
3563    -> decltype(      __a0.get().*__f)
3564    { return          __a0.get().*__f; }
3565
3566template <class _Fp, class _A0,
3567          class = __enable_if_bullet6<_Fp, _A0>>
3568inline _LIBCPP_INLINE_VISIBILITY
3569_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3570__invoke(_Fp&& __f, _A0&& __a0)
3571    noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
3572    -> decltype(      (*static_cast<_A0&&>(__a0)).*__f)
3573    { return          (*static_cast<_A0&&>(__a0)).*__f; }
3574
3575template <class _Fp, class _A0,
3576          class = __enable_if_bullet6<_Fp, _A0>>
3577inline _LIBCPP_INLINE_VISIBILITY
3578_LIBCPP_CONSTEXPR auto
3579__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3580    noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
3581    -> decltype(      (*static_cast<_A0&&>(__a0)).*__f)
3582    { return          (*static_cast<_A0&&>(__a0)).*__f; }
3583
3584// bullet 7
3585
3586template <class _Fp, class ..._Args>
3587inline _LIBCPP_INLINE_VISIBILITY
3588_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3589__invoke(_Fp&& __f, _Args&& ...__args)
3590    noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
3591    -> decltype(      static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
3592    { return          static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
3593
3594template <class _Fp, class ..._Args>
3595inline _LIBCPP_INLINE_VISIBILITY
3596_LIBCPP_CONSTEXPR auto
3597__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
3598    noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
3599    -> decltype(      static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
3600    { return          static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
3601
3602// __invokable
3603template <class _Ret, class _Fp, class ..._Args>
3604struct __invokable_r
3605{
3606  template <class _XFp, class ..._XArgs>
3607  static auto __try_call(int) -> decltype(
3608    _VSTD::__invoke(declval<_XFp>(), declval<_XArgs>()...));
3609  template <class _XFp, class ..._XArgs>
3610  static __nat __try_call(...);
3611
3612  // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void,
3613  // or incomplete array types as required by the standard.
3614  using _Result = decltype(__try_call<_Fp, _Args...>(0));
3615
3616  using type =
3617  typename conditional<
3618      _IsNotSame<_Result, __nat>::value,
3619      typename conditional<
3620          is_void<_Ret>::value,
3621          true_type,
3622          is_convertible<_Result, _Ret>
3623      >::type,
3624      false_type
3625  >::type;
3626  static const bool value = type::value;
3627};
3628template <class _Fp, class ..._Args>
3629using __invokable = __invokable_r<void, _Fp, _Args...>;
3630
3631template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
3632struct __nothrow_invokable_r_imp {
3633  static const bool value = false;
3634};
3635
3636template <class _Ret, class _Fp, class ..._Args>
3637struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
3638{
3639    typedef __nothrow_invokable_r_imp _ThisT;
3640
3641    template <class _Tp>
3642    static void __test_noexcept(_Tp) noexcept;
3643
3644    static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
3645        _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...)));
3646};
3647
3648template <class _Ret, class _Fp, class ..._Args>
3649struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
3650{
3651    static const bool value = noexcept(
3652        _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...));
3653};
3654
3655template <class _Ret, class _Fp, class ..._Args>
3656using __nothrow_invokable_r =
3657    __nothrow_invokable_r_imp<
3658            __invokable_r<_Ret, _Fp, _Args...>::value,
3659            is_void<_Ret>::value,
3660            _Ret, _Fp, _Args...
3661    >;
3662
3663template <class _Fp, class ..._Args>
3664using __nothrow_invokable =
3665    __nothrow_invokable_r_imp<
3666            __invokable<_Fp, _Args...>::value,
3667            true, void, _Fp, _Args...
3668    >;
3669
3670template <class _Fp, class ..._Args>
3671struct __invoke_of
3672    : public enable_if<
3673        __invokable<_Fp, _Args...>::value,
3674        typename __invokable_r<void, _Fp, _Args...>::_Result>
3675{
3676};
3677
3678#endif // _LIBCPP_CXX03_LANG
3679
3680// result_of
3681
3682#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3683template <class _Callable> class _LIBCPP_DEPRECATED_IN_CXX17 result_of;
3684
3685#ifndef _LIBCPP_CXX03_LANG
3686
3687template <class _Fp, class ..._Args>
3688class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)>
3689    : public __invoke_of<_Fp, _Args...>
3690{
3691};
3692
3693#else // C++03
3694
3695template <class _Fn, bool, bool>
3696class __result_of
3697{
3698};
3699
3700template <class _Fn, class ..._Args>
3701class __result_of<_Fn(_Args...), true, false>
3702{
3703public:
3704    typedef decltype(declval<_Fn>()(declval<_Args>()...)) type;
3705};
3706
3707template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
3708struct __result_of_mp;
3709
3710// member function pointer
3711
3712template <class _MP, class _Tp>
3713struct __result_of_mp<_MP, _Tp, true>
3714{
3715    using type = typename __member_pointer_traits<_MP>::_ReturnType;
3716};
3717
3718// member data pointer
3719
3720template <class _MP, class _Tp, bool>
3721struct __result_of_mdp;
3722
3723template <class _Rp, class _Class, class _Tp>
3724struct __result_of_mdp<_Rp _Class::*, _Tp, false>
3725{
3726    using type = typename __apply_cv<decltype(*declval<_Tp>()), _Rp>::type&;
3727};
3728
3729template <class _Rp, class _Class, class _Tp>
3730struct __result_of_mdp<_Rp _Class::*, _Tp, true>
3731{
3732    using type = typename __apply_cv<_Tp, _Rp>::type&;
3733};
3734
3735template <class _Rp, class _Class, class _Tp>
3736struct __result_of_mp<_Rp _Class::*, _Tp, false>
3737    : public __result_of_mdp<_Rp _Class::*, _Tp,
3738            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
3739{
3740};
3741
3742template <class _Fn, class _Tp>
3743class __result_of<_Fn(_Tp), false, true>  // _Fn must be member pointer
3744    : public __result_of_mp<typename remove_reference<_Fn>::type,
3745                            _Tp,
3746                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
3747{
3748};
3749
3750template <class _Fn, class _Tp, class ..._Args>
3751class __result_of<_Fn(_Tp, _Args...), false, true>  // _Fn must be member pointer
3752    : public __result_of_mp<typename remove_reference<_Fn>::type,
3753                            _Tp,
3754                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
3755{
3756};
3757
3758template <class _Fn, class ..._Args>
3759class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_Args...)>
3760    : public __result_of<_Fn(_Args...),
3761                         is_class<typename remove_reference<_Fn>::type>::value ||
3762                         is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
3763                         is_member_pointer<typename remove_reference<_Fn>::type>::value
3764                        >
3765{
3766};
3767
3768#endif // C++03
3769
3770#if _LIBCPP_STD_VER > 11
3771template <class _Tp> using result_of_t _LIBCPP_DEPRECATED_IN_CXX17 = typename result_of<_Tp>::type;
3772#endif // _LIBCPP_STD_VER > 11
3773#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3774
3775#if _LIBCPP_STD_VER > 14
3776
3777// invoke_result
3778
3779template <class _Fn, class... _Args>
3780struct _LIBCPP_TEMPLATE_VIS invoke_result
3781    : __invoke_of<_Fn, _Args...>
3782{
3783};
3784
3785template <class _Fn, class... _Args>
3786using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3787
3788// is_invocable
3789
3790template <class _Fn, class ..._Args>
3791struct _LIBCPP_TEMPLATE_VIS is_invocable
3792    : integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
3793
3794template <class _Ret, class _Fn, class ..._Args>
3795struct _LIBCPP_TEMPLATE_VIS is_invocable_r
3796    : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
3797
3798template <class _Fn, class ..._Args>
3799inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
3800
3801template <class _Ret, class _Fn, class ..._Args>
3802inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;
3803
3804// is_nothrow_invocable
3805
3806template <class _Fn, class ..._Args>
3807struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable
3808    : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {};
3809
3810template <class _Ret, class _Fn, class ..._Args>
3811struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
3812    : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
3813
3814template <class _Fn, class ..._Args>
3815inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
3816
3817template <class _Ret, class _Fn, class ..._Args>
3818inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3819
3820#endif // _LIBCPP_STD_VER > 14
3821
3822// __swappable
3823
3824template <class _Tp> struct __is_swappable;
3825template <class _Tp> struct __is_nothrow_swappable;
3826
3827
3828#ifndef _LIBCPP_CXX03_LANG
3829template <class _Tp>
3830using __swap_result_t = typename enable_if<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>::type;
3831#else
3832template <class>
3833using __swap_result_t = void;
3834#endif
3835
3836template <class _Tp>
3837inline _LIBCPP_INLINE_VISIBILITY
3838_LIBCPP_CONSTEXPR_AFTER_CXX17 __swap_result_t<_Tp>
3839swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
3840                                    is_nothrow_move_assignable<_Tp>::value);
3841
3842template<class _Tp, size_t _Np>
3843inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3844typename enable_if<
3845    __is_swappable<_Tp>::value
3846>::type
3847swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
3848
3849namespace __detail
3850{
3851// ALL generic swap overloads MUST already have a declaration available at this point.
3852
3853template <class _Tp, class _Up = _Tp,
3854          bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value>
3855struct __swappable_with
3856{
3857    template <class _LHS, class _RHS>
3858    static decltype(swap(declval<_LHS>(), declval<_RHS>()))
3859    __test_swap(int);
3860    template <class, class>
3861    static __nat __test_swap(long);
3862
3863    // Extra parens are needed for the C++03 definition of decltype.
3864    typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1;
3865    typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2;
3866
3867    static const bool value = _IsNotSame<__swap1, __nat>::value
3868                           && _IsNotSame<__swap2, __nat>::value;
3869};
3870
3871template <class _Tp, class _Up>
3872struct __swappable_with<_Tp, _Up,  false> : false_type {};
3873
3874template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value>
3875struct __nothrow_swappable_with {
3876  static const bool value =
3877#ifndef _LIBCPP_HAS_NO_NOEXCEPT
3878      noexcept(swap(declval<_Tp>(), declval<_Up>()))
3879  &&  noexcept(swap(declval<_Up>(), declval<_Tp>()));
3880#else
3881      false;
3882#endif
3883};
3884
3885template <class _Tp, class _Up>
3886struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
3887
3888} // namespace __detail
3889
3890template <class _Tp>
3891struct __is_swappable
3892    : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value>
3893{
3894};
3895
3896template <class _Tp>
3897struct __is_nothrow_swappable
3898    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value>
3899{
3900};
3901
3902#if _LIBCPP_STD_VER > 14
3903
3904template <class _Tp, class _Up>
3905struct _LIBCPP_TEMPLATE_VIS is_swappable_with
3906    : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value>
3907{
3908};
3909
3910template <class _Tp>
3911struct _LIBCPP_TEMPLATE_VIS is_swappable
3912    : public conditional<
3913        __is_referenceable<_Tp>::value,
3914        is_swappable_with<
3915            typename add_lvalue_reference<_Tp>::type,
3916            typename add_lvalue_reference<_Tp>::type>,
3917        false_type
3918    >::type
3919{
3920};
3921
3922template <class _Tp, class _Up>
3923struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with
3924    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value>
3925{
3926};
3927
3928template <class _Tp>
3929struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable
3930    : public conditional<
3931        __is_referenceable<_Tp>::value,
3932        is_nothrow_swappable_with<
3933            typename add_lvalue_reference<_Tp>::type,
3934            typename add_lvalue_reference<_Tp>::type>,
3935        false_type
3936    >::type
3937{
3938};
3939
3940template <class _Tp, class _Up>
3941inline constexpr bool is_swappable_with_v = is_swappable_with<_Tp, _Up>::value;
3942
3943template <class _Tp>
3944inline constexpr bool is_swappable_v = is_swappable<_Tp>::value;
3945
3946template <class _Tp, class _Up>
3947inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<_Tp, _Up>::value;
3948
3949template <class _Tp>
3950inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value;
3951
3952#endif // _LIBCPP_STD_VER > 14
3953
3954template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl;
3955
3956template <class _Tp>
3957struct __underlying_type_impl<_Tp, false> {};
3958
3959template <class _Tp>
3960struct __underlying_type_impl<_Tp, true>
3961{
3962    typedef __underlying_type(_Tp) type;
3963};
3964
3965template <class _Tp>
3966struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
3967
3968#if _LIBCPP_STD_VER > 11
3969template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
3970#endif
3971
3972template <class _Tp, bool = is_enum<_Tp>::value>
3973struct __sfinae_underlying_type
3974{
3975    typedef typename underlying_type<_Tp>::type type;
3976    typedef decltype(((type)1) + 0) __promoted_type;
3977};
3978
3979template <class _Tp>
3980struct __sfinae_underlying_type<_Tp, false> {};
3981
3982inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3983int __convert_to_integral(int __val) { return __val; }
3984
3985inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3986unsigned __convert_to_integral(unsigned __val) { return __val; }
3987
3988inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3989long __convert_to_integral(long __val) { return __val; }
3990
3991inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3992unsigned long __convert_to_integral(unsigned long __val) { return __val; }
3993
3994inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3995long long __convert_to_integral(long long __val) { return __val; }
3996
3997inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3998unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
3999
4000template<typename _Fp>
4001inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
4002typename enable_if<is_floating_point<_Fp>::value, long long>::type
4003 __convert_to_integral(_Fp __val) { return __val; }
4004
4005#ifndef _LIBCPP_HAS_NO_INT128
4006inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
4007__int128_t __convert_to_integral(__int128_t __val) { return __val; }
4008
4009inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
4010__uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
4011#endif
4012
4013template <class _Tp>
4014inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
4015typename __sfinae_underlying_type<_Tp>::__promoted_type
4016__convert_to_integral(_Tp __val) { return __val; }
4017
4018// is_scoped_enum [meta.unary.prop]
4019
4020#if _LIBCPP_STD_VER > 20
4021template <class _Tp, bool = is_enum_v<_Tp> >
4022struct __is_scoped_enum_helper : false_type {};
4023
4024template <class _Tp>
4025struct __is_scoped_enum_helper<_Tp, true>
4026    : public bool_constant<!is_convertible_v<_Tp, underlying_type_t<_Tp> > > {};
4027
4028template <class _Tp>
4029struct _LIBCPP_TEMPLATE_VIS is_scoped_enum
4030    : public __is_scoped_enum_helper<_Tp> {};
4031
4032template <class _Tp>
4033inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
4034#endif
4035
4036#if _LIBCPP_STD_VER > 14
4037
4038template <class... _Args>
4039struct conjunction : _And<_Args...> {};
4040template<class... _Args>
4041inline constexpr bool conjunction_v = conjunction<_Args...>::value;
4042
4043template <class... _Args>
4044struct disjunction : _Or<_Args...> {};
4045template<class... _Args>
4046inline constexpr bool disjunction_v = disjunction<_Args...>::value;
4047
4048template <class _Tp>
4049struct negation : _Not<_Tp> {};
4050template<class _Tp>
4051inline constexpr bool negation_v = negation<_Tp>::value;
4052#endif // _LIBCPP_STD_VER > 14
4053
4054// These traits are used in __tree and __hash_table
4055struct __extract_key_fail_tag {};
4056struct __extract_key_self_tag {};
4057struct __extract_key_first_tag {};
4058
4059template <class _ValTy, class _Key,
4060          class _RawValTy = typename __unconstref<_ValTy>::type>
4061struct __can_extract_key
4062    : conditional<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag,
4063                  __extract_key_fail_tag>::type {};
4064
4065template <class _Pair, class _Key, class _First, class _Second>
4066struct __can_extract_key<_Pair, _Key, pair<_First, _Second> >
4067    : conditional<_IsSame<typename remove_const<_First>::type, _Key>::value,
4068                  __extract_key_first_tag, __extract_key_fail_tag>::type {};
4069
4070// __can_extract_map_key uses true_type/false_type instead of the tags.
4071// It returns true if _Key != _ContainerValueTy (the container is a map not a set)
4072// and _ValTy == _Key.
4073template <class _ValTy, class _Key, class _ContainerValueTy,
4074          class _RawValTy = typename __unconstref<_ValTy>::type>
4075struct __can_extract_map_key
4076    : integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {};
4077
4078// This specialization returns __extract_key_fail_tag for non-map containers
4079// because _Key == _ContainerValueTy
4080template <class _ValTy, class _Key, class _RawValTy>
4081struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
4082    : false_type {};
4083
4084#if _LIBCPP_STD_VER > 17
4085_LIBCPP_INLINE_VISIBILITY
4086inline constexpr bool is_constant_evaluated() noexcept {
4087  return __builtin_is_constant_evaluated();
4088}
4089#endif
4090
4091inline _LIBCPP_CONSTEXPR
4092bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); }
4093
4094template <class _CharT>
4095using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
4096
4097template<class _Tp>
4098using __make_const_lvalue_ref = const typename remove_reference<_Tp>::type&;
4099
4100#if _LIBCPP_STD_VER > 17
4101template<bool _Const, class _Tp>
4102using __maybe_const = conditional_t<_Const, const _Tp, _Tp>;
4103#endif // _LIBCPP_STD_VER > 17
4104
4105_LIBCPP_END_NAMESPACE_STD
4106
4107#endif // _LIBCPP_TYPE_TRAITS
4108