1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TYPE_TRAITS
11#define _LIBCPP_TYPE_TRAITS
12
13/*
14    type_traits synopsis
15
16namespace std
17{
18
19    // helper class:
20    template <class T, T v> struct integral_constant;
21    typedef integral_constant<bool, true>  true_type;   // C++11
22    typedef integral_constant<bool, false> false_type;  // C++11
23
24    template <bool B>                                   // C++14
25    using bool_constant = integral_constant<bool, B>;   // C++14
26    typedef bool_constant<true> true_type;              // C++14
27    typedef bool_constant<false> false_type;            // C++14
28
29    // helper traits
30    template <bool, class T = void> struct enable_if;
31    template <bool, class T, class F> struct conditional;
32
33    // Primary classification traits:
34    template <class T> struct is_void;
35    template <class T> struct is_null_pointer;  // C++14
36    template <class T> struct is_integral;
37    template <class T> struct is_floating_point;
38    template <class T> struct is_array;
39    template <class T> struct is_pointer;
40    template <class T> struct is_lvalue_reference;
41    template <class T> struct is_rvalue_reference;
42    template <class T> struct is_member_object_pointer;
43    template <class T> struct is_member_function_pointer;
44    template <class T> struct is_enum;
45    template <class T> struct is_union;
46    template <class T> struct is_class;
47    template <class T> struct is_function;
48
49    // Secondary classification traits:
50    template <class T> struct is_reference;
51    template <class T> struct is_arithmetic;
52    template <class T> struct is_fundamental;
53    template <class T> struct is_member_pointer;
54    template <class T> struct is_scoped_enum; // C++2b
55    template <class T> struct is_scalar;
56    template <class T> struct is_object;
57    template <class T> struct is_compound;
58
59    // Const-volatile properties and transformations:
60    template <class T> struct is_const;
61    template <class T> struct is_volatile;
62    template <class T> struct remove_const;
63    template <class T> struct remove_volatile;
64    template <class T> struct remove_cv;
65    template <class T> struct add_const;
66    template <class T> struct add_volatile;
67    template <class T> struct add_cv;
68
69    // Reference transformations:
70    template <class T> struct remove_reference;
71    template <class T> struct add_lvalue_reference;
72    template <class T> struct add_rvalue_reference;
73
74    // Pointer transformations:
75    template <class T> struct remove_pointer;
76    template <class T> struct add_pointer;
77
78    template<class T> struct type_identity;                     // C++20
79    template<class T>
80      using type_identity_t = typename type_identity<T>::type;  // C++20
81
82    // Integral properties:
83    template <class T> struct is_signed;
84    template <class T> struct is_unsigned;
85    template <class T> struct make_signed;
86    template <class T> struct make_unsigned;
87
88    // Array properties and transformations:
89    template <class T> struct rank;
90    template <class T, unsigned I = 0> struct extent;
91    template <class T> struct remove_extent;
92    template <class T> struct remove_all_extents;
93
94    template <class T> struct is_bounded_array;                 // C++20
95    template <class T> struct is_unbounded_array;               // C++20
96
97    // Member introspection:
98    template <class T> struct is_pod;
99    template <class T> struct is_trivial;
100    template <class T> struct is_trivially_copyable;
101    template <class T> struct is_standard_layout;
102    template <class T> struct is_literal_type; // Deprecated in C++17; removed in C++20
103    template <class T> struct is_empty;
104    template <class T> struct is_polymorphic;
105    template <class T> struct is_abstract;
106    template <class T> struct is_final; // C++14
107    template <class T> struct is_aggregate; // C++17
108
109    template <class T, class... Args> struct is_constructible;
110    template <class T>                struct is_default_constructible;
111    template <class T>                struct is_copy_constructible;
112    template <class T>                struct is_move_constructible;
113    template <class T, class U>       struct is_assignable;
114    template <class T>                struct is_copy_assignable;
115    template <class T>                struct is_move_assignable;
116    template <class T, class U>       struct is_swappable_with;       // C++17
117    template <class T>                struct is_swappable;            // C++17
118    template <class T>                struct is_destructible;
119
120    template <class T, class... Args> struct is_trivially_constructible;
121    template <class T>                struct is_trivially_default_constructible;
122    template <class T>                struct is_trivially_copy_constructible;
123    template <class T>                struct is_trivially_move_constructible;
124    template <class T, class U>       struct is_trivially_assignable;
125    template <class T>                struct is_trivially_copy_assignable;
126    template <class T>                struct is_trivially_move_assignable;
127    template <class T>                struct is_trivially_destructible;
128
129    template <class T, class... Args> struct is_nothrow_constructible;
130    template <class T>                struct is_nothrow_default_constructible;
131    template <class T>                struct is_nothrow_copy_constructible;
132    template <class T>                struct is_nothrow_move_constructible;
133    template <class T, class U>       struct is_nothrow_assignable;
134    template <class T>                struct is_nothrow_copy_assignable;
135    template <class T>                struct is_nothrow_move_assignable;
136    template <class T, class U>       struct is_nothrow_swappable_with; // C++17
137    template <class T>                struct is_nothrow_swappable;      // C++17
138    template <class T>                struct is_nothrow_destructible;
139
140    template <class T> struct has_virtual_destructor;
141
142    template<class T> struct has_unique_object_representations;         // C++17
143
144    // Relationships between types:
145    template <class T, class U> struct is_same;
146    template <class Base, class Derived> struct is_base_of;
147
148    template <class From, class To> struct is_convertible;
149    template <typename From, typename To> struct is_nothrow_convertible;                  // C++20
150    template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20
151
152    template <class Fn, class... ArgTypes> struct is_invocable;
153    template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
154
155    template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
156    template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
157
158    // Alignment properties and transformations:
159    template <class T> struct alignment_of;
160    template <size_t Len, size_t Align = most_stringent_alignment_requirement>
161        struct aligned_storage;
162    template <size_t Len, class... Types> struct aligned_union;
163    template <class T> struct remove_cvref; // C++20
164
165    template <class T> struct decay;
166    template <class... T> struct common_type;
167    template <class T> struct underlying_type;
168    template <class> class result_of; // undefined; deprecated in C++17; removed in C++20
169    template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20
170    template <class Fn, class... ArgTypes> struct invoke_result;  // C++17
171
172    // const-volatile modifications:
173    template <class T>
174      using remove_const_t    = typename remove_const<T>::type;  // C++14
175    template <class T>
176      using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
177    template <class T>
178      using remove_cv_t       = typename remove_cv<T>::type;  // C++14
179    template <class T>
180      using add_const_t       = typename add_const<T>::type;  // C++14
181    template <class T>
182      using add_volatile_t    = typename add_volatile<T>::type;  // C++14
183    template <class T>
184      using add_cv_t          = typename add_cv<T>::type;  // C++14
185
186    // reference modifications:
187    template <class T>
188      using remove_reference_t     = typename remove_reference<T>::type;  // C++14
189    template <class T>
190      using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
191    template <class T>
192      using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
193
194    // sign modifications:
195    template <class T>
196      using make_signed_t   = typename make_signed<T>::type;  // C++14
197    template <class T>
198      using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
199
200    // array modifications:
201    template <class T>
202      using remove_extent_t      = typename remove_extent<T>::type;  // C++14
203    template <class T>
204      using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
205
206    template <class T>
207      inline constexpr bool is_bounded_array_v
208        = is_bounded_array<T>::value;                                     // C++20
209      inline constexpr bool is_unbounded_array_v
210        = is_unbounded_array<T>::value;                                   // C++20
211
212    // pointer modifications:
213    template <class T>
214      using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
215    template <class T>
216      using add_pointer_t    = typename add_pointer<T>::type;  // C++14
217
218    // other transformations:
219    template <size_t Len, size_t Align=default-alignment>
220      using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
221    template <size_t Len, class... Types>
222      using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
223    template <class T>
224      using remove_cvref_t    = typename remove_cvref<T>::type;  // C++20
225    template <class T>
226      using decay_t           = typename decay<T>::type;  // C++14
227    template <bool b, class T=void>
228      using enable_if_t       = typename enable_if<b,T>::type;  // C++14
229    template <bool b, class T, class F>
230      using conditional_t     = typename conditional<b,T,F>::type;  // C++14
231    template <class... T>
232      using common_type_t     = typename common_type<T...>::type;  // C++14
233    template <class T>
234      using underlying_type_t = typename underlying_type<T>::type;  // C++14
235    template <class T>
236      using result_of_t       = typename result_of<T>::type;  // C++14; deprecated in C++17; removed in C++20
237    template <class Fn, class... ArgTypes>
238      using invoke_result_t   = typename invoke_result<Fn, ArgTypes...>::type;  // C++17
239
240    template <class...>
241      using void_t = void;   // C++17
242
243      // See C++14 20.10.4.1, primary type categories
244      template <class T> inline constexpr bool is_void_v
245        = is_void<T>::value;                                             // C++17
246      template <class T> inline constexpr bool is_null_pointer_v
247        = is_null_pointer<T>::value;                                     // C++17
248      template <class T> inline constexpr bool is_integral_v
249        = is_integral<T>::value;                                         // C++17
250      template <class T> inline constexpr bool is_floating_point_v
251        = is_floating_point<T>::value;                                   // C++17
252      template <class T> inline constexpr bool is_array_v
253        = is_array<T>::value;                                            // C++17
254      template <class T> inline constexpr bool is_pointer_v
255        = is_pointer<T>::value;                                          // C++17
256      template <class T> inline constexpr bool is_lvalue_reference_v
257        = is_lvalue_reference<T>::value;                                 // C++17
258      template <class T> inline constexpr bool is_rvalue_reference_v
259        = is_rvalue_reference<T>::value;                                 // C++17
260      template <class T> inline constexpr bool is_member_object_pointer_v
261        = is_member_object_pointer<T>::value;                            // C++17
262      template <class T> inline constexpr bool is_member_function_pointer_v
263        = is_member_function_pointer<T>::value;                          // C++17
264      template <class T> inline constexpr bool is_enum_v
265        = is_enum<T>::value;                                             // C++17
266      template <class T> inline constexpr bool is_union_v
267        = is_union<T>::value;                                            // C++17
268      template <class T> inline constexpr bool is_class_v
269        = is_class<T>::value;                                            // C++17
270      template <class T> inline constexpr bool is_function_v
271        = is_function<T>::value;                                         // C++17
272
273      // See C++14 20.10.4.2, composite type categories
274      template <class T> inline constexpr bool is_reference_v
275        = is_reference<T>::value;                                        // C++17
276      template <class T> inline constexpr bool is_arithmetic_v
277        = is_arithmetic<T>::value;                                       // C++17
278      template <class T> inline constexpr bool is_fundamental_v
279        = is_fundamental<T>::value;                                      // C++17
280      template <class T> inline constexpr bool is_object_v
281        = is_object<T>::value;                                           // C++17
282      template <class T> inline constexpr bool is_scalar_v
283        = is_scalar<T>::value;                                           // C++17
284      template <class T> inline constexpr bool is_compound_v
285        = is_compound<T>::value;                                         // C++17
286      template <class T> inline constexpr bool is_member_pointer_v
287        = is_member_pointer<T>::value;                                   // C++17
288      template <class T> inline constexpr bool is_scoped_enum_v
289        = is_scoped_enum<T>::value;                                      // C++2b
290
291      // See C++14 20.10.4.3, type properties
292      template <class T> inline constexpr bool is_const_v
293        = is_const<T>::value;                                            // C++17
294      template <class T> inline constexpr bool is_volatile_v
295        = is_volatile<T>::value;                                         // C++17
296      template <class T> inline constexpr bool is_trivial_v
297        = is_trivial<T>::value;                                          // C++17
298      template <class T> inline constexpr bool is_trivially_copyable_v
299        = is_trivially_copyable<T>::value;                               // C++17
300      template <class T> inline constexpr bool is_standard_layout_v
301        = is_standard_layout<T>::value;                                  // C++17
302      template <class T> inline constexpr bool is_pod_v
303        = is_pod<T>::value;                                              // C++17
304      template <class T> inline constexpr bool is_literal_type_v
305        = is_literal_type<T>::value;                                     // C++17; deprecated in C++17; removed in C++20
306      template <class T> inline constexpr bool is_empty_v
307        = is_empty<T>::value;                                            // C++17
308      template <class T> inline constexpr bool is_polymorphic_v
309        = is_polymorphic<T>::value;                                      // C++17
310      template <class T> inline constexpr bool is_abstract_v
311        = is_abstract<T>::value;                                         // C++17
312      template <class T> inline constexpr bool is_final_v
313        = is_final<T>::value;                                            // C++17
314      template <class T> inline constexpr bool is_aggregate_v
315        = is_aggregate<T>::value;                                        // C++17
316      template <class T> inline constexpr bool is_signed_v
317        = is_signed<T>::value;                                           // C++17
318      template <class T> inline constexpr bool is_unsigned_v
319        = is_unsigned<T>::value;                                         // C++17
320      template <class T, class... Args> inline constexpr bool is_constructible_v
321        = is_constructible<T, Args...>::value;                           // C++17
322      template <class T> inline constexpr bool is_default_constructible_v
323        = is_default_constructible<T>::value;                            // C++17
324      template <class T> inline constexpr bool is_copy_constructible_v
325        = is_copy_constructible<T>::value;                               // C++17
326      template <class T> inline constexpr bool is_move_constructible_v
327        = is_move_constructible<T>::value;                               // C++17
328      template <class T, class U> inline constexpr bool is_assignable_v
329        = is_assignable<T, U>::value;                                    // C++17
330      template <class T> inline constexpr bool is_copy_assignable_v
331        = is_copy_assignable<T>::value;                                  // C++17
332      template <class T> inline constexpr bool is_move_assignable_v
333        = is_move_assignable<T>::value;                                  // C++17
334      template <class T, class U> inline constexpr bool is_swappable_with_v
335        = is_swappable_with<T, U>::value;                                // C++17
336      template <class T> inline constexpr bool is_swappable_v
337        = is_swappable<T>::value;                                        // C++17
338      template <class T> inline constexpr bool is_destructible_v
339        = is_destructible<T>::value;                                     // C++17
340      template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
341        = is_trivially_constructible<T, Args...>::value;                 // C++17
342      template <class T> inline constexpr bool is_trivially_default_constructible_v
343        = is_trivially_default_constructible<T>::value;                  // C++17
344      template <class T> inline constexpr bool is_trivially_copy_constructible_v
345        = is_trivially_copy_constructible<T>::value;                     // C++17
346      template <class T> inline constexpr bool is_trivially_move_constructible_v
347        = is_trivially_move_constructible<T>::value;                     // C++17
348      template <class T, class U> inline constexpr bool is_trivially_assignable_v
349        = is_trivially_assignable<T, U>::value;                          // C++17
350      template <class T> inline constexpr bool is_trivially_copy_assignable_v
351        = is_trivially_copy_assignable<T>::value;                        // C++17
352      template <class T> inline constexpr bool is_trivially_move_assignable_v
353        = is_trivially_move_assignable<T>::value;                        // C++17
354      template <class T> inline constexpr bool is_trivially_destructible_v
355        = is_trivially_destructible<T>::value;                           // C++17
356      template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
357        = is_nothrow_constructible<T, Args...>::value;                   // C++17
358      template <class T> inline constexpr bool is_nothrow_default_constructible_v
359        = is_nothrow_default_constructible<T>::value;                    // C++17
360      template <class T> inline constexpr bool is_nothrow_copy_constructible_v
361        = is_nothrow_copy_constructible<T>::value;                       // C++17
362      template <class T> inline constexpr bool is_nothrow_move_constructible_v
363        = is_nothrow_move_constructible<T>::value;                       // C++17
364      template <class T, class U> inline constexpr bool is_nothrow_assignable_v
365        = is_nothrow_assignable<T, U>::value;                            // C++17
366      template <class T> inline constexpr bool is_nothrow_copy_assignable_v
367        = is_nothrow_copy_assignable<T>::value;                          // C++17
368      template <class T> inline constexpr bool is_nothrow_move_assignable_v
369        = is_nothrow_move_assignable<T>::value;                          // C++17
370      template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
371        = is_nothrow_swappable_with<T, U>::value;                       // C++17
372      template <class T> inline constexpr bool is_nothrow_swappable_v
373        = is_nothrow_swappable<T>::value;                               // C++17
374      template <class T> inline constexpr bool is_nothrow_destructible_v
375        = is_nothrow_destructible<T>::value;                             // C++17
376      template <class T> inline constexpr bool has_virtual_destructor_v
377        = has_virtual_destructor<T>::value;                              // C++17
378      template<class T> inline constexpr bool has_unique_object_representations_v // C++17
379        = has_unique_object_representations<T>::value;
380
381      // See C++14 20.10.5, type property queries
382      template <class T> inline constexpr size_t alignment_of_v
383        = alignment_of<T>::value;                                        // C++17
384      template <class T> inline constexpr size_t rank_v
385        = rank<T>::value;                                                // C++17
386      template <class T, unsigned I = 0> inline constexpr size_t extent_v
387        = extent<T, I>::value;                                           // C++17
388
389      // See C++14 20.10.6, type relations
390      template <class T, class U> inline constexpr bool is_same_v
391        = is_same<T, U>::value;                                          // C++17
392      template <class Base, class Derived> inline constexpr bool is_base_of_v
393        = is_base_of<Base, Derived>::value;                              // C++17
394      template <class From, class To> inline constexpr bool is_convertible_v
395        = is_convertible<From, To>::value;                               // C++17
396      template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
397        = is_invocable<Fn, ArgTypes...>::value;                          // C++17
398      template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
399        = is_invocable_r<R, Fn, ArgTypes...>::value;                     // C++17
400      template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
401        = is_nothrow_invocable<Fn, ArgTypes...>::value;                  // C++17
402      template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
403        = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;             // C++17
404
405      // [meta.logical], logical operator traits:
406      template<class... B> struct conjunction;                           // C++17
407      template<class... B>
408        inline constexpr bool conjunction_v = conjunction<B...>::value;  // C++17
409      template<class... B> struct disjunction;                           // C++17
410      template<class... B>
411        inline constexpr bool disjunction_v = disjunction<B...>::value;  // C++17
412      template<class B> struct negation;                                 // C++17
413      template<class B>
414        inline constexpr bool negation_v = negation<B>::value;           // C++17
415
416}
417
418*/
419#include <__assert> // all public C++ headers provide the assertion handler
420#include <__config>
421#include <__type_traits/add_const.h>
422#include <__type_traits/add_cv.h>
423#include <__type_traits/add_lvalue_reference.h>
424#include <__type_traits/add_pointer.h>
425#include <__type_traits/add_rvalue_reference.h>
426#include <__type_traits/add_volatile.h>
427#include <__type_traits/conditional.h>
428#include <__type_traits/decay.h>
429#include <__type_traits/enable_if.h>
430#include <__type_traits/extent.h>
431#include <__type_traits/integral_constant.h>
432#include <__type_traits/is_abstract.h>
433#include <__type_traits/is_aggregate.h>
434#include <__type_traits/is_arithmetic.h>
435#include <__type_traits/is_array.h>
436#include <__type_traits/is_base_of.h>
437#include <__type_traits/is_bounded_array.h>
438#include <__type_traits/is_callable.h>
439#include <__type_traits/is_class.h>
440#include <__type_traits/is_compound.h>
441#include <__type_traits/is_const.h>
442#include <__type_traits/is_convertible.h>
443#include <__type_traits/is_empty.h>
444#include <__type_traits/is_enum.h>
445#include <__type_traits/is_final.h>
446#include <__type_traits/is_floating_point.h>
447#include <__type_traits/is_function.h>
448#include <__type_traits/is_fundamental.h>
449#include <__type_traits/is_integral.h>
450#include <__type_traits/is_member_function_pointer.h>
451#include <__type_traits/is_member_object_pointer.h>
452#include <__type_traits/is_member_pointer.h>
453#include <__type_traits/is_null_pointer.h>
454#include <__type_traits/is_object.h>
455#include <__type_traits/is_pointer.h>
456#include <__type_traits/is_reference.h>
457#include <__type_traits/is_reference_wrapper.h>
458#include <__type_traits/is_referenceable.h>
459#include <__type_traits/is_same.h>
460#include <__type_traits/is_scalar.h>
461#include <__type_traits/is_signed.h>
462#include <__type_traits/is_unbounded_array.h>
463#include <__type_traits/is_union.h>
464#include <__type_traits/is_unsigned.h>
465#include <__type_traits/is_void.h>
466#include <__type_traits/is_volatile.h>
467#include <__type_traits/rank.h>
468#include <__type_traits/remove_all_extents.h>
469#include <__type_traits/remove_const.h>
470#include <__type_traits/remove_cv.h>
471#include <__type_traits/remove_extent.h>
472#include <__type_traits/remove_pointer.h>
473#include <__type_traits/remove_reference.h>
474#include <__type_traits/remove_volatile.h>
475#include <__type_traits/type_identity.h>
476#include <__utility/declval.h>
477#include <cstddef>
478#include <version>
479
480#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
481#  pragma GCC system_header
482#endif
483
484_LIBCPP_BEGIN_NAMESPACE_STD
485
486template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair;
487template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
488
489template <bool> struct _MetaBase;
490template <>
491struct _MetaBase<true> {
492  template <class _Tp, class _Up>
493  using _SelectImpl _LIBCPP_NODEBUG = _Tp;
494  template <template <class...> class _FirstFn, template <class...> class, class ..._Args>
495  using _SelectApplyImpl _LIBCPP_NODEBUG = _FirstFn<_Args...>;
496  template <class _First, class...>
497  using _FirstImpl _LIBCPP_NODEBUG = _First;
498  template <class, class _Second, class...>
499  using _SecondImpl _LIBCPP_NODEBUG = _Second;
500  template <class _Result, class _First, class ..._Rest>
501  using _OrImpl _LIBCPP_NODEBUG = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
502};
503
504template <>
505struct _MetaBase<false> {
506  template <class _Tp, class _Up>
507  using _SelectImpl _LIBCPP_NODEBUG = _Up;
508  template <template <class...> class, template <class...> class _SecondFn, class ..._Args>
509  using _SelectApplyImpl _LIBCPP_NODEBUG = _SecondFn<_Args...>;
510  template <class _Result, class ...>
511  using _OrImpl _LIBCPP_NODEBUG = _Result;
512};
513template <bool _Cond, class _IfRes, class _ElseRes>
514using _If _LIBCPP_NODEBUG = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
515template <class ..._Rest>
516using _Or _LIBCPP_NODEBUG = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
517template <class _Pred>
518struct _Not : _BoolConstant<!_Pred::value> {};
519template <class ..._Args>
520using _FirstType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
521template <class ..._Args>
522using _SecondType _LIBCPP_NODEBUG = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
523
524template <class ...> using __expand_to_true = true_type;
525template <class ..._Pred>
526__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
527template <class ...>
528false_type __and_helper(...);
529template <class ..._Pred>
530using _And _LIBCPP_NODEBUG = decltype(__and_helper<_Pred...>(0));
531
532template <template <class...> class _Func, class ..._Args>
533struct _Lazy : _Func<_Args...> {};
534
535// Member detector base
536
537template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> >
538true_type __sfinae_test_impl(int);
539template <template <class...> class, class ...>
540false_type __sfinae_test_impl(...);
541
542template <template <class ...> class _Templ, class ..._Args>
543using _IsValidExpansion _LIBCPP_NODEBUG = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
544
545template <class>
546struct __void_t { typedef void type; };
547
548template <class _Tp, bool>
549struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
550
551// is_same
552
553template <class _Tp>
554using __test_for_primary_template = __enable_if_t<
555    _IsSame<_Tp, typename _Tp::__primary_template>::value
556  >;
557template <class _Tp>
558using __is_primary_template = _IsValidExpansion<
559    __test_for_primary_template, _Tp
560  >;
561
562// is_integral
563
564// [basic.fundamental] defines five standard signed integer types;
565// __int128_t is an extended signed integer type.
566// The signed and unsigned integer types, plus bool and the
567// five types with "char" in their name, compose the "integral" types.
568
569template <class _Tp> struct __libcpp_is_signed_integer : public false_type {};
570template <> struct __libcpp_is_signed_integer<signed char>      : public true_type {};
571template <> struct __libcpp_is_signed_integer<signed short>     : public true_type {};
572template <> struct __libcpp_is_signed_integer<signed int>       : public true_type {};
573template <> struct __libcpp_is_signed_integer<signed long>      : public true_type {};
574template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
575#ifndef _LIBCPP_HAS_NO_INT128
576template <> struct __libcpp_is_signed_integer<__int128_t>       : public true_type {};
577#endif
578
579template <class _Tp> struct __libcpp_is_unsigned_integer : public false_type {};
580template <> struct __libcpp_is_unsigned_integer<unsigned char>      : public true_type {};
581template <> struct __libcpp_is_unsigned_integer<unsigned short>     : public true_type {};
582template <> struct __libcpp_is_unsigned_integer<unsigned int>       : public true_type {};
583template <> struct __libcpp_is_unsigned_integer<unsigned long>      : public true_type {};
584template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
585#ifndef _LIBCPP_HAS_NO_INT128
586template <> struct __libcpp_is_unsigned_integer<__uint128_t>        : public true_type {};
587#endif
588
589template <class _Tp>
590struct __unconstref {
591    typedef _LIBCPP_NODEBUG typename remove_const<typename remove_reference<_Tp>::type>::type type;
592};
593
594template <class _Tp>
595using __uncvref_t _LIBCPP_NODEBUG = typename remove_cv<typename remove_reference<_Tp>::type>::type;
596
597// __is_same_uncvref
598
599template <class _Tp, class _Up>
600struct __is_same_uncvref : _IsSame<__uncvref_t<_Tp>, __uncvref_t<_Up> > {};
601
602#if _LIBCPP_STD_VER > 17
603// remove_cvref - same as __uncvref
604template <class _Tp>
605struct remove_cvref {
606    using type _LIBCPP_NODEBUG = __uncvref_t<_Tp>;
607};
608
609template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type;
610#endif
611
612
613struct __any
614{
615    __any(...);
616};
617
618// __is_core_convertible
619
620// [conv.general]/3 says "E is convertible to T" whenever "T t=E;" is well-formed.
621// We can't test for that, but we can test implicit convertibility by passing it
622// to a function. Notice that __is_core_convertible<void,void> is false,
623// and __is_core_convertible<immovable-type,immovable-type> is true in C++17 and later.
624
625template <class _Tp, class _Up, class = void>
626struct __is_core_convertible : public false_type {};
627
628template <class _Tp, class _Up>
629struct __is_core_convertible<_Tp, _Up, decltype(
630    static_cast<void(*)(_Up)>(0) ( static_cast<_Tp(*)()>(0)() )
631)> : public true_type {};
632
633// is_nothrow_convertible
634
635#if _LIBCPP_STD_VER > 17
636
637template <typename _Tp>
638static void __test_noexcept(_Tp) noexcept;
639
640template<typename _Fm, typename _To>
641static bool_constant<noexcept(_VSTD::__test_noexcept<_To>(declval<_Fm>()))>
642__is_nothrow_convertible_test();
643
644template <typename _Fm, typename _To>
645struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>())
646{ };
647
648template <typename _Fm, typename _To>
649struct is_nothrow_convertible : _Or<
650    _And<is_void<_To>, is_void<_Fm>>,
651    _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>>
652>::type { };
653
654template <typename _Fm, typename _To>
655inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
656
657#endif // _LIBCPP_STD_VER > 17
658
659// is_polymorphic
660
661#if __has_feature(is_polymorphic) || defined(_LIBCPP_COMPILER_MSVC)
662
663template <class _Tp>
664struct _LIBCPP_TEMPLATE_VIS is_polymorphic
665    : public integral_constant<bool, __is_polymorphic(_Tp)> {};
666
667#else
668
669template<typename _Tp> char &__is_polymorphic_impl(
670    typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
671                       int>::type);
672template<typename _Tp> __two &__is_polymorphic_impl(...);
673
674template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic
675    : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
676
677#endif // __has_feature(is_polymorphic)
678
679#if _LIBCPP_STD_VER > 14
680template <class _Tp>
681inline constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value;
682#endif
683
684// has_virtual_destructor
685
686#if __has_feature(has_virtual_destructor) || defined(_LIBCPP_COMPILER_GCC)
687
688template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
689    : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
690
691#else
692
693template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
694    : public false_type {};
695
696#endif
697
698#if _LIBCPP_STD_VER > 14
699template <class _Tp>
700inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<_Tp>::value;
701#endif
702
703// has_unique_object_representations
704
705#if _LIBCPP_STD_VER > 14
706
707template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
708    : public integral_constant<bool,
709       __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
710
711template <class _Tp>
712inline constexpr bool has_unique_object_representations_v = has_unique_object_representations<_Tp>::value;
713
714#endif
715
716// alignment_of
717
718template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
719    : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
720
721#if _LIBCPP_STD_VER > 14
722template <class _Tp>
723inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
724#endif
725
726// aligned_storage
727
728template <class _Hp, class _Tp>
729struct __type_list
730{
731    typedef _Hp _Head;
732    typedef _Tp _Tail;
733};
734
735struct __nat
736{
737#ifndef _LIBCPP_CXX03_LANG
738    __nat() = delete;
739    __nat(const __nat&) = delete;
740    __nat& operator=(const __nat&) = delete;
741    ~__nat() = delete;
742#endif
743};
744
745template <class _Tp>
746struct __align_type
747{
748    static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp);
749    typedef _Tp type;
750};
751
752struct __struct_double {long double __lx;};
753struct __struct_double4 {double __lx[4];};
754
755typedef
756    __type_list<__align_type<unsigned char>,
757    __type_list<__align_type<unsigned short>,
758    __type_list<__align_type<unsigned int>,
759    __type_list<__align_type<unsigned long>,
760    __type_list<__align_type<unsigned long long>,
761    __type_list<__align_type<double>,
762    __type_list<__align_type<long double>,
763    __type_list<__align_type<__struct_double>,
764    __type_list<__align_type<__struct_double4>,
765    __type_list<__align_type<int*>,
766    __nat
767    > > > > > > > > > > __all_types;
768
769template <size_t _Align>
770struct _ALIGNAS(_Align) __fallback_overaligned {};
771
772template <class _TL, size_t _Align> struct __find_pod;
773
774template <class _Hp, size_t _Align>
775struct __find_pod<__type_list<_Hp, __nat>, _Align>
776{
777    typedef typename conditional<
778                             _Align == _Hp::value,
779                             typename _Hp::type,
780                             __fallback_overaligned<_Align>
781                         >::type type;
782};
783
784template <class _Hp, class _Tp, size_t _Align>
785struct __find_pod<__type_list<_Hp, _Tp>, _Align>
786{
787    typedef typename conditional<
788                             _Align == _Hp::value,
789                             typename _Hp::type,
790                             typename __find_pod<_Tp, _Align>::type
791                         >::type type;
792};
793
794template <class _TL, size_t _Len> struct __find_max_align;
795
796template <class _Hp, size_t _Len>
797struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
798
799template <size_t _Len, size_t _A1, size_t _A2>
800struct __select_align
801{
802private:
803    static const size_t __min = _A2 < _A1 ? _A2 : _A1;
804    static const size_t __max = _A1 < _A2 ? _A2 : _A1;
805public:
806    static const size_t value = _Len < __max ? __min : __max;
807};
808
809template <class _Hp, class _Tp, size_t _Len>
810struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
811    : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
812
813template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
814struct _LIBCPP_TEMPLATE_VIS aligned_storage
815{
816    typedef typename __find_pod<__all_types, _Align>::type _Aligner;
817    union type
818    {
819        _Aligner __align;
820        unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
821    };
822};
823
824#if _LIBCPP_STD_VER > 11
825template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
826    using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
827#endif
828
829#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
830template <size_t _Len>\
831struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
832{\
833    struct _ALIGNAS(n) type\
834    {\
835        unsigned char __lx[(_Len + n - 1)/n * n];\
836    };\
837}
838
839_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
840_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
841_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
842_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
843_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
844_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
845_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
846_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
847_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
848_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
849_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
850_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
851_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
852_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
853// PE/COFF does not support alignment beyond 8192 (=0x2000)
854#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
855_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
856#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
857
858#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
859
860
861// aligned_union
862
863template <size_t _I0, size_t ..._In>
864struct __static_max;
865
866template <size_t _I0>
867struct __static_max<_I0>
868{
869    static const size_t value = _I0;
870};
871
872template <size_t _I0, size_t _I1, size_t ..._In>
873struct __static_max<_I0, _I1, _In...>
874{
875    static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
876                                             __static_max<_I1, _In...>::value;
877};
878
879template <size_t _Len, class _Type0, class ..._Types>
880struct aligned_union
881{
882    static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0),
883                                                       _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
884    static const size_t __len = __static_max<_Len, sizeof(_Type0),
885                                             sizeof(_Types)...>::value;
886    typedef typename aligned_storage<__len, alignment_value>::type type;
887};
888
889#if _LIBCPP_STD_VER > 11
890template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
891#endif
892
893template <class _Tp>
894struct __numeric_type
895{
896   static void __test(...);
897   static float __test(float);
898   static double __test(char);
899   static double __test(int);
900   static double __test(unsigned);
901   static double __test(long);
902   static double __test(unsigned long);
903   static double __test(long long);
904   static double __test(unsigned long long);
905   static double __test(double);
906   static long double __test(long double);
907
908   typedef decltype(__test(declval<_Tp>())) type;
909   static const bool value = _IsNotSame<type, void>::value;
910};
911
912template <>
913struct __numeric_type<void>
914{
915   static const bool value = true;
916};
917
918// __promote
919
920template <class _A1, class _A2 = void, class _A3 = void,
921          bool = __numeric_type<_A1>::value &&
922                 __numeric_type<_A2>::value &&
923                 __numeric_type<_A3>::value>
924class __promote_imp
925{
926public:
927    static const bool value = false;
928};
929
930template <class _A1, class _A2, class _A3>
931class __promote_imp<_A1, _A2, _A3, true>
932{
933private:
934    typedef typename __promote_imp<_A1>::type __type1;
935    typedef typename __promote_imp<_A2>::type __type2;
936    typedef typename __promote_imp<_A3>::type __type3;
937public:
938    typedef decltype(__type1() + __type2() + __type3()) type;
939    static const bool value = true;
940};
941
942template <class _A1, class _A2>
943class __promote_imp<_A1, _A2, void, true>
944{
945private:
946    typedef typename __promote_imp<_A1>::type __type1;
947    typedef typename __promote_imp<_A2>::type __type2;
948public:
949    typedef decltype(__type1() + __type2()) type;
950    static const bool value = true;
951};
952
953template <class _A1>
954class __promote_imp<_A1, void, void, true>
955{
956public:
957    typedef typename __numeric_type<_A1>::type type;
958    static const bool value = true;
959};
960
961template <class _A1, class _A2 = void, class _A3 = void>
962class __promote : public __promote_imp<_A1, _A2, _A3> {};
963
964// make_signed / make_unsigned
965
966typedef
967    __type_list<signed char,
968    __type_list<signed short,
969    __type_list<signed int,
970    __type_list<signed long,
971    __type_list<signed long long,
972#ifndef _LIBCPP_HAS_NO_INT128
973    __type_list<__int128_t,
974#endif
975    __nat
976#ifndef _LIBCPP_HAS_NO_INT128
977    >
978#endif
979    > > > > > __signed_types;
980
981typedef
982    __type_list<unsigned char,
983    __type_list<unsigned short,
984    __type_list<unsigned int,
985    __type_list<unsigned long,
986    __type_list<unsigned long long,
987#ifndef _LIBCPP_HAS_NO_INT128
988    __type_list<__uint128_t,
989#endif
990    __nat
991#ifndef _LIBCPP_HAS_NO_INT128
992    >
993#endif
994    > > > > > __unsigned_types;
995
996template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
997
998template <class _Hp, class _Tp, size_t _Size>
999struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
1000{
1001    typedef _LIBCPP_NODEBUG _Hp type;
1002};
1003
1004template <class _Hp, class _Tp, size_t _Size>
1005struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
1006{
1007    typedef _LIBCPP_NODEBUG typename __find_first<_Tp, _Size>::type type;
1008};
1009
1010template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
1011                             bool = is_volatile<typename remove_reference<_Tp>::type>::value>
1012struct __apply_cv
1013{
1014    typedef _LIBCPP_NODEBUG _Up type;
1015};
1016
1017template <class _Tp, class _Up>
1018struct __apply_cv<_Tp, _Up, true, false>
1019{
1020    typedef _LIBCPP_NODEBUG const _Up type;
1021};
1022
1023template <class _Tp, class _Up>
1024struct __apply_cv<_Tp, _Up, false, true>
1025{
1026    typedef volatile _Up type;
1027};
1028
1029template <class _Tp, class _Up>
1030struct __apply_cv<_Tp, _Up, true, true>
1031{
1032    typedef const volatile _Up type;
1033};
1034
1035template <class _Tp, class _Up>
1036struct __apply_cv<_Tp&, _Up, false, false>
1037{
1038    typedef _Up& type;
1039};
1040
1041template <class _Tp, class _Up>
1042struct __apply_cv<_Tp&, _Up, true, false>
1043{
1044    typedef const _Up& type;
1045};
1046
1047template <class _Tp, class _Up>
1048struct __apply_cv<_Tp&, _Up, false, true>
1049{
1050    typedef volatile _Up& type;
1051};
1052
1053template <class _Tp, class _Up>
1054struct __apply_cv<_Tp&, _Up, true, true>
1055{
1056    typedef const volatile _Up& type;
1057};
1058
1059template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1060struct __make_signed {};
1061
1062template <class _Tp>
1063struct __make_signed<_Tp, true>
1064{
1065    typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
1066};
1067
1068template <> struct __make_signed<bool,               true> {};
1069template <> struct __make_signed<  signed short,     true> {typedef short     type;};
1070template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
1071template <> struct __make_signed<  signed int,       true> {typedef int       type;};
1072template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
1073template <> struct __make_signed<  signed long,      true> {typedef long      type;};
1074template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
1075template <> struct __make_signed<  signed long long, true> {typedef long long type;};
1076template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
1077#ifndef _LIBCPP_HAS_NO_INT128
1078template <> struct __make_signed<__int128_t,         true> {typedef __int128_t type;};
1079template <> struct __make_signed<__uint128_t,        true> {typedef __int128_t type;};
1080#endif
1081
1082template <class _Tp>
1083struct _LIBCPP_TEMPLATE_VIS make_signed
1084{
1085    typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
1086};
1087
1088#if _LIBCPP_STD_VER > 11
1089template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
1090#endif
1091
1092template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1093struct __make_unsigned {};
1094
1095template <class _Tp>
1096struct __make_unsigned<_Tp, true>
1097{
1098    typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
1099};
1100
1101template <> struct __make_unsigned<bool,               true> {};
1102template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
1103template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
1104template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
1105template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
1106template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
1107template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
1108template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
1109template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
1110#ifndef _LIBCPP_HAS_NO_INT128
1111template <> struct __make_unsigned<__int128_t,         true> {typedef __uint128_t        type;};
1112template <> struct __make_unsigned<__uint128_t,        true> {typedef __uint128_t        type;};
1113#endif
1114
1115template <class _Tp>
1116struct _LIBCPP_TEMPLATE_VIS make_unsigned
1117{
1118    typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
1119};
1120
1121#if _LIBCPP_STD_VER > 11
1122template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
1123#endif
1124
1125#ifndef _LIBCPP_CXX03_LANG
1126template <class _Tp>
1127_LIBCPP_HIDE_FROM_ABI constexpr
1128typename make_unsigned<_Tp>::type __to_unsigned_like(_Tp __x) noexcept {
1129    return static_cast<typename make_unsigned<_Tp>::type>(__x);
1130}
1131#endif
1132
1133#if _LIBCPP_STD_VER > 14
1134template <class...> using void_t = void;
1135#endif
1136
1137#if _LIBCPP_STD_VER > 17
1138// Let COND_RES(X, Y) be:
1139template <class _Tp, class _Up>
1140using __cond_type = decltype(false ? declval<_Tp>() : declval<_Up>());
1141
1142template <class _Tp, class _Up, class = void>
1143struct __common_type3 {};
1144
1145// sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
1146template <class _Tp, class _Up>
1147struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>>
1148{
1149    using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
1150};
1151
1152template <class _Tp, class _Up, class = void>
1153struct __common_type2_imp : __common_type3<_Tp, _Up> {};
1154#else
1155template <class _Tp, class _Up, class = void>
1156struct __common_type2_imp {};
1157#endif
1158
1159// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
1160template <class _Tp, class _Up>
1161struct __common_type2_imp<_Tp, _Up,
1162                          typename __void_t<decltype(
1163                                            true ? declval<_Tp>() : declval<_Up>()
1164                                            )>::type>
1165{
1166  typedef _LIBCPP_NODEBUG typename decay<decltype(
1167                         true ? declval<_Tp>() : declval<_Up>()
1168                         )>::type type;
1169};
1170
1171template <class, class = void>
1172struct __common_type_impl {};
1173
1174// Clang provides variadic templates in C++03 as an extension.
1175#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__)
1176# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
1177template <class... _Tp>
1178struct __common_types;
1179template <class... _Tp>
1180struct _LIBCPP_TEMPLATE_VIS common_type;
1181#else
1182# define _LIBCPP_OPTIONAL_PACK(...)
1183struct __no_arg;
1184template <class _Tp, class _Up, class = __no_arg>
1185struct __common_types;
1186template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg,
1187          class _Unused = __no_arg>
1188struct common_type {
1189  static_assert(sizeof(_Unused) == 0,
1190                "common_type accepts at most 3 arguments in C++03");
1191};
1192#endif // _LIBCPP_CXX03_LANG
1193
1194template <class _Tp, class _Up>
1195struct __common_type_impl<
1196    __common_types<_Tp, _Up>,
1197    typename __void_t<typename common_type<_Tp, _Up>::type>::type>
1198{
1199  typedef typename common_type<_Tp, _Up>::type type;
1200};
1201
1202template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
1203struct __common_type_impl<
1204    __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>,
1205    typename __void_t<typename common_type<_Tp, _Up>::type>::type>
1206    : __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type,
1207                                        _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {
1208};
1209
1210// bullet 1 - sizeof...(Tp) == 0
1211
1212template <>
1213struct _LIBCPP_TEMPLATE_VIS common_type<> {};
1214
1215// bullet 2 - sizeof...(Tp) == 1
1216
1217template <class _Tp>
1218struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
1219    : public common_type<_Tp, _Tp> {};
1220
1221// bullet 3 - sizeof...(Tp) == 2
1222
1223// sub-bullet 1 - "If is_same_v<T1, D1> is false or ..."
1224template <class _Tp, class _Up>
1225struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
1226    : conditional<
1227        _IsSame<_Tp, typename decay<_Tp>::type>::value && _IsSame<_Up, typename decay<_Up>::type>::value,
1228        __common_type2_imp<_Tp, _Up>,
1229        common_type<typename decay<_Tp>::type, typename decay<_Up>::type>
1230    >::type
1231{};
1232
1233// bullet 4 - sizeof...(Tp) > 2
1234
1235template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
1236struct _LIBCPP_TEMPLATE_VIS
1237    common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>
1238    : __common_type_impl<
1239          __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {};
1240
1241#undef _LIBCPP_OPTIONAL_PACK
1242
1243#if _LIBCPP_STD_VER > 11
1244template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
1245#endif
1246
1247#if _LIBCPP_STD_VER > 11
1248// Let COPYCV(FROM, TO) be an alias for type TO with the addition of FROM's
1249// top-level cv-qualifiers.
1250template <class _From, class _To>
1251struct __copy_cv
1252{
1253    using type = _To;
1254};
1255
1256template <class _From, class _To>
1257struct __copy_cv<const _From, _To>
1258{
1259    using type = add_const_t<_To>;
1260};
1261
1262template <class _From, class _To>
1263struct __copy_cv<volatile _From, _To>
1264{
1265    using type = add_volatile_t<_To>;
1266};
1267
1268template <class _From, class _To>
1269struct __copy_cv<const volatile _From, _To>
1270{
1271    using type = add_cv_t<_To>;
1272};
1273
1274template <class _From, class _To>
1275using __copy_cv_t = typename __copy_cv<_From, _To>::type;
1276
1277template <class _From, class _To>
1278struct __copy_cvref
1279{
1280    using type = __copy_cv_t<_From, _To>;
1281};
1282
1283template <class _From, class _To>
1284struct __copy_cvref<_From&, _To>
1285{
1286    using type = add_lvalue_reference_t<__copy_cv_t<_From, _To>>;
1287};
1288
1289template <class _From, class _To>
1290struct __copy_cvref<_From&&, _To>
1291{
1292    using type = add_rvalue_reference_t<__copy_cv_t<_From, _To>>;
1293};
1294
1295template <class _From, class _To>
1296using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
1297
1298#endif // _LIBCPP_STD_VER > 11
1299
1300// common_reference
1301#if _LIBCPP_STD_VER > 17
1302// Let COND_RES(X, Y) be:
1303template <class _Xp, class _Yp>
1304using __cond_res =
1305    decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
1306
1307// Let `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes the same type as `U`
1308// with the addition of `A`'s cv and reference qualifiers, for a non-reference cv-unqualified type
1309// `U`.
1310// [Note: `XREF(A)` is `__xref<A>::template __apply`]
1311template <class _Tp>
1312struct __xref {
1313  template<class _Up>
1314  using __apply = __copy_cvref_t<_Tp, _Up>;
1315};
1316
1317// Given types A and B, let X be remove_reference_t<A>, let Y be remove_reference_t<B>,
1318// and let COMMON-REF(A, B) be:
1319template<class _Ap, class _Bp, class _Xp = remove_reference_t<_Ap>, class _Yp = remove_reference_t<_Bp>>
1320struct __common_ref;
1321
1322template<class _Xp, class _Yp>
1323using __common_ref_t = typename __common_ref<_Xp, _Yp>::__type;
1324
1325template<class _Xp, class _Yp>
1326using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>;
1327
1328
1329//    If A and B are both lvalue reference types, COMMON-REF(A, B) is
1330//    COND-RES(COPYCV(X, Y)&, COPYCV(Y, X)&) if that type exists and is a reference type.
1331template<class _Ap, class _Bp, class _Xp, class _Yp>
1332requires requires { typename __cv_cond_res<_Xp, _Yp>; } && is_reference_v<__cv_cond_res<_Xp, _Yp>>
1333struct __common_ref<_Ap&, _Bp&, _Xp, _Yp>
1334{
1335    using __type = __cv_cond_res<_Xp, _Yp>;
1336};
1337
1338//    Otherwise, let C be remove_reference_t<COMMON-REF(X&, Y&)>&&. ...
1339template <class _Xp, class _Yp>
1340using __common_ref_C = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
1341
1342
1343//    .... If A and B are both rvalue reference types, C is well-formed, and
1344//    is_convertible_v<A, C> && is_convertible_v<B, C> is true, then COMMON-REF(A, B) is C.
1345template<class _Ap, class _Bp, class _Xp, class _Yp>
1346requires
1347  requires { typename __common_ref_C<_Xp, _Yp>; } &&
1348  is_convertible_v<_Ap&&, __common_ref_C<_Xp, _Yp>> &&
1349  is_convertible_v<_Bp&&, __common_ref_C<_Xp, _Yp>>
1350struct __common_ref<_Ap&&, _Bp&&, _Xp, _Yp>
1351{
1352    using __type = __common_ref_C<_Xp, _Yp>;
1353};
1354
1355//    Otherwise, let D be COMMON-REF(const X&, Y&). ...
1356template <class _Tp, class _Up>
1357using __common_ref_D = __common_ref_t<const _Tp&, _Up&>;
1358
1359//    ... If A is an rvalue reference and B is an lvalue reference and D is well-formed and
1360//    is_convertible_v<A, D> is true, then COMMON-REF(A, B) is D.
1361template<class _Ap, class _Bp, class _Xp, class _Yp>
1362requires requires { typename __common_ref_D<_Xp, _Yp>; } &&
1363         is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>>
1364struct __common_ref<_Ap&&, _Bp&, _Xp, _Yp>
1365{
1366    using __type = __common_ref_D<_Xp, _Yp>;
1367};
1368
1369//    Otherwise, if A is an lvalue reference and B is an rvalue reference, then
1370//    COMMON-REF(A, B) is COMMON-REF(B, A).
1371template<class _Ap, class _Bp, class _Xp, class _Yp>
1372struct __common_ref<_Ap&, _Bp&&, _Xp, _Yp> : __common_ref<_Bp&&, _Ap&> {};
1373
1374//    Otherwise, COMMON-REF(A, B) is ill-formed.
1375template<class _Ap, class _Bp, class _Xp, class _Yp>
1376struct __common_ref {};
1377
1378// Note C: For the common_reference trait applied to a parameter pack [...]
1379
1380template <class...>
1381struct common_reference;
1382
1383template <class... _Types>
1384using common_reference_t = typename common_reference<_Types...>::type;
1385
1386// bullet 1 - sizeof...(T) == 0
1387template<>
1388struct common_reference<> {};
1389
1390// bullet 2 - sizeof...(T) == 1
1391template <class _Tp>
1392struct common_reference<_Tp>
1393{
1394    using type = _Tp;
1395};
1396
1397// bullet 3 - sizeof...(T) == 2
1398template <class _Tp, class _Up> struct __common_reference_sub_bullet3;
1399template <class _Tp, class _Up> struct __common_reference_sub_bullet2 : __common_reference_sub_bullet3<_Tp, _Up> {};
1400template <class _Tp, class _Up> struct __common_reference_sub_bullet1 : __common_reference_sub_bullet2<_Tp, _Up> {};
1401
1402// sub-bullet 1 - If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, then
1403// the member typedef `type` denotes that type.
1404template <class _Tp, class _Up> struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
1405
1406template <class _Tp, class _Up>
1407requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
1408struct __common_reference_sub_bullet1<_Tp, _Up>
1409{
1410    using type = __common_ref_t<_Tp, _Up>;
1411};
1412
1413// sub-bullet 2 - Otherwise, if basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>, XREF(T1), XREF(T2)>::type
1414// is well-formed, then the member typedef `type` denotes that type.
1415template <class, class, template <class> class, template <class> class> struct basic_common_reference {};
1416
1417template <class _Tp, class _Up>
1418using __basic_common_reference_t = typename basic_common_reference<
1419    remove_cvref_t<_Tp>, remove_cvref_t<_Up>,
1420    __xref<_Tp>::template __apply, __xref<_Up>::template __apply>::type;
1421
1422template <class _Tp, class _Up>
1423requires requires { typename __basic_common_reference_t<_Tp, _Up>; }
1424struct __common_reference_sub_bullet2<_Tp, _Up>
1425{
1426    using type = __basic_common_reference_t<_Tp, _Up>;
1427};
1428
1429// sub-bullet 3 - Otherwise, if COND-RES(T1, T2) is well-formed,
1430// then the member typedef `type` denotes that type.
1431template <class _Tp, class _Up>
1432requires requires { typename __cond_res<_Tp, _Up>; }
1433struct __common_reference_sub_bullet3<_Tp, _Up>
1434{
1435    using type = __cond_res<_Tp, _Up>;
1436};
1437
1438
1439// sub-bullet 4 & 5 - Otherwise, if common_type_t<T1, T2> is well-formed,
1440//                    then the member typedef `type` denotes that type.
1441//                  - Otherwise, there shall be no member `type`.
1442template <class _Tp, class _Up> struct __common_reference_sub_bullet3 : common_type<_Tp, _Up> {};
1443
1444// bullet 4 - If there is such a type `C`, the member typedef type shall denote the same type, if
1445//            any, as `common_reference_t<C, Rest...>`.
1446template <class _Tp, class _Up, class _Vp, class... _Rest>
1447requires requires { typename common_reference_t<_Tp, _Up>; }
1448struct common_reference<_Tp, _Up, _Vp, _Rest...>
1449    : common_reference<common_reference_t<_Tp, _Up>, _Vp, _Rest...>
1450{};
1451
1452// bullet 5 - Otherwise, there shall be no member `type`.
1453template <class...> struct common_reference {};
1454
1455#endif // _LIBCPP_STD_VER > 17
1456
1457// is_assignable
1458
1459template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG _Tp type; };
1460
1461#if __has_keyword(__is_assignable)
1462
1463template<class _Tp, class _Up>
1464struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
1465
1466#if _LIBCPP_STD_VER > 14
1467template <class _Tp, class _Arg>
1468inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
1469#endif
1470
1471#else // __has_keyword(__is_assignable)
1472
1473template <class _Tp, class _Arg>
1474typename __select_2nd<decltype((declval<_Tp>() = declval<_Arg>())), true_type>::type
1475__is_assignable_test(int);
1476
1477template <class, class>
1478false_type __is_assignable_test(...);
1479
1480
1481template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
1482struct __is_assignable_imp
1483    : public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {};
1484
1485template <class _Tp, class _Arg>
1486struct __is_assignable_imp<_Tp, _Arg, true>
1487    : public false_type
1488{
1489};
1490
1491template <class _Tp, class _Arg>
1492struct is_assignable
1493    : public __is_assignable_imp<_Tp, _Arg> {};
1494
1495#if _LIBCPP_STD_VER > 14
1496template <class _Tp, class _Arg>
1497inline constexpr bool is_assignable_v = is_assignable<_Tp, _Arg>::value;
1498#endif
1499
1500#endif // __has_keyword(__is_assignable)
1501
1502// is_copy_assignable
1503
1504template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
1505    : public is_assignable<typename add_lvalue_reference<_Tp>::type,
1506                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
1507
1508#if _LIBCPP_STD_VER > 14
1509template <class _Tp>
1510inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
1511#endif
1512
1513// is_move_assignable
1514
1515template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable
1516    : public is_assignable<typename add_lvalue_reference<_Tp>::type,
1517                           typename add_rvalue_reference<_Tp>::type> {};
1518
1519#if _LIBCPP_STD_VER > 14
1520template <class _Tp>
1521inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
1522#endif
1523
1524// is_destructible
1525
1526#if __has_keyword(__is_destructible)
1527
1528template<class _Tp>
1529struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
1530
1531#if _LIBCPP_STD_VER > 14
1532template <class _Tp>
1533inline constexpr bool is_destructible_v = __is_destructible(_Tp);
1534#endif
1535
1536#else // __has_keyword(__is_destructible)
1537
1538//  if it's a reference, return true
1539//  if it's a function, return false
1540//  if it's   void,     return false
1541//  if it's an array of unknown bound, return false
1542//  Otherwise, return "declval<_Up&>().~_Up()" is well-formed
1543//    where _Up is remove_all_extents<_Tp>::type
1544
1545template <class>
1546struct __is_destructible_apply { typedef int type; };
1547
1548template <typename _Tp>
1549struct __is_destructor_wellformed {
1550    template <typename _Tp1>
1551    static char  __test (
1552        typename __is_destructible_apply<decltype(declval<_Tp1&>().~_Tp1())>::type
1553    );
1554
1555    template <typename _Tp1>
1556    static __two __test (...);
1557
1558    static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
1559};
1560
1561template <class _Tp, bool>
1562struct __destructible_imp;
1563
1564template <class _Tp>
1565struct __destructible_imp<_Tp, false>
1566   : public integral_constant<bool,
1567        __is_destructor_wellformed<typename remove_all_extents<_Tp>::type>::value> {};
1568
1569template <class _Tp>
1570struct __destructible_imp<_Tp, true>
1571    : public true_type {};
1572
1573template <class _Tp, bool>
1574struct __destructible_false;
1575
1576template <class _Tp>
1577struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, is_reference<_Tp>::value> {};
1578
1579template <class _Tp>
1580struct __destructible_false<_Tp, true> : public false_type {};
1581
1582template <class _Tp>
1583struct is_destructible
1584    : public __destructible_false<_Tp, is_function<_Tp>::value> {};
1585
1586template <class _Tp>
1587struct is_destructible<_Tp[]>
1588    : public false_type {};
1589
1590template <>
1591struct is_destructible<void>
1592    : public false_type {};
1593
1594#if _LIBCPP_STD_VER > 14
1595template <class _Tp>
1596inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
1597#endif
1598
1599#endif // __has_keyword(__is_destructible)
1600
1601template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
1602struct __member_pointer_traits_imp
1603{
1604};
1605
1606template <class _Rp, class _Class, class ..._Param>
1607struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
1608{
1609    typedef _Class _ClassType;
1610    typedef _Rp _ReturnType;
1611    typedef _Rp (_FnType) (_Param...);
1612};
1613
1614template <class _Rp, class _Class, class ..._Param>
1615struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
1616{
1617    typedef _Class _ClassType;
1618    typedef _Rp _ReturnType;
1619    typedef _Rp (_FnType) (_Param..., ...);
1620};
1621
1622template <class _Rp, class _Class, class ..._Param>
1623struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
1624{
1625    typedef _Class const _ClassType;
1626    typedef _Rp _ReturnType;
1627    typedef _Rp (_FnType) (_Param...);
1628};
1629
1630template <class _Rp, class _Class, class ..._Param>
1631struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
1632{
1633    typedef _Class const _ClassType;
1634    typedef _Rp _ReturnType;
1635    typedef _Rp (_FnType) (_Param..., ...);
1636};
1637
1638template <class _Rp, class _Class, class ..._Param>
1639struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
1640{
1641    typedef _Class volatile _ClassType;
1642    typedef _Rp _ReturnType;
1643    typedef _Rp (_FnType) (_Param...);
1644};
1645
1646template <class _Rp, class _Class, class ..._Param>
1647struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
1648{
1649    typedef _Class volatile _ClassType;
1650    typedef _Rp _ReturnType;
1651    typedef _Rp (_FnType) (_Param..., ...);
1652};
1653
1654template <class _Rp, class _Class, class ..._Param>
1655struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
1656{
1657    typedef _Class const volatile _ClassType;
1658    typedef _Rp _ReturnType;
1659    typedef _Rp (_FnType) (_Param...);
1660};
1661
1662template <class _Rp, class _Class, class ..._Param>
1663struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
1664{
1665    typedef _Class const volatile _ClassType;
1666    typedef _Rp _ReturnType;
1667    typedef _Rp (_FnType) (_Param..., ...);
1668};
1669
1670#if __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
1671
1672template <class _Rp, class _Class, class ..._Param>
1673struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
1674{
1675    typedef _Class& _ClassType;
1676    typedef _Rp _ReturnType;
1677    typedef _Rp (_FnType) (_Param...);
1678};
1679
1680template <class _Rp, class _Class, class ..._Param>
1681struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
1682{
1683    typedef _Class& _ClassType;
1684    typedef _Rp _ReturnType;
1685    typedef _Rp (_FnType) (_Param..., ...);
1686};
1687
1688template <class _Rp, class _Class, class ..._Param>
1689struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
1690{
1691    typedef _Class const& _ClassType;
1692    typedef _Rp _ReturnType;
1693    typedef _Rp (_FnType) (_Param...);
1694};
1695
1696template <class _Rp, class _Class, class ..._Param>
1697struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
1698{
1699    typedef _Class const& _ClassType;
1700    typedef _Rp _ReturnType;
1701    typedef _Rp (_FnType) (_Param..., ...);
1702};
1703
1704template <class _Rp, class _Class, class ..._Param>
1705struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
1706{
1707    typedef _Class volatile& _ClassType;
1708    typedef _Rp _ReturnType;
1709    typedef _Rp (_FnType) (_Param...);
1710};
1711
1712template <class _Rp, class _Class, class ..._Param>
1713struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
1714{
1715    typedef _Class volatile& _ClassType;
1716    typedef _Rp _ReturnType;
1717    typedef _Rp (_FnType) (_Param..., ...);
1718};
1719
1720template <class _Rp, class _Class, class ..._Param>
1721struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
1722{
1723    typedef _Class const volatile& _ClassType;
1724    typedef _Rp _ReturnType;
1725    typedef _Rp (_FnType) (_Param...);
1726};
1727
1728template <class _Rp, class _Class, class ..._Param>
1729struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
1730{
1731    typedef _Class const volatile& _ClassType;
1732    typedef _Rp _ReturnType;
1733    typedef _Rp (_FnType) (_Param..., ...);
1734};
1735
1736template <class _Rp, class _Class, class ..._Param>
1737struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
1738{
1739    typedef _Class&& _ClassType;
1740    typedef _Rp _ReturnType;
1741    typedef _Rp (_FnType) (_Param...);
1742};
1743
1744template <class _Rp, class _Class, class ..._Param>
1745struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
1746{
1747    typedef _Class&& _ClassType;
1748    typedef _Rp _ReturnType;
1749    typedef _Rp (_FnType) (_Param..., ...);
1750};
1751
1752template <class _Rp, class _Class, class ..._Param>
1753struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
1754{
1755    typedef _Class const&& _ClassType;
1756    typedef _Rp _ReturnType;
1757    typedef _Rp (_FnType) (_Param...);
1758};
1759
1760template <class _Rp, class _Class, class ..._Param>
1761struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
1762{
1763    typedef _Class const&& _ClassType;
1764    typedef _Rp _ReturnType;
1765    typedef _Rp (_FnType) (_Param..., ...);
1766};
1767
1768template <class _Rp, class _Class, class ..._Param>
1769struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
1770{
1771    typedef _Class volatile&& _ClassType;
1772    typedef _Rp _ReturnType;
1773    typedef _Rp (_FnType) (_Param...);
1774};
1775
1776template <class _Rp, class _Class, class ..._Param>
1777struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
1778{
1779    typedef _Class volatile&& _ClassType;
1780    typedef _Rp _ReturnType;
1781    typedef _Rp (_FnType) (_Param..., ...);
1782};
1783
1784template <class _Rp, class _Class, class ..._Param>
1785struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
1786{
1787    typedef _Class const volatile&& _ClassType;
1788    typedef _Rp _ReturnType;
1789    typedef _Rp (_FnType) (_Param...);
1790};
1791
1792template <class _Rp, class _Class, class ..._Param>
1793struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
1794{
1795    typedef _Class const volatile&& _ClassType;
1796    typedef _Rp _ReturnType;
1797    typedef _Rp (_FnType) (_Param..., ...);
1798};
1799
1800#endif // __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
1801
1802
1803template <class _Rp, class _Class>
1804struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
1805{
1806    typedef _Class _ClassType;
1807    typedef _Rp _ReturnType;
1808};
1809
1810template <class _MP>
1811struct __member_pointer_traits
1812    : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
1813                    is_member_function_pointer<_MP>::value,
1814                    is_member_object_pointer<_MP>::value>
1815{
1816//     typedef ... _ClassType;
1817//     typedef ... _ReturnType;
1818//     typedef ... _FnType;
1819};
1820
1821
1822template <class _DecayedFp>
1823struct __member_pointer_class_type {};
1824
1825template <class _Ret, class _ClassType>
1826struct __member_pointer_class_type<_Ret _ClassType::*> {
1827  typedef _ClassType type;
1828};
1829
1830// template <class T, class... Args> struct is_constructible;
1831
1832template <class _Tp, class ..._Args>
1833struct _LIBCPP_TEMPLATE_VIS is_constructible
1834    : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
1835{ };
1836
1837#if _LIBCPP_STD_VER > 14
1838template <class _Tp, class ..._Args>
1839inline constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value;
1840#endif
1841
1842// is_default_constructible
1843
1844template <class _Tp>
1845struct _LIBCPP_TEMPLATE_VIS is_default_constructible
1846    : public is_constructible<_Tp>
1847    {};
1848
1849#if _LIBCPP_STD_VER > 14
1850template <class _Tp>
1851inline constexpr bool is_default_constructible_v = is_default_constructible<_Tp>::value;
1852#endif
1853
1854#ifndef _LIBCPP_CXX03_LANG
1855// First of all, we can't implement this check in C++03 mode because the {}
1856// default initialization syntax isn't valid.
1857// Second, we implement the trait in a funny manner with two defaulted template
1858// arguments to workaround Clang's PR43454.
1859template <class _Tp>
1860void __test_implicit_default_constructible(_Tp);
1861
1862template <class _Tp, class = void, class = typename is_default_constructible<_Tp>::type>
1863struct __is_implicitly_default_constructible
1864    : false_type
1865{ };
1866
1867template <class _Tp>
1868struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true_type>
1869    : true_type
1870{ };
1871
1872template <class _Tp>
1873struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), false_type>
1874    : false_type
1875{ };
1876#endif // !C++03
1877
1878// is_copy_constructible
1879
1880template <class _Tp>
1881struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
1882    : public is_constructible<_Tp,
1883                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
1884
1885#if _LIBCPP_STD_VER > 14
1886template <class _Tp>
1887inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
1888#endif
1889
1890// is_move_constructible
1891
1892template <class _Tp>
1893struct _LIBCPP_TEMPLATE_VIS is_move_constructible
1894    : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
1895    {};
1896
1897#if _LIBCPP_STD_VER > 14
1898template <class _Tp>
1899inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
1900#endif
1901
1902// is_trivially_constructible
1903
1904template <class _Tp, class... _Args>
1905struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
1906    : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
1907{
1908};
1909
1910#if _LIBCPP_STD_VER > 14
1911template <class _Tp, class... _Args>
1912inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value;
1913#endif
1914
1915// is_trivially_default_constructible
1916
1917template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
1918    : public is_trivially_constructible<_Tp>
1919    {};
1920
1921#if _LIBCPP_STD_VER > 14
1922template <class _Tp>
1923inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<_Tp>::value;
1924#endif
1925
1926// is_trivially_copy_constructible
1927
1928template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
1929    : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
1930    {};
1931
1932#if _LIBCPP_STD_VER > 14
1933template <class _Tp>
1934inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value;
1935#endif
1936
1937// is_trivially_move_constructible
1938
1939template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
1940    : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
1941    {};
1942
1943#if _LIBCPP_STD_VER > 14
1944template <class _Tp>
1945inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value;
1946#endif
1947
1948// is_trivially_assignable
1949
1950template <class _Tp, class _Arg>
1951struct is_trivially_assignable
1952    : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
1953{ };
1954
1955#if _LIBCPP_STD_VER > 14
1956template <class _Tp, class _Arg>
1957inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<_Tp, _Arg>::value;
1958#endif
1959
1960// is_trivially_copy_assignable
1961
1962template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
1963    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
1964                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
1965
1966#if _LIBCPP_STD_VER > 14
1967template <class _Tp>
1968inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value;
1969#endif
1970
1971// is_trivially_move_assignable
1972
1973template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
1974    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
1975                                     typename add_rvalue_reference<_Tp>::type>
1976    {};
1977
1978#if _LIBCPP_STD_VER > 14
1979template <class _Tp>
1980inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value;
1981#endif
1982
1983// is_trivially_destructible
1984
1985#if __has_keyword(__is_trivially_destructible)
1986
1987template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
1988    : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
1989
1990#elif __has_feature(has_trivial_destructor) || defined(_LIBCPP_COMPILER_GCC)
1991
1992template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
1993    : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
1994
1995#else
1996
1997template <class _Tp> struct __libcpp_trivial_destructor
1998    : public integral_constant<bool, is_scalar<_Tp>::value ||
1999                                     is_reference<_Tp>::value> {};
2000
2001template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
2002    : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
2003
2004template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]>
2005    : public false_type {};
2006
2007#endif
2008
2009#if _LIBCPP_STD_VER > 14
2010template <class _Tp>
2011inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
2012#endif
2013
2014// is_nothrow_constructible
2015
2016#if __has_keyword(__is_nothrow_constructible)
2017
2018template <class _Tp, class... _Args>
2019struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
2020    : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
2021
2022#else
2023
2024template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
2025
2026template <class _Tp, class... _Args>
2027struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
2028    : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
2029{
2030};
2031
2032template <class _Tp>
2033void __implicit_conversion_to(_Tp) noexcept { }
2034
2035template <class _Tp, class _Arg>
2036struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
2037    : public integral_constant<bool, noexcept(_VSTD::__implicit_conversion_to<_Tp>(declval<_Arg>()))>
2038{
2039};
2040
2041template <class _Tp, bool _IsReference, class... _Args>
2042struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
2043    : public false_type
2044{
2045};
2046
2047template <class _Tp, class... _Args>
2048struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
2049    : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
2050{
2051};
2052
2053template <class _Tp, size_t _Ns>
2054struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
2055    : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
2056{
2057};
2058
2059#endif // _LIBCPP_HAS_NO_NOEXCEPT
2060
2061
2062#if _LIBCPP_STD_VER > 14
2063template <class _Tp, class ..._Args>
2064inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
2065#endif
2066
2067// is_nothrow_default_constructible
2068
2069template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
2070    : public is_nothrow_constructible<_Tp>
2071    {};
2072
2073#if _LIBCPP_STD_VER > 14
2074template <class _Tp>
2075inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value;
2076#endif
2077
2078// is_nothrow_copy_constructible
2079
2080template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
2081    : public is_nothrow_constructible<_Tp,
2082                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2083
2084#if _LIBCPP_STD_VER > 14
2085template <class _Tp>
2086inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value;
2087#endif
2088
2089// is_nothrow_move_constructible
2090
2091template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
2092    : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2093    {};
2094
2095#if _LIBCPP_STD_VER > 14
2096template <class _Tp>
2097inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value;
2098#endif
2099
2100// is_nothrow_assignable
2101
2102#if __has_keyword(__is_nothrow_assignable)
2103
2104template <class _Tp, class _Arg>
2105struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
2106    : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
2107
2108#else
2109
2110template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
2111
2112template <class _Tp, class _Arg>
2113struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
2114    : public false_type
2115{
2116};
2117
2118template <class _Tp, class _Arg>
2119struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
2120    : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Arg>()) >
2121{
2122};
2123
2124template <class _Tp, class _Arg>
2125struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
2126    : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
2127{
2128};
2129
2130#endif // _LIBCPP_HAS_NO_NOEXCEPT
2131
2132#if _LIBCPP_STD_VER > 14
2133template <class _Tp, class _Arg>
2134inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value;
2135#endif
2136
2137// is_nothrow_copy_assignable
2138
2139template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
2140    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
2141                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2142
2143#if _LIBCPP_STD_VER > 14
2144template <class _Tp>
2145inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
2146#endif
2147
2148// is_nothrow_move_assignable
2149
2150template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
2151    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
2152                                     typename add_rvalue_reference<_Tp>::type>
2153    {};
2154
2155#if _LIBCPP_STD_VER > 14
2156template <class _Tp>
2157inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
2158#endif
2159
2160// is_nothrow_destructible
2161
2162#if !defined(_LIBCPP_CXX03_LANG)
2163
2164template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
2165
2166template <class _Tp>
2167struct __libcpp_is_nothrow_destructible<false, _Tp>
2168    : public false_type
2169{
2170};
2171
2172template <class _Tp>
2173struct __libcpp_is_nothrow_destructible<true, _Tp>
2174    : public integral_constant<bool, noexcept(declval<_Tp>().~_Tp()) >
2175{
2176};
2177
2178template <class _Tp>
2179struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
2180    : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
2181{
2182};
2183
2184template <class _Tp, size_t _Ns>
2185struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
2186    : public is_nothrow_destructible<_Tp>
2187{
2188};
2189
2190template <class _Tp>
2191struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
2192    : public true_type
2193{
2194};
2195
2196template <class _Tp>
2197struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
2198    : public true_type
2199{
2200};
2201
2202#else
2203
2204template <class _Tp> struct __libcpp_nothrow_destructor
2205    : public integral_constant<bool, is_scalar<_Tp>::value ||
2206                                     is_reference<_Tp>::value> {};
2207
2208template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
2209    : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
2210
2211template <class _Tp>
2212struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
2213    : public false_type {};
2214
2215#endif
2216
2217#if _LIBCPP_STD_VER > 14
2218template <class _Tp>
2219inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
2220#endif
2221
2222// is_pod
2223
2224#if __has_feature(is_pod) || defined(_LIBCPP_COMPILER_GCC)
2225
2226template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
2227    : public integral_constant<bool, __is_pod(_Tp)> {};
2228
2229#else
2230
2231template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
2232    : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
2233                                     is_trivially_copy_constructible<_Tp>::value      &&
2234                                     is_trivially_copy_assignable<_Tp>::value    &&
2235                                     is_trivially_destructible<_Tp>::value> {};
2236
2237#endif
2238
2239#if _LIBCPP_STD_VER > 14
2240template <class _Tp>
2241inline constexpr bool is_pod_v = is_pod<_Tp>::value;
2242#endif
2243
2244// is_literal_type;
2245
2246#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
2247template <class _Tp> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 is_literal_type
2248    : public integral_constant<bool, __is_literal_type(_Tp)>
2249    {};
2250
2251#if _LIBCPP_STD_VER > 14
2252template <class _Tp>
2253_LIBCPP_DEPRECATED_IN_CXX17 inline constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
2254#endif // _LIBCPP_STD_VER > 14
2255#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
2256
2257// is_standard_layout;
2258
2259template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
2260#if __has_feature(is_standard_layout) || defined(_LIBCPP_COMPILER_GCC)
2261    : public integral_constant<bool, __is_standard_layout(_Tp)>
2262#else
2263    : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
2264#endif
2265    {};
2266
2267#if _LIBCPP_STD_VER > 14
2268template <class _Tp>
2269inline constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
2270#endif
2271
2272// is_trivially_copyable;
2273
2274template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
2275    : public integral_constant<bool, __is_trivially_copyable(_Tp)>
2276    {};
2277
2278#if _LIBCPP_STD_VER > 14
2279template <class _Tp>
2280inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value;
2281#endif
2282
2283// is_trivial;
2284
2285template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
2286#if __has_feature(is_trivial) || defined(_LIBCPP_COMPILER_GCC)
2287    : public integral_constant<bool, __is_trivial(_Tp)>
2288#else
2289    : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
2290                                 is_trivially_default_constructible<_Tp>::value>
2291#endif
2292    {};
2293
2294#if _LIBCPP_STD_VER > 14
2295template <class _Tp>
2296inline constexpr bool is_trivial_v = is_trivial<_Tp>::value;
2297#endif
2298
2299
2300#ifndef _LIBCPP_CXX03_LANG
2301
2302template <class _Fp, class _A0,
2303         class _DecayFp = typename decay<_Fp>::type,
2304         class _DecayA0 = typename decay<_A0>::type,
2305         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
2306using __enable_if_bullet1 = typename enable_if
2307    <
2308        is_member_function_pointer<_DecayFp>::value
2309        && is_base_of<_ClassT, _DecayA0>::value
2310    >::type;
2311
2312template <class _Fp, class _A0,
2313         class _DecayFp = typename decay<_Fp>::type,
2314         class _DecayA0 = typename decay<_A0>::type>
2315using __enable_if_bullet2 = typename enable_if
2316    <
2317        is_member_function_pointer<_DecayFp>::value
2318        && __is_reference_wrapper<_DecayA0>::value
2319    >::type;
2320
2321template <class _Fp, class _A0,
2322         class _DecayFp = typename decay<_Fp>::type,
2323         class _DecayA0 = typename decay<_A0>::type,
2324         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
2325using __enable_if_bullet3 = typename enable_if
2326    <
2327        is_member_function_pointer<_DecayFp>::value
2328        && !is_base_of<_ClassT, _DecayA0>::value
2329        && !__is_reference_wrapper<_DecayA0>::value
2330    >::type;
2331
2332template <class _Fp, class _A0,
2333         class _DecayFp = typename decay<_Fp>::type,
2334         class _DecayA0 = typename decay<_A0>::type,
2335         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
2336using __enable_if_bullet4 = typename enable_if
2337    <
2338        is_member_object_pointer<_DecayFp>::value
2339        && is_base_of<_ClassT, _DecayA0>::value
2340    >::type;
2341
2342template <class _Fp, class _A0,
2343         class _DecayFp = typename decay<_Fp>::type,
2344         class _DecayA0 = typename decay<_A0>::type>
2345using __enable_if_bullet5 = typename enable_if
2346    <
2347        is_member_object_pointer<_DecayFp>::value
2348        && __is_reference_wrapper<_DecayA0>::value
2349    >::type;
2350
2351template <class _Fp, class _A0,
2352         class _DecayFp = typename decay<_Fp>::type,
2353         class _DecayA0 = typename decay<_A0>::type,
2354         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
2355using __enable_if_bullet6 = typename enable_if
2356    <
2357        is_member_object_pointer<_DecayFp>::value
2358        && !is_base_of<_ClassT, _DecayA0>::value
2359        && !__is_reference_wrapper<_DecayA0>::value
2360    >::type;
2361
2362// __invoke forward declarations
2363
2364// fall back - none of the bullets
2365
2366template <class ..._Args>
2367auto __invoke(__any, _Args&& ...__args) -> __nat;
2368
2369// bullets 1, 2 and 3
2370
2371template <class _Fp, class _A0, class ..._Args,
2372          class = __enable_if_bullet1<_Fp, _A0>>
2373inline _LIBCPP_INLINE_VISIBILITY
2374constexpr auto
2375__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
2376    noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
2377    -> decltype(      (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
2378    { return          (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
2379
2380template <class _Fp, class _A0, class ..._Args,
2381          class = __enable_if_bullet2<_Fp, _A0>>
2382inline _LIBCPP_INLINE_VISIBILITY
2383constexpr auto
2384__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
2385    noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
2386    -> decltype(      (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
2387    { return          (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
2388
2389template <class _Fp, class _A0, class ..._Args,
2390          class = __enable_if_bullet3<_Fp, _A0>>
2391inline _LIBCPP_INLINE_VISIBILITY
2392constexpr auto
2393__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
2394    noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
2395    -> decltype(      ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
2396    { return          ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
2397
2398// bullets 4, 5 and 6
2399
2400template <class _Fp, class _A0,
2401          class = __enable_if_bullet4<_Fp, _A0>>
2402inline _LIBCPP_INLINE_VISIBILITY
2403constexpr auto
2404__invoke(_Fp&& __f, _A0&& __a0)
2405    noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
2406    -> decltype(      static_cast<_A0&&>(__a0).*__f)
2407    { return          static_cast<_A0&&>(__a0).*__f; }
2408
2409template <class _Fp, class _A0,
2410          class = __enable_if_bullet5<_Fp, _A0>>
2411inline _LIBCPP_INLINE_VISIBILITY
2412constexpr auto
2413__invoke(_Fp&& __f, _A0&& __a0)
2414    noexcept(noexcept(__a0.get().*__f))
2415    -> decltype(      __a0.get().*__f)
2416    { return          __a0.get().*__f; }
2417
2418template <class _Fp, class _A0,
2419          class = __enable_if_bullet6<_Fp, _A0>>
2420inline _LIBCPP_INLINE_VISIBILITY
2421constexpr auto
2422__invoke(_Fp&& __f, _A0&& __a0)
2423    noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
2424    -> decltype(      (*static_cast<_A0&&>(__a0)).*__f)
2425    { return          (*static_cast<_A0&&>(__a0)).*__f; }
2426
2427// bullet 7
2428
2429template <class _Fp, class ..._Args>
2430inline _LIBCPP_INLINE_VISIBILITY
2431constexpr auto
2432__invoke(_Fp&& __f, _Args&& ...__args)
2433    noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
2434    -> decltype(      static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
2435    { return          static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
2436
2437// __invokable
2438template <class _Ret, class _Fp, class ..._Args>
2439struct __invokable_r
2440{
2441  template <class _XFp, class ..._XArgs>
2442  static auto __try_call(int) -> decltype(
2443    _VSTD::__invoke(declval<_XFp>(), declval<_XArgs>()...));
2444  template <class _XFp, class ..._XArgs>
2445  static __nat __try_call(...);
2446
2447  // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void,
2448  // or incomplete array types as required by the standard.
2449  using _Result = decltype(__try_call<_Fp, _Args...>(0));
2450
2451  using type = typename conditional<
2452      _IsNotSame<_Result, __nat>::value,
2453      typename conditional< is_void<_Ret>::value, true_type, __is_core_convertible<_Result, _Ret> >::type,
2454      false_type >::type;
2455  static const bool value = type::value;
2456};
2457template <class _Fp, class ..._Args>
2458using __invokable = __invokable_r<void, _Fp, _Args...>;
2459
2460template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
2461struct __nothrow_invokable_r_imp {
2462  static const bool value = false;
2463};
2464
2465template <class _Ret, class _Fp, class ..._Args>
2466struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
2467{
2468    typedef __nothrow_invokable_r_imp _ThisT;
2469
2470    template <class _Tp>
2471    static void __test_noexcept(_Tp) noexcept;
2472
2473    static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
2474        _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...)));
2475};
2476
2477template <class _Ret, class _Fp, class ..._Args>
2478struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
2479{
2480    static const bool value = noexcept(
2481        _VSTD::__invoke(declval<_Fp>(), declval<_Args>()...));
2482};
2483
2484template <class _Ret, class _Fp, class ..._Args>
2485using __nothrow_invokable_r =
2486    __nothrow_invokable_r_imp<
2487            __invokable_r<_Ret, _Fp, _Args...>::value,
2488            is_void<_Ret>::value,
2489            _Ret, _Fp, _Args...
2490    >;
2491
2492template <class _Fp, class ..._Args>
2493using __nothrow_invokable =
2494    __nothrow_invokable_r_imp<
2495            __invokable<_Fp, _Args...>::value,
2496            true, void, _Fp, _Args...
2497    >;
2498
2499template <class _Fp, class ..._Args>
2500struct __invoke_of
2501    : public enable_if<
2502        __invokable<_Fp, _Args...>::value,
2503        typename __invokable_r<void, _Fp, _Args...>::_Result>
2504{
2505};
2506
2507#else
2508
2509// Assume that it's a functor in C++03
2510template <class _Func, class... _Args>
2511_LIBCPP_HIDE_FROM_ABI
2512decltype(std::declval<_Func>()(std::declval<_Args>()...)) __invoke(_Func&& __func, _Args&&... __args) {
2513    return static_cast<_Func&&>(__func)(static_cast<_Args&&>(__args)...);
2514}
2515
2516#endif // _LIBCPP_CXX03_LANG
2517
2518// result_of
2519
2520#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
2521template <class _Callable> class _LIBCPP_DEPRECATED_IN_CXX17 result_of;
2522
2523#ifndef _LIBCPP_CXX03_LANG
2524
2525template <class _Fp, class ..._Args>
2526class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)>
2527    : public __invoke_of<_Fp, _Args...>
2528{
2529};
2530
2531#else // C++03
2532
2533template <class _Fn, bool, bool>
2534class __result_of
2535{
2536};
2537
2538template <class _Fn, class ..._Args>
2539class __result_of<_Fn(_Args...), true, false>
2540{
2541public:
2542    typedef decltype(declval<_Fn>()(declval<_Args>()...)) type;
2543};
2544
2545template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
2546struct __result_of_mp;
2547
2548// member function pointer
2549
2550template <class _MP, class _Tp>
2551struct __result_of_mp<_MP, _Tp, true>
2552{
2553    using type = typename __member_pointer_traits<_MP>::_ReturnType;
2554};
2555
2556// member data pointer
2557
2558template <class _MP, class _Tp, bool>
2559struct __result_of_mdp;
2560
2561template <class _Rp, class _Class, class _Tp>
2562struct __result_of_mdp<_Rp _Class::*, _Tp, false>
2563{
2564    using type = typename __apply_cv<decltype(*declval<_Tp>()), _Rp>::type&;
2565};
2566
2567template <class _Rp, class _Class, class _Tp>
2568struct __result_of_mdp<_Rp _Class::*, _Tp, true>
2569{
2570    using type = typename __apply_cv<_Tp, _Rp>::type&;
2571};
2572
2573template <class _Rp, class _Class, class _Tp>
2574struct __result_of_mp<_Rp _Class::*, _Tp, false>
2575    : public __result_of_mdp<_Rp _Class::*, _Tp,
2576            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
2577{
2578};
2579
2580template <class _Fn, class _Tp>
2581class __result_of<_Fn(_Tp), false, true>  // _Fn must be member pointer
2582    : public __result_of_mp<typename remove_reference<_Fn>::type,
2583                            _Tp,
2584                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2585{
2586};
2587
2588template <class _Fn, class _Tp, class ..._Args>
2589class __result_of<_Fn(_Tp, _Args...), false, true>  // _Fn must be member pointer
2590    : public __result_of_mp<typename remove_reference<_Fn>::type,
2591                            _Tp,
2592                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2593{
2594};
2595
2596template <class _Fn, class ..._Args>
2597class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_Args...)>
2598    : public __result_of<_Fn(_Args...),
2599                         is_class<typename remove_reference<_Fn>::type>::value ||
2600                         is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
2601                         is_member_pointer<typename remove_reference<_Fn>::type>::value
2602                        >
2603{
2604};
2605
2606#endif // C++03
2607
2608#if _LIBCPP_STD_VER > 11
2609template <class _Tp> using result_of_t _LIBCPP_DEPRECATED_IN_CXX17 = typename result_of<_Tp>::type;
2610#endif // _LIBCPP_STD_VER > 11
2611#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
2612
2613#if _LIBCPP_STD_VER > 14
2614
2615// invoke_result
2616
2617template <class _Fn, class... _Args>
2618struct _LIBCPP_TEMPLATE_VIS invoke_result
2619    : __invoke_of<_Fn, _Args...>
2620{
2621};
2622
2623template <class _Fn, class... _Args>
2624using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
2625
2626// is_invocable
2627
2628template <class _Fn, class ..._Args>
2629struct _LIBCPP_TEMPLATE_VIS is_invocable
2630    : integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
2631
2632template <class _Ret, class _Fn, class ..._Args>
2633struct _LIBCPP_TEMPLATE_VIS is_invocable_r
2634    : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
2635
2636template <class _Fn, class ..._Args>
2637inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
2638
2639template <class _Ret, class _Fn, class ..._Args>
2640inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;
2641
2642// is_nothrow_invocable
2643
2644template <class _Fn, class ..._Args>
2645struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable
2646    : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {};
2647
2648template <class _Ret, class _Fn, class ..._Args>
2649struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
2650    : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
2651
2652template <class _Fn, class ..._Args>
2653inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
2654
2655template <class _Ret, class _Fn, class ..._Args>
2656inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
2657
2658#endif // _LIBCPP_STD_VER > 14
2659
2660// __swappable
2661
2662template <class _Tp> struct __is_swappable;
2663template <class _Tp> struct __is_nothrow_swappable;
2664
2665
2666#ifndef _LIBCPP_CXX03_LANG
2667template <class _Tp>
2668using __swap_result_t = typename enable_if<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>::type;
2669#else
2670template <class>
2671using __swap_result_t = void;
2672#endif
2673
2674template <class _Tp>
2675inline _LIBCPP_INLINE_VISIBILITY
2676_LIBCPP_CONSTEXPR_AFTER_CXX17 __swap_result_t<_Tp>
2677swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
2678                                    is_nothrow_move_assignable<_Tp>::value);
2679
2680template<class _Tp, size_t _Np>
2681inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2682typename enable_if<
2683    __is_swappable<_Tp>::value
2684>::type
2685swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
2686
2687namespace __detail
2688{
2689// ALL generic swap overloads MUST already have a declaration available at this point.
2690
2691template <class _Tp, class _Up = _Tp,
2692          bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value>
2693struct __swappable_with
2694{
2695    template <class _LHS, class _RHS>
2696    static decltype(swap(declval<_LHS>(), declval<_RHS>()))
2697    __test_swap(int);
2698    template <class, class>
2699    static __nat __test_swap(long);
2700
2701    // Extra parens are needed for the C++03 definition of decltype.
2702    typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1;
2703    typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2;
2704
2705    static const bool value = _IsNotSame<__swap1, __nat>::value
2706                           && _IsNotSame<__swap2, __nat>::value;
2707};
2708
2709template <class _Tp, class _Up>
2710struct __swappable_with<_Tp, _Up,  false> : false_type {};
2711
2712template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value>
2713struct __nothrow_swappable_with {
2714  static const bool value =
2715#ifndef _LIBCPP_HAS_NO_NOEXCEPT
2716      noexcept(swap(declval<_Tp>(), declval<_Up>()))
2717  &&  noexcept(swap(declval<_Up>(), declval<_Tp>()));
2718#else
2719      false;
2720#endif
2721};
2722
2723template <class _Tp, class _Up>
2724struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
2725
2726} // namespace __detail
2727
2728template <class _Tp>
2729struct __is_swappable
2730    : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value>
2731{
2732};
2733
2734template <class _Tp>
2735struct __is_nothrow_swappable
2736    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value>
2737{
2738};
2739
2740#if _LIBCPP_STD_VER > 14
2741
2742template <class _Tp, class _Up>
2743struct _LIBCPP_TEMPLATE_VIS is_swappable_with
2744    : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value>
2745{
2746};
2747
2748template <class _Tp>
2749struct _LIBCPP_TEMPLATE_VIS is_swappable
2750    : public conditional<
2751        __is_referenceable<_Tp>::value,
2752        is_swappable_with<
2753            typename add_lvalue_reference<_Tp>::type,
2754            typename add_lvalue_reference<_Tp>::type>,
2755        false_type
2756    >::type
2757{
2758};
2759
2760template <class _Tp, class _Up>
2761struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with
2762    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value>
2763{
2764};
2765
2766template <class _Tp>
2767struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable
2768    : public conditional<
2769        __is_referenceable<_Tp>::value,
2770        is_nothrow_swappable_with<
2771            typename add_lvalue_reference<_Tp>::type,
2772            typename add_lvalue_reference<_Tp>::type>,
2773        false_type
2774    >::type
2775{
2776};
2777
2778template <class _Tp, class _Up>
2779inline constexpr bool is_swappable_with_v = is_swappable_with<_Tp, _Up>::value;
2780
2781template <class _Tp>
2782inline constexpr bool is_swappable_v = is_swappable<_Tp>::value;
2783
2784template <class _Tp, class _Up>
2785inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<_Tp, _Up>::value;
2786
2787template <class _Tp>
2788inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value;
2789
2790#endif // _LIBCPP_STD_VER > 14
2791
2792template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl;
2793
2794template <class _Tp>
2795struct __underlying_type_impl<_Tp, false> {};
2796
2797template <class _Tp>
2798struct __underlying_type_impl<_Tp, true>
2799{
2800    typedef __underlying_type(_Tp) type;
2801};
2802
2803template <class _Tp>
2804struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
2805
2806#if _LIBCPP_STD_VER > 11
2807template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
2808#endif
2809
2810template <class _Tp, bool = is_enum<_Tp>::value>
2811struct __sfinae_underlying_type
2812{
2813    typedef typename underlying_type<_Tp>::type type;
2814    typedef decltype(((type)1) + 0) __promoted_type;
2815};
2816
2817template <class _Tp>
2818struct __sfinae_underlying_type<_Tp, false> {};
2819
2820inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2821int __convert_to_integral(int __val) { return __val; }
2822
2823inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2824unsigned __convert_to_integral(unsigned __val) { return __val; }
2825
2826inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2827long __convert_to_integral(long __val) { return __val; }
2828
2829inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2830unsigned long __convert_to_integral(unsigned long __val) { return __val; }
2831
2832inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2833long long __convert_to_integral(long long __val) { return __val; }
2834
2835inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2836unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
2837
2838template<typename _Fp>
2839inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2840typename enable_if<is_floating_point<_Fp>::value, long long>::type
2841 __convert_to_integral(_Fp __val) { return __val; }
2842
2843#ifndef _LIBCPP_HAS_NO_INT128
2844inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2845__int128_t __convert_to_integral(__int128_t __val) { return __val; }
2846
2847inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2848__uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
2849#endif
2850
2851template <class _Tp>
2852inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2853typename __sfinae_underlying_type<_Tp>::__promoted_type
2854__convert_to_integral(_Tp __val) { return __val; }
2855
2856// is_scoped_enum [meta.unary.prop]
2857
2858#if _LIBCPP_STD_VER > 20
2859template <class _Tp, bool = is_enum_v<_Tp> >
2860struct __is_scoped_enum_helper : false_type {};
2861
2862template <class _Tp>
2863struct __is_scoped_enum_helper<_Tp, true>
2864    : public bool_constant<!is_convertible_v<_Tp, underlying_type_t<_Tp> > > {};
2865
2866template <class _Tp>
2867struct _LIBCPP_TEMPLATE_VIS is_scoped_enum
2868    : public __is_scoped_enum_helper<_Tp> {};
2869
2870template <class _Tp>
2871inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
2872#endif
2873
2874#if _LIBCPP_STD_VER > 14
2875
2876template <class... _Args>
2877struct conjunction : _And<_Args...> {};
2878template<class... _Args>
2879inline constexpr bool conjunction_v = conjunction<_Args...>::value;
2880
2881template <class... _Args>
2882struct disjunction : _Or<_Args...> {};
2883template<class... _Args>
2884inline constexpr bool disjunction_v = disjunction<_Args...>::value;
2885
2886template <class _Tp>
2887struct negation : _Not<_Tp> {};
2888template<class _Tp>
2889inline constexpr bool negation_v = negation<_Tp>::value;
2890#endif // _LIBCPP_STD_VER > 14
2891
2892// These traits are used in __tree and __hash_table
2893struct __extract_key_fail_tag {};
2894struct __extract_key_self_tag {};
2895struct __extract_key_first_tag {};
2896
2897template <class _ValTy, class _Key,
2898          class _RawValTy = typename __unconstref<_ValTy>::type>
2899struct __can_extract_key
2900    : conditional<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag,
2901                  __extract_key_fail_tag>::type {};
2902
2903template <class _Pair, class _Key, class _First, class _Second>
2904struct __can_extract_key<_Pair, _Key, pair<_First, _Second> >
2905    : conditional<_IsSame<typename remove_const<_First>::type, _Key>::value,
2906                  __extract_key_first_tag, __extract_key_fail_tag>::type {};
2907
2908// __can_extract_map_key uses true_type/false_type instead of the tags.
2909// It returns true if _Key != _ContainerValueTy (the container is a map not a set)
2910// and _ValTy == _Key.
2911template <class _ValTy, class _Key, class _ContainerValueTy,
2912          class _RawValTy = typename __unconstref<_ValTy>::type>
2913struct __can_extract_map_key
2914    : integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {};
2915
2916// This specialization returns __extract_key_fail_tag for non-map containers
2917// because _Key == _ContainerValueTy
2918template <class _ValTy, class _Key, class _RawValTy>
2919struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
2920    : false_type {};
2921
2922#if _LIBCPP_STD_VER > 17
2923_LIBCPP_INLINE_VISIBILITY
2924inline constexpr bool is_constant_evaluated() noexcept {
2925  return __builtin_is_constant_evaluated();
2926}
2927#endif
2928
2929inline _LIBCPP_CONSTEXPR
2930bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); }
2931
2932template <class _CharT>
2933using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
2934
2935template<class _Tp>
2936using __make_const_lvalue_ref = const typename remove_reference<_Tp>::type&;
2937
2938#if _LIBCPP_STD_VER > 17
2939template<bool _Const, class _Tp>
2940using __maybe_const = conditional_t<_Const, const _Tp, _Tp>;
2941#endif // _LIBCPP_STD_VER > 17
2942
2943_LIBCPP_END_NAMESPACE_STD
2944
2945#endif // _LIBCPP_TYPE_TRAITS
2946