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