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