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