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