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