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// is_copy_constructible
2811
2812template <class _Tp>
2813struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
2814    : public is_constructible<_Tp,
2815                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2816
2817#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2818template <class _Tp>
2819_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_constructible_v
2820    = is_copy_constructible<_Tp>::value;
2821#endif
2822
2823// is_move_constructible
2824
2825template <class _Tp>
2826struct _LIBCPP_TEMPLATE_VIS is_move_constructible
2827    : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2828    {};
2829
2830#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2831template <class _Tp>
2832_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_constructible_v
2833    = is_move_constructible<_Tp>::value;
2834#endif
2835
2836// is_trivially_constructible
2837
2838#if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501
2839
2840template <class _Tp, class... _Args>
2841struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
2842    : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
2843{
2844};
2845
2846#else  // !__has_feature(is_trivially_constructible)
2847
2848template <class _Tp, class... _Args>
2849struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
2850    : false_type
2851{
2852};
2853
2854template <class _Tp>
2855struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp>
2856#if __has_feature(has_trivial_constructor) || defined(_LIBCPP_COMPILER_GCC)
2857    : integral_constant<bool, __has_trivial_constructor(_Tp)>
2858#else
2859    : integral_constant<bool, is_scalar<_Tp>::value>
2860#endif
2861{
2862};
2863
2864template <class _Tp>
2865struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&>
2866    : integral_constant<bool, is_scalar<_Tp>::value>
2867{
2868};
2869
2870template <class _Tp>
2871struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&>
2872    : integral_constant<bool, is_scalar<_Tp>::value>
2873{
2874};
2875
2876template <class _Tp>
2877struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&>
2878    : integral_constant<bool, is_scalar<_Tp>::value>
2879{
2880};
2881
2882#endif  // !__has_feature(is_trivially_constructible)
2883
2884
2885#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2886template <class _Tp, class... _Args>
2887_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_constructible_v
2888    = is_trivially_constructible<_Tp, _Args...>::value;
2889#endif
2890
2891// is_trivially_default_constructible
2892
2893template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
2894    : public is_trivially_constructible<_Tp>
2895    {};
2896
2897#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2898template <class _Tp>
2899_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v
2900    = is_trivially_default_constructible<_Tp>::value;
2901#endif
2902
2903// is_trivially_copy_constructible
2904
2905template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
2906    : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
2907    {};
2908
2909#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2910template <class _Tp>
2911_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v
2912    = is_trivially_copy_constructible<_Tp>::value;
2913#endif
2914
2915// is_trivially_move_constructible
2916
2917template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
2918    : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
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_move_constructible_v
2924    = is_trivially_move_constructible<_Tp>::value;
2925#endif
2926
2927// is_trivially_assignable
2928
2929#if __has_feature(is_trivially_assignable) || _GNUC_VER >= 501
2930
2931template <class _Tp, class _Arg>
2932struct is_trivially_assignable
2933    : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
2934{
2935};
2936
2937#else  // !__has_feature(is_trivially_assignable)
2938
2939template <class _Tp, class _Arg>
2940struct is_trivially_assignable
2941    : public false_type {};
2942
2943template <class _Tp>
2944struct is_trivially_assignable<_Tp&, _Tp>
2945    : integral_constant<bool, is_scalar<_Tp>::value> {};
2946
2947template <class _Tp>
2948struct is_trivially_assignable<_Tp&, _Tp&>
2949    : integral_constant<bool, is_scalar<_Tp>::value> {};
2950
2951template <class _Tp>
2952struct is_trivially_assignable<_Tp&, const _Tp&>
2953    : integral_constant<bool, is_scalar<_Tp>::value> {};
2954
2955template <class _Tp>
2956struct is_trivially_assignable<_Tp&, _Tp&&>
2957    : integral_constant<bool, is_scalar<_Tp>::value> {};
2958
2959#endif  // !__has_feature(is_trivially_assignable)
2960
2961#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2962template <class _Tp, class _Arg>
2963_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_assignable_v
2964    = is_trivially_assignable<_Tp, _Arg>::value;
2965#endif
2966
2967// is_trivially_copy_assignable
2968
2969template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
2970    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2971                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2972
2973#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2974template <class _Tp>
2975_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v
2976    = is_trivially_copy_assignable<_Tp>::value;
2977#endif
2978
2979// is_trivially_move_assignable
2980
2981template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
2982    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2983                                     typename add_rvalue_reference<_Tp>::type>
2984    {};
2985
2986#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2987template <class _Tp>
2988_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v
2989    = is_trivially_move_assignable<_Tp>::value;
2990#endif
2991
2992// is_trivially_destructible
2993
2994#if __has_keyword(__is_trivially_destructible)
2995
2996template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
2997    : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
2998
2999#elif __has_feature(has_trivial_destructor) || defined(_LIBCPP_COMPILER_GCC)
3000
3001template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3002    : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
3003
3004#else
3005
3006template <class _Tp> struct __libcpp_trivial_destructor
3007    : public integral_constant<bool, is_scalar<_Tp>::value ||
3008                                     is_reference<_Tp>::value> {};
3009
3010template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3011    : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
3012
3013template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]>
3014    : public false_type {};
3015
3016#endif
3017
3018#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3019template <class _Tp>
3020_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_destructible_v
3021    = is_trivially_destructible<_Tp>::value;
3022#endif
3023
3024// is_nothrow_constructible
3025
3026#if __has_keyword(__is_nothrow_constructible)
3027
3028template <class _Tp, class... _Args>
3029struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3030    : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
3031
3032#else
3033
3034template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
3035
3036template <class _Tp, class... _Args>
3037struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
3038    : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
3039{
3040};
3041
3042template <class _Tp>
3043void __implicit_conversion_to(_Tp) noexcept { }
3044
3045template <class _Tp, class _Arg>
3046struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
3047    : public integral_constant<bool, noexcept(__implicit_conversion_to<_Tp>(declval<_Arg>()))>
3048{
3049};
3050
3051template <class _Tp, bool _IsReference, class... _Args>
3052struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
3053    : public false_type
3054{
3055};
3056
3057template <class _Tp, class... _Args>
3058struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
3059    : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
3060{
3061};
3062
3063template <class _Tp, size_t _Ns>
3064struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
3065    : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
3066{
3067};
3068
3069#endif  // _LIBCPP_HAS_NO_NOEXCEPT
3070
3071
3072#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3073template <class _Tp, class ..._Args>
3074_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v
3075    = is_nothrow_constructible<_Tp, _Args...>::value;
3076#endif
3077
3078// is_nothrow_default_constructible
3079
3080template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
3081    : public is_nothrow_constructible<_Tp>
3082    {};
3083
3084#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3085template <class _Tp>
3086_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v
3087    = is_nothrow_default_constructible<_Tp>::value;
3088#endif
3089
3090// is_nothrow_copy_constructible
3091
3092template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
3093    : public is_nothrow_constructible<_Tp,
3094                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3095
3096#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3097template <class _Tp>
3098_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v
3099    = is_nothrow_copy_constructible<_Tp>::value;
3100#endif
3101
3102// is_nothrow_move_constructible
3103
3104template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
3105    : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
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_move_constructible_v
3111    = is_nothrow_move_constructible<_Tp>::value;
3112#endif
3113
3114// is_nothrow_assignable
3115
3116#if __has_keyword(__is_nothrow_assignable)
3117
3118template <class _Tp, class _Arg>
3119struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
3120    : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
3121
3122#else
3123
3124template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
3125
3126template <class _Tp, class _Arg>
3127struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
3128    : public false_type
3129{
3130};
3131
3132template <class _Tp, class _Arg>
3133struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
3134    : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>()) >
3135{
3136};
3137
3138template <class _Tp, class _Arg>
3139struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
3140    : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
3141{
3142};
3143
3144#endif  // _LIBCPP_HAS_NO_NOEXCEPT
3145
3146#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3147template <class _Tp, class _Arg>
3148_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v
3149    = is_nothrow_assignable<_Tp, _Arg>::value;
3150#endif
3151
3152// is_nothrow_copy_assignable
3153
3154template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
3155    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3156                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3157
3158#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3159template <class _Tp>
3160_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v
3161    = is_nothrow_copy_assignable<_Tp>::value;
3162#endif
3163
3164// is_nothrow_move_assignable
3165
3166template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
3167    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3168                                     typename add_rvalue_reference<_Tp>::type>
3169    {};
3170
3171#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3172template <class _Tp>
3173_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v
3174    = is_nothrow_move_assignable<_Tp>::value;
3175#endif
3176
3177// is_nothrow_destructible
3178
3179#if !defined(_LIBCPP_CXX03_LANG)
3180
3181template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
3182
3183template <class _Tp>
3184struct __libcpp_is_nothrow_destructible<false, _Tp>
3185    : public false_type
3186{
3187};
3188
3189template <class _Tp>
3190struct __libcpp_is_nothrow_destructible<true, _Tp>
3191    : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>().~_Tp()) >
3192{
3193};
3194
3195template <class _Tp>
3196struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
3197    : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
3198{
3199};
3200
3201template <class _Tp, size_t _Ns>
3202struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
3203    : public is_nothrow_destructible<_Tp>
3204{
3205};
3206
3207template <class _Tp>
3208struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
3209    : public true_type
3210{
3211};
3212
3213template <class _Tp>
3214struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
3215    : public true_type
3216{
3217};
3218
3219#else
3220
3221template <class _Tp> struct __libcpp_nothrow_destructor
3222    : public integral_constant<bool, is_scalar<_Tp>::value ||
3223                                     is_reference<_Tp>::value> {};
3224
3225template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
3226    : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
3227
3228template <class _Tp>
3229struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
3230    : public false_type {};
3231
3232#endif
3233
3234#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3235template <class _Tp>
3236_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v
3237    = is_nothrow_destructible<_Tp>::value;
3238#endif
3239
3240// is_pod
3241
3242#if __has_feature(is_pod) || defined(_LIBCPP_COMPILER_GCC)
3243
3244template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
3245    : public integral_constant<bool, __is_pod(_Tp)> {};
3246
3247#else
3248
3249template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
3250    : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
3251                                     is_trivially_copy_constructible<_Tp>::value      &&
3252                                     is_trivially_copy_assignable<_Tp>::value    &&
3253                                     is_trivially_destructible<_Tp>::value> {};
3254
3255#endif
3256
3257#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3258template <class _Tp>
3259_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pod_v
3260    = is_pod<_Tp>::value;
3261#endif
3262
3263// is_literal_type;
3264
3265template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_literal_type
3266    : public integral_constant<bool, __is_literal_type(_Tp)>
3267    {};
3268
3269#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3270template <class _Tp>
3271_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v
3272    = is_literal_type<_Tp>::value;
3273#endif
3274
3275// is_standard_layout;
3276
3277template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
3278#if __has_feature(is_standard_layout) || defined(_LIBCPP_COMPILER_GCC)
3279    : public integral_constant<bool, __is_standard_layout(_Tp)>
3280#else
3281    : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3282#endif
3283    {};
3284
3285#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3286template <class _Tp>
3287_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_standard_layout_v
3288    = is_standard_layout<_Tp>::value;
3289#endif
3290
3291// is_trivially_copyable;
3292
3293template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
3294#if __has_feature(is_trivially_copyable)
3295    : public integral_constant<bool, __is_trivially_copyable(_Tp)>
3296#elif _GNUC_VER >= 501
3297    : public integral_constant<bool, !is_volatile<_Tp>::value && __is_trivially_copyable(_Tp)>
3298#else
3299    : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3300#endif
3301    {};
3302
3303#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3304template <class _Tp>
3305_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copyable_v
3306    = is_trivially_copyable<_Tp>::value;
3307#endif
3308
3309// is_trivial;
3310
3311template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
3312#if __has_feature(is_trivial) || defined(_LIBCPP_COMPILER_GCC)
3313    : public integral_constant<bool, __is_trivial(_Tp)>
3314#else
3315    : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
3316                                 is_trivially_default_constructible<_Tp>::value>
3317#endif
3318    {};
3319
3320#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3321template <class _Tp>
3322_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivial_v
3323    = is_trivial<_Tp>::value;
3324#endif
3325
3326template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
3327template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
3328template <class _Tp> struct __is_reference_wrapper
3329    : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
3330
3331#ifndef _LIBCPP_CXX03_LANG
3332
3333template <class _Fp, class _A0,
3334         class _DecayFp = typename decay<_Fp>::type,
3335         class _DecayA0 = typename decay<_A0>::type,
3336         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3337using __enable_if_bullet1 = typename enable_if
3338    <
3339        is_member_function_pointer<_DecayFp>::value
3340        && is_base_of<_ClassT, _DecayA0>::value
3341    >::type;
3342
3343template <class _Fp, class _A0,
3344         class _DecayFp = typename decay<_Fp>::type,
3345         class _DecayA0 = typename decay<_A0>::type>
3346using __enable_if_bullet2 = typename enable_if
3347    <
3348        is_member_function_pointer<_DecayFp>::value
3349        && __is_reference_wrapper<_DecayA0>::value
3350    >::type;
3351
3352template <class _Fp, class _A0,
3353         class _DecayFp = typename decay<_Fp>::type,
3354         class _DecayA0 = typename decay<_A0>::type,
3355         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3356using __enable_if_bullet3 = typename enable_if
3357    <
3358        is_member_function_pointer<_DecayFp>::value
3359        && !is_base_of<_ClassT, _DecayA0>::value
3360        && !__is_reference_wrapper<_DecayA0>::value
3361    >::type;
3362
3363template <class _Fp, class _A0,
3364         class _DecayFp = typename decay<_Fp>::type,
3365         class _DecayA0 = typename decay<_A0>::type,
3366         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3367using __enable_if_bullet4 = typename enable_if
3368    <
3369        is_member_object_pointer<_DecayFp>::value
3370        && is_base_of<_ClassT, _DecayA0>::value
3371    >::type;
3372
3373template <class _Fp, class _A0,
3374         class _DecayFp = typename decay<_Fp>::type,
3375         class _DecayA0 = typename decay<_A0>::type>
3376using __enable_if_bullet5 = typename enable_if
3377    <
3378        is_member_object_pointer<_DecayFp>::value
3379        && __is_reference_wrapper<_DecayA0>::value
3380    >::type;
3381
3382template <class _Fp, class _A0,
3383         class _DecayFp = typename decay<_Fp>::type,
3384         class _DecayA0 = typename decay<_A0>::type,
3385         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3386using __enable_if_bullet6 = typename enable_if
3387    <
3388        is_member_object_pointer<_DecayFp>::value
3389        && !is_base_of<_ClassT, _DecayA0>::value
3390        && !__is_reference_wrapper<_DecayA0>::value
3391    >::type;
3392
3393// __invoke forward declarations
3394
3395// fall back - none of the bullets
3396
3397#define _LIBCPP_INVOKE_RETURN(...) \
3398    noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \
3399    { return __VA_ARGS__; }
3400
3401template <class ..._Args>
3402auto __invoke(__any, _Args&& ...__args) -> __nat;
3403
3404template <class ..._Args>
3405auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
3406
3407// bullets 1, 2 and 3
3408
3409template <class _Fp, class _A0, class ..._Args,
3410          class = __enable_if_bullet1<_Fp, _A0>>
3411inline _LIBCPP_INLINE_VISIBILITY
3412auto
3413__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3414_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
3415
3416template <class _Fp, class _A0, class ..._Args,
3417          class = __enable_if_bullet1<_Fp, _A0>>
3418inline _LIBCPP_INLINE_VISIBILITY
3419_LIBCPP_CONSTEXPR auto
3420__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3421_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
3422
3423template <class _Fp, class _A0, class ..._Args,
3424          class = __enable_if_bullet2<_Fp, _A0>>
3425inline _LIBCPP_INLINE_VISIBILITY
3426auto
3427__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3428_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...))
3429
3430template <class _Fp, class _A0, class ..._Args,
3431          class = __enable_if_bullet2<_Fp, _A0>>
3432inline _LIBCPP_INLINE_VISIBILITY
3433_LIBCPP_CONSTEXPR auto
3434__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3435_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...))
3436
3437template <class _Fp, class _A0, class ..._Args,
3438          class = __enable_if_bullet3<_Fp, _A0>>
3439inline _LIBCPP_INLINE_VISIBILITY
3440auto
3441__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3442_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
3443
3444template <class _Fp, class _A0, class ..._Args,
3445          class = __enable_if_bullet3<_Fp, _A0>>
3446inline _LIBCPP_INLINE_VISIBILITY
3447_LIBCPP_CONSTEXPR auto
3448__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3449_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
3450
3451// bullets 4, 5 and 6
3452
3453template <class _Fp, class _A0,
3454          class = __enable_if_bullet4<_Fp, _A0>>
3455inline _LIBCPP_INLINE_VISIBILITY
3456auto
3457__invoke(_Fp&& __f, _A0&& __a0)
3458_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f)
3459
3460template <class _Fp, class _A0,
3461          class = __enable_if_bullet4<_Fp, _A0>>
3462inline _LIBCPP_INLINE_VISIBILITY
3463_LIBCPP_CONSTEXPR auto
3464__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3465_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f)
3466
3467template <class _Fp, class _A0,
3468          class = __enable_if_bullet5<_Fp, _A0>>
3469inline _LIBCPP_INLINE_VISIBILITY
3470auto
3471__invoke(_Fp&& __f, _A0&& __a0)
3472_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
3473
3474template <class _Fp, class _A0,
3475          class = __enable_if_bullet5<_Fp, _A0>>
3476inline _LIBCPP_INLINE_VISIBILITY
3477_LIBCPP_CONSTEXPR auto
3478__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3479_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
3480
3481template <class _Fp, class _A0,
3482          class = __enable_if_bullet6<_Fp, _A0>>
3483inline _LIBCPP_INLINE_VISIBILITY
3484auto
3485__invoke(_Fp&& __f, _A0&& __a0)
3486_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f)
3487
3488template <class _Fp, class _A0,
3489          class = __enable_if_bullet6<_Fp, _A0>>
3490inline _LIBCPP_INLINE_VISIBILITY
3491_LIBCPP_CONSTEXPR auto
3492__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3493_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f)
3494
3495// bullet 7
3496
3497template <class _Fp, class ..._Args>
3498inline _LIBCPP_INLINE_VISIBILITY
3499auto
3500__invoke(_Fp&& __f, _Args&& ...__args)
3501_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
3502
3503template <class _Fp, class ..._Args>
3504inline _LIBCPP_INLINE_VISIBILITY
3505_LIBCPP_CONSTEXPR auto
3506__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
3507_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
3508
3509#undef _LIBCPP_INVOKE_RETURN
3510
3511// __invokable
3512template <class _Ret, class _Fp, class ..._Args>
3513struct __invokable_r
3514{
3515  template <class _XFp, class ..._XArgs>
3516  static auto __try_call(int) -> decltype(
3517    _VSTD::__invoke(_VSTD::declval<_XFp>(), _VSTD::declval<_XArgs>()...));
3518  template <class _XFp, class ..._XArgs>
3519  static __nat __try_call(...);
3520
3521  // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void,
3522  // or incomplete array types as required by the standard.
3523  using _Result = decltype(__try_call<_Fp, _Args...>(0));
3524
3525  using type =
3526  typename conditional<
3527      _IsNotSame<_Result, __nat>::value,
3528      typename conditional<
3529          is_void<_Ret>::value,
3530          true_type,
3531          is_convertible<_Result, _Ret>
3532      >::type,
3533      false_type
3534  >::type;
3535  static const bool value = type::value;
3536};
3537template <class _Fp, class ..._Args>
3538using __invokable = __invokable_r<void, _Fp, _Args...>;
3539
3540template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
3541struct __nothrow_invokable_r_imp {
3542  static const bool value = false;
3543};
3544
3545template <class _Ret, class _Fp, class ..._Args>
3546struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
3547{
3548    typedef __nothrow_invokable_r_imp _ThisT;
3549
3550    template <class _Tp>
3551    static void __test_noexcept(_Tp) noexcept;
3552
3553    static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
3554        _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)));
3555};
3556
3557template <class _Ret, class _Fp, class ..._Args>
3558struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
3559{
3560    static const bool value = noexcept(
3561        _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
3562};
3563
3564template <class _Ret, class _Fp, class ..._Args>
3565using __nothrow_invokable_r =
3566    __nothrow_invokable_r_imp<
3567            __invokable_r<_Ret, _Fp, _Args...>::value,
3568            is_void<_Ret>::value,
3569            _Ret, _Fp, _Args...
3570    >;
3571
3572template <class _Fp, class ..._Args>
3573using __nothrow_invokable =
3574    __nothrow_invokable_r_imp<
3575            __invokable<_Fp, _Args...>::value,
3576            true, void, _Fp, _Args...
3577    >;
3578
3579template <class _Fp, class ..._Args>
3580struct __invoke_of
3581    : public enable_if<
3582        __invokable<_Fp, _Args...>::value,
3583        typename __invokable_r<void, _Fp, _Args...>::_Result>
3584{
3585};
3586
3587// result_of
3588
3589template <class _Fp, class ..._Args>
3590class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)>
3591    : public __invoke_of<_Fp, _Args...>
3592{
3593};
3594
3595#if _LIBCPP_STD_VER > 11
3596template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
3597#endif
3598
3599#if _LIBCPP_STD_VER > 14
3600
3601// invoke_result
3602
3603template <class _Fn, class... _Args>
3604struct _LIBCPP_TEMPLATE_VIS invoke_result
3605    : __invoke_of<_Fn, _Args...>
3606{
3607};
3608
3609template <class _Fn, class... _Args>
3610using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
3611
3612// is_invocable
3613
3614template <class _Fn, class ..._Args>
3615struct _LIBCPP_TEMPLATE_VIS is_invocable
3616    : integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
3617
3618template <class _Ret, class _Fn, class ..._Args>
3619struct _LIBCPP_TEMPLATE_VIS is_invocable_r
3620    : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
3621
3622template <class _Fn, class ..._Args>
3623_LIBCPP_INLINE_VAR constexpr bool is_invocable_v
3624    = is_invocable<_Fn, _Args...>::value;
3625
3626template <class _Ret, class _Fn, class ..._Args>
3627_LIBCPP_INLINE_VAR constexpr bool is_invocable_r_v
3628    = is_invocable_r<_Ret, _Fn, _Args...>::value;
3629
3630// is_nothrow_invocable
3631
3632template <class _Fn, class ..._Args>
3633struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable
3634    : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {};
3635
3636template <class _Ret, class _Fn, class ..._Args>
3637struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
3638    : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
3639
3640template <class _Fn, class ..._Args>
3641_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_v
3642    = is_nothrow_invocable<_Fn, _Args...>::value;
3643
3644template <class _Ret, class _Fn, class ..._Args>
3645_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v
3646    = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
3647
3648#endif // _LIBCPP_STD_VER > 14
3649
3650#endif  // !defined(_LIBCPP_CXX03_LANG)
3651
3652template <class _Tp> struct __is_swappable;
3653template <class _Tp> struct __is_nothrow_swappable;
3654
3655// swap, swap_ranges
3656
3657template <class _ForwardIterator1, class _ForwardIterator2>
3658inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3659_ForwardIterator2
3660swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2);
3661
3662template <class _Tp>
3663inline _LIBCPP_INLINE_VISIBILITY
3664#ifndef _LIBCPP_CXX03_LANG
3665typename enable_if
3666<
3667    is_move_constructible<_Tp>::value &&
3668    is_move_assignable<_Tp>::value
3669>::type
3670#else
3671void
3672#endif
3673_LIBCPP_CONSTEXPR_AFTER_CXX17
3674swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
3675                                    is_nothrow_move_assignable<_Tp>::value)
3676{
3677    _Tp __t(_VSTD::move(__x));
3678    __x = _VSTD::move(__y);
3679    __y = _VSTD::move(__t);
3680}
3681
3682template<class _Tp, size_t _Np>
3683inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3684typename enable_if<
3685    __is_swappable<_Tp>::value
3686>::type
3687swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
3688{
3689    _VSTD::swap_ranges(__a, __a + _Np, __b);
3690}
3691
3692template <class _ForwardIterator1, class _ForwardIterator2>
3693inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3694_ForwardIterator2
3695swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
3696{
3697    for(; __first1 != __last1; ++__first1, (void) ++__first2)
3698        swap(*__first1, *__first2);
3699    return __first2;
3700}
3701
3702// iter_swap
3703
3704template <class _ForwardIterator1, class _ForwardIterator2>
3705inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3706void
3707iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
3708    //                                  _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
3709               _NOEXCEPT_(_NOEXCEPT_(swap(*_VSTD::declval<_ForwardIterator1>(),
3710                                          *_VSTD::declval<_ForwardIterator2>())))
3711{
3712    swap(*__a, *__b);
3713}
3714
3715// __swappable
3716
3717namespace __detail
3718{
3719// ALL generic swap overloads MUST already have a declaration available at this point.
3720
3721template <class _Tp, class _Up = _Tp,
3722          bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value>
3723struct __swappable_with
3724{
3725    template <class _LHS, class _RHS>
3726    static decltype(swap(_VSTD::declval<_LHS>(), _VSTD::declval<_RHS>()))
3727    __test_swap(int);
3728    template <class, class>
3729    static __nat __test_swap(long);
3730
3731    // Extra parens are needed for the C++03 definition of decltype.
3732    typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1;
3733    typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2;
3734
3735    static const bool value = _IsNotSame<__swap1, __nat>::value
3736                           && _IsNotSame<__swap2, __nat>::value;
3737};
3738
3739template <class _Tp, class _Up>
3740struct __swappable_with<_Tp, _Up,  false> : false_type {};
3741
3742template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value>
3743struct __nothrow_swappable_with {
3744  static const bool value =
3745#ifndef _LIBCPP_HAS_NO_NOEXCEPT
3746      noexcept(swap(_VSTD::declval<_Tp>(), _VSTD::declval<_Up>()))
3747  &&  noexcept(swap(_VSTD::declval<_Up>(), _VSTD::declval<_Tp>()));
3748#else
3749      false;
3750#endif
3751};
3752
3753template <class _Tp, class _Up>
3754struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
3755
3756}  // __detail
3757
3758template <class _Tp>
3759struct __is_swappable
3760    : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value>
3761{
3762};
3763
3764template <class _Tp>
3765struct __is_nothrow_swappable
3766    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value>
3767{
3768};
3769
3770#if _LIBCPP_STD_VER > 14
3771
3772template <class _Tp, class _Up>
3773struct _LIBCPP_TEMPLATE_VIS is_swappable_with
3774    : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value>
3775{
3776};
3777
3778template <class _Tp>
3779struct _LIBCPP_TEMPLATE_VIS is_swappable
3780    : public conditional<
3781        __is_referenceable<_Tp>::value,
3782        is_swappable_with<
3783            typename add_lvalue_reference<_Tp>::type,
3784            typename add_lvalue_reference<_Tp>::type>,
3785        false_type
3786    >::type
3787{
3788};
3789
3790template <class _Tp, class _Up>
3791struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with
3792    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value>
3793{
3794};
3795
3796template <class _Tp>
3797struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable
3798    : public conditional<
3799        __is_referenceable<_Tp>::value,
3800        is_nothrow_swappable_with<
3801            typename add_lvalue_reference<_Tp>::type,
3802            typename add_lvalue_reference<_Tp>::type>,
3803        false_type
3804    >::type
3805{
3806};
3807
3808template <class _Tp, class _Up>
3809_LIBCPP_INLINE_VAR constexpr bool is_swappable_with_v
3810    = is_swappable_with<_Tp, _Up>::value;
3811
3812template <class _Tp>
3813_LIBCPP_INLINE_VAR constexpr bool is_swappable_v
3814    = is_swappable<_Tp>::value;
3815
3816template <class _Tp, class _Up>
3817_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_with_v
3818    = is_nothrow_swappable_with<_Tp, _Up>::value;
3819
3820template <class _Tp>
3821_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_v
3822    = is_nothrow_swappable<_Tp>::value;
3823
3824#endif // _LIBCPP_STD_VER > 14
3825
3826template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl;
3827
3828template <class _Tp>
3829struct __underlying_type_impl<_Tp, false> {};
3830
3831template <class _Tp>
3832struct __underlying_type_impl<_Tp, true>
3833{
3834    typedef __underlying_type(_Tp) type;
3835};
3836
3837template <class _Tp>
3838struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
3839
3840#if _LIBCPP_STD_VER > 11
3841template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
3842#endif
3843
3844
3845template <class _Tp, bool = is_enum<_Tp>::value>
3846struct __sfinae_underlying_type
3847{
3848    typedef typename underlying_type<_Tp>::type type;
3849    typedef decltype(((type)1) + 0) __promoted_type;
3850};
3851
3852template <class _Tp>
3853struct __sfinae_underlying_type<_Tp, false> {};
3854
3855inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3856int __convert_to_integral(int __val) { return __val; }
3857
3858inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3859unsigned __convert_to_integral(unsigned __val) { return __val; }
3860
3861inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3862long __convert_to_integral(long __val) { return __val; }
3863
3864inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3865unsigned long __convert_to_integral(unsigned long __val) { return __val; }
3866
3867inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3868long long __convert_to_integral(long long __val) { return __val; }
3869
3870inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3871unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
3872
3873template<typename _Fp>
3874inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3875typename enable_if<is_floating_point<_Fp>::value, long long>::type
3876 __convert_to_integral(_Fp __val) { return __val; }
3877
3878#ifndef _LIBCPP_HAS_NO_INT128
3879inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3880__int128_t __convert_to_integral(__int128_t __val) { return __val; }
3881
3882inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3883__uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
3884#endif
3885
3886template <class _Tp>
3887inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3888typename __sfinae_underlying_type<_Tp>::__promoted_type
3889__convert_to_integral(_Tp __val) { return __val; }
3890
3891#ifndef _LIBCPP_CXX03_LANG
3892
3893template <class _Tp>
3894struct __has_operator_addressof_member_imp
3895{
3896    template <class _Up>
3897        static auto __test(int)
3898            -> typename __select_2nd<decltype(_VSTD::declval<_Up>().operator&()), true_type>::type;
3899    template <class>
3900        static auto __test(long) -> false_type;
3901
3902    static const bool value = decltype(__test<_Tp>(0))::value;
3903};
3904
3905template <class _Tp>
3906struct __has_operator_addressof_free_imp
3907{
3908    template <class _Up>
3909        static auto __test(int)
3910            -> typename __select_2nd<decltype(operator&(_VSTD::declval<_Up>())), true_type>::type;
3911    template <class>
3912        static auto __test(long) -> false_type;
3913
3914    static const bool value = decltype(__test<_Tp>(0))::value;
3915};
3916
3917template <class _Tp>
3918struct __has_operator_addressof
3919    : public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
3920                                  || __has_operator_addressof_free_imp<_Tp>::value>
3921{};
3922
3923#endif  // _LIBCPP_CXX03_LANG
3924
3925#if _LIBCPP_STD_VER > 14
3926
3927template <class...> using void_t = void;
3928
3929template <class... _Args>
3930struct conjunction : _And<_Args...> {};
3931template<class... _Args>
3932_LIBCPP_INLINE_VAR constexpr bool conjunction_v
3933    = conjunction<_Args...>::value;
3934
3935template <class... _Args>
3936struct disjunction : _Or<_Args...> {};
3937template<class... _Args>
3938_LIBCPP_INLINE_VAR constexpr bool disjunction_v
3939    = disjunction<_Args...>::value;
3940
3941template <class _Tp>
3942struct negation : _Not<_Tp> {};
3943template<class _Tp>
3944_LIBCPP_INLINE_VAR constexpr bool negation_v
3945    = negation<_Tp>::value;
3946#endif  // _LIBCPP_STD_VER > 14
3947
3948// These traits are used in __tree and __hash_table
3949#ifndef _LIBCPP_CXX03_LANG
3950struct __extract_key_fail_tag {};
3951struct __extract_key_self_tag {};
3952struct __extract_key_first_tag {};
3953
3954template <class _ValTy, class _Key,
3955          class _RawValTy = typename __unconstref<_ValTy>::type>
3956struct __can_extract_key
3957    : conditional<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag,
3958                  __extract_key_fail_tag>::type {};
3959
3960template <class _Pair, class _Key, class _First, class _Second>
3961struct __can_extract_key<_Pair, _Key, pair<_First, _Second>>
3962    : conditional<_IsSame<typename remove_const<_First>::type, _Key>::value,
3963                  __extract_key_first_tag, __extract_key_fail_tag>::type {};
3964
3965// __can_extract_map_key uses true_type/false_type instead of the tags.
3966// It returns true if _Key != _ContainerValueTy (the container is a map not a set)
3967// and _ValTy == _Key.
3968template <class _ValTy, class _Key, class _ContainerValueTy,
3969          class _RawValTy = typename __unconstref<_ValTy>::type>
3970struct __can_extract_map_key
3971    : integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {};
3972
3973// This specialization returns __extract_key_fail_tag for non-map containers
3974// because _Key == _ContainerValueTy
3975template <class _ValTy, class _Key, class _RawValTy>
3976struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
3977    : false_type {};
3978
3979#endif
3980
3981#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
3982#if _LIBCPP_STD_VER > 17
3983_LIBCPP_INLINE_VISIBILITY
3984inline constexpr bool is_constant_evaluated() noexcept {
3985  return __builtin_is_constant_evaluated();
3986}
3987#endif
3988
3989inline _LIBCPP_CONSTEXPR
3990bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); }
3991#else
3992inline _LIBCPP_CONSTEXPR
3993bool __libcpp_is_constant_evaluated() _NOEXCEPT { return false; }
3994#endif
3995
3996template <class _CharT>
3997using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
3998
3999_LIBCPP_END_NAMESPACE_STD
4000
4001#if _LIBCPP_STD_VER > 14
4002// std::byte
4003namespace std  // purposefully not versioned
4004{
4005template <class _Integer>
4006  constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
4007  operator<<=(byte& __lhs, _Integer __shift) noexcept
4008  { return __lhs = __lhs << __shift; }
4009
4010template <class _Integer>
4011  constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
4012  operator<< (byte  __lhs, _Integer __shift) noexcept
4013  { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); }
4014
4015template <class _Integer>
4016  constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
4017  operator>>=(byte& __lhs, _Integer __shift) noexcept
4018  { return __lhs = __lhs >> __shift; }
4019
4020template <class _Integer>
4021  constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
4022  operator>> (byte  __lhs, _Integer __shift) noexcept
4023  { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
4024
4025template <class _Integer>
4026  constexpr typename enable_if<is_integral_v<_Integer>, _Integer>::type
4027  to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
4028
4029}
4030#endif
4031
4032#endif  // _LIBCPP_TYPE_TRAITS
4033