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