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