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