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