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