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