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