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