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