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