]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libc++/include/type_traits
MFC r276517:
[FreeBSD/stable/10.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;
23     typedef integral_constant<bool, false> false_type;
24
25     // helper traits
26     template <bool, class T = void> struct enable_if;
27     template <bool, class T, class F> struct conditional;
28
29     // Primary classification traits:
30     template <class T> struct is_void;
31     template <class T> struct is_null_pointer;  // C++14
32     template <class T> struct is_integral;
33     template <class T> struct is_floating_point;
34     template <class T> struct is_array;
35     template <class T> struct is_pointer;
36     template <class T> struct is_lvalue_reference;
37     template <class T> struct is_rvalue_reference;
38     template <class T> struct is_member_object_pointer;
39     template <class T> struct is_member_function_pointer;
40     template <class T> struct is_enum;
41     template <class T> struct is_union;
42     template <class T> struct is_class;
43     template <class T> struct is_function;
44
45     // Secondary classification traits:
46     template <class T> struct is_reference;
47     template <class T> struct is_arithmetic;
48     template <class T> struct is_fundamental;
49     template <class T> struct is_member_pointer;
50     template <class T> struct is_scalar;
51     template <class T> struct is_object;
52     template <class T> struct is_compound;
53
54     // Const-volatile properties and transformations:
55     template <class T> struct is_const;
56     template <class T> struct is_volatile;
57     template <class T> struct remove_const;
58     template <class T> struct remove_volatile;
59     template <class T> struct remove_cv;
60     template <class T> struct add_const;
61     template <class T> struct add_volatile;
62     template <class T> struct add_cv;
63
64     // Reference transformations:
65     template <class T> struct remove_reference;
66     template <class T> struct add_lvalue_reference;
67     template <class T> struct add_rvalue_reference;
68
69     // Pointer transformations:
70     template <class T> struct remove_pointer;
71     template <class T> struct add_pointer;
72
73     // Integral properties:
74     template <class T> struct is_signed;
75     template <class T> struct is_unsigned;
76     template <class T> struct make_signed;
77     template <class T> struct make_unsigned;
78
79     // Array properties and transformations:
80     template <class T> struct rank;
81     template <class T, unsigned I = 0> struct extent;
82     template <class T> struct remove_extent;
83     template <class T> struct remove_all_extents;
84
85     // Member introspection:
86     template <class T> struct is_pod;
87     template <class T> struct is_trivial;
88     template <class T> struct is_trivially_copyable;
89     template <class T> struct is_standard_layout;
90     template <class T> struct is_literal_type;
91     template <class T> struct is_empty;
92     template <class T> struct is_polymorphic;
93     template <class T> struct is_abstract;
94
95     template <class T, class... Args> struct is_constructible;
96     template <class T>                struct is_default_constructible;
97     template <class T>                struct is_copy_constructible;
98     template <class T>                struct is_move_constructible;
99     template <class T, class U>       struct is_assignable;
100     template <class T>                struct is_copy_assignable;
101     template <class T>                struct is_move_assignable;
102     template <class T>                struct is_destructible;
103
104     template <class T, class... Args> struct is_trivially_constructible;
105     template <class T>                struct is_trivially_default_constructible;
106     template <class T>                struct is_trivially_copy_constructible;
107     template <class T>                struct is_trivially_move_constructible;
108     template <class T, class U>       struct is_trivially_assignable;
109     template <class T>                struct is_trivially_copy_assignable;
110     template <class T>                struct is_trivially_move_assignable;
111     template <class T>                struct is_trivially_destructible;
112
113     template <class T, class... Args> struct is_nothrow_constructible;
114     template <class T>                struct is_nothrow_default_constructible;
115     template <class T>                struct is_nothrow_copy_constructible;
116     template <class T>                struct is_nothrow_move_constructible;
117     template <class T, class U>       struct is_nothrow_assignable;
118     template <class T>                struct is_nothrow_copy_assignable;
119     template <class T>                struct is_nothrow_move_assignable;
120     template <class T>                struct is_nothrow_destructible;
121
122     template <class T> struct has_virtual_destructor;
123
124     // Relationships between types:
125     template <class T, class U> struct is_same;
126     template <class Base, class Derived> struct is_base_of;
127     template <class From, class To> struct is_convertible;
128
129     // Alignment properties and transformations:
130     template <class T> struct alignment_of;
131     template <size_t Len, size_t Align = most_stringent_alignment_requirement>
132         struct aligned_storage;
133     template <size_t Len, class... Types> struct aligned_union;
134
135     template <class T> struct decay;
136     template <class... T> struct common_type;
137     template <class T> struct underlying_type;
138     template <class> class result_of; // undefined
139     template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
140
141     // const-volatile modifications:
142     template <class T>
143       using remove_const_t    = typename remove_const<T>::type;  // C++14
144     template <class T>
145       using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
146     template <class T>
147       using remove_cv_t       = typename remove_cv<T>::type;  // C++14
148     template <class T>
149       using add_const_t       = typename add_const<T>::type;  // C++14
150     template <class T>
151       using add_volatile_t    = typename add_volatile<T>::type;  // C++14
152     template <class T>
153       using add_cv_t          = typename add_cv<T>::type;  // C++14
154   
155     // reference modifications:
156     template <class T>
157       using remove_reference_t     = typename remove_reference<T>::type;  // C++14
158     template <class T>
159       using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
160     template <class T>
161       using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
162   
163     // sign modifications:
164     template <class T>
165       using make_signed_t   = typename make_signed<T>::type;  // C++14
166     template <class T>
167       using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
168   
169     // array modifications:
170     template <class T>
171       using remove_extent_t      = typename remove_extent<T>::type;  // C++14
172     template <class T>
173       using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
174
175     // pointer modifications:
176     template <class T>
177       using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
178     template <class T>
179       using add_pointer_t    = typename add_pointer<T>::type;  // C++14
180
181     // other transformations:
182     template <size_t Len, std::size_t Align=default-alignment>
183       using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
184     template <std::size_t Len, class... Types>
185       using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
186     template <class T>
187       using decay_t           = typename decay<T>::type;  // C++14
188     template <bool b, class T=void>
189       using enable_if_t       = typename enable_if<b,T>::type;  // C++14
190     template <bool b, class T, class F>
191       using conditional_t     = typename conditional<b,T,F>::type;  // C++14
192     template <class... T>
193       using common_type_t     = typename common_type<T...>::type;  // C++14
194     template <class T>
195       using underlying_type_t = typename underlying_type<T>::type;  // C++14
196     template <class F, class... ArgTypes>
197       using result_of_t       = typename result_of<F(ArgTypes...)>::type;  // C++14
198
199 }  // std
200
201 */
202 #include <__config>
203 #include <cstddef>
204
205 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
206 #pragma GCC system_header
207 #endif
208
209 _LIBCPP_BEGIN_NAMESPACE_STD
210
211 template <bool _Bp, class _If, class _Then>
212     struct _LIBCPP_TYPE_VIS_ONLY conditional {typedef _If type;};
213 template <class _If, class _Then>
214     struct _LIBCPP_TYPE_VIS_ONLY conditional<false, _If, _Then> {typedef _Then type;};
215
216 #if _LIBCPP_STD_VER > 11
217 template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
218 #endif
219
220 template <bool, class _Tp = void> struct _LIBCPP_TYPE_VIS_ONLY enable_if {};
221 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY enable_if<true, _Tp> {typedef _Tp type;};
222
223 #if _LIBCPP_STD_VER > 11
224 template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
225 #endif
226
227
228 struct __two {char __lx[2];};
229
230 // helper class:
231
232 template <class _Tp, _Tp __v>
233 struct _LIBCPP_TYPE_VIS_ONLY integral_constant
234 {
235     static _LIBCPP_CONSTEXPR const _Tp      value = __v;
236     typedef _Tp               value_type;
237     typedef integral_constant type;
238     _LIBCPP_INLINE_VISIBILITY
239         _LIBCPP_CONSTEXPR operator value_type() const {return value;}
240 #if _LIBCPP_STD_VER > 11
241     _LIBCPP_INLINE_VISIBILITY
242          constexpr value_type operator ()() const {return value;}
243 #endif
244 };
245
246 template <class _Tp, _Tp __v>
247 _LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
248
249 typedef integral_constant<bool, true>  true_type;
250 typedef integral_constant<bool, false> false_type;
251
252 // is_const
253
254 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_const            : public false_type {};
255 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_const<_Tp const> : public true_type {};
256
257 // is_volatile
258
259 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_volatile               : public false_type {};
260 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_volatile<_Tp volatile> : public true_type {};
261
262 // remove_const
263
264 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_const            {typedef _Tp type;};
265 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_const<const _Tp> {typedef _Tp type;};
266 #if _LIBCPP_STD_VER > 11
267 template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
268 #endif
269
270 // remove_volatile
271
272 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_volatile               {typedef _Tp type;};
273 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_volatile<volatile _Tp> {typedef _Tp type;};
274 #if _LIBCPP_STD_VER > 11
275 template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
276 #endif
277
278 // remove_cv
279
280 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_cv
281 {typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
282 #if _LIBCPP_STD_VER > 11
283 template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
284 #endif
285
286 // is_void
287
288 template <class _Tp> struct __libcpp_is_void       : public false_type {};
289 template <>          struct __libcpp_is_void<void> : public true_type {};
290
291 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_void
292     : public __libcpp_is_void<typename remove_cv<_Tp>::type> {};
293
294 // __is_nullptr_t
295
296 template <class _Tp> struct __libcpp___is_nullptr       : public false_type {};
297 template <>          struct __libcpp___is_nullptr<nullptr_t> : public true_type {};
298
299 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY __is_nullptr_t
300     : public __libcpp___is_nullptr<typename remove_cv<_Tp>::type> {};
301
302 #if _LIBCPP_STD_VER > 11
303 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_null_pointer
304     : public __libcpp___is_nullptr<typename remove_cv<_Tp>::type> {};
305 #endif
306
307 // is_integral
308
309 template <class _Tp> struct __libcpp_is_integral                     : public false_type {};
310 template <>          struct __libcpp_is_integral<bool>               : public true_type {};
311 template <>          struct __libcpp_is_integral<char>               : public true_type {};
312 template <>          struct __libcpp_is_integral<signed char>        : public true_type {};
313 template <>          struct __libcpp_is_integral<unsigned char>      : public true_type {};
314 template <>          struct __libcpp_is_integral<wchar_t>            : public true_type {};
315 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
316 template <>          struct __libcpp_is_integral<char16_t>           : public true_type {};
317 template <>          struct __libcpp_is_integral<char32_t>           : public true_type {};
318 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
319 template <>          struct __libcpp_is_integral<short>              : public true_type {};
320 template <>          struct __libcpp_is_integral<unsigned short>     : public true_type {};
321 template <>          struct __libcpp_is_integral<int>                : public true_type {};
322 template <>          struct __libcpp_is_integral<unsigned int>       : public true_type {};
323 template <>          struct __libcpp_is_integral<long>               : public true_type {};
324 template <>          struct __libcpp_is_integral<unsigned long>      : public true_type {};
325 template <>          struct __libcpp_is_integral<long long>          : public true_type {};
326 template <>          struct __libcpp_is_integral<unsigned long long> : public true_type {};
327
328 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_integral
329     : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
330
331 // is_floating_point
332
333 template <class _Tp> struct __libcpp_is_floating_point              : public false_type {};
334 template <>          struct __libcpp_is_floating_point<float>       : public true_type {};
335 template <>          struct __libcpp_is_floating_point<double>      : public true_type {};
336 template <>          struct __libcpp_is_floating_point<long double> : public true_type {};
337
338 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_floating_point
339     : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
340
341 // is_array
342
343 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_array
344     : public false_type {};
345 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_array<_Tp[]>
346     : public true_type {};
347 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY is_array<_Tp[_Np]>
348     : public true_type {};
349
350 // is_pointer
351
352 template <class _Tp> struct __libcpp_is_pointer       : public false_type {};
353 template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
354
355 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pointer
356     : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> {};
357
358 // is_reference
359
360 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_lvalue_reference       : public false_type {};
361 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_lvalue_reference<_Tp&> : public true_type {};
362
363 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_rvalue_reference        : public false_type {};
364 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
365 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_rvalue_reference<_Tp&&> : public true_type {};
366 #endif
367
368 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference        : public false_type {};
369 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&>  : public true_type {};
370 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
371 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&&> : public true_type {};
372 #endif
373
374 #if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
375 #define _LIBCPP_HAS_TYPE_TRAITS
376 #endif
377
378 // is_union
379
380 #if __has_feature(is_union) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
381
382 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_union
383     : public integral_constant<bool, __is_union(_Tp)> {};
384
385 #else
386
387 template <class _Tp> struct __libcpp_union : public false_type {};
388 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_union
389     : public __libcpp_union<typename remove_cv<_Tp>::type> {};
390
391 #endif
392
393 // is_class
394
395 #if __has_feature(is_class) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
396
397 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_class
398     : public integral_constant<bool, __is_class(_Tp)> {};
399
400 #else
401
402 namespace __is_class_imp
403 {
404 template <class _Tp> char  __test(int _Tp::*);
405 template <class _Tp> __two __test(...);
406 }
407
408 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_class
409     : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
410
411 #endif
412
413 // is_same
414
415 template <class _Tp, class _Up> struct _LIBCPP_TYPE_VIS_ONLY is_same           : public false_type {};
416 template <class _Tp>            struct _LIBCPP_TYPE_VIS_ONLY is_same<_Tp, _Tp> : public true_type {};
417
418 // is_function
419
420 namespace __is_function_imp
421 {
422 template <class _Tp> char  __test(_Tp*);
423 template <class _Tp> __two __test(...);
424 template <class _Tp> _Tp&  __source();
425 }
426
427 template <class _Tp, bool = is_class<_Tp>::value ||
428                             is_union<_Tp>::value ||
429                             is_void<_Tp>::value  ||
430                             is_reference<_Tp>::value ||
431                             __is_nullptr_t<_Tp>::value >
432 struct __libcpp_is_function
433     : public integral_constant<bool, sizeof(__is_function_imp::__test<_Tp>(__is_function_imp::__source<_Tp>())) == 1>
434     {};
435 template <class _Tp> struct __libcpp_is_function<_Tp, true> : public false_type {};
436
437 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_function
438     : public __libcpp_is_function<_Tp> {};
439
440 // is_member_function_pointer
441
442 // template <class _Tp> struct            __libcpp_is_member_function_pointer             : public false_type {};
443 // template <class _Tp, class _Up> struct __libcpp_is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
444 // 
445
446 template <class _MP, bool _IsMemberFuctionPtr, bool _IsMemberObjectPtr>
447 struct __member_pointer_traits_imp
448 {  // forward declaration; specializations later
449 };
450
451
452 namespace __libcpp_is_member_function_pointer_imp {
453         template <typename _Tp>
454         char __test(typename std::__member_pointer_traits_imp<_Tp, true, false>::_FnType *);
455
456         template <typename>
457         std::__two __test(...);
458 };
459         
460 template <class _Tp> struct __libcpp_is_member_function_pointer
461     : public integral_constant<bool, sizeof(__libcpp_is_member_function_pointer_imp::__test<_Tp>(nullptr)) == 1> {};
462
463 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_function_pointer
464     : public __libcpp_is_member_function_pointer<typename remove_cv<_Tp>::type> {};
465
466 // is_member_pointer
467
468 template <class _Tp>            struct __libcpp_is_member_pointer             : public false_type {};
469 template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> : public true_type {};
470
471 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_pointer
472     : public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {};
473
474 // is_member_object_pointer
475
476 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_object_pointer
477     : public integral_constant<bool, is_member_pointer<_Tp>::value &&
478                                     !is_member_function_pointer<_Tp>::value> {};
479
480 // is_enum
481
482 #if __has_feature(is_enum) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
483
484 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_enum
485     : public integral_constant<bool, __is_enum(_Tp)> {};
486
487 #else
488
489 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_enum
490     : public integral_constant<bool, !is_void<_Tp>::value             &&
491                                      !is_integral<_Tp>::value         &&
492                                      !is_floating_point<_Tp>::value   &&
493                                      !is_array<_Tp>::value            &&
494                                      !is_pointer<_Tp>::value          &&
495                                      !is_reference<_Tp>::value        &&
496                                      !is_member_pointer<_Tp>::value   &&
497                                      !is_union<_Tp>::value            &&
498                                      !is_class<_Tp>::value            &&
499                                      !is_function<_Tp>::value         > {};
500
501 #endif
502
503 // is_arithmetic
504
505 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_arithmetic
506     : public integral_constant<bool, is_integral<_Tp>::value      ||
507                                      is_floating_point<_Tp>::value> {};
508
509 // is_fundamental
510
511 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_fundamental
512     : public integral_constant<bool, is_void<_Tp>::value        ||
513                                      __is_nullptr_t<_Tp>::value ||
514                                      is_arithmetic<_Tp>::value> {};
515
516 // is_scalar
517
518 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_scalar
519     : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
520                                      is_member_pointer<_Tp>::value ||
521                                      is_pointer<_Tp>::value        ||
522                                      __is_nullptr_t<_Tp>::value    ||
523                                      is_enum<_Tp>::value           > {};
524
525 template <> struct _LIBCPP_TYPE_VIS_ONLY is_scalar<nullptr_t> : public true_type {};
526
527 // is_object
528
529 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_object
530     : public integral_constant<bool, is_scalar<_Tp>::value ||
531                                      is_array<_Tp>::value  ||
532                                      is_union<_Tp>::value  ||
533                                      is_class<_Tp>::value  > {};
534
535 // is_compound
536
537 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_compound
538     : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
539
540 // add_const
541
542 template <class _Tp, bool = is_reference<_Tp>::value ||
543                             is_function<_Tp>::value  ||
544                             is_const<_Tp>::value     >
545 struct __add_const             {typedef _Tp type;};
546
547 template <class _Tp>
548 struct __add_const<_Tp, false> {typedef const _Tp type;};
549
550 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_const
551     {typedef typename __add_const<_Tp>::type type;};
552
553 #if _LIBCPP_STD_VER > 11
554 template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
555 #endif
556
557 // add_volatile
558
559 template <class _Tp, bool = is_reference<_Tp>::value ||
560                             is_function<_Tp>::value  ||
561                             is_volatile<_Tp>::value  >
562 struct __add_volatile             {typedef _Tp type;};
563
564 template <class _Tp>
565 struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
566
567 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_volatile
568     {typedef typename __add_volatile<_Tp>::type type;};
569
570 #if _LIBCPP_STD_VER > 11
571 template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
572 #endif
573
574 // add_cv
575
576 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_cv
577     {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;};
578
579 #if _LIBCPP_STD_VER > 11
580 template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
581 #endif
582
583 // remove_reference
584
585 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference        {typedef _Tp type;};
586 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference<_Tp&>  {typedef _Tp type;};
587 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
588 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference<_Tp&&> {typedef _Tp type;};
589 #endif
590
591 #if _LIBCPP_STD_VER > 11
592 template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
593 #endif
594
595 // add_lvalue_reference
596
597 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference                      {typedef _Tp& type;};
598 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
599 template <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<void>                {typedef void type;};
600 template <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<const void>          {typedef const void type;};
601 template <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<volatile void>       {typedef volatile void type;};
602 template <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<const volatile void> {typedef const volatile void type;};
603
604 #if _LIBCPP_STD_VER > 11
605 template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
606 #endif
607
608 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
609
610 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY  add_rvalue_reference                     {typedef _Tp&& type;};
611 template <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<void>                {typedef void type;};
612 template <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<const void>          {typedef const void type;};
613 template <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<volatile void>       {typedef volatile void type;};
614 template <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<const volatile void> {typedef const volatile void type;};
615
616 #if _LIBCPP_STD_VER > 11
617 template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
618 #endif
619
620 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
621
622 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
623
624 template <class _Tp>
625 typename add_rvalue_reference<_Tp>::type
626 declval() _NOEXCEPT;
627
628 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
629
630 template <class _Tp>
631 typename add_lvalue_reference<_Tp>::type
632 declval();
633
634 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
635
636 struct __any
637 {
638     __any(...);
639 };
640
641 // remove_pointer
642
643 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer                      {typedef _Tp type;};
644 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp*>                {typedef _Tp type;};
645 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* const>          {typedef _Tp type;};
646 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* volatile>       {typedef _Tp type;};
647 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* const volatile> {typedef _Tp type;};
648
649 #if _LIBCPP_STD_VER > 11
650 template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
651 #endif
652
653 // add_pointer
654
655 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_pointer
656     {typedef typename remove_reference<_Tp>::type* type;};
657
658 #if _LIBCPP_STD_VER > 11
659 template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
660 #endif
661
662 // is_signed
663
664 template <class _Tp, bool = is_integral<_Tp>::value>
665 struct ___is_signed : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};
666
667 template <class _Tp>
668 struct ___is_signed<_Tp, false> : public true_type {};  // floating point
669
670 template <class _Tp, bool = is_arithmetic<_Tp>::value>
671 struct __libcpp_is_signed : public ___is_signed<_Tp> {};
672
673 template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
674
675 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_signed : public __libcpp_is_signed<_Tp> {};
676
677 // is_unsigned
678
679 template <class _Tp, bool = is_integral<_Tp>::value>
680 struct ___is_unsigned : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};
681
682 template <class _Tp>
683 struct ___is_unsigned<_Tp, false> : public false_type {};  // floating point
684
685 template <class _Tp, bool = is_arithmetic<_Tp>::value>
686 struct __libcpp_is_unsigned : public ___is_unsigned<_Tp> {};
687
688 template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
689
690 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_unsigned : public __libcpp_is_unsigned<_Tp> {};
691
692 // rank
693
694 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY rank
695     : public integral_constant<size_t, 0> {};
696 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[]>
697     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
698 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[_Np]>
699     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
700
701 // extent
702
703 template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TYPE_VIS_ONLY extent
704     : public integral_constant<size_t, 0> {};
705 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[], 0>
706     : public integral_constant<size_t, 0> {};
707 template <class _Tp, unsigned _Ip> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[], _Ip>
708     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
709 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], 0>
710     : public integral_constant<size_t, _Np> {};
711 template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], _Ip>
712     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
713
714 // remove_extent
715
716 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_extent
717     {typedef _Tp type;};
718 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_extent<_Tp[]>
719     {typedef _Tp type;};
720 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY remove_extent<_Tp[_Np]>
721     {typedef _Tp type;};
722
723 #if _LIBCPP_STD_VER > 11
724 template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
725 #endif
726
727 // remove_all_extents
728
729 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents
730     {typedef _Tp type;};
731 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents<_Tp[]>
732     {typedef typename remove_all_extents<_Tp>::type type;};
733 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents<_Tp[_Np]>
734     {typedef typename remove_all_extents<_Tp>::type type;};
735
736 #if _LIBCPP_STD_VER > 11
737 template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
738 #endif
739
740 // decay
741
742 template <class _Tp>
743 struct _LIBCPP_TYPE_VIS_ONLY decay
744 {
745 private:
746     typedef typename remove_reference<_Tp>::type _Up;
747 public:
748     typedef typename conditional
749                      <
750                          is_array<_Up>::value,
751                          typename remove_extent<_Up>::type*,
752                          typename conditional
753                          <
754                               is_function<_Up>::value,
755                               typename add_pointer<_Up>::type,
756                               typename remove_cv<_Up>::type
757                          >::type
758                      >::type type;
759 };
760
761 #if _LIBCPP_STD_VER > 11
762 template <class _Tp> using decay_t = typename decay<_Tp>::type;
763 #endif
764
765 // is_abstract
766
767 namespace __is_abstract_imp
768 {
769 template <class _Tp> char  __test(_Tp (*)[1]);
770 template <class _Tp> __two __test(...);
771 }
772
773 template <class _Tp, bool = is_class<_Tp>::value>
774 struct __libcpp_abstract : public integral_constant<bool, sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
775
776 template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {};
777
778 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_abstract : public __libcpp_abstract<_Tp> {};
779
780 // is_base_of
781
782 #ifdef _LIBCPP_HAS_IS_BASE_OF
783
784 template <class _Bp, class _Dp>
785 struct _LIBCPP_TYPE_VIS_ONLY is_base_of
786     : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
787
788 #else  // __has_feature(is_base_of)
789
790 namespace __is_base_of_imp
791 {
792 template <class _Tp>
793 struct _Dst
794 {
795     _Dst(const volatile _Tp &);
796 };
797 template <class _Tp>
798 struct _Src
799 {
800     operator const volatile _Tp &();
801     template <class _Up> operator const _Dst<_Up> &();
802 };
803 template <size_t> struct __one { typedef char type; };
804 template <class _Bp, class _Dp> typename __one<sizeof(_Dst<_Bp>(declval<_Src<_Dp> >()))>::type __test(int);
805 template <class _Bp, class _Dp> __two __test(...);
806 }
807
808 template <class _Bp, class _Dp>
809 struct _LIBCPP_TYPE_VIS_ONLY is_base_of
810     : public integral_constant<bool, is_class<_Bp>::value &&
811                                      sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {};
812
813 #endif  // __has_feature(is_base_of)
814
815 // is_convertible
816
817 #if __has_feature(is_convertible_to)
818
819 template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible
820     : public integral_constant<bool, __is_convertible_to(_T1, _T2) &&
821                                      !is_abstract<_T2>::value> {};
822
823 #else  // __has_feature(is_convertible_to)
824
825 namespace __is_convertible_imp
826 {
827 template <class _Tp> char  __test(_Tp);
828 template <class _Tp> __two __test(...);
829 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
830 template <class _Tp> _Tp&& __source();
831 #else
832 template <class _Tp> typename remove_reference<_Tp>::type& __source();
833 #endif
834
835 template <class _Tp, bool _IsArray =    is_array<_Tp>::value,
836                      bool _IsFunction = is_function<_Tp>::value,
837                      bool _IsVoid =     is_void<_Tp>::value>
838                      struct __is_array_function_or_void                          {enum {value = 0};};
839 template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
840 template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
841 template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
842 }
843
844 template <class _Tp,
845     unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
846 struct __is_convertible_check
847 {
848     static const size_t __v = 0;
849 };
850
851 template <class _Tp>
852 struct __is_convertible_check<_Tp, 0>
853 {
854     static const size_t __v = sizeof(_Tp);
855 };
856
857 template <class _T1, class _T2,
858     unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
859     unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
860 struct __is_convertible
861     : public integral_constant<bool,
862 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
863         sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
864 #else
865         sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
866          && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value
867               && (!is_const<typename remove_reference<_T2>::type>::value
868                   || is_volatile<typename remove_reference<_T2>::type>::value)
869                   && (is_same<typename remove_cv<_T1>::type,
870                               typename remove_cv<typename remove_reference<_T2>::type>::type>::value
871                       || is_base_of<typename remove_reference<_T2>::type, _T1>::value))
872 #endif
873     >
874 {};
875
876 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 0> : false_type {};
877
878 template <class _T1> struct __is_convertible<_T1, const _T1&, 1, 0> : true_type {};
879 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
880 template <class _T1> struct __is_convertible<_T1, _T1&&, 1, 0> : true_type {};
881 template <class _T1> struct __is_convertible<_T1, const _T1&&, 1, 0> : true_type {};
882 template <class _T1> struct __is_convertible<_T1, volatile _T1&&, 1, 0> : true_type {};
883 template <class _T1> struct __is_convertible<_T1, const volatile _T1&&, 1, 0> : true_type {};
884 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
885
886 template <class _T1, class _T2> struct __is_convertible<_T1, _T2*, 1, 0>
887     : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*>::value> {};
888
889 template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const, 1, 0>
890     : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const>::value> {};
891
892 template <class _T1, class _T2> struct __is_convertible<_T1, _T2* volatile, 1, 0>
893     : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*volatile>::value> {};
894
895 template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const volatile, 1, 0>
896     : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const volatile>::value> {};
897
898 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 0>                : public false_type {};
899 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
900 template <class _T1>            struct __is_convertible<_T1, _T1&&, 2, 0>               : public true_type {};
901 #endif
902 template <class _T1>            struct __is_convertible<_T1, _T1&, 2, 0>               : public true_type {};
903 template <class _T1>            struct __is_convertible<_T1, _T1*, 2, 0>               : public true_type {};
904 template <class _T1>            struct __is_convertible<_T1, _T1*const, 2, 0>          : public true_type {};
905 template <class _T1>            struct __is_convertible<_T1, _T1*volatile, 2, 0>       : public true_type {};
906 template <class _T1>            struct __is_convertible<_T1, _T1*const volatile, 2, 0> : public true_type {};
907
908 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 0> : public false_type {};
909
910 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
911 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
912 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
913 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
914
915 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
916 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
917 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
918 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
919
920 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
921 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
922 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
923 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
924
925 template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible
926     : public __is_convertible<_T1, _T2>
927 {
928     static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
929     static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
930 };
931
932 #endif  // __has_feature(is_convertible_to)
933
934 // is_empty
935
936 #if __has_feature(is_empty)
937
938 template <class _Tp>
939 struct _LIBCPP_TYPE_VIS_ONLY is_empty
940     : public integral_constant<bool, __is_empty(_Tp)> {};
941
942 #else  // __has_feature(is_empty)
943
944 template <class _Tp>
945 struct __is_empty1
946     : public _Tp
947 {
948     double __lx;
949 };
950
951 struct __is_empty2
952 {
953     double __lx;
954 };
955
956 template <class _Tp, bool = is_class<_Tp>::value>
957 struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
958
959 template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
960
961 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_empty : public __libcpp_empty<_Tp> {};
962
963 #endif  // __has_feature(is_empty)
964
965 // is_polymorphic
966
967 #if __has_feature(is_polymorphic)
968
969 template <class _Tp>
970 struct _LIBCPP_TYPE_VIS_ONLY is_polymorphic
971     : public integral_constant<bool, __is_polymorphic(_Tp)> {};
972
973 #else
974
975 template<typename _Tp> char &__is_polymorphic_impl(
976     typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
977                        int>::type);
978 template<typename _Tp> __two &__is_polymorphic_impl(...);
979
980 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_polymorphic
981     : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
982
983 #endif // __has_feature(is_polymorphic)
984
985 // has_virtual_destructor
986
987 #if __has_feature(has_virtual_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
988
989 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor
990     : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
991
992 #else  // _LIBCPP_HAS_TYPE_TRAITS
993
994 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor
995     : public false_type {};
996
997 #endif  // _LIBCPP_HAS_TYPE_TRAITS
998
999 // alignment_of
1000
1001 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY alignment_of
1002     : public integral_constant<size_t, __alignof__(_Tp)> {};
1003
1004 // aligned_storage
1005
1006 template <class _Hp, class _Tp>
1007 struct __type_list
1008 {
1009     typedef _Hp _Head;
1010     typedef _Tp _Tail;
1011 };
1012
1013 struct __nat
1014 {
1015 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1016     __nat() = delete;
1017     __nat(const __nat&) = delete;
1018     __nat& operator=(const __nat&) = delete;
1019     ~__nat() = delete;
1020 #endif
1021 };
1022
1023 template <class _Tp>
1024 struct __align_type
1025 {
1026     static const size_t value = alignment_of<_Tp>::value;
1027     typedef _Tp type;
1028 };
1029
1030 struct __struct_double {long double __lx;};
1031 struct __struct_double4 {double __lx[4];};
1032
1033 typedef
1034     __type_list<__align_type<unsigned char>,
1035     __type_list<__align_type<unsigned short>,
1036     __type_list<__align_type<unsigned int>,
1037     __type_list<__align_type<unsigned long>,
1038     __type_list<__align_type<unsigned long long>,
1039     __type_list<__align_type<double>,
1040     __type_list<__align_type<long double>,
1041     __type_list<__align_type<__struct_double>,
1042     __type_list<__align_type<__struct_double4>,
1043     __type_list<__align_type<int*>,
1044     __nat
1045     > > > > > > > > > > __all_types;
1046
1047 template <class _TL, size_t _Align> struct __find_pod;
1048
1049 template <class _Hp, size_t _Align>
1050 struct __find_pod<__type_list<_Hp, __nat>, _Align>
1051 {
1052     typedef typename conditional<
1053                              _Align == _Hp::value,
1054                              typename _Hp::type,
1055                              void
1056                          >::type type;
1057 };
1058
1059 template <class _Hp, class _Tp, size_t _Align>
1060 struct __find_pod<__type_list<_Hp, _Tp>, _Align>
1061 {
1062     typedef typename conditional<
1063                              _Align == _Hp::value,
1064                              typename _Hp::type,
1065                              typename __find_pod<_Tp, _Align>::type
1066                          >::type type;
1067 };
1068
1069 template <class _TL, size_t _Len> struct __find_max_align;
1070
1071 template <class _Hp, size_t _Len>
1072 struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
1073
1074 template <size_t _Len, size_t _A1, size_t _A2>
1075 struct __select_align
1076 {
1077 private:
1078     static const size_t __min = _A2 < _A1 ? _A2 : _A1;
1079     static const size_t __max = _A1 < _A2 ? _A2 : _A1;
1080 public:
1081     static const size_t value = _Len < __max ? __min : __max;
1082 };
1083
1084 template <class _Hp, class _Tp, size_t _Len>
1085 struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
1086     : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
1087
1088 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1089 struct _LIBCPP_TYPE_VIS_ONLY aligned_storage
1090 {
1091     typedef typename __find_pod<__all_types, _Align>::type _Aligner;
1092     static_assert(!is_void<_Aligner>::value, "");
1093     union type
1094     {
1095         _Aligner __align;
1096         unsigned char __data[_Len];
1097     };
1098 };
1099
1100 #if _LIBCPP_STD_VER > 11
1101 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1102     using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
1103 #endif
1104
1105 #define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
1106 template <size_t _Len>\
1107 struct _LIBCPP_TYPE_VIS_ONLY aligned_storage<_Len, n>\
1108 {\
1109     struct _ALIGNAS(n) type\
1110     {\
1111         unsigned char __lx[_Len];\
1112     };\
1113 }
1114
1115 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
1116 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
1117 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
1118 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
1119 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
1120 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
1121 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
1122 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
1123 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
1124 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
1125 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
1126 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
1127 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
1128 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
1129 // MSDN says that MSVC does not support alignment beyond 8192 (=0x2000)
1130 #if !defined(_LIBCPP_MSVC)
1131 _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
1132 #endif // !_LIBCPP_MSVC
1133
1134 #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
1135
1136 #ifndef _LIBCPP_HAS_NO_VARIADICS
1137
1138 // aligned_union
1139
1140 template <size_t _I0, size_t ..._In>
1141 struct __static_max;
1142
1143 template <size_t _I0>
1144 struct __static_max<_I0>
1145 {
1146     static const size_t value = _I0;
1147 };
1148
1149 template <size_t _I0, size_t _I1, size_t ..._In>
1150 struct __static_max<_I0, _I1, _In...>
1151 {
1152     static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
1153                                              __static_max<_I1, _In...>::value;
1154 };
1155
1156 template <size_t _Len, class _Type0, class ..._Types>
1157 struct aligned_union
1158 {
1159     static const size_t alignment_value = __static_max<__alignof__(_Type0),
1160                                                        __alignof__(_Types)...>::value;
1161     static const size_t __len = __static_max<_Len, sizeof(_Type0),
1162                                              sizeof(_Types)...>::value;
1163     typedef typename aligned_storage<__len, alignment_value>::type type;
1164 };
1165
1166 #if _LIBCPP_STD_VER > 11
1167 template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
1168 #endif
1169
1170 #endif  // _LIBCPP_HAS_NO_VARIADICS
1171
1172 // __promote
1173
1174 template <class _A1, class _A2 = void, class _A3 = void,
1175           bool = (is_arithmetic<_A1>::value || is_void<_A1>::value) &&
1176                  (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
1177                  (is_arithmetic<_A3>::value || is_void<_A3>::value)>
1178 class __promote {};
1179
1180 template <class _A1, class _A2, class _A3>
1181 class __promote<_A1, _A2, _A3, true>
1182 {
1183 private:
1184     typedef typename __promote<_A1>::type __type1;
1185     typedef typename __promote<_A2>::type __type2;
1186     typedef typename __promote<_A3>::type __type3;
1187 public:
1188     typedef decltype(__type1() + __type2() + __type3()) type;
1189 };
1190
1191 template <class _A1, class _A2>
1192 class __promote<_A1, _A2, void, true>
1193 {
1194 private:
1195     typedef typename __promote<_A1>::type __type1;
1196     typedef typename __promote<_A2>::type __type2;
1197 public:
1198     typedef decltype(__type1() + __type2()) type;
1199 };
1200
1201 template <class _A1>
1202 class __promote<_A1, void, void, true>
1203 {
1204 public:
1205     typedef typename conditional<is_arithmetic<_A1>::value,
1206                      typename conditional<is_integral<_A1>::value, double, _A1>::type,
1207                      void
1208             >::type type;
1209 };
1210
1211 #ifdef _LIBCPP_STORE_AS_OPTIMIZATION
1212
1213 // __transform
1214
1215 template <class _Tp, size_t = sizeof(_Tp), bool = is_scalar<_Tp>::value> struct __transform {typedef _Tp type;};
1216 template <class _Tp> struct __transform<_Tp, 1, true> {typedef unsigned char      type;};
1217 template <class _Tp> struct __transform<_Tp, 2, true> {typedef unsigned short     type;};
1218 template <class _Tp> struct __transform<_Tp, 4, true> {typedef unsigned int       type;};
1219 template <class _Tp> struct __transform<_Tp, 8, true> {typedef unsigned long long type;};
1220
1221 #endif  // _LIBCPP_STORE_AS_OPTIMIZATION
1222
1223 // make_signed / make_unsigned
1224
1225 typedef
1226     __type_list<signed char,
1227     __type_list<signed short,
1228     __type_list<signed int,
1229     __type_list<signed long,
1230     __type_list<signed long long,
1231     __nat
1232     > > > > > __signed_types;
1233
1234 typedef
1235     __type_list<unsigned char,
1236     __type_list<unsigned short,
1237     __type_list<unsigned int,
1238     __type_list<unsigned long,
1239     __type_list<unsigned long long,
1240     __nat
1241     > > > > > __unsigned_types;
1242
1243 template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
1244
1245 template <class _Hp, class _Tp, size_t _Size>
1246 struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
1247 {
1248     typedef _Hp type;
1249 };
1250
1251 template <class _Hp, class _Tp, size_t _Size>
1252 struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
1253 {
1254     typedef typename __find_first<_Tp, _Size>::type type;
1255 };
1256
1257 template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
1258                              bool = is_volatile<typename remove_reference<_Tp>::type>::value>
1259 struct __apply_cv
1260 {
1261     typedef _Up type;
1262 };
1263
1264 template <class _Tp, class _Up>
1265 struct __apply_cv<_Tp, _Up, true, false>
1266 {
1267     typedef const _Up type;
1268 };
1269
1270 template <class _Tp, class _Up>
1271 struct __apply_cv<_Tp, _Up, false, true>
1272 {
1273     typedef volatile _Up type;
1274 };
1275
1276 template <class _Tp, class _Up>
1277 struct __apply_cv<_Tp, _Up, true, true>
1278 {
1279     typedef const volatile _Up type;
1280 };
1281
1282 template <class _Tp, class _Up>
1283 struct __apply_cv<_Tp&, _Up, false, false>
1284 {
1285     typedef _Up& type;
1286 };
1287
1288 template <class _Tp, class _Up>
1289 struct __apply_cv<_Tp&, _Up, true, false>
1290 {
1291     typedef const _Up& type;
1292 };
1293
1294 template <class _Tp, class _Up>
1295 struct __apply_cv<_Tp&, _Up, false, true>
1296 {
1297     typedef volatile _Up& type;
1298 };
1299
1300 template <class _Tp, class _Up>
1301 struct __apply_cv<_Tp&, _Up, true, true>
1302 {
1303     typedef const volatile _Up& type;
1304 };
1305
1306 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1307 struct __make_signed {};
1308
1309 template <class _Tp>
1310 struct __make_signed<_Tp, true>
1311 {
1312     typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
1313 };
1314
1315 template <> struct __make_signed<bool,               true> {};
1316 template <> struct __make_signed<  signed short,     true> {typedef short     type;};
1317 template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
1318 template <> struct __make_signed<  signed int,       true> {typedef int       type;};
1319 template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
1320 template <> struct __make_signed<  signed long,      true> {typedef long      type;};
1321 template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
1322 template <> struct __make_signed<  signed long long, true> {typedef long long type;};
1323 template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
1324
1325 template <class _Tp>
1326 struct _LIBCPP_TYPE_VIS_ONLY make_signed
1327 {
1328     typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
1329 };
1330
1331 #if _LIBCPP_STD_VER > 11
1332 template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
1333 #endif
1334
1335 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1336 struct __make_unsigned {};
1337
1338 template <class _Tp>
1339 struct __make_unsigned<_Tp, true>
1340 {
1341     typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
1342 };
1343
1344 template <> struct __make_unsigned<bool,               true> {};
1345 template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
1346 template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
1347 template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
1348 template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
1349 template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
1350 template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
1351 template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
1352 template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
1353
1354 template <class _Tp>
1355 struct _LIBCPP_TYPE_VIS_ONLY make_unsigned
1356 {
1357     typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
1358 };
1359
1360 #if _LIBCPP_STD_VER > 11
1361 template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
1362 #endif
1363
1364 #ifdef _LIBCPP_HAS_NO_VARIADICS
1365
1366 template <class _Tp, class _Up = void, class V = void>
1367 struct _LIBCPP_TYPE_VIS_ONLY common_type
1368 {
1369 public:
1370     typedef typename common_type<typename common_type<_Tp, _Up>::type, V>::type type;
1371 };
1372
1373 template <class _Tp>
1374 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, void, void>
1375 {
1376 public:
1377     typedef _Tp type;
1378 };
1379
1380 template <class _Tp, class _Up>
1381 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, void>
1382 {
1383 private:
1384 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1385     static _Tp&& __t();
1386     static _Up&& __u();
1387 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1388     static _Tp __t();
1389     static _Up __u();
1390 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1391 public:
1392     typedef typename remove_reference<decltype(true ? __t() : __u())>::type type;
1393 };
1394
1395 #else  // _LIBCPP_HAS_NO_VARIADICS
1396
1397 template <class ..._Tp> struct common_type;
1398
1399 template <class _Tp>
1400 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp>
1401 {
1402     typedef typename decay<_Tp>::type type;
1403 };
1404
1405 template <class _Tp, class _Up>
1406 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up>
1407 {
1408 private:
1409     static _Tp&& __t();
1410     static _Up&& __u();
1411     static bool __f();
1412 public:
1413     typedef typename decay<decltype(__f() ? __t() : __u())>::type type;
1414 };
1415
1416 template <class _Tp, class _Up, class ..._Vp>
1417 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, _Vp...>
1418 {
1419     typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
1420 };
1421
1422 #if _LIBCPP_STD_VER > 11
1423 template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
1424 #endif
1425
1426 #endif  // _LIBCPP_HAS_NO_VARIADICS
1427
1428 // is_assignable
1429
1430 template<typename, typename _Tp> struct __select_2nd { typedef _Tp type; };
1431
1432 template <class _Tp, class _Arg>
1433 typename __select_2nd<decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>())), true_type>::type
1434 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1435 __is_assignable_test(_Tp&&, _Arg&&);
1436 #else
1437 __is_assignable_test(_Tp, _Arg&);
1438 #endif
1439
1440 template <class _Arg>
1441 false_type
1442 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1443 __is_assignable_test(__any, _Arg&&);
1444 #else
1445 __is_assignable_test(__any, _Arg&);
1446 #endif
1447
1448 template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
1449 struct __is_assignable_imp
1450     : public common_type
1451         <
1452             decltype(__is_assignable_test(declval<_Tp>(), declval<_Arg>()))
1453         >::type {};
1454
1455 template <class _Tp, class _Arg>
1456 struct __is_assignable_imp<_Tp, _Arg, true>
1457     : public false_type
1458 {
1459 };
1460
1461 template <class _Tp, class _Arg>
1462 struct is_assignable
1463     : public __is_assignable_imp<_Tp, _Arg> {};
1464
1465 // is_copy_assignable
1466
1467 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_copy_assignable
1468     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
1469                      const typename add_lvalue_reference<_Tp>::type> {};
1470
1471 // is_move_assignable
1472
1473 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_move_assignable
1474 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1475     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
1476                      const typename add_rvalue_reference<_Tp>::type> {};
1477 #else
1478     : public is_copy_assignable<_Tp> {};
1479 #endif
1480
1481 // is_destructible
1482
1483 template <class _Tp>
1484 struct __destructible_test
1485 {
1486     _Tp __t;
1487 };
1488
1489 template <class _Tp>
1490 decltype((_VSTD::declval<__destructible_test<_Tp> >().~__destructible_test<_Tp>(), true_type()))
1491 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1492 __is_destructible_test(_Tp&&);
1493 #else
1494 __is_destructible_test(_Tp&);
1495 #endif
1496
1497 false_type
1498 __is_destructible_test(__any);
1499
1500 template <class _Tp, bool = is_void<_Tp>::value || is_abstract<_Tp>::value
1501                                                 || is_function<_Tp>::value>
1502 struct __destructible_imp
1503     : public common_type
1504         <
1505             decltype(__is_destructible_test(declval<_Tp>()))
1506         >::type {};
1507
1508 template <class _Tp>
1509 struct __destructible_imp<_Tp, true>
1510     : public false_type {};
1511
1512 template <class _Tp>
1513 struct is_destructible
1514     : public __destructible_imp<_Tp> {};
1515
1516 template <class _Tp>
1517 struct is_destructible<_Tp[]>
1518     : public false_type {};
1519
1520 // move
1521
1522 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1523
1524 template <class _Tp>
1525 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1526 typename remove_reference<_Tp>::type&&
1527 move(_Tp&& __t) _NOEXCEPT
1528 {
1529     typedef typename remove_reference<_Tp>::type _Up;
1530     return static_cast<_Up&&>(__t);
1531 }
1532
1533 template <class _Tp>
1534 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1535 _Tp&&
1536 forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
1537 {
1538     return static_cast<_Tp&&>(__t);
1539 }
1540
1541 template <class _Tp>
1542 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1543 _Tp&&
1544 forward(typename std::remove_reference<_Tp>::type&& __t) _NOEXCEPT
1545 {
1546     static_assert(!std::is_lvalue_reference<_Tp>::value,
1547                   "Can not forward an rvalue as an lvalue.");
1548     return static_cast<_Tp&&>(__t);
1549 }
1550
1551 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1552
1553 template <class _Tp>
1554 inline _LIBCPP_INLINE_VISIBILITY
1555 _Tp&
1556 move(_Tp& __t)
1557 {
1558     return __t;
1559 }
1560
1561 template <class _Tp>
1562 inline _LIBCPP_INLINE_VISIBILITY
1563 const _Tp&
1564 move(const _Tp& __t)
1565 {
1566     return __t;
1567 }
1568
1569 template <class _Tp>
1570 inline _LIBCPP_INLINE_VISIBILITY
1571 _Tp&
1572 forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
1573 {
1574     return __t;
1575 }
1576
1577
1578 template <class _Tp>
1579 class __rv
1580 {
1581     typedef typename remove_reference<_Tp>::type _Trr;
1582     _Trr& t_;
1583 public:
1584     _LIBCPP_INLINE_VISIBILITY
1585     _Trr* operator->() {return &t_;}
1586     _LIBCPP_INLINE_VISIBILITY
1587     explicit __rv(_Trr& __t) : t_(__t) {}
1588 };
1589
1590 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1591
1592 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1593
1594 template <class _Tp>
1595 inline _LIBCPP_INLINE_VISIBILITY
1596 typename decay<_Tp>::type
1597 __decay_copy(_Tp&& __t)
1598 {
1599     return _VSTD::forward<_Tp>(__t);
1600 }
1601
1602 #else
1603
1604 template <class _Tp>
1605 inline _LIBCPP_INLINE_VISIBILITY
1606 typename decay<_Tp>::type
1607 __decay_copy(const _Tp& __t)
1608 {
1609     return _VSTD::forward<_Tp>(__t);
1610 }
1611
1612 #endif
1613
1614 #ifndef _LIBCPP_HAS_NO_VARIADICS
1615
1616 template <class _Rp, class _Class, class ..._Param>
1617 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
1618 {
1619     typedef _Class _ClassType;
1620     typedef _Rp _ReturnType;
1621     typedef _Rp (_FnType) (_Param...);
1622 };
1623
1624 template <class _Rp, class _Class, class ..._Param>
1625 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
1626 {
1627     typedef _Class const _ClassType;
1628     typedef _Rp _ReturnType;
1629     typedef _Rp (_FnType) (_Param...);
1630 };
1631
1632 template <class _Rp, class _Class, class ..._Param>
1633 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
1634 {
1635     typedef _Class volatile _ClassType;
1636     typedef _Rp _ReturnType;
1637     typedef _Rp (_FnType) (_Param...);
1638 };
1639
1640 template <class _Rp, class _Class, class ..._Param>
1641 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
1642 {
1643     typedef _Class const volatile _ClassType;
1644     typedef _Rp _ReturnType;
1645     typedef _Rp (_FnType) (_Param...);
1646 };
1647
1648 #if __has_feature(cxx_reference_qualified_functions)
1649
1650 template <class _Rp, class _Class, class ..._Param>
1651 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
1652 {
1653     typedef _Class& _ClassType;
1654     typedef _Rp _ReturnType;
1655     typedef _Rp (_FnType) (_Param...);
1656 };
1657
1658 template <class _Rp, class _Class, class ..._Param>
1659 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
1660 {
1661     typedef _Class const& _ClassType;
1662     typedef _Rp _ReturnType;
1663     typedef _Rp (_FnType) (_Param...);
1664 };
1665
1666 template <class _Rp, class _Class, class ..._Param>
1667 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
1668 {
1669     typedef _Class volatile& _ClassType;
1670     typedef _Rp _ReturnType;
1671     typedef _Rp (_FnType) (_Param...);
1672 };
1673
1674 template <class _Rp, class _Class, class ..._Param>
1675 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
1676 {
1677     typedef _Class const volatile& _ClassType;
1678     typedef _Rp _ReturnType;
1679     typedef _Rp (_FnType) (_Param...);
1680 };
1681
1682 template <class _Rp, class _Class, class ..._Param>
1683 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
1684 {
1685     typedef _Class&& _ClassType;
1686     typedef _Rp _ReturnType;
1687     typedef _Rp (_FnType) (_Param...);
1688 };
1689
1690 template <class _Rp, class _Class, class ..._Param>
1691 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
1692 {
1693     typedef _Class const&& _ClassType;
1694     typedef _Rp _ReturnType;
1695     typedef _Rp (_FnType) (_Param...);
1696 };
1697
1698 template <class _Rp, class _Class, class ..._Param>
1699 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
1700 {
1701     typedef _Class volatile&& _ClassType;
1702     typedef _Rp _ReturnType;
1703     typedef _Rp (_FnType) (_Param...);
1704 };
1705
1706 template <class _Rp, class _Class, class ..._Param>
1707 struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
1708 {
1709     typedef _Class const volatile&& _ClassType;
1710     typedef _Rp _ReturnType;
1711     typedef _Rp (_FnType) (_Param...);
1712 };
1713
1714 #endif  // __has_feature(cxx_reference_qualified_functions)
1715
1716 #else  // _LIBCPP_HAS_NO_VARIADICS
1717
1718 template <class _Rp, class _Class>
1719 struct __member_pointer_traits_imp<_Rp (_Class::*)(), true, false>
1720 {
1721     typedef _Class _ClassType;
1722     typedef _Rp _ReturnType;
1723     typedef _Rp (_FnType) ();
1724 };
1725
1726 template <class _Rp, class _Class, class _P0>
1727 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0), true, false>
1728 {
1729     typedef _Class _ClassType;
1730     typedef _Rp _ReturnType;
1731     typedef _Rp (_FnType) (_P0);
1732 };
1733
1734 template <class _Rp, class _Class, class _P0, class _P1>
1735 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1), true, false>
1736 {
1737     typedef _Class _ClassType;
1738     typedef _Rp _ReturnType;
1739     typedef _Rp (_FnType) (_P0, _P1);
1740 };
1741
1742 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
1743 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2), true, false>
1744 {
1745     typedef _Class _ClassType;
1746     typedef _Rp _ReturnType;
1747     typedef _Rp (_FnType) (_P0, _P1, _P2);
1748 };
1749
1750 template <class _Rp, class _Class>
1751 struct __member_pointer_traits_imp<_Rp (_Class::*)() const, true, false>
1752 {
1753     typedef _Class const _ClassType;
1754     typedef _Rp _ReturnType;
1755     typedef _Rp (_FnType) ();
1756 };
1757
1758 template <class _Rp, class _Class, class _P0>
1759 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const, true, false>
1760 {
1761     typedef _Class const _ClassType;
1762     typedef _Rp _ReturnType;
1763     typedef _Rp (_FnType) (_P0);
1764 };
1765
1766 template <class _Rp, class _Class, class _P0, class _P1>
1767 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const, true, false>
1768 {
1769     typedef _Class const _ClassType;
1770     typedef _Rp _ReturnType;
1771     typedef _Rp (_FnType) (_P0, _P1);
1772 };
1773
1774 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
1775 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const, true, false>
1776 {
1777     typedef _Class const _ClassType;
1778     typedef _Rp _ReturnType;
1779     typedef _Rp (_FnType) (_P0, _P1, _P2);
1780 };
1781
1782 template <class _Rp, class _Class>
1783 struct __member_pointer_traits_imp<_Rp (_Class::*)() volatile, true, false>
1784 {
1785     typedef _Class volatile _ClassType;
1786     typedef _Rp _ReturnType;
1787     typedef _Rp (_FnType) ();
1788 };
1789
1790 template <class _Rp, class _Class, class _P0>
1791 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) volatile, true, false>
1792 {
1793     typedef _Class volatile _ClassType;
1794     typedef _Rp _ReturnType;
1795     typedef _Rp (_FnType) (_P0);
1796 };
1797
1798 template <class _Rp, class _Class, class _P0, class _P1>
1799 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) volatile, true, false>
1800 {
1801     typedef _Class volatile _ClassType;
1802     typedef _Rp _ReturnType;
1803     typedef _Rp (_FnType) (_P0, _P1);
1804 };
1805
1806 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
1807 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) volatile, true, false>
1808 {
1809     typedef _Class volatile _ClassType;
1810     typedef _Rp _ReturnType;
1811     typedef _Rp (_FnType) (_P0, _P1, _P2);
1812 };
1813
1814 template <class _Rp, class _Class>
1815 struct __member_pointer_traits_imp<_Rp (_Class::*)() const volatile, true, false>
1816 {
1817     typedef _Class const volatile _ClassType;
1818     typedef _Rp _ReturnType;
1819     typedef _Rp (_FnType) ();
1820 };
1821
1822 template <class _Rp, class _Class, class _P0>
1823 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const volatile, true, false>
1824 {
1825     typedef _Class const volatile _ClassType;
1826     typedef _Rp _ReturnType;
1827     typedef _Rp (_FnType) (_P0);
1828 };
1829
1830 template <class _Rp, class _Class, class _P0, class _P1>
1831 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const volatile, true, false>
1832 {
1833     typedef _Class const volatile _ClassType;
1834     typedef _Rp _ReturnType;
1835     typedef _Rp (_FnType) (_P0, _P1);
1836 };
1837
1838 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
1839 struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const volatile, true, false>
1840 {
1841     typedef _Class const volatile _ClassType;
1842     typedef _Rp _ReturnType;
1843     typedef _Rp (_FnType) (_P0, _P1, _P2);
1844 };
1845
1846 #endif  // _LIBCPP_HAS_NO_VARIADICS
1847
1848 template <class _Rp, class _Class>
1849 struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
1850 {
1851     typedef _Class _ClassType;
1852     typedef _Rp _ReturnType;
1853 };
1854
1855 template <class _MP>
1856 struct __member_pointer_traits
1857     : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
1858                     is_member_function_pointer<_MP>::value,
1859                     is_member_object_pointer<_MP>::value>
1860 {
1861 //     typedef ... _ClassType;
1862 //     typedef ... _ReturnType;
1863 //     typedef ... _FnType;
1864 };
1865
1866 // result_of
1867
1868 template <class _Callable> class result_of;
1869
1870 #ifdef _LIBCPP_HAS_NO_VARIADICS
1871
1872 template <class _Fn, bool, bool>
1873 class __result_of
1874 {
1875 };
1876
1877 template <class _Fn>
1878 class __result_of<_Fn(), true, false>
1879 {
1880 public:
1881     typedef decltype(declval<_Fn>()()) type;
1882 };
1883
1884 template <class _Fn, class _A0>
1885 class __result_of<_Fn(_A0), true, false>
1886 {
1887 public:
1888     typedef decltype(declval<_Fn>()(declval<_A0>())) type;
1889 };
1890
1891 template <class _Fn, class _A0, class _A1>
1892 class __result_of<_Fn(_A0, _A1), true, false>
1893 {
1894 public:
1895     typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
1896 };
1897
1898 template <class _Fn, class _A0, class _A1, class _A2>
1899 class __result_of<_Fn(_A0, _A1, _A2), true, false>
1900 {
1901 public:
1902     typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
1903 };
1904
1905 template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
1906 struct __result_of_mp;
1907
1908 // member function pointer
1909
1910 template <class _MP, class _Tp>
1911 struct __result_of_mp<_MP, _Tp, true>
1912     : public common_type<typename __member_pointer_traits<_MP>::_ReturnType>
1913 {
1914 };
1915
1916 // member data pointer
1917
1918 template <class _MP, class _Tp, bool>
1919 struct __result_of_mdp;
1920
1921 template <class _Rp, class _Class, class _Tp>
1922 struct __result_of_mdp<_Rp _Class::*, _Tp, false>
1923 {
1924     typedef typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type& type;
1925 };
1926
1927 template <class _Rp, class _Class, class _Tp>
1928 struct __result_of_mdp<_Rp _Class::*, _Tp, true>
1929 {
1930     typedef typename __apply_cv<_Tp, _Rp>::type& type;
1931 };
1932
1933 template <class _Rp, class _Class, class _Tp>
1934 struct __result_of_mp<_Rp _Class::*, _Tp, false>
1935     : public __result_of_mdp<_Rp _Class::*, _Tp,
1936             is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
1937 {
1938 };
1939
1940
1941
1942 template <class _Fn, class _Tp>
1943 class __result_of<_Fn(_Tp), false, true>  // _Fn must be member pointer
1944     : public __result_of_mp<typename remove_reference<_Fn>::type,
1945                             _Tp,
1946                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1947 {
1948 };
1949
1950 template <class _Fn, class _Tp, class _A0>
1951 class __result_of<_Fn(_Tp, _A0), false, true>  // _Fn must be member pointer
1952     : public __result_of_mp<typename remove_reference<_Fn>::type,
1953                             _Tp,
1954                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1955 {
1956 };
1957
1958 template <class _Fn, class _Tp, class _A0, class _A1>
1959 class __result_of<_Fn(_Tp, _A0, _A1), false, true>  // _Fn must be member pointer
1960     : public __result_of_mp<typename remove_reference<_Fn>::type,
1961                             _Tp,
1962                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1963 {
1964 };
1965
1966 template <class _Fn, class _Tp, class _A0, class _A1, class _A2>
1967 class __result_of<_Fn(_Tp, _A0, _A1, _A2), false, true>  // _Fn must be member pointer
1968     : public __result_of_mp<typename remove_reference<_Fn>::type,
1969                             _Tp,
1970                             is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1971 {
1972 };
1973
1974 // result_of
1975
1976 template <class _Fn>
1977 class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn()>
1978     : public __result_of<_Fn(),
1979                          is_class<typename remove_reference<_Fn>::type>::value ||
1980                          is_function<typename remove_reference<_Fn>::type>::value,
1981                          is_member_pointer<typename remove_reference<_Fn>::type>::value
1982                         >
1983 {
1984 };
1985
1986 template <class _Fn, class _A0>
1987 class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0)>
1988     : public __result_of<_Fn(_A0),
1989                          is_class<typename remove_reference<_Fn>::type>::value ||
1990                          is_function<typename remove_reference<_Fn>::type>::value,
1991                          is_member_pointer<typename remove_reference<_Fn>::type>::value
1992                         >
1993 {
1994 };
1995
1996 template <class _Fn, class _A0, class _A1>
1997 class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1)>
1998     : public __result_of<_Fn(_A0, _A1),
1999                          is_class<typename remove_reference<_Fn>::type>::value ||
2000                          is_function<typename remove_reference<_Fn>::type>::value,
2001                          is_member_pointer<typename remove_reference<_Fn>::type>::value
2002                         >
2003 {
2004 };
2005
2006 template <class _Fn, class _A0, class _A1, class _A2>
2007 class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1, _A2)>
2008     : public __result_of<_Fn(_A0, _A1, _A2),
2009                          is_class<typename remove_reference<_Fn>::type>::value ||
2010                          is_function<typename remove_reference<_Fn>::type>::value,
2011                          is_member_pointer<typename remove_reference<_Fn>::type>::value
2012                         >
2013 {
2014 };
2015
2016 #endif  // _LIBCPP_HAS_NO_VARIADICS
2017
2018 // template <class T, class... Args> struct is_constructible;
2019
2020 namespace __is_construct
2021 {
2022 struct __nat {};
2023 }
2024
2025 #if __has_feature(is_constructible)
2026
2027 template <class _Tp, class ..._Args>
2028 struct _LIBCPP_TYPE_VIS_ONLY is_constructible
2029     : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
2030     {};
2031
2032 #else
2033
2034 #ifndef _LIBCPP_HAS_NO_VARIADICS
2035
2036 //      main is_constructible test
2037
2038 template <class _Tp, class ..._Args>
2039 typename __select_2nd<decltype(_VSTD::move(_Tp(_VSTD::declval<_Args>()...))), true_type>::type
2040 __is_constructible_test(_Tp&&, _Args&& ...);
2041
2042 template <class ..._Args>
2043 false_type
2044 __is_constructible_test(__any, _Args&& ...);
2045
2046 template <bool, class _Tp, class... _Args>
2047 struct __libcpp_is_constructible // false, _Tp is not a scalar
2048     : public common_type
2049              <
2050                  decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...))
2051              >::type
2052     {};
2053
2054 //      function types are not constructible
2055
2056 template <class _Rp, class... _A1, class... _A2>
2057 struct __libcpp_is_constructible<false, _Rp(_A1...), _A2...>
2058     : public false_type
2059     {};
2060
2061 //      handle scalars and reference types
2062
2063 //      Scalars are default constructible, references are not
2064
2065 template <class _Tp>
2066 struct __libcpp_is_constructible<true, _Tp>
2067     : public is_scalar<_Tp>
2068     {};
2069
2070 //      Scalars and references are constructible from one arg if that arg is
2071 //          implicitly convertible to the scalar or reference.
2072
2073 template <class _Tp>
2074 struct __is_constructible_ref
2075 {
2076     true_type static __lxx(_Tp);
2077     false_type static __lxx(...);
2078 };
2079
2080 template <class _Tp, class _A0>
2081 struct __libcpp_is_constructible<true, _Tp, _A0>
2082     : public common_type
2083              <
2084                  decltype(__is_constructible_ref<_Tp>::__lxx(declval<_A0>()))
2085              >::type
2086     {};
2087
2088 //      Scalars and references are not constructible from multiple args.
2089
2090 template <class _Tp, class _A0, class ..._Args>
2091 struct __libcpp_is_constructible<true, _Tp, _A0, _Args...>
2092     : public false_type
2093     {};
2094
2095 //      Treat scalars and reference types separately
2096
2097 template <bool, class _Tp, class... _Args>
2098 struct __is_constructible_void_check
2099     : public __libcpp_is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2100                                 _Tp, _Args...>
2101     {};
2102
2103 //      If any of T or Args is void, is_constructible should be false
2104
2105 template <class _Tp, class... _Args>
2106 struct __is_constructible_void_check<true, _Tp, _Args...>
2107     : public false_type
2108     {};
2109
2110 template <class ..._Args> struct __contains_void;
2111
2112 template <> struct __contains_void<> : false_type {};
2113
2114 template <class _A0, class ..._Args>
2115 struct __contains_void<_A0, _Args...>
2116 {
2117     static const bool value = is_void<_A0>::value ||
2118                               __contains_void<_Args...>::value;
2119 };
2120
2121 //      is_constructible entry point
2122
2123 template <class _Tp, class... _Args>
2124 struct _LIBCPP_TYPE_VIS_ONLY is_constructible
2125     : public __is_constructible_void_check<__contains_void<_Tp, _Args...>::value
2126                                         || is_abstract<_Tp>::value,
2127                                            _Tp, _Args...>
2128     {};
2129
2130 //      Array types are default constructible if their element type
2131 //      is default constructible
2132
2133 template <class _Ap, size_t _Np>
2134 struct __libcpp_is_constructible<false, _Ap[_Np]>
2135     : public is_constructible<typename remove_all_extents<_Ap>::type>
2136     {};
2137
2138 //      Otherwise array types are not constructible by this syntax
2139
2140 template <class _Ap, size_t _Np, class ..._Args>
2141 struct __libcpp_is_constructible<false, _Ap[_Np], _Args...>
2142     : public false_type
2143     {};
2144
2145 //      Incomplete array types are not constructible
2146
2147 template <class _Ap, class ..._Args>
2148 struct __libcpp_is_constructible<false, _Ap[], _Args...>
2149     : public false_type
2150     {};
2151
2152 #else  // _LIBCPP_HAS_NO_VARIADICS
2153
2154 // template <class T> struct is_constructible0;
2155
2156 //      main is_constructible0 test
2157
2158 template <class _Tp>
2159 decltype((_Tp(), true_type()))
2160 __is_constructible0_test(_Tp&);
2161
2162 false_type
2163 __is_constructible0_test(__any);
2164
2165 template <class _Tp, class _A0>
2166 decltype((_Tp(_VSTD::declval<_A0>()), true_type()))
2167 __is_constructible1_test(_Tp&, _A0&);
2168
2169 template <class _A0>
2170 false_type
2171 __is_constructible1_test(__any, _A0&);
2172
2173 template <class _Tp, class _A0, class _A1>
2174 decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>()), true_type()))
2175 __is_constructible2_test(_Tp&, _A0&, _A1&);
2176
2177 template <class _A0, class _A1>
2178 false_type
2179 __is_constructible2_test(__any, _A0&, _A1&);
2180
2181 template <bool, class _Tp>
2182 struct __is_constructible0_imp // false, _Tp is not a scalar
2183     : public common_type
2184              <
2185                  decltype(__is_constructible0_test(declval<_Tp&>()))
2186              >::type
2187     {};
2188
2189 template <bool, class _Tp, class _A0>
2190 struct __is_constructible1_imp // false, _Tp is not a scalar
2191     : public common_type
2192              <
2193                  decltype(__is_constructible1_test(declval<_Tp&>(), declval<_A0&>()))
2194              >::type
2195     {};
2196
2197 template <bool, class _Tp, class _A0, class _A1>
2198 struct __is_constructible2_imp // false, _Tp is not a scalar
2199     : public common_type
2200              <
2201                  decltype(__is_constructible2_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>()))
2202              >::type
2203     {};
2204
2205 //      handle scalars and reference types
2206
2207 //      Scalars are default constructible, references are not
2208
2209 template <class _Tp>
2210 struct __is_constructible0_imp<true, _Tp>
2211     : public is_scalar<_Tp>
2212     {};
2213
2214 template <class _Tp, class _A0>
2215 struct __is_constructible1_imp<true, _Tp, _A0>
2216     : public is_convertible<_A0, _Tp>
2217     {};
2218
2219 template <class _Tp, class _A0, class _A1>
2220 struct __is_constructible2_imp<true, _Tp, _A0, _A1>
2221     : public false_type
2222     {};
2223
2224 //      Treat scalars and reference types separately
2225
2226 template <bool, class _Tp>
2227 struct __is_constructible0_void_check
2228     : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2229                                 _Tp>
2230     {};
2231
2232 template <bool, class _Tp, class _A0>
2233 struct __is_constructible1_void_check
2234     : public __is_constructible1_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2235                                 _Tp, _A0>
2236     {};
2237
2238 template <bool, class _Tp, class _A0, class _A1>
2239 struct __is_constructible2_void_check
2240     : public __is_constructible2_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2241                                 _Tp, _A0, _A1>
2242     {};
2243
2244 //      If any of T or Args is void, is_constructible should be false
2245
2246 template <class _Tp>
2247 struct __is_constructible0_void_check<true, _Tp>
2248     : public false_type
2249     {};
2250
2251 template <class _Tp, class _A0>
2252 struct __is_constructible1_void_check<true, _Tp, _A0>
2253     : public false_type
2254     {};
2255
2256 template <class _Tp, class _A0, class _A1>
2257 struct __is_constructible2_void_check<true, _Tp, _A0, _A1>
2258     : public false_type
2259     {};
2260
2261 //      is_constructible entry point
2262
2263 template <class _Tp, class _A0 = __is_construct::__nat,
2264                      class _A1 = __is_construct::__nat>
2265 struct _LIBCPP_TYPE_VIS_ONLY is_constructible
2266     : public __is_constructible2_void_check<is_void<_Tp>::value
2267                                         || is_abstract<_Tp>::value
2268                                         || is_function<_Tp>::value
2269                                         || is_void<_A0>::value
2270                                         || is_void<_A1>::value,
2271                                            _Tp, _A0, _A1>
2272     {};
2273
2274 template <class _Tp>
2275 struct _LIBCPP_TYPE_VIS_ONLY is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat>
2276     : public __is_constructible0_void_check<is_void<_Tp>::value
2277                                         || is_abstract<_Tp>::value
2278                                         || is_function<_Tp>::value,
2279                                            _Tp>
2280     {};
2281
2282 template <class _Tp, class _A0>
2283 struct _LIBCPP_TYPE_VIS_ONLY is_constructible<_Tp, _A0, __is_construct::__nat>
2284     : public __is_constructible1_void_check<is_void<_Tp>::value
2285                                         || is_abstract<_Tp>::value
2286                                         || is_function<_Tp>::value
2287                                         || is_void<_A0>::value,
2288                                            _Tp, _A0>
2289     {};
2290
2291 //      Array types are default constructible if their element type
2292 //      is default constructible
2293
2294 template <class _Ap, size_t _Np>
2295 struct __is_constructible0_imp<false, _Ap[_Np]>
2296     : public is_constructible<typename remove_all_extents<_Ap>::type>
2297     {};
2298
2299 template <class _Ap, size_t _Np, class _A0>
2300 struct __is_constructible1_imp<false, _Ap[_Np], _A0>
2301     : public false_type
2302     {};
2303
2304 template <class _Ap, size_t _Np, class _A0, class _A1>
2305 struct __is_constructible2_imp<false, _Ap[_Np], _A0, _A1>
2306     : public false_type
2307     {};
2308
2309 //      Incomplete array types are not constructible
2310
2311 template <class _Ap>
2312 struct __is_constructible0_imp<false, _Ap[]>
2313     : public false_type
2314     {};
2315
2316 template <class _Ap, class _A0>
2317 struct __is_constructible1_imp<false, _Ap[], _A0>
2318     : public false_type
2319     {};
2320
2321 template <class _Ap, class _A0, class _A1>
2322 struct __is_constructible2_imp<false, _Ap[], _A0, _A1>
2323     : public false_type
2324     {};
2325
2326 #endif  // _LIBCPP_HAS_NO_VARIADICS
2327 #endif  // __has_feature(is_constructible)
2328
2329 // is_default_constructible
2330
2331 template <class _Tp>
2332 struct _LIBCPP_TYPE_VIS_ONLY is_default_constructible
2333     : public is_constructible<_Tp>
2334     {};
2335
2336 // is_copy_constructible
2337
2338 template <class _Tp>
2339 struct _LIBCPP_TYPE_VIS_ONLY is_copy_constructible
2340     : public is_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
2341     {};
2342
2343 // is_move_constructible
2344
2345 template <class _Tp>
2346 struct _LIBCPP_TYPE_VIS_ONLY is_move_constructible
2347 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2348     : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2349 #else
2350     : public is_copy_constructible<_Tp>
2351 #endif
2352     {};
2353
2354 // is_trivially_constructible
2355
2356 #ifndef _LIBCPP_HAS_NO_VARIADICS
2357
2358 #if __has_feature(is_trivially_constructible)
2359
2360 template <class _Tp, class... _Args>
2361 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible
2362     : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
2363 {
2364 };
2365
2366 #else  // !__has_feature(is_trivially_constructible)
2367
2368 template <class _Tp, class... _Args>
2369 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible
2370     : false_type
2371 {
2372 };
2373
2374 template <class _Tp>
2375 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp>
2376 #if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2377     : integral_constant<bool, __has_trivial_constructor(_Tp)>
2378 #else
2379     : integral_constant<bool, is_scalar<_Tp>::value>
2380 #endif
2381 {
2382 };
2383
2384 template <class _Tp>
2385 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2386 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&&>
2387 #else
2388 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp>
2389 #endif
2390     : integral_constant<bool, is_scalar<_Tp>::value>
2391 {
2392 };
2393
2394 template <class _Tp>
2395 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&>
2396     : integral_constant<bool, is_scalar<_Tp>::value>
2397 {
2398 };
2399
2400 template <class _Tp>
2401 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&>
2402     : integral_constant<bool, is_scalar<_Tp>::value>
2403 {
2404 };
2405
2406 #endif  // !__has_feature(is_trivially_constructible)
2407
2408 #else  // _LIBCPP_HAS_NO_VARIADICS
2409
2410 template <class _Tp, class _A0 = __is_construct::__nat,
2411                      class _A1 = __is_construct::__nat>
2412 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible
2413     : false_type
2414 {
2415 };
2416
2417 #if __has_feature(is_trivially_constructible)
2418
2419 template <class _Tp>
2420 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, __is_construct::__nat,
2421                                                        __is_construct::__nat>
2422     : integral_constant<bool, __is_trivially_constructible(_Tp)>
2423 {
2424 };
2425
2426 template <class _Tp>
2427 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp,
2428                                                        __is_construct::__nat>
2429     : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)>
2430 {
2431 };
2432
2433 template <class _Tp>
2434 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&,
2435                                                        __is_construct::__nat>
2436     : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)>
2437 {
2438 };
2439
2440 template <class _Tp>
2441 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&,
2442                                                        __is_construct::__nat>
2443     : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)>
2444 {
2445 };
2446
2447 #else  // !__has_feature(is_trivially_constructible)
2448
2449 template <class _Tp>
2450 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, __is_construct::__nat,
2451                                                        __is_construct::__nat>
2452     : integral_constant<bool, is_scalar<_Tp>::value>
2453 {
2454 };
2455
2456 template <class _Tp>
2457 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp,
2458                                                        __is_construct::__nat>
2459     : integral_constant<bool, is_scalar<_Tp>::value>
2460 {
2461 };
2462
2463 template <class _Tp>
2464 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&,
2465                                                        __is_construct::__nat>
2466     : integral_constant<bool, is_scalar<_Tp>::value>
2467 {
2468 };
2469
2470 template <class _Tp>
2471 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&,
2472                                                        __is_construct::__nat>
2473     : integral_constant<bool, is_scalar<_Tp>::value>
2474 {
2475 };
2476
2477 #endif  // !__has_feature(is_trivially_constructible)
2478
2479 #endif  // _LIBCPP_HAS_NO_VARIADICS
2480
2481 // is_trivially_default_constructible
2482
2483 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_default_constructible
2484     : public is_trivially_constructible<_Tp>
2485     {};
2486
2487 // is_trivially_copy_constructible
2488
2489 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_constructible
2490     : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
2491     {};
2492
2493 // is_trivially_move_constructible
2494
2495 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_constructible
2496 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2497     : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2498 #else
2499     : public is_trivially_copy_constructible<_Tp>
2500 #endif
2501     {};
2502
2503 // is_trivially_assignable
2504
2505 #if __has_feature(is_trivially_constructible)
2506
2507 template <class _Tp, class _Arg>
2508 struct is_trivially_assignable
2509     : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
2510 {
2511 };
2512
2513 #else  // !__has_feature(is_trivially_constructible)
2514
2515 template <class _Tp, class _Arg>
2516 struct is_trivially_assignable
2517     : public false_type {};
2518
2519 template <class _Tp>
2520 struct is_trivially_assignable<_Tp&, _Tp>
2521     : integral_constant<bool, is_scalar<_Tp>::value> {};
2522
2523 template <class _Tp>
2524 struct is_trivially_assignable<_Tp&, _Tp&>
2525     : integral_constant<bool, is_scalar<_Tp>::value> {};
2526
2527 template <class _Tp>
2528 struct is_trivially_assignable<_Tp&, const _Tp&>
2529     : integral_constant<bool, is_scalar<_Tp>::value> {};
2530
2531 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2532
2533 template <class _Tp>
2534 struct is_trivially_assignable<_Tp&, _Tp&&>
2535     : integral_constant<bool, is_scalar<_Tp>::value> {};
2536
2537 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2538
2539 #endif  // !__has_feature(is_trivially_constructible)
2540
2541 // is_trivially_copy_assignable
2542
2543 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_assignable
2544     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2545                                const typename add_lvalue_reference<_Tp>::type>
2546     {};
2547
2548 // is_trivially_move_assignable
2549
2550 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_assignable
2551     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2552 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2553                                      typename add_rvalue_reference<_Tp>::type>
2554 #else
2555                                      typename add_lvalue_reference<_Tp>::type>
2556 #endif
2557     {};
2558
2559 // is_trivially_destructible
2560
2561 #if __has_feature(has_trivial_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2562
2563 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible
2564     : public integral_constant<bool, __has_trivial_destructor(_Tp)> {};
2565
2566 #else  // _LIBCPP_HAS_TYPE_TRAITS
2567
2568 template <class _Tp> struct __libcpp_trivial_destructor
2569     : public integral_constant<bool, is_scalar<_Tp>::value ||
2570                                      is_reference<_Tp>::value> {};
2571
2572 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible
2573     : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
2574
2575 #endif  // _LIBCPP_HAS_TYPE_TRAITS
2576
2577 // is_nothrow_constructible
2578
2579 #if 0
2580 template <class _Tp, class... _Args>
2581 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
2582     : public integral_constant<bool, __is_nothrow_constructible(_Tp(_Args...))>
2583 {
2584 };
2585
2586 #else
2587
2588 #ifndef _LIBCPP_HAS_NO_VARIADICS
2589
2590 #if __has_feature(cxx_noexcept)
2591
2592 template <bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
2593
2594 template <class _Tp, class... _Args>
2595 struct __libcpp_is_nothrow_constructible<true, _Tp, _Args...>
2596     : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
2597 {
2598 };
2599
2600 template <class _Tp, class... _Args>
2601 struct __libcpp_is_nothrow_constructible<false, _Tp, _Args...>
2602     : public false_type
2603 {
2604 };
2605
2606 template <class _Tp, class... _Args>
2607 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
2608     : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, _Tp, _Args...>
2609 {
2610 };
2611
2612 template <class _Tp, size_t _Ns>
2613 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp[_Ns]>
2614     : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, _Tp>
2615 {
2616 };
2617
2618 #else  // __has_feature(cxx_noexcept)
2619
2620 template <class _Tp, class... _Args>
2621 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
2622     : false_type
2623 {
2624 };
2625
2626 template <class _Tp>
2627 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp>
2628 #if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2629     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
2630 #else
2631     : integral_constant<bool, is_scalar<_Tp>::value>
2632 #endif
2633 {
2634 };
2635
2636 template <class _Tp>
2637 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2638 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&&>
2639 #else
2640 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp>
2641 #endif
2642 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2643     : integral_constant<bool, __has_nothrow_copy(_Tp)>
2644 #else
2645     : integral_constant<bool, is_scalar<_Tp>::value>
2646 #endif
2647 {
2648 };
2649
2650 template <class _Tp>
2651 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&>
2652 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2653     : integral_constant<bool, __has_nothrow_copy(_Tp)>
2654 #else
2655     : integral_constant<bool, is_scalar<_Tp>::value>
2656 #endif
2657 {
2658 };
2659
2660 template <class _Tp>
2661 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&>
2662 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2663     : integral_constant<bool, __has_nothrow_copy(_Tp)>
2664 #else
2665     : integral_constant<bool, is_scalar<_Tp>::value>
2666 #endif
2667 {
2668 };
2669
2670 #endif  // __has_feature(cxx_noexcept)
2671
2672 #else  // _LIBCPP_HAS_NO_VARIADICS
2673
2674 template <class _Tp, class _A0 = __is_construct::__nat,
2675                      class _A1 = __is_construct::__nat>
2676 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
2677     : false_type
2678 {
2679 };
2680
2681 template <class _Tp>
2682 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, __is_construct::__nat,
2683                                                        __is_construct::__nat>
2684 #if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2685     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
2686 #else
2687     : integral_constant<bool, is_scalar<_Tp>::value>
2688 #endif
2689 {
2690 };
2691
2692 template <class _Tp>
2693 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp,
2694                                                        __is_construct::__nat>
2695 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2696     : integral_constant<bool, __has_nothrow_copy(_Tp)>
2697 #else
2698     : integral_constant<bool, is_scalar<_Tp>::value>
2699 #endif
2700 {
2701 };
2702
2703 template <class _Tp>
2704 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&,
2705                                                        __is_construct::__nat>
2706 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2707     : integral_constant<bool, __has_nothrow_copy(_Tp)>
2708 #else
2709     : integral_constant<bool, is_scalar<_Tp>::value>
2710 #endif
2711 {
2712 };
2713
2714 template <class _Tp>
2715 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&,
2716                                                        __is_construct::__nat>
2717 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2718     : integral_constant<bool, __has_nothrow_copy(_Tp)>
2719 #else
2720     : integral_constant<bool, is_scalar<_Tp>::value>
2721 #endif
2722 {
2723 };
2724
2725 #endif  // _LIBCPP_HAS_NO_VARIADICS
2726 #endif  // __has_feature(is_nothrow_constructible)
2727
2728 // is_nothrow_default_constructible
2729
2730 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_default_constructible
2731     : public is_nothrow_constructible<_Tp>
2732     {};
2733
2734 // is_nothrow_copy_constructible
2735
2736 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_constructible
2737     : public is_nothrow_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
2738     {};
2739
2740 // is_nothrow_move_constructible
2741
2742 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_constructible
2743 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2744     : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2745 #else
2746     : public is_nothrow_copy_constructible<_Tp>
2747 #endif
2748     {};
2749
2750 // is_nothrow_assignable
2751
2752 #if __has_feature(cxx_noexcept)
2753
2754 template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
2755
2756 template <class _Tp, class _Arg>
2757 struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
2758     : public false_type
2759 {
2760 };
2761
2762 template <class _Tp, class _Arg>
2763 struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
2764     : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>()) >
2765 {
2766 };
2767
2768 template <class _Tp, class _Arg>
2769 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable
2770     : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
2771 {
2772 };
2773
2774 #else  // __has_feature(cxx_noexcept)
2775
2776 template <class _Tp, class _Arg>
2777 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable
2778     : public false_type {};
2779
2780 template <class _Tp>
2781 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp>
2782 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2783     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2784 #else
2785     : integral_constant<bool, is_scalar<_Tp>::value> {};
2786 #endif
2787
2788 template <class _Tp>
2789 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp&>
2790 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2791     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2792 #else
2793     : integral_constant<bool, is_scalar<_Tp>::value> {};
2794 #endif
2795
2796 template <class _Tp>
2797 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, const _Tp&>
2798 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2799     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2800 #else
2801     : integral_constant<bool, is_scalar<_Tp>::value> {};
2802 #endif
2803
2804 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2805
2806 template <class _Tp>
2807 struct is_nothrow_assignable<_Tp&, _Tp&&>
2808 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2809     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2810 #else
2811     : integral_constant<bool, is_scalar<_Tp>::value> {};
2812 #endif
2813
2814 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2815
2816 #endif  // __has_feature(cxx_noexcept)
2817
2818 // is_nothrow_copy_assignable
2819
2820 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_assignable
2821     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
2822                                const typename add_lvalue_reference<_Tp>::type>
2823     {};
2824
2825 // is_nothrow_move_assignable
2826
2827 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_assignable
2828     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
2829 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2830                                      typename add_rvalue_reference<_Tp>::type>
2831 #else
2832                                      typename add_lvalue_reference<_Tp>::type>
2833 #endif
2834     {};
2835
2836 // is_nothrow_destructible
2837
2838 #if __has_feature(cxx_noexcept)
2839
2840 template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
2841
2842 template <class _Tp>
2843 struct __libcpp_is_nothrow_destructible<false, _Tp>
2844     : public false_type
2845 {
2846 };
2847
2848 template <class _Tp>
2849 struct __libcpp_is_nothrow_destructible<true, _Tp>
2850     : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>().~_Tp()) >
2851 {
2852 };
2853
2854 template <class _Tp>
2855 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible
2856     : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
2857 {
2858 };
2859
2860 template <class _Tp, size_t _Ns>
2861 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp[_Ns]>
2862     : public is_nothrow_destructible<_Tp>
2863 {
2864 };
2865
2866 template <class _Tp>
2867 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp&>
2868     : public true_type
2869 {
2870 };
2871
2872 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2873
2874 template <class _Tp>
2875 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp&&>
2876     : public true_type
2877 {
2878 };
2879
2880 #endif
2881
2882 #else
2883
2884 template <class _Tp> struct __libcpp_nothrow_destructor
2885     : public integral_constant<bool, is_scalar<_Tp>::value ||
2886                                      is_reference<_Tp>::value> {};
2887
2888 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible
2889     : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
2890
2891 #endif
2892
2893 // is_pod
2894
2895 #if __has_feature(is_pod) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
2896
2897 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod
2898     : public integral_constant<bool, __is_pod(_Tp)> {};
2899
2900 #else  // _LIBCPP_HAS_TYPE_TRAITS
2901
2902 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod
2903     : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
2904                                      is_trivially_copy_constructible<_Tp>::value      &&
2905                                      is_trivially_copy_assignable<_Tp>::value    &&
2906                                      is_trivially_destructible<_Tp>::value> {};
2907
2908 #endif  // _LIBCPP_HAS_TYPE_TRAITS
2909
2910 // is_literal_type;
2911
2912 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_literal_type
2913 #if __has_feature(is_literal)
2914     : public integral_constant<bool, __is_literal(_Tp)>
2915 #else
2916     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value ||
2917                               is_reference<typename remove_all_extents<_Tp>::type>::value>
2918 #endif
2919     {};
2920     
2921 // is_standard_layout;
2922
2923 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_standard_layout
2924 #if __has_feature(is_standard_layout)
2925     : public integral_constant<bool, __is_standard_layout(_Tp)>
2926 #else
2927     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
2928 #endif
2929     {};
2930     
2931 // is_trivially_copyable;
2932
2933 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copyable
2934 #if __has_feature(is_trivially_copyable)
2935     : public integral_constant<bool, __is_trivially_copyable(_Tp)>
2936 #else
2937     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
2938 #endif
2939     {};
2940     
2941 // is_trivial;
2942
2943 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivial
2944 #if __has_feature(is_trivial)
2945     : public integral_constant<bool, __is_trivial(_Tp)>
2946 #else
2947     : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
2948                                  is_trivially_default_constructible<_Tp>::value>
2949 #endif
2950     {};
2951
2952 #ifndef _LIBCPP_HAS_NO_VARIADICS
2953
2954 // Check for complete types
2955
2956 template <class ..._Tp> struct __check_complete;
2957
2958 template <>
2959 struct __check_complete<>
2960 {
2961 };
2962
2963 template <class _Hp, class _T0, class ..._Tp>
2964 struct __check_complete<_Hp, _T0, _Tp...>
2965     : private __check_complete<_Hp>,
2966       private __check_complete<_T0, _Tp...>
2967 {
2968 };
2969
2970 template <class _Hp>
2971 struct __check_complete<_Hp, _Hp>
2972     : private __check_complete<_Hp>
2973 {
2974 };
2975
2976 template <class _Tp>
2977 struct __check_complete<_Tp>
2978 {
2979     static_assert(sizeof(_Tp) > 0, "Type must be complete.");
2980 };
2981
2982 template <class _Tp>
2983 struct __check_complete<_Tp&>
2984     : private __check_complete<_Tp>
2985 {
2986 };
2987
2988 template <class _Tp>
2989 struct __check_complete<_Tp&&>
2990     : private __check_complete<_Tp>
2991 {
2992 };
2993
2994 template <class _Rp, class ..._Param>
2995 struct __check_complete<_Rp (*)(_Param...)>
2996     : private __check_complete<_Rp>
2997 {
2998 };
2999
3000 template <class ..._Param>
3001 struct __check_complete<void (*)(_Param...)>
3002 {
3003 };
3004
3005 template <class _Rp, class ..._Param>
3006 struct __check_complete<_Rp (_Param...)>
3007     : private __check_complete<_Rp>
3008 {
3009 };
3010
3011 template <class ..._Param>
3012 struct __check_complete<void (_Param...)>
3013 {
3014 };
3015
3016 template <class _Rp, class _Class, class ..._Param>
3017 struct __check_complete<_Rp (_Class::*)(_Param...)>
3018     : private __check_complete<_Class>
3019 {
3020 };
3021
3022 template <class _Rp, class _Class, class ..._Param>
3023 struct __check_complete<_Rp (_Class::*)(_Param...) const>
3024     : private __check_complete<_Class>
3025 {
3026 };
3027
3028 template <class _Rp, class _Class, class ..._Param>
3029 struct __check_complete<_Rp (_Class::*)(_Param...) volatile>
3030     : private __check_complete<_Class>
3031 {
3032 };
3033
3034 template <class _Rp, class _Class, class ..._Param>
3035 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile>
3036     : private __check_complete<_Class>
3037 {
3038 };
3039
3040 #if __has_feature(cxx_reference_qualified_functions)
3041
3042 template <class _Rp, class _Class, class ..._Param>
3043 struct __check_complete<_Rp (_Class::*)(_Param...) &>
3044     : private __check_complete<_Class>
3045 {
3046 };
3047
3048 template <class _Rp, class _Class, class ..._Param>
3049 struct __check_complete<_Rp (_Class::*)(_Param...) const&>
3050     : private __check_complete<_Class>
3051 {
3052 };
3053
3054 template <class _Rp, class _Class, class ..._Param>
3055 struct __check_complete<_Rp (_Class::*)(_Param...) volatile&>
3056     : private __check_complete<_Class>
3057 {
3058 };
3059
3060 template <class _Rp, class _Class, class ..._Param>
3061 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&>
3062     : private __check_complete<_Class>
3063 {
3064 };
3065
3066 template <class _Rp, class _Class, class ..._Param>
3067 struct __check_complete<_Rp (_Class::*)(_Param...) &&>
3068     : private __check_complete<_Class>
3069 {
3070 };
3071
3072 template <class _Rp, class _Class, class ..._Param>
3073 struct __check_complete<_Rp (_Class::*)(_Param...) const&&>
3074     : private __check_complete<_Class>
3075 {
3076 };
3077
3078 template <class _Rp, class _Class, class ..._Param>
3079 struct __check_complete<_Rp (_Class::*)(_Param...) volatile&&>
3080     : private __check_complete<_Class>
3081 {
3082 };
3083
3084 template <class _Rp, class _Class, class ..._Param>
3085 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&&>
3086     : private __check_complete<_Class>
3087 {
3088 };
3089
3090 #endif
3091
3092 template <class _Rp, class _Class>
3093 struct __check_complete<_Rp _Class::*>
3094     : private __check_complete<_Class>
3095 {
3096 };
3097
3098 // __invoke forward declarations
3099
3100 // fall back - none of the bullets
3101
3102 template <class ..._Args>
3103 auto
3104 __invoke(__any, _Args&& ...__args)
3105     -> __nat;
3106
3107 // bullets 1 and 2
3108
3109 template <class _Fp, class _A0, class ..._Args,
3110             class = typename enable_if
3111             <
3112                 is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
3113                 is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
3114                            typename remove_reference<_A0>::type>::value
3115             >::type
3116          >
3117 _LIBCPP_INLINE_VISIBILITY
3118 auto
3119 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3120     -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...));
3121
3122 template <class _Fp, class _A0, class ..._Args,
3123             class = typename enable_if
3124             <
3125                 is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
3126                 !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
3127                            typename remove_reference<_A0>::type>::value
3128             >::type
3129          >
3130 _LIBCPP_INLINE_VISIBILITY
3131 auto
3132 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3133     -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...));
3134
3135 // bullets 3 and 4
3136
3137 template <class _Fp, class _A0,
3138             class = typename enable_if
3139             <
3140                 is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
3141                 is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
3142                            typename remove_reference<_A0>::type>::value
3143             >::type
3144          >
3145 _LIBCPP_INLINE_VISIBILITY
3146 auto
3147 __invoke(_Fp&& __f, _A0&& __a0)
3148     -> decltype(_VSTD::forward<_A0>(__a0).*__f);
3149
3150 template <class _Fp, class _A0,
3151             class = typename enable_if
3152             <
3153                 is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
3154                 !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
3155                            typename remove_reference<_A0>::type>::value
3156             >::type
3157          >
3158 _LIBCPP_INLINE_VISIBILITY
3159 auto
3160 __invoke(_Fp&& __f, _A0&& __a0)
3161     -> decltype((*_VSTD::forward<_A0>(__a0)).*__f);
3162
3163 // bullet 5
3164
3165 template <class _Fp, class ..._Args>
3166 _LIBCPP_INLINE_VISIBILITY
3167 auto
3168 __invoke(_Fp&& __f, _Args&& ...__args)
3169     -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...));
3170
3171 // __invokable
3172
3173 template <class _Fp, class ..._Args>
3174 struct __invokable_imp
3175     : private __check_complete<_Fp>
3176 {
3177     typedef decltype(
3178             __invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)
3179                     ) type;
3180     static const bool value = !is_same<type, __nat>::value;
3181 };
3182
3183 template <class _Fp, class ..._Args>
3184 struct __invokable
3185     : public integral_constant<bool,
3186           __invokable_imp<_Fp, _Args...>::value>
3187 {
3188 };
3189
3190 // __invoke_of
3191
3192 template <bool _Invokable, class _Fp, class ..._Args>
3193 struct __invoke_of_imp  // false
3194 {
3195 };
3196
3197 template <class _Fp, class ..._Args>
3198 struct __invoke_of_imp<true, _Fp, _Args...>
3199 {
3200     typedef typename __invokable_imp<_Fp, _Args...>::type type;
3201 };
3202
3203 template <class _Fp, class ..._Args>
3204 struct __invoke_of
3205     : public __invoke_of_imp<__invokable<_Fp, _Args...>::value, _Fp, _Args...>
3206 {
3207 };
3208
3209 template <class _Fp, class ..._Args>
3210 class _LIBCPP_TYPE_VIS_ONLY result_of<_Fp(_Args...)>
3211     : public __invoke_of<_Fp, _Args...>
3212 {
3213 };
3214
3215 #if _LIBCPP_STD_VER > 11
3216 template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
3217 #endif
3218
3219 #endif  // _LIBCPP_HAS_NO_VARIADICS
3220
3221 template <class _Tp>
3222 inline _LIBCPP_INLINE_VISIBILITY
3223 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
3224 typename enable_if
3225 <
3226     is_move_constructible<_Tp>::value &&
3227     is_move_assignable<_Tp>::value
3228 >::type
3229 #else
3230 void
3231 #endif
3232 swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
3233                                     is_nothrow_move_assignable<_Tp>::value)
3234 {
3235     _Tp __t(_VSTD::move(__x));
3236     __x = _VSTD::move(__y);
3237     __y = _VSTD::move(__t);
3238 }
3239
3240 template <class _ForwardIterator1, class _ForwardIterator2>
3241 inline _LIBCPP_INLINE_VISIBILITY
3242 void
3243 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
3244     //                                  _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
3245                _NOEXCEPT_(_NOEXCEPT_(swap(*_VSTD::declval<_ForwardIterator1>(),
3246                                           *_VSTD::declval<_ForwardIterator2>())))
3247 {
3248     swap(*__a, *__b);
3249 }
3250
3251 // __swappable
3252
3253 namespace __detail
3254 {
3255
3256 using _VSTD::swap;
3257 __nat swap(__any, __any);
3258
3259 template <class _Tp>
3260 struct __swappable
3261 {
3262     typedef decltype(swap(_VSTD::declval<_Tp&>(), _VSTD::declval<_Tp&>())) type;
3263     static const bool value = !is_same<type, __nat>::value;
3264 };
3265
3266 }  // __detail
3267
3268 template <class _Tp>
3269 struct __is_swappable
3270     : public integral_constant<bool, __detail::__swappable<_Tp>::value>
3271 {
3272 };
3273
3274 #if __has_feature(cxx_noexcept)
3275
3276 template <bool, class _Tp>
3277 struct __is_nothrow_swappable_imp
3278     : public integral_constant<bool, noexcept(swap(_VSTD::declval<_Tp&>(),
3279                                                    _VSTD::declval<_Tp&>()))>
3280 {
3281 };
3282
3283 template <class _Tp>
3284 struct __is_nothrow_swappable_imp<false, _Tp>
3285     : public false_type
3286 {
3287 };
3288
3289 template <class _Tp>
3290 struct __is_nothrow_swappable
3291     : public __is_nothrow_swappable_imp<__is_swappable<_Tp>::value, _Tp>
3292 {
3293 };
3294
3295 #else  // __has_feature(cxx_noexcept)
3296
3297 template <class _Tp>
3298 struct __is_nothrow_swappable
3299     : public false_type
3300 {
3301 };
3302
3303 #endif  // __has_feature(cxx_noexcept)
3304
3305 #ifdef _LIBCXX_UNDERLYING_TYPE
3306
3307 template <class _Tp>
3308 struct underlying_type
3309 {
3310     typedef _LIBCXX_UNDERLYING_TYPE(_Tp) type;
3311 };
3312
3313 #if _LIBCPP_STD_VER > 11
3314 template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
3315 #endif
3316
3317 #else  // _LIBCXX_UNDERLYING_TYPE
3318
3319 template <class _Tp, bool _Support = false>
3320 struct underlying_type
3321 {
3322     static_assert(_Support, "The underyling_type trait requires compiler "
3323                             "support. Either no such support exists or "
3324                             "libc++ does not know how to use it.");
3325 };
3326
3327 #endif // _LIBCXX_UNDERLYING_TYPE
3328
3329 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
3330
3331 template <class _Tp>
3332 struct __has_operator_addressof_imp
3333 {
3334     template <class>
3335         static auto __test(__any) -> false_type;
3336     template <class _Up>
3337         static auto __test(_Up* __u)
3338             -> typename __select_2nd<decltype(__u->operator&()), true_type>::type;
3339
3340     static const bool value = decltype(__test<_Tp>(nullptr))::value;
3341 };
3342
3343 template <class _Tp>
3344 struct __has_operator_addressof
3345     : public integral_constant<bool, __has_operator_addressof_imp<_Tp>::value>
3346 {};
3347
3348 #endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
3349
3350 _LIBCPP_END_NAMESPACE_STD
3351
3352 #endif  // _LIBCPP_TYPE_TRAITS