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