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