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