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