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