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