1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TYPE_TRAITS
11#define _LIBCPP_TYPE_TRAITS
12
13/*
14    type_traits synopsis
15
16namespace std
17{
18
19    // helper class:
20    template <class T, T v> struct integral_constant;
21    typedef integral_constant<bool, true>  true_type;   // C++11
22    typedef integral_constant<bool, false> false_type;  // C++11
23
24    template <bool B>                                   // C++14
25    using bool_constant = integral_constant<bool, B>;   // C++14
26    typedef bool_constant<true> true_type;              // C++14
27    typedef bool_constant<false> false_type;            // C++14
28
29    // helper traits
30    template <bool, class T = void> struct enable_if;
31    template <bool, class T, class F> struct conditional;
32
33    // Primary classification traits:
34    template <class T> struct is_void;
35    template <class T> struct is_null_pointer;  // C++14
36    template <class T> struct is_integral;
37    template <class T> struct is_floating_point;
38    template <class T> struct is_array;
39    template <class T> struct is_pointer;
40    template <class T> struct is_lvalue_reference;
41    template <class T> struct is_rvalue_reference;
42    template <class T> struct is_member_object_pointer;
43    template <class T> struct is_member_function_pointer;
44    template <class T> struct is_enum;
45    template <class T> struct is_union;
46    template <class T> struct is_class;
47    template <class T> struct is_function;
48
49    // Secondary classification traits:
50    template <class T> struct is_reference;
51    template <class T> struct is_arithmetic;
52    template <class T> struct is_fundamental;
53    template <class T> struct is_member_pointer;
54    template <class T> struct is_scoped_enum; // C++2b
55    template <class T> struct is_scalar;
56    template <class T> struct is_object;
57    template <class T> struct is_compound;
58
59    // Const-volatile properties and transformations:
60    template <class T> struct is_const;
61    template <class T> struct is_volatile;
62    template <class T> struct remove_const;
63    template <class T> struct remove_volatile;
64    template <class T> struct remove_cv;
65    template <class T> struct add_const;
66    template <class T> struct add_volatile;
67    template <class T> struct add_cv;
68
69    // Reference transformations:
70    template <class T> struct remove_reference;
71    template <class T> struct add_lvalue_reference;
72    template <class T> struct add_rvalue_reference;
73
74    // Pointer transformations:
75    template <class T> struct remove_pointer;
76    template <class T> struct add_pointer;
77
78    template<class T> struct type_identity;                     // C++20
79    template<class T>
80      using type_identity_t = typename type_identity<T>::type;  // C++20
81
82    // Integral properties:
83    template <class T> struct is_signed;
84    template <class T> struct is_unsigned;
85    template <class T> struct make_signed;
86    template <class T> struct make_unsigned;
87
88    // Array properties and transformations:
89    template <class T> struct rank;
90    template <class T, unsigned I = 0> struct extent;
91    template <class T> struct remove_extent;
92    template <class T> struct remove_all_extents;
93
94    template <class T> struct is_bounded_array;                 // C++20
95    template <class T> struct is_unbounded_array;               // C++20
96
97    // Member introspection:
98    template <class T> struct is_pod;
99    template <class T> struct is_trivial;
100    template <class T> struct is_trivially_copyable;
101    template <class T> struct is_standard_layout;
102    template <class T> struct is_literal_type; // Deprecated in C++17; removed in C++20
103    template <class T> struct is_empty;
104    template <class T> struct is_polymorphic;
105    template <class T> struct is_abstract;
106    template <class T> struct is_final; // C++14
107    template <class T> struct is_aggregate; // C++17
108
109    template <class T, class... Args> struct is_constructible;
110    template <class T>                struct is_default_constructible;
111    template <class T>                struct is_copy_constructible;
112    template <class T>                struct is_move_constructible;
113    template <class T, class U>       struct is_assignable;
114    template <class T>                struct is_copy_assignable;
115    template <class T>                struct is_move_assignable;
116    template <class T, class U>       struct is_swappable_with;       // C++17
117    template <class T>                struct is_swappable;            // C++17
118    template <class T>                struct is_destructible;
119
120    template <class T, class... Args> struct is_trivially_constructible;
121    template <class T>                struct is_trivially_default_constructible;
122    template <class T>                struct is_trivially_copy_constructible;
123    template <class T>                struct is_trivially_move_constructible;
124    template <class T, class U>       struct is_trivially_assignable;
125    template <class T>                struct is_trivially_copy_assignable;
126    template <class T>                struct is_trivially_move_assignable;
127    template <class T>                struct is_trivially_destructible;
128
129    template <class T, class... Args> struct is_nothrow_constructible;
130    template <class T>                struct is_nothrow_default_constructible;
131    template <class T>                struct is_nothrow_copy_constructible;
132    template <class T>                struct is_nothrow_move_constructible;
133    template <class T, class U>       struct is_nothrow_assignable;
134    template <class T>                struct is_nothrow_copy_assignable;
135    template <class T>                struct is_nothrow_move_assignable;
136    template <class T, class U>       struct is_nothrow_swappable_with; // C++17
137    template <class T>                struct is_nothrow_swappable;      // C++17
138    template <class T>                struct is_nothrow_destructible;
139
140    template <class T> struct has_virtual_destructor;
141
142    template<class T> struct has_unique_object_representations;         // C++17
143
144    // Relationships between types:
145    template <class T, class U> struct is_same;
146    template <class Base, class Derived> struct is_base_of;
147
148    template <class From, class To> struct is_convertible;
149    template <typename From, typename To> struct is_nothrow_convertible;                  // C++20
150    template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20
151
152    template <class Fn, class... ArgTypes> struct is_invocable;
153    template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
154
155    template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
156    template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
157
158    // Alignment properties and transformations:
159    template <class T> struct alignment_of;
160    template <size_t Len, size_t Align = most_stringent_alignment_requirement>
161        struct aligned_storage;
162    template <size_t Len, class... Types> struct aligned_union;
163    template <class T> struct remove_cvref; // C++20
164
165    template <class T> struct decay;
166    template <class... T> struct common_type;
167    template <class T> struct underlying_type;
168    template <class> class result_of; // undefined; deprecated in C++17; removed in C++20
169    template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20
170    template <class Fn, class... ArgTypes> struct invoke_result;  // C++17
171
172    // const-volatile modifications:
173    template <class T>
174      using remove_const_t    = typename remove_const<T>::type;  // C++14
175    template <class T>
176      using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
177    template <class T>
178      using remove_cv_t       = typename remove_cv<T>::type;  // C++14
179    template <class T>
180      using add_const_t       = typename add_const<T>::type;  // C++14
181    template <class T>
182      using add_volatile_t    = typename add_volatile<T>::type;  // C++14
183    template <class T>
184      using add_cv_t          = typename add_cv<T>::type;  // C++14
185
186    // reference modifications:
187    template <class T>
188      using remove_reference_t     = typename remove_reference<T>::type;  // C++14
189    template <class T>
190      using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
191    template <class T>
192      using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
193
194    // sign modifications:
195    template <class T>
196      using make_signed_t   = typename make_signed<T>::type;  // C++14
197    template <class T>
198      using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
199
200    // array modifications:
201    template <class T>
202      using remove_extent_t      = typename remove_extent<T>::type;  // C++14
203    template <class T>
204      using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
205
206    template <class T>
207      inline constexpr bool is_bounded_array_v
208        = is_bounded_array<T>::value;                                     // C++20
209      inline constexpr bool is_unbounded_array_v
210        = is_unbounded_array<T>::value;                                   // C++20
211
212    // pointer modifications:
213    template <class T>
214      using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
215    template <class T>
216      using add_pointer_t    = typename add_pointer<T>::type;  // C++14
217
218    // other transformations:
219    template <size_t Len, size_t Align=default-alignment>
220      using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
221    template <size_t Len, class... Types>
222      using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
223    template <class T>
224      using remove_cvref_t    = typename remove_cvref<T>::type;  // C++20
225    template <class T>
226      using decay_t           = typename decay<T>::type;  // C++14
227    template <bool b, class T=void>
228      using enable_if_t       = typename enable_if<b,T>::type;  // C++14
229    template <bool b, class T, class F>
230      using conditional_t     = typename conditional<b,T,F>::type;  // C++14
231    template <class... T>
232      using common_type_t     = typename common_type<T...>::type;  // C++14
233    template <class T>
234      using underlying_type_t = typename underlying_type<T>::type;  // C++14
235    template <class T>
236      using result_of_t       = typename result_of<T>::type;  // C++14; deprecated in C++17; removed in C++20
237    template <class Fn, class... ArgTypes>
238      using invoke_result_t   = typename invoke_result<Fn, ArgTypes...>::type;  // C++17
239
240    template <class...>
241      using void_t = void;   // C++17
242
243      // See C++14 20.10.4.1, primary type categories
244      template <class T> inline constexpr bool is_void_v
245        = is_void<T>::value;                                             // C++17
246      template <class T> inline constexpr bool is_null_pointer_v
247        = is_null_pointer<T>::value;                                     // C++17
248      template <class T> inline constexpr bool is_integral_v
249        = is_integral<T>::value;                                         // C++17
250      template <class T> inline constexpr bool is_floating_point_v
251        = is_floating_point<T>::value;                                   // C++17
252      template <class T> inline constexpr bool is_array_v
253        = is_array<T>::value;                                            // C++17
254      template <class T> inline constexpr bool is_pointer_v
255        = is_pointer<T>::value;                                          // C++17
256      template <class T> inline constexpr bool is_lvalue_reference_v
257        = is_lvalue_reference<T>::value;                                 // C++17
258      template <class T> inline constexpr bool is_rvalue_reference_v
259        = is_rvalue_reference<T>::value;                                 // C++17
260      template <class T> inline constexpr bool is_member_object_pointer_v
261        = is_member_object_pointer<T>::value;                            // C++17
262      template <class T> inline constexpr bool is_member_function_pointer_v
263        = is_member_function_pointer<T>::value;                          // C++17
264      template <class T> inline constexpr bool is_enum_v
265        = is_enum<T>::value;                                             // C++17
266      template <class T> inline constexpr bool is_union_v
267        = is_union<T>::value;                                            // C++17
268      template <class T> inline constexpr bool is_class_v
269        = is_class<T>::value;                                            // C++17
270      template <class T> inline constexpr bool is_function_v
271        = is_function<T>::value;                                         // C++17
272
273      // See C++14 20.10.4.2, composite type categories
274      template <class T> inline constexpr bool is_reference_v
275        = is_reference<T>::value;                                        // C++17
276      template <class T> inline constexpr bool is_arithmetic_v
277        = is_arithmetic<T>::value;                                       // C++17
278      template <class T> inline constexpr bool is_fundamental_v
279        = is_fundamental<T>::value;                                      // C++17
280      template <class T> inline constexpr bool is_object_v
281        = is_object<T>::value;                                           // C++17
282      template <class T> inline constexpr bool is_scalar_v
283        = is_scalar<T>::value;                                           // C++17
284      template <class T> inline constexpr bool is_compound_v
285        = is_compound<T>::value;                                         // C++17
286      template <class T> inline constexpr bool is_member_pointer_v
287        = is_member_pointer<T>::value;                                   // C++17
288      template <class T> inline constexpr bool is_scoped_enum_v
289        = is_scoped_enum<T>::value;                                      // C++2b
290
291      // See C++14 20.10.4.3, type properties
292      template <class T> inline constexpr bool is_const_v
293        = is_const<T>::value;                                            // C++17
294      template <class T> inline constexpr bool is_volatile_v
295        = is_volatile<T>::value;                                         // C++17
296      template <class T> inline constexpr bool is_trivial_v
297        = is_trivial<T>::value;                                          // C++17
298      template <class T> inline constexpr bool is_trivially_copyable_v
299        = is_trivially_copyable<T>::value;                               // C++17
300      template <class T> inline constexpr bool is_standard_layout_v
301        = is_standard_layout<T>::value;                                  // C++17
302      template <class T> inline constexpr bool is_pod_v
303        = is_pod<T>::value;                                              // C++17
304      template <class T> inline constexpr bool is_literal_type_v
305        = is_literal_type<T>::value;                                     // C++17; deprecated in C++17; removed in C++20
306      template <class T> inline constexpr bool is_empty_v
307        = is_empty<T>::value;                                            // C++17
308      template <class T> inline constexpr bool is_polymorphic_v
309        = is_polymorphic<T>::value;                                      // C++17
310      template <class T> inline constexpr bool is_abstract_v
311        = is_abstract<T>::value;                                         // C++17
312      template <class T> inline constexpr bool is_final_v
313        = is_final<T>::value;                                            // C++17
314      template <class T> inline constexpr bool is_aggregate_v
315        = is_aggregate<T>::value;                                        // C++17
316      template <class T> inline constexpr bool is_signed_v
317        = is_signed<T>::value;                                           // C++17
318      template <class T> inline constexpr bool is_unsigned_v
319        = is_unsigned<T>::value;                                         // C++17
320      template <class T, class... Args> inline constexpr bool is_constructible_v
321        = is_constructible<T, Args...>::value;                           // C++17
322      template <class T> inline constexpr bool is_default_constructible_v
323        = is_default_constructible<T>::value;                            // C++17
324      template <class T> inline constexpr bool is_copy_constructible_v
325        = is_copy_constructible<T>::value;                               // C++17
326      template <class T> inline constexpr bool is_move_constructible_v
327        = is_move_constructible<T>::value;                               // C++17
328      template <class T, class U> inline constexpr bool is_assignable_v
329        = is_assignable<T, U>::value;                                    // C++17
330      template <class T> inline constexpr bool is_copy_assignable_v
331        = is_copy_assignable<T>::value;                                  // C++17
332      template <class T> inline constexpr bool is_move_assignable_v
333        = is_move_assignable<T>::value;                                  // C++17
334      template <class T, class U> inline constexpr bool is_swappable_with_v
335        = is_swappable_with<T, U>::value;                                // C++17
336      template <class T> inline constexpr bool is_swappable_v
337        = is_swappable<T>::value;                                        // C++17
338      template <class T> inline constexpr bool is_destructible_v
339        = is_destructible<T>::value;                                     // C++17
340      template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
341        = is_trivially_constructible<T, Args...>::value;                 // C++17
342      template <class T> inline constexpr bool is_trivially_default_constructible_v
343        = is_trivially_default_constructible<T>::value;                  // C++17
344      template <class T> inline constexpr bool is_trivially_copy_constructible_v
345        = is_trivially_copy_constructible<T>::value;                     // C++17
346      template <class T> inline constexpr bool is_trivially_move_constructible_v
347        = is_trivially_move_constructible<T>::value;                     // C++17
348      template <class T, class U> inline constexpr bool is_trivially_assignable_v
349        = is_trivially_assignable<T, U>::value;                          // C++17
350      template <class T> inline constexpr bool is_trivially_copy_assignable_v
351        = is_trivially_copy_assignable<T>::value;                        // C++17
352      template <class T> inline constexpr bool is_trivially_move_assignable_v
353        = is_trivially_move_assignable<T>::value;                        // C++17
354      template <class T> inline constexpr bool is_trivially_destructible_v
355        = is_trivially_destructible<T>::value;                           // C++17
356      template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
357        = is_nothrow_constructible<T, Args...>::value;                   // C++17
358      template <class T> inline constexpr bool is_nothrow_default_constructible_v
359        = is_nothrow_default_constructible<T>::value;                    // C++17
360      template <class T> inline constexpr bool is_nothrow_copy_constructible_v
361        = is_nothrow_copy_constructible<T>::value;                       // C++17
362      template <class T> inline constexpr bool is_nothrow_move_constructible_v
363        = is_nothrow_move_constructible<T>::value;                       // C++17
364      template <class T, class U> inline constexpr bool is_nothrow_assignable_v
365        = is_nothrow_assignable<T, U>::value;                            // C++17
366      template <class T> inline constexpr bool is_nothrow_copy_assignable_v
367        = is_nothrow_copy_assignable<T>::value;                          // C++17
368      template <class T> inline constexpr bool is_nothrow_move_assignable_v
369        = is_nothrow_move_assignable<T>::value;                          // C++17
370      template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
371        = is_nothrow_swappable_with<T, U>::value;                       // C++17
372      template <class T> inline constexpr bool is_nothrow_swappable_v
373        = is_nothrow_swappable<T>::value;                               // C++17
374      template <class T> inline constexpr bool is_nothrow_destructible_v
375        = is_nothrow_destructible<T>::value;                             // C++17
376      template <class T> inline constexpr bool has_virtual_destructor_v
377        = has_virtual_destructor<T>::value;                              // C++17
378      template<class T> inline constexpr bool has_unique_object_representations_v // C++17
379        = has_unique_object_representations<T>::value;
380
381      // See C++14 20.10.5, type property queries
382      template <class T> inline constexpr size_t alignment_of_v
383        = alignment_of<T>::value;                                        // C++17
384      template <class T> inline constexpr size_t rank_v
385        = rank<T>::value;                                                // C++17
386      template <class T, unsigned I = 0> inline constexpr size_t extent_v
387        = extent<T, I>::value;                                           // C++17
388
389      // See C++14 20.10.6, type relations
390      template <class T, class U> inline constexpr bool is_same_v
391        = is_same<T, U>::value;                                          // C++17
392      template <class Base, class Derived> inline constexpr bool is_base_of_v
393        = is_base_of<Base, Derived>::value;                              // C++17
394      template <class From, class To> inline constexpr bool is_convertible_v
395        = is_convertible<From, To>::value;                               // C++17
396      template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
397        = is_invocable<Fn, ArgTypes...>::value;                          // C++17
398      template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
399        = is_invocable_r<R, Fn, ArgTypes...>::value;                     // C++17
400      template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
401        = is_nothrow_invocable<Fn, ArgTypes...>::value;                  // C++17
402      template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
403        = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;             // C++17
404
405      // [meta.logical], logical operator traits:
406      template<class... B> struct conjunction;                           // C++17
407      template<class... B>
408        inline constexpr bool conjunction_v = conjunction<B...>::value;  // C++17
409      template<class... B> struct disjunction;                           // C++17
410      template<class... B>
411        inline constexpr bool disjunction_v = disjunction<B...>::value;  // C++17
412      template<class B> struct negation;                                 // C++17
413      template<class B>
414        inline constexpr bool negation_v = negation<B>::value;           // C++17
415
416}
417
418*/
419#include <__assert> // all public C++ headers provide the assertion handler
420#include <__config>
421#include <__functional/invoke.h>
422#include <__type_traits/add_const.h>
423#include <__type_traits/add_cv.h>
424#include <__type_traits/add_lvalue_reference.h>
425#include <__type_traits/add_pointer.h>
426#include <__type_traits/add_rvalue_reference.h>
427#include <__type_traits/add_volatile.h>
428#include <__type_traits/alignment_of.h>
429#include <__type_traits/apply_cv.h>
430#include <__type_traits/conditional.h>
431#include <__type_traits/conjunction.h>
432#include <__type_traits/decay.h>
433#include <__type_traits/disjunction.h>
434#include <__type_traits/enable_if.h>
435#include <__type_traits/extent.h>
436#include <__type_traits/has_unique_object_representation.h>
437#include <__type_traits/has_virtual_destructor.h>
438#include <__type_traits/integral_constant.h>
439#include <__type_traits/is_abstract.h>
440#include <__type_traits/is_aggregate.h>
441#include <__type_traits/is_arithmetic.h>
442#include <__type_traits/is_array.h>
443#include <__type_traits/is_assignable.h>
444#include <__type_traits/is_base_of.h>
445#include <__type_traits/is_bounded_array.h>
446#include <__type_traits/is_callable.h>
447#include <__type_traits/is_class.h>
448#include <__type_traits/is_compound.h>
449#include <__type_traits/is_const.h>
450#include <__type_traits/is_constant_evaluated.h>
451#include <__type_traits/is_convertible.h>
452#include <__type_traits/is_copy_assignable.h>
453#include <__type_traits/is_empty.h>
454#include <__type_traits/is_enum.h>
455#include <__type_traits/is_final.h>
456#include <__type_traits/is_floating_point.h>
457#include <__type_traits/is_function.h>
458#include <__type_traits/is_fundamental.h>
459#include <__type_traits/is_integral.h>
460#include <__type_traits/is_literal_type.h>
461#include <__type_traits/is_member_function_pointer.h>
462#include <__type_traits/is_member_object_pointer.h>
463#include <__type_traits/is_member_pointer.h>
464#include <__type_traits/is_move_assignable.h>
465#include <__type_traits/is_null_pointer.h>
466#include <__type_traits/is_object.h>
467#include <__type_traits/is_pod.h>
468#include <__type_traits/is_pointer.h>
469#include <__type_traits/is_polymorphic.h>
470#include <__type_traits/is_reference.h>
471#include <__type_traits/is_reference_wrapper.h>
472#include <__type_traits/is_referenceable.h>
473#include <__type_traits/is_same.h>
474#include <__type_traits/is_scalar.h>
475#include <__type_traits/is_scoped_enum.h>
476#include <__type_traits/is_signed.h>
477#include <__type_traits/is_standard_layout.h>
478#include <__type_traits/is_trivial.h>
479#include <__type_traits/is_trivially_copyable.h>
480#include <__type_traits/is_unbounded_array.h>
481#include <__type_traits/is_union.h>
482#include <__type_traits/is_unsigned.h>
483#include <__type_traits/is_void.h>
484#include <__type_traits/is_volatile.h>
485#include <__type_traits/rank.h>
486#include <__type_traits/remove_all_extents.h>
487#include <__type_traits/remove_const.h>
488#include <__type_traits/remove_cv.h>
489#include <__type_traits/remove_extent.h>
490#include <__type_traits/remove_pointer.h>
491#include <__type_traits/remove_reference.h>
492#include <__type_traits/remove_volatile.h>
493#include <__type_traits/type_identity.h>
494#include <__type_traits/underlying_type.h>
495#include <__utility/declval.h>
496#include <cstddef>
497#include <version>
498
499#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
500#  pragma GCC system_header
501#endif
502
503_LIBCPP_BEGIN_NAMESPACE_STD
504
505template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair;
506template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
507
508template <bool> struct _MetaBase;
509template <>
510struct _MetaBase<true> {
511  template <class _Tp, class _Up>
512  using _SelectImpl _LIBCPP_NODEBUG = _Tp;
513  template <template <class...> class _FirstFn, template <class...> class, class ..._Args>
514  using _SelectApplyImpl _LIBCPP_NODEBUG = _FirstFn<_Args...>;
515  template <class _First, class...>
516  using _FirstImpl _LIBCPP_NODEBUG = _First;
517  template <class, class _Second, class...>
518  using _SecondImpl _LIBCPP_NODEBUG = _Second;
519  template <class _Result, class _First, class ..._Rest>
520  using _OrImpl _LIBCPP_NODEBUG = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
521};
522
523template <>
524struct _MetaBase<false> {
525  template <class _Tp, class _Up>
526  using _SelectImpl _LIBCPP_NODEBUG = _Up;
527  template <template <class...> class, template <class...> class _SecondFn, class ..._Args>
528  using _SelectApplyImpl _LIBCPP_NODEBUG = _SecondFn<_Args...>;
529  template <class _Result, class ...>
530  using _OrImpl _LIBCPP_NODEBUG = _Result;
531};
532template <bool _Cond, class _IfRes, class _ElseRes>
533using _If _LIBCPP_NODEBUG = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
534template <class ..._Rest>
535using _Or _LIBCPP_NODEBUG = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
536template <class _Pred>
537struct _Not : _BoolConstant<!_Pred::value> {};
538template <class ..._Args>
539using _FirstType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
540template <class ..._Args>
541using _SecondType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
542
543template <class ...> using __expand_to_true = true_type;
544template <class ..._Pred>
545__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
546template <class ...>
547false_type __and_helper(...);
548template <class ..._Pred>
549using _And _LIBCPP_NODEBUG = decltype(__and_helper<_Pred...>(0));
550
551template <template <class...> class _Func, class ..._Args>
552struct _Lazy : _Func<_Args...> {};
553
554// Member detector base
555
556template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> >
557true_type __sfinae_test_impl(int);
558template <template <class...> class, class ...>
559false_type __sfinae_test_impl(...);
560
561template <template <class ...> class _Templ, class ..._Args>
562using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
563
564template <class>
565struct __void_t { typedef void type; };
566
567template <class _Tp, bool>
568struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
569
570// is_same
571
572template <class _Tp>
573using __test_for_primary_template = __enable_if_t<
574    _IsSame<_Tp, typename _Tp::__primary_template>::value
575  >;
576template <class _Tp>
577using __is_primary_template = _IsValidExpansion<
578    __test_for_primary_template, _Tp
579  >;
580
581// is_integral
582
583// [basic.fundamental] defines five standard signed integer types;
584// __int128_t is an extended signed integer type.
585// The signed and unsigned integer types, plus bool and the
586// five types with "char" in their name, compose the "integral" types.
587
588template <class _Tp> struct __libcpp_is_signed_integer : public false_type {};
589template <> struct __libcpp_is_signed_integer<signed char>      : public true_type {};
590template <> struct __libcpp_is_signed_integer<signed short>     : public true_type {};
591template <> struct __libcpp_is_signed_integer<signed int>       : public true_type {};
592template <> struct __libcpp_is_signed_integer<signed long>      : public true_type {};
593template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
594#ifndef _LIBCPP_HAS_NO_INT128
595template <> struct __libcpp_is_signed_integer<__int128_t>       : public true_type {};
596#endif
597
598template <class _Tp> struct __libcpp_is_unsigned_integer : public false_type {};
599template <> struct __libcpp_is_unsigned_integer<unsigned char>      : public true_type {};
600template <> struct __libcpp_is_unsigned_integer<unsigned short>     : public true_type {};
601template <> struct __libcpp_is_unsigned_integer<unsigned int>       : public true_type {};
602template <> struct __libcpp_is_unsigned_integer<unsigned long>      : public true_type {};
603template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
604#ifndef _LIBCPP_HAS_NO_INT128
605template <> struct __libcpp_is_unsigned_integer<__uint128_t>        : public true_type {};
606#endif
607
608template <class _Tp>
609struct __unconstref {
610    typedef _LIBCPP_NODEBUG typename remove_const<typename remove_reference<_Tp>::type>::type type;
611};
612
613template <class _Tp>
614using __uncvref_t _LIBCPP_NODEBUG = typename remove_cv<typename remove_reference<_Tp>::type>::type;
615
616// __is_same_uncvref
617
618template <class _Tp, class _Up>
619struct __is_same_uncvref : _IsSame<__uncvref_t<_Tp>, __uncvref_t<_Up> > {};
620
621#if _LIBCPP_STD_VER > 17
622// remove_cvref - same as __uncvref
623template <class _Tp>
624struct remove_cvref {
625    using type _LIBCPP_NODEBUG = __uncvref_t<_Tp>;
626};
627
628template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type;
629#endif
630
631// is_nothrow_convertible
632
633#if _LIBCPP_STD_VER > 17
634
635template <typename _Tp>
636static void __test_noexcept(_Tp) noexcept;
637
638template<typename _Fm, typename _To>
639static bool_constant<noexcept(_VSTD::__test_noexcept<_To>(declval<_Fm>()))>
640__is_nothrow_convertible_test();
641
642template <typename _Fm, typename _To>
643struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>())
644{ };
645
646template <typename _Fm, typename _To>
647struct is_nothrow_convertible : _Or<
648    _And<is_void<_To>, is_void<_Fm>>,
649    _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>>
650>::type { };
651
652template <typename _Fm, typename _To>
653inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
654
655#endif // _LIBCPP_STD_VER > 17
656
657// aligned_storage
658
659template <class _Hp, class _Tp>
660struct __type_list
661{
662    typedef _Hp _Head;
663    typedef _Tp _Tail;
664};
665
666template <class _Tp>
667struct __align_type
668{
669    static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp);
670    typedef _Tp type;
671};
672
673struct __struct_double {long double __lx;};
674struct __struct_double4 {double __lx[4];};
675
676typedef
677    __type_list<__align_type<unsigned char>,
678    __type_list<__align_type<unsigned short>,
679    __type_list<__align_type<unsigned int>,
680    __type_list<__align_type<unsigned long>,
681    __type_list<__align_type<unsigned long long>,
682    __type_list<__align_type<double>,
683    __type_list<__align_type<long double>,
684    __type_list<__align_type<__struct_double>,
685    __type_list<__align_type<__struct_double4>,
686    __type_list<__align_type<int*>,
687    __nat
688    > > > > > > > > > > __all_types;
689
690template <size_t _Align>
691struct _ALIGNAS(_Align) __fallback_overaligned {};
692
693template <class _TL, size_t _Align> struct __find_pod;
694
695template <class _Hp, size_t _Align>
696struct __find_pod<__type_list<_Hp, __nat>, _Align>
697{
698    typedef typename conditional<
699                             _Align == _Hp::value,
700                             typename _Hp::type,
701                             __fallback_overaligned<_Align>
702                         >::type type;
703};
704
705template <class _Hp, class _Tp, size_t _Align>
706struct __find_pod<__type_list<_Hp, _Tp>, _Align>
707{
708    typedef typename conditional<
709                             _Align == _Hp::value,
710                             typename _Hp::type,
711                             typename __find_pod<_Tp, _Align>::type
712                         >::type type;
713};
714
715template <class _TL, size_t _Len> struct __find_max_align;
716
717template <class _Hp, size_t _Len>
718struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
719
720template <size_t _Len, size_t _A1, size_t _A2>
721struct __select_align
722{
723private:
724    static const size_t __min = _A2 < _A1 ? _A2 : _A1;
725    static const size_t __max = _A1 < _A2 ? _A2 : _A1;
726public:
727    static const size_t value = _Len < __max ? __min : __max;
728};
729
730template <class _Hp, class _Tp, size_t _Len>
731struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
732    : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
733
734template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
735struct _LIBCPP_TEMPLATE_VIS aligned_storage
736{
737    typedef typename __find_pod<__all_types, _Align>::type _Aligner;
738    union type
739    {
740        _Aligner __align;
741        unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
742    };
743};
744
745#if _LIBCPP_STD_VER > 11
746template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
747    using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
748#endif
749
750#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
751template <size_t _Len>\
752struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
753{\
754    struct _ALIGNAS(n) type\
755    {\
756        unsigned char __lx[(_Len + n - 1)/n * n];\
757    };\
758}
759
760_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
761_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
762_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
763_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
764_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
765_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
766_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
767_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
768_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
769_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
770_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
771_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
772_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
773_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
774// PE/COFF does not support alignment beyond 8192 (=0x2000)
775#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
776_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
777#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
778
779#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
780
781
782// aligned_union
783
784template <size_t _I0, size_t ..._In>
785struct __static_max;
786
787template <size_t _I0>
788struct __static_max<_I0>
789{
790    static const size_t value = _I0;
791};
792
793template <size_t _I0, size_t _I1, size_t ..._In>
794struct __static_max<_I0, _I1, _In...>
795{
796    static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
797                                             __static_max<_I1, _In...>::value;
798};
799
800template <size_t _Len, class _Type0, class ..._Types>
801struct aligned_union
802{
803    static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0),
804                                                       _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
805    static const size_t __len = __static_max<_Len, sizeof(_Type0),
806                                             sizeof(_Types)...>::value;
807    typedef typename aligned_storage<__len, alignment_value>::type type;
808};
809
810#if _LIBCPP_STD_VER > 11
811template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
812#endif
813
814template <class _Tp>
815struct __numeric_type
816{
817   static void __test(...);
818   static float __test(float);
819   static double __test(char);
820   static double __test(int);
821   static double __test(unsigned);
822   static double __test(long);
823   static double __test(unsigned long);
824   static double __test(long long);
825   static double __test(unsigned long long);
826   static double __test(double);
827   static long double __test(long double);
828
829   typedef decltype(__test(declval<_Tp>())) type;
830   static const bool value = _IsNotSame<type, void>::value;
831};
832
833template <>
834struct __numeric_type<void>
835{
836   static const bool value = true;
837};
838
839// __promote
840
841template <class _A1, class _A2 = void, class _A3 = void,
842          bool = __numeric_type<_A1>::value &&
843                 __numeric_type<_A2>::value &&
844                 __numeric_type<_A3>::value>
845class __promote_imp
846{
847public:
848    static const bool value = false;
849};
850
851template <class _A1, class _A2, class _A3>
852class __promote_imp<_A1, _A2, _A3, true>
853{
854private:
855    typedef typename __promote_imp<_A1>::type __type1;
856    typedef typename __promote_imp<_A2>::type __type2;
857    typedef typename __promote_imp<_A3>::type __type3;
858public:
859    typedef decltype(__type1() + __type2() + __type3()) type;
860    static const bool value = true;
861};
862
863template <class _A1, class _A2>
864class __promote_imp<_A1, _A2, void, true>
865{
866private:
867    typedef typename __promote_imp<_A1>::type __type1;
868    typedef typename __promote_imp<_A2>::type __type2;
869public:
870    typedef decltype(__type1() + __type2()) type;
871    static const bool value = true;
872};
873
874template <class _A1>
875class __promote_imp<_A1, void, void, true>
876{
877public:
878    typedef typename __numeric_type<_A1>::type type;
879    static const bool value = true;
880};
881
882template <class _A1, class _A2 = void, class _A3 = void>
883class __promote : public __promote_imp<_A1, _A2, _A3> {};
884
885// make_signed / make_unsigned
886
887typedef
888    __type_list<signed char,
889    __type_list<signed short,
890    __type_list<signed int,
891    __type_list<signed long,
892    __type_list<signed long long,
893#ifndef _LIBCPP_HAS_NO_INT128
894    __type_list<__int128_t,
895#endif
896    __nat
897#ifndef _LIBCPP_HAS_NO_INT128
898    >
899#endif
900    > > > > > __signed_types;
901
902typedef
903    __type_list<unsigned char,
904    __type_list<unsigned short,
905    __type_list<unsigned int,
906    __type_list<unsigned long,
907    __type_list<unsigned long long,
908#ifndef _LIBCPP_HAS_NO_INT128
909    __type_list<__uint128_t,
910#endif
911    __nat
912#ifndef _LIBCPP_HAS_NO_INT128
913    >
914#endif
915    > > > > > __unsigned_types;
916
917template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
918
919template <class _Hp, class _Tp, size_t _Size>
920struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
921{
922    typedef _LIBCPP_NODEBUG _Hp type;
923};
924
925template <class _Hp, class _Tp, size_t _Size>
926struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
927{
928    typedef _LIBCPP_NODEBUG typename __find_first<_Tp, _Size>::type type;
929};
930
931template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
932struct __make_signed {};
933
934template <class _Tp>
935struct __make_signed<_Tp, true>
936{
937    typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
938};
939
940template <> struct __make_signed<bool,               true> {};
941template <> struct __make_signed<  signed short,     true> {typedef short     type;};
942template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
943template <> struct __make_signed<  signed int,       true> {typedef int       type;};
944template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
945template <> struct __make_signed<  signed long,      true> {typedef long      type;};
946template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
947template <> struct __make_signed<  signed long long, true> {typedef long long type;};
948template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
949#ifndef _LIBCPP_HAS_NO_INT128
950template <> struct __make_signed<__int128_t,         true> {typedef __int128_t type;};
951template <> struct __make_signed<__uint128_t,        true> {typedef __int128_t type;};
952#endif
953
954template <class _Tp>
955struct _LIBCPP_TEMPLATE_VIS make_signed
956{
957    typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
958};
959
960#if _LIBCPP_STD_VER > 11
961template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
962#endif
963
964template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
965struct __make_unsigned {};
966
967template <class _Tp>
968struct __make_unsigned<_Tp, true>
969{
970    typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
971};
972
973template <> struct __make_unsigned<bool,               true> {};
974template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
975template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
976template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
977template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
978template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
979template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
980template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
981template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
982#ifndef _LIBCPP_HAS_NO_INT128
983template <> struct __make_unsigned<__int128_t,         true> {typedef __uint128_t        type;};
984template <> struct __make_unsigned<__uint128_t,        true> {typedef __uint128_t        type;};
985#endif
986
987template <class _Tp>
988struct _LIBCPP_TEMPLATE_VIS make_unsigned
989{
990    typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
991};
992
993#if _LIBCPP_STD_VER > 11
994template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
995#endif
996
997#ifndef _LIBCPP_CXX03_LANG
998template <class _Tp>
999_LIBCPP_HIDE_FROM_ABI constexpr
1000typename make_unsigned<_Tp>::type __to_unsigned_like(_Tp __x) noexcept {
1001    return static_cast<typename make_unsigned<_Tp>::type>(__x);
1002}
1003#endif
1004
1005#if _LIBCPP_STD_VER > 14
1006template <class...> using void_t = void;
1007#endif
1008
1009#if _LIBCPP_STD_VER > 17
1010// Let COND_RES(X, Y) be:
1011template <class _Tp, class _Up>
1012using __cond_type = decltype(false ? declval<_Tp>() : declval<_Up>());
1013
1014template <class _Tp, class _Up, class = void>
1015struct __common_type3 {};
1016
1017// sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
1018template <class _Tp, class _Up>
1019struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>>
1020{
1021    using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
1022};
1023
1024template <class _Tp, class _Up, class = void>
1025struct __common_type2_imp : __common_type3<_Tp, _Up> {};
1026#else
1027template <class _Tp, class _Up, class = void>
1028struct __common_type2_imp {};
1029#endif
1030
1031// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
1032template <class _Tp, class _Up>
1033struct __common_type2_imp<_Tp, _Up,
1034                          typename __void_t<decltype(
1035                                            true ? declval<_Tp>() : declval<_Up>()
1036                                            )>::type>
1037{
1038  typedef _LIBCPP_NODEBUG typename decay<decltype(
1039                         true ? declval<_Tp>() : declval<_Up>()
1040                         )>::type type;
1041};
1042
1043template <class, class = void>
1044struct __common_type_impl {};
1045
1046// Clang provides variadic templates in C++03 as an extension.
1047#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__)
1048# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
1049template <class... _Tp>
1050struct __common_types;
1051template <class... _Tp>
1052struct _LIBCPP_TEMPLATE_VIS common_type;
1053#else
1054# define _LIBCPP_OPTIONAL_PACK(...)
1055struct __no_arg;
1056template <class _Tp, class _Up, class = __no_arg>
1057struct __common_types;
1058template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg,
1059          class _Unused = __no_arg>
1060struct common_type {
1061  static_assert(sizeof(_Unused) == 0,
1062                "common_type accepts at most 3 arguments in C++03");
1063};
1064#endif // _LIBCPP_CXX03_LANG
1065
1066template <class _Tp, class _Up>
1067struct __common_type_impl<
1068    __common_types<_Tp, _Up>,
1069    typename __void_t<typename common_type<_Tp, _Up>::type>::type>
1070{
1071  typedef typename common_type<_Tp, _Up>::type type;
1072};
1073
1074template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
1075struct __common_type_impl<
1076    __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>,
1077    typename __void_t<typename common_type<_Tp, _Up>::type>::type>
1078    : __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type,
1079                                        _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {
1080};
1081
1082// bullet 1 - sizeof...(Tp) == 0
1083
1084template <>
1085struct _LIBCPP_TEMPLATE_VIS common_type<> {};
1086
1087// bullet 2 - sizeof...(Tp) == 1
1088
1089template <class _Tp>
1090struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
1091    : public common_type<_Tp, _Tp> {};
1092
1093// bullet 3 - sizeof...(Tp) == 2
1094
1095// sub-bullet 1 - "If is_same_v<T1, D1> is false or ..."
1096template <class _Tp, class _Up>
1097struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
1098    : conditional<
1099        _IsSame<_Tp, typename decay<_Tp>::type>::value && _IsSame<_Up, typename decay<_Up>::type>::value,
1100        __common_type2_imp<_Tp, _Up>,
1101        common_type<typename decay<_Tp>::type, typename decay<_Up>::type>
1102    >::type
1103{};
1104
1105// bullet 4 - sizeof...(Tp) > 2
1106
1107template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
1108struct _LIBCPP_TEMPLATE_VIS
1109    common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>
1110    : __common_type_impl<
1111          __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {};
1112
1113#undef _LIBCPP_OPTIONAL_PACK
1114
1115#if _LIBCPP_STD_VER > 11
1116template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
1117#endif
1118
1119#if _LIBCPP_STD_VER > 11
1120// Let COPYCV(FROM, TO) be an alias for type TO with the addition of FROM's
1121// top-level cv-qualifiers.
1122template <class _From, class _To>
1123struct __copy_cv
1124{
1125    using type = _To;
1126};
1127
1128template <class _From, class _To>
1129struct __copy_cv<const _From, _To>
1130{
1131    using type = add_const_t<_To>;
1132};
1133
1134template <class _From, class _To>
1135struct __copy_cv<volatile _From, _To>
1136{
1137    using type = add_volatile_t<_To>;
1138};
1139
1140template <class _From, class _To>
1141struct __copy_cv<const volatile _From, _To>
1142{
1143    using type = add_cv_t<_To>;
1144};
1145
1146template <class _From, class _To>
1147using __copy_cv_t = typename __copy_cv<_From, _To>::type;
1148
1149template <class _From, class _To>
1150struct __copy_cvref
1151{
1152    using type = __copy_cv_t<_From, _To>;
1153};
1154
1155template <class _From, class _To>
1156struct __copy_cvref<_From&, _To>
1157{
1158    using type = add_lvalue_reference_t<__copy_cv_t<_From, _To>>;
1159};
1160
1161template <class _From, class _To>
1162struct __copy_cvref<_From&&, _To>
1163{
1164    using type = add_rvalue_reference_t<__copy_cv_t<_From, _To>>;
1165};
1166
1167template <class _From, class _To>
1168using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
1169
1170#endif // _LIBCPP_STD_VER > 11
1171
1172// common_reference
1173#if _LIBCPP_STD_VER > 17
1174// Let COND_RES(X, Y) be:
1175template <class _Xp, class _Yp>
1176using __cond_res =
1177    decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
1178
1179// Let `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes the same type as `U`
1180// with the addition of `A`'s cv and reference qualifiers, for a non-reference cv-unqualified type
1181// `U`.
1182// [Note: `XREF(A)` is `__xref<A>::template __apply`]
1183template <class _Tp>
1184struct __xref {
1185  template<class _Up>
1186  using __apply = __copy_cvref_t<_Tp, _Up>;
1187};
1188
1189// Given types A and B, let X be remove_reference_t<A>, let Y be remove_reference_t<B>,
1190// and let COMMON-REF(A, B) be:
1191template<class _Ap, class _Bp, class _Xp = remove_reference_t<_Ap>, class _Yp = remove_reference_t<_Bp>>
1192struct __common_ref;
1193
1194template<class _Xp, class _Yp>
1195using __common_ref_t = typename __common_ref<_Xp, _Yp>::__type;
1196
1197template<class _Xp, class _Yp>
1198using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>;
1199
1200
1201//    If A and B are both lvalue reference types, COMMON-REF(A, B) is
1202//    COND-RES(COPYCV(X, Y)&, COPYCV(Y, X)&) if that type exists and is a reference type.
1203template<class _Ap, class _Bp, class _Xp, class _Yp>
1204requires requires { typename __cv_cond_res<_Xp, _Yp>; } && is_reference_v<__cv_cond_res<_Xp, _Yp>>
1205struct __common_ref<_Ap&, _Bp&, _Xp, _Yp>
1206{
1207    using __type = __cv_cond_res<_Xp, _Yp>;
1208};
1209
1210//    Otherwise, let C be remove_reference_t<COMMON-REF(X&, Y&)>&&. ...
1211template <class _Xp, class _Yp>
1212using __common_ref_C = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
1213
1214
1215//    .... If A and B are both rvalue reference types, C is well-formed, and
1216//    is_convertible_v<A, C> && is_convertible_v<B, C> is true, then COMMON-REF(A, B) is C.
1217template<class _Ap, class _Bp, class _Xp, class _Yp>
1218requires
1219  requires { typename __common_ref_C<_Xp, _Yp>; } &&
1220  is_convertible_v<_Ap&&, __common_ref_C<_Xp, _Yp>> &&
1221  is_convertible_v<_Bp&&, __common_ref_C<_Xp, _Yp>>
1222struct __common_ref<_Ap&&, _Bp&&, _Xp, _Yp>
1223{
1224    using __type = __common_ref_C<_Xp, _Yp>;
1225};
1226
1227//    Otherwise, let D be COMMON-REF(const X&, Y&). ...
1228template <class _Tp, class _Up>
1229using __common_ref_D = __common_ref_t<const _Tp&, _Up&>;
1230
1231//    ... If A is an rvalue reference and B is an lvalue reference and D is well-formed and
1232//    is_convertible_v<A, D> is true, then COMMON-REF(A, B) is D.
1233template<class _Ap, class _Bp, class _Xp, class _Yp>
1234requires requires { typename __common_ref_D<_Xp, _Yp>; } &&
1235         is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>>
1236struct __common_ref<_Ap&&, _Bp&, _Xp, _Yp>
1237{
1238    using __type = __common_ref_D<_Xp, _Yp>;
1239};
1240
1241//    Otherwise, if A is an lvalue reference and B is an rvalue reference, then
1242//    COMMON-REF(A, B) is COMMON-REF(B, A).
1243template<class _Ap, class _Bp, class _Xp, class _Yp>
1244struct __common_ref<_Ap&, _Bp&&, _Xp, _Yp> : __common_ref<_Bp&&, _Ap&> {};
1245
1246//    Otherwise, COMMON-REF(A, B) is ill-formed.
1247template<class _Ap, class _Bp, class _Xp, class _Yp>
1248struct __common_ref {};
1249
1250// Note C: For the common_reference trait applied to a parameter pack [...]
1251
1252template <class...>
1253struct common_reference;
1254
1255template <class... _Types>
1256using common_reference_t = typename common_reference<_Types...>::type;
1257
1258// bullet 1 - sizeof...(T) == 0
1259template<>
1260struct common_reference<> {};
1261
1262// bullet 2 - sizeof...(T) == 1
1263template <class _Tp>
1264struct common_reference<_Tp>
1265{
1266    using type = _Tp;
1267};
1268
1269// bullet 3 - sizeof...(T) == 2
1270template <class _Tp, class _Up> struct __common_reference_sub_bullet3;
1271template <class _Tp, class _Up> struct __common_reference_sub_bullet2 : __common_reference_sub_bullet3<_Tp, _Up> {};
1272template <class _Tp, class _Up> struct __common_reference_sub_bullet1 : __common_reference_sub_bullet2<_Tp, _Up> {};
1273
1274// sub-bullet 1 - If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, then
1275// the member typedef `type` denotes that type.
1276template <class _Tp, class _Up> struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
1277
1278template <class _Tp, class _Up>
1279requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
1280struct __common_reference_sub_bullet1<_Tp, _Up>
1281{
1282    using type = __common_ref_t<_Tp, _Up>;
1283};
1284
1285// sub-bullet 2 - Otherwise, if basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>, XREF(T1), XREF(T2)>::type
1286// is well-formed, then the member typedef `type` denotes that type.
1287template <class, class, template <class> class, template <class> class> struct basic_common_reference {};
1288
1289template <class _Tp, class _Up>
1290using __basic_common_reference_t = typename basic_common_reference<
1291    remove_cvref_t<_Tp>, remove_cvref_t<_Up>,
1292    __xref<_Tp>::template __apply, __xref<_Up>::template __apply>::type;
1293
1294template <class _Tp, class _Up>
1295requires requires { typename __basic_common_reference_t<_Tp, _Up>; }
1296struct __common_reference_sub_bullet2<_Tp, _Up>
1297{
1298    using type = __basic_common_reference_t<_Tp, _Up>;
1299};
1300
1301// sub-bullet 3 - Otherwise, if COND-RES(T1, T2) is well-formed,
1302// then the member typedef `type` denotes that type.
1303template <class _Tp, class _Up>
1304requires requires { typename __cond_res<_Tp, _Up>; }
1305struct __common_reference_sub_bullet3<_Tp, _Up>
1306{
1307    using type = __cond_res<_Tp, _Up>;
1308};
1309
1310
1311// sub-bullet 4 & 5 - Otherwise, if common_type_t<T1, T2> is well-formed,
1312//                    then the member typedef `type` denotes that type.
1313//                  - Otherwise, there shall be no member `type`.
1314template <class _Tp, class _Up> struct __common_reference_sub_bullet3 : common_type<_Tp, _Up> {};
1315
1316// bullet 4 - If there is such a type `C`, the member typedef type shall denote the same type, if
1317//            any, as `common_reference_t<C, Rest...>`.
1318template <class _Tp, class _Up, class _Vp, class... _Rest>
1319requires requires { typename common_reference_t<_Tp, _Up>; }
1320struct common_reference<_Tp, _Up, _Vp, _Rest...>
1321    : common_reference<common_reference_t<_Tp, _Up>, _Vp, _Rest...>
1322{};
1323
1324// bullet 5 - Otherwise, there shall be no member `type`.
1325template <class...> struct common_reference {};
1326
1327#endif // _LIBCPP_STD_VER > 17
1328
1329// is_destructible
1330
1331#if __has_keyword(__is_destructible)
1332
1333template<class _Tp>
1334struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
1335
1336#if _LIBCPP_STD_VER > 14
1337template <class _Tp>
1338inline constexpr bool is_destructible_v = __is_destructible(_Tp);
1339#endif
1340
1341#else // __has_keyword(__is_destructible)
1342
1343//  if it's a reference, return true
1344//  if it's a function, return false
1345//  if it's   void,     return false
1346//  if it's an array of unknown bound, return false
1347//  Otherwise, return "declval<_Up&>().~_Up()" is well-formed
1348//    where _Up is remove_all_extents<_Tp>::type
1349
1350template <class>
1351struct __is_destructible_apply { typedef int type; };
1352
1353template <typename _Tp>
1354struct __is_destructor_wellformed {
1355    template <typename _Tp1>
1356    static true_type  __test (
1357        typename __is_destructible_apply<decltype(declval<_Tp1&>().~_Tp1())>::type
1358    );
1359
1360    template <typename _Tp1>
1361    static false_type __test (...);
1362
1363    static const bool value = decltype(__test<_Tp>(12))::value;
1364};
1365
1366template <class _Tp, bool>
1367struct __destructible_imp;
1368
1369template <class _Tp>
1370struct __destructible_imp<_Tp, false>
1371   : public integral_constant<bool,
1372        __is_destructor_wellformed<typename remove_all_extents<_Tp>::type>::value> {};
1373
1374template <class _Tp>
1375struct __destructible_imp<_Tp, true>
1376    : public true_type {};
1377
1378template <class _Tp, bool>
1379struct __destructible_false;
1380
1381template <class _Tp>
1382struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, is_reference<_Tp>::value> {};
1383
1384template <class _Tp>
1385struct __destructible_false<_Tp, true> : public false_type {};
1386
1387template <class _Tp>
1388struct is_destructible
1389    : public __destructible_false<_Tp, is_function<_Tp>::value> {};
1390
1391template <class _Tp>
1392struct is_destructible<_Tp[]>
1393    : public false_type {};
1394
1395template <>
1396struct is_destructible<void>
1397    : public false_type {};
1398
1399#if _LIBCPP_STD_VER > 14
1400template <class _Tp>
1401inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
1402#endif
1403
1404#endif // __has_keyword(__is_destructible)
1405
1406// template <class T, class... Args> struct is_constructible;
1407
1408template <class _Tp, class ..._Args>
1409struct _LIBCPP_TEMPLATE_VIS is_constructible
1410    : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
1411{ };
1412
1413#if _LIBCPP_STD_VER > 14
1414template <class _Tp, class ..._Args>
1415inline constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value;
1416#endif
1417
1418// is_default_constructible
1419
1420template <class _Tp>
1421struct _LIBCPP_TEMPLATE_VIS is_default_constructible
1422    : public is_constructible<_Tp>
1423    {};
1424
1425#if _LIBCPP_STD_VER > 14
1426template <class _Tp>
1427inline constexpr bool is_default_constructible_v = is_default_constructible<_Tp>::value;
1428#endif
1429
1430#ifndef _LIBCPP_CXX03_LANG
1431// First of all, we can't implement this check in C++03 mode because the {}
1432// default initialization syntax isn't valid.
1433// Second, we implement the trait in a funny manner with two defaulted template
1434// arguments to workaround Clang's PR43454.
1435template <class _Tp>
1436void __test_implicit_default_constructible(_Tp);
1437
1438template <class _Tp, class = void, class = typename is_default_constructible<_Tp>::type>
1439struct __is_implicitly_default_constructible
1440    : false_type
1441{ };
1442
1443template <class _Tp>
1444struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true_type>
1445    : true_type
1446{ };
1447
1448template <class _Tp>
1449struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), false_type>
1450    : false_type
1451{ };
1452#endif // !C++03
1453
1454// is_copy_constructible
1455
1456template <class _Tp>
1457struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
1458    : public is_constructible<_Tp,
1459                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
1460
1461#if _LIBCPP_STD_VER > 14
1462template <class _Tp>
1463inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
1464#endif
1465
1466// is_move_constructible
1467
1468template <class _Tp>
1469struct _LIBCPP_TEMPLATE_VIS is_move_constructible
1470    : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
1471    {};
1472
1473#if _LIBCPP_STD_VER > 14
1474template <class _Tp>
1475inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
1476#endif
1477
1478// is_trivially_constructible
1479
1480template <class _Tp, class... _Args>
1481struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
1482    : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
1483{
1484};
1485
1486#if _LIBCPP_STD_VER > 14
1487template <class _Tp, class... _Args>
1488inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value;
1489#endif
1490
1491// is_trivially_default_constructible
1492
1493template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
1494    : public is_trivially_constructible<_Tp>
1495    {};
1496
1497#if _LIBCPP_STD_VER > 14
1498template <class _Tp>
1499inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<_Tp>::value;
1500#endif
1501
1502// is_trivially_copy_constructible
1503
1504template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
1505    : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
1506    {};
1507
1508#if _LIBCPP_STD_VER > 14
1509template <class _Tp>
1510inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value;
1511#endif
1512
1513// is_trivially_move_constructible
1514
1515template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
1516    : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
1517    {};
1518
1519#if _LIBCPP_STD_VER > 14
1520template <class _Tp>
1521inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value;
1522#endif
1523
1524// is_trivially_assignable
1525
1526template <class _Tp, class _Arg>
1527struct is_trivially_assignable
1528    : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
1529{ };
1530
1531#if _LIBCPP_STD_VER > 14
1532template <class _Tp, class _Arg>
1533inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<_Tp, _Arg>::value;
1534#endif
1535
1536// is_trivially_copy_assignable
1537
1538template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
1539    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
1540                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
1541
1542#if _LIBCPP_STD_VER > 14
1543template <class _Tp>
1544inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value;
1545#endif
1546
1547// is_trivially_move_assignable
1548
1549template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
1550    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
1551                                     typename add_rvalue_reference<_Tp>::type>
1552    {};
1553
1554#if _LIBCPP_STD_VER > 14
1555template <class _Tp>
1556inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value;
1557#endif
1558
1559// is_trivially_destructible
1560
1561#if __has_keyword(__is_trivially_destructible)
1562
1563template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
1564    : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
1565
1566#elif __has_feature(has_trivial_destructor) || defined(_LIBCPP_COMPILER_GCC)
1567
1568template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
1569    : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
1570
1571#else
1572
1573template <class _Tp> struct __libcpp_trivial_destructor
1574    : public integral_constant<bool, is_scalar<_Tp>::value ||
1575                                     is_reference<_Tp>::value> {};
1576
1577template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
1578    : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
1579
1580template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]>
1581    : public false_type {};
1582
1583#endif
1584
1585#if _LIBCPP_STD_VER > 14
1586template <class _Tp>
1587inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
1588#endif
1589
1590// is_nothrow_constructible
1591
1592#if __has_keyword(__is_nothrow_constructible)
1593
1594template <class _Tp, class... _Args>
1595struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
1596    : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
1597
1598#else
1599
1600template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
1601
1602template <class _Tp, class... _Args>
1603struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
1604    : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1605{
1606};
1607
1608template <class _Tp>
1609void __implicit_conversion_to(_Tp) noexcept { }
1610
1611template <class _Tp, class _Arg>
1612struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
1613    : public integral_constant<bool, noexcept(_VSTD::__implicit_conversion_to<_Tp>(declval<_Arg>()))>
1614{
1615};
1616
1617template <class _Tp, bool _IsReference, class... _Args>
1618struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
1619    : public false_type
1620{
1621};
1622
1623template <class _Tp, class... _Args>
1624struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
1625    : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
1626{
1627};
1628
1629template <class _Tp, size_t _Ns>
1630struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
1631    : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
1632{
1633};
1634
1635#endif // _LIBCPP_HAS_NO_NOEXCEPT
1636
1637
1638#if _LIBCPP_STD_VER > 14
1639template <class _Tp, class ..._Args>
1640inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
1641#endif
1642
1643// is_nothrow_default_constructible
1644
1645template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
1646    : public is_nothrow_constructible<_Tp>
1647    {};
1648
1649#if _LIBCPP_STD_VER > 14
1650template <class _Tp>
1651inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value;
1652#endif
1653
1654// is_nothrow_copy_constructible
1655
1656template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
1657    : public is_nothrow_constructible<_Tp,
1658                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
1659
1660#if _LIBCPP_STD_VER > 14
1661template <class _Tp>
1662inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value;
1663#endif
1664
1665// is_nothrow_move_constructible
1666
1667template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
1668    : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
1669    {};
1670
1671#if _LIBCPP_STD_VER > 14
1672template <class _Tp>
1673inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value;
1674#endif
1675
1676// is_nothrow_assignable
1677
1678#if __has_keyword(__is_nothrow_assignable)
1679
1680template <class _Tp, class _Arg>
1681struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
1682    : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
1683
1684#else
1685
1686template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
1687
1688template <class _Tp, class _Arg>
1689struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
1690    : public false_type
1691{
1692};
1693
1694template <class _Tp, class _Arg>
1695struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
1696    : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Arg>()) >
1697{
1698};
1699
1700template <class _Tp, class _Arg>
1701struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
1702    : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
1703{
1704};
1705
1706#endif // _LIBCPP_HAS_NO_NOEXCEPT
1707
1708#if _LIBCPP_STD_VER > 14
1709template <class _Tp, class _Arg>
1710inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value;
1711#endif
1712
1713// is_nothrow_copy_assignable
1714
1715template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
1716    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
1717                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
1718
1719#if _LIBCPP_STD_VER > 14
1720template <class _Tp>
1721inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
1722#endif
1723
1724// is_nothrow_move_assignable
1725
1726template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
1727    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
1728                                     typename add_rvalue_reference<_Tp>::type>
1729    {};
1730
1731#if _LIBCPP_STD_VER > 14
1732template <class _Tp>
1733inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
1734#endif
1735
1736// is_nothrow_destructible
1737
1738#if !defined(_LIBCPP_CXX03_LANG)
1739
1740template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
1741
1742template <class _Tp>
1743struct __libcpp_is_nothrow_destructible<false, _Tp>
1744    : public false_type
1745{
1746};
1747
1748template <class _Tp>
1749struct __libcpp_is_nothrow_destructible<true, _Tp>
1750    : public integral_constant<bool, noexcept(declval<_Tp>().~_Tp()) >
1751{
1752};
1753
1754template <class _Tp>
1755struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
1756    : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
1757{
1758};
1759
1760template <class _Tp, size_t _Ns>
1761struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
1762    : public is_nothrow_destructible<_Tp>
1763{
1764};
1765
1766template <class _Tp>
1767struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
1768    : public true_type
1769{
1770};
1771
1772template <class _Tp>
1773struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
1774    : public true_type
1775{
1776};
1777
1778#else
1779
1780template <class _Tp> struct __libcpp_nothrow_destructor
1781    : public integral_constant<bool, is_scalar<_Tp>::value ||
1782                                     is_reference<_Tp>::value> {};
1783
1784template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
1785    : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
1786
1787template <class _Tp>
1788struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
1789    : public false_type {};
1790
1791#endif
1792
1793#if _LIBCPP_STD_VER > 14
1794template <class _Tp>
1795inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
1796#endif
1797
1798// result_of
1799
1800#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
1801template <class _Callable> class _LIBCPP_DEPRECATED_IN_CXX17 result_of;
1802
1803#ifndef _LIBCPP_CXX03_LANG
1804
1805template <class _Fp, class ..._Args>
1806class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)>
1807    : public __invoke_of<_Fp, _Args...>
1808{
1809};
1810
1811#else // C++03
1812
1813template <class _Fn, bool, bool>
1814class __result_of
1815{
1816};
1817
1818template <class _Fn, class ..._Args>
1819class __result_of<_Fn(_Args...), true, false>
1820{
1821public:
1822    typedef decltype(declval<_Fn>()(declval<_Args>()...)) type;
1823};
1824
1825template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
1826struct __result_of_mp;
1827
1828// member function pointer
1829
1830template <class _MP, class _Tp>
1831struct __result_of_mp<_MP, _Tp, true>
1832{
1833    using type = typename __member_pointer_traits<_MP>::_ReturnType;
1834};
1835
1836// member data pointer
1837
1838template <class _MP, class _Tp, bool>
1839struct __result_of_mdp;
1840
1841template <class _Rp, class _Class, class _Tp>
1842struct __result_of_mdp<_Rp _Class::*, _Tp, false>
1843{
1844    using type = typename __apply_cv<decltype(*declval<_Tp>()), _Rp>::type&;
1845};
1846
1847template <class _Rp, class _Class, class _Tp>
1848struct __result_of_mdp<_Rp _Class::*, _Tp, true>
1849{
1850    using type = typename __apply_cv<_Tp, _Rp>::type&;
1851};
1852
1853template <class _Rp, class _Class, class _Tp>
1854struct __result_of_mp<_Rp _Class::*, _Tp, false>
1855    : public __result_of_mdp<_Rp _Class::*, _Tp,
1856            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
1857{
1858};
1859
1860template <class _Fn, class _Tp>
1861class __result_of<_Fn(_Tp), false, true>  // _Fn must be member pointer
1862    : public __result_of_mp<typename remove_reference<_Fn>::type,
1863                            _Tp,
1864                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1865{
1866};
1867
1868template <class _Fn, class _Tp, class ..._Args>
1869class __result_of<_Fn(_Tp, _Args...), false, true>  // _Fn must be member pointer
1870    : public __result_of_mp<typename remove_reference<_Fn>::type,
1871                            _Tp,
1872                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1873{
1874};
1875
1876template <class _Fn, class ..._Args>
1877class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_Args...)>
1878    : public __result_of<_Fn(_Args...),
1879                         is_class<typename remove_reference<_Fn>::type>::value ||
1880                         is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
1881                         is_member_pointer<typename remove_reference<_Fn>::type>::value
1882                        >
1883{
1884};
1885
1886#endif // C++03
1887
1888#if _LIBCPP_STD_VER > 11
1889template <class _Tp> using result_of_t _LIBCPP_DEPRECATED_IN_CXX17 = typename result_of<_Tp>::type;
1890#endif // _LIBCPP_STD_VER > 11
1891#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
1892
1893// __swappable
1894
1895template <class _Tp> struct __is_swappable;
1896template <class _Tp> struct __is_nothrow_swappable;
1897
1898
1899#ifndef _LIBCPP_CXX03_LANG
1900template <class _Tp>
1901using __swap_result_t = typename enable_if<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>::type;
1902#else
1903template <class>
1904using __swap_result_t = void;
1905#endif
1906
1907template <class _Tp>
1908inline _LIBCPP_INLINE_VISIBILITY
1909_LIBCPP_CONSTEXPR_AFTER_CXX17 __swap_result_t<_Tp>
1910swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
1911                                    is_nothrow_move_assignable<_Tp>::value);
1912
1913template<class _Tp, size_t _Np>
1914inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1915typename enable_if<
1916    __is_swappable<_Tp>::value
1917>::type
1918swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
1919
1920namespace __detail
1921{
1922// ALL generic swap overloads MUST already have a declaration available at this point.
1923
1924template <class _Tp, class _Up = _Tp,
1925          bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value>
1926struct __swappable_with
1927{
1928    template <class _LHS, class _RHS>
1929    static decltype(swap(declval<_LHS>(), declval<_RHS>()))
1930    __test_swap(int);
1931    template <class, class>
1932    static __nat __test_swap(long);
1933
1934    // Extra parens are needed for the C++03 definition of decltype.
1935    typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1;
1936    typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2;
1937
1938    static const bool value = _IsNotSame<__swap1, __nat>::value
1939                           && _IsNotSame<__swap2, __nat>::value;
1940};
1941
1942template <class _Tp, class _Up>
1943struct __swappable_with<_Tp, _Up,  false> : false_type {};
1944
1945template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value>
1946struct __nothrow_swappable_with {
1947  static const bool value =
1948#ifndef _LIBCPP_HAS_NO_NOEXCEPT
1949      noexcept(swap(declval<_Tp>(), declval<_Up>()))
1950  &&  noexcept(swap(declval<_Up>(), declval<_Tp>()));
1951#else
1952      false;
1953#endif
1954};
1955
1956template <class _Tp, class _Up>
1957struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
1958
1959} // namespace __detail
1960
1961template <class _Tp>
1962struct __is_swappable
1963    : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value>
1964{
1965};
1966
1967template <class _Tp>
1968struct __is_nothrow_swappable
1969    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value>
1970{
1971};
1972
1973#if _LIBCPP_STD_VER > 14
1974
1975template <class _Tp, class _Up>
1976struct _LIBCPP_TEMPLATE_VIS is_swappable_with
1977    : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value>
1978{
1979};
1980
1981template <class _Tp>
1982struct _LIBCPP_TEMPLATE_VIS is_swappable
1983    : public conditional<
1984        __is_referenceable<_Tp>::value,
1985        is_swappable_with<
1986            typename add_lvalue_reference<_Tp>::type,
1987            typename add_lvalue_reference<_Tp>::type>,
1988        false_type
1989    >::type
1990{
1991};
1992
1993template <class _Tp, class _Up>
1994struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with
1995    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value>
1996{
1997};
1998
1999template <class _Tp>
2000struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable
2001    : public conditional<
2002        __is_referenceable<_Tp>::value,
2003        is_nothrow_swappable_with<
2004            typename add_lvalue_reference<_Tp>::type,
2005            typename add_lvalue_reference<_Tp>::type>,
2006        false_type
2007    >::type
2008{
2009};
2010
2011template <class _Tp, class _Up>
2012inline constexpr bool is_swappable_with_v = is_swappable_with<_Tp, _Up>::value;
2013
2014template <class _Tp>
2015inline constexpr bool is_swappable_v = is_swappable<_Tp>::value;
2016
2017template <class _Tp, class _Up>
2018inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<_Tp, _Up>::value;
2019
2020template <class _Tp>
2021inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value;
2022
2023#endif // _LIBCPP_STD_VER > 14
2024
2025template <class _Tp, bool = is_enum<_Tp>::value>
2026struct __sfinae_underlying_type
2027{
2028    typedef typename underlying_type<_Tp>::type type;
2029    typedef decltype(((type)1) + 0) __promoted_type;
2030};
2031
2032template <class _Tp>
2033struct __sfinae_underlying_type<_Tp, false> {};
2034
2035inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2036int __convert_to_integral(int __val) { return __val; }
2037
2038inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2039unsigned __convert_to_integral(unsigned __val) { return __val; }
2040
2041inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2042long __convert_to_integral(long __val) { return __val; }
2043
2044inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2045unsigned long __convert_to_integral(unsigned long __val) { return __val; }
2046
2047inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2048long long __convert_to_integral(long long __val) { return __val; }
2049
2050inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2051unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
2052
2053template<typename _Fp>
2054inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2055typename enable_if<is_floating_point<_Fp>::value, long long>::type
2056 __convert_to_integral(_Fp __val) { return __val; }
2057
2058#ifndef _LIBCPP_HAS_NO_INT128
2059inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2060__int128_t __convert_to_integral(__int128_t __val) { return __val; }
2061
2062inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2063__uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
2064#endif
2065
2066template <class _Tp>
2067inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2068typename __sfinae_underlying_type<_Tp>::__promoted_type
2069__convert_to_integral(_Tp __val) { return __val; }
2070
2071#if _LIBCPP_STD_VER > 14
2072template <class _Tp>
2073struct negation : _Not<_Tp> {};
2074template<class _Tp>
2075inline constexpr bool negation_v = negation<_Tp>::value;
2076#endif // _LIBCPP_STD_VER > 14
2077
2078// These traits are used in __tree and __hash_table
2079struct __extract_key_fail_tag {};
2080struct __extract_key_self_tag {};
2081struct __extract_key_first_tag {};
2082
2083template <class _ValTy, class _Key,
2084          class _RawValTy = typename __unconstref<_ValTy>::type>
2085struct __can_extract_key
2086    : conditional<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag,
2087                  __extract_key_fail_tag>::type {};
2088
2089template <class _Pair, class _Key, class _First, class _Second>
2090struct __can_extract_key<_Pair, _Key, pair<_First, _Second> >
2091    : conditional<_IsSame<typename remove_const<_First>::type, _Key>::value,
2092                  __extract_key_first_tag, __extract_key_fail_tag>::type {};
2093
2094// __can_extract_map_key uses true_type/false_type instead of the tags.
2095// It returns true if _Key != _ContainerValueTy (the container is a map not a set)
2096// and _ValTy == _Key.
2097template <class _ValTy, class _Key, class _ContainerValueTy,
2098          class _RawValTy = typename __unconstref<_ValTy>::type>
2099struct __can_extract_map_key
2100    : integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {};
2101
2102// This specialization returns __extract_key_fail_tag for non-map containers
2103// because _Key == _ContainerValueTy
2104template <class _ValTy, class _Key, class _RawValTy>
2105struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
2106    : false_type {};
2107
2108template <class _CharT>
2109using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
2110
2111template<class _Tp>
2112using __make_const_lvalue_ref = const typename remove_reference<_Tp>::type&;
2113
2114#if _LIBCPP_STD_VER > 17
2115template<bool _Const, class _Tp>
2116using __maybe_const = conditional_t<_Const, const _Tp, _Tp>;
2117#endif // _LIBCPP_STD_VER > 17
2118
2119_LIBCPP_END_NAMESPACE_STD
2120
2121#endif // _LIBCPP_TYPE_TRAITS
2122