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