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