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