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