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