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