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