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