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    template <std::size_t Len, class... Types> struct aligned_union;
133
134    template <class T> struct decay;
135    template <class... T> struct common_type;
136    template <class T> struct underlying_type;
137    template <class> class result_of; // undefined
138    template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
139
140}  // std
141
142*/
143#include <__config>
144#include <cstddef>
145
146#pragma GCC system_header
147
148_LIBCPP_BEGIN_NAMESPACE_STD
149
150template <bool _B, class _If, class _Then>
151    struct _LIBCPP_VISIBLE conditional {typedef _If type;};
152template <class _If, class _Then>
153    struct _LIBCPP_VISIBLE conditional<false, _If, _Then> {typedef _Then type;};
154
155template <bool, class _Tp = void> struct _LIBCPP_VISIBLE enable_if {};
156template <class _Tp> struct _LIBCPP_VISIBLE enable_if<true, _Tp> {typedef _Tp type;};
157
158struct __two {char _[2];};
159
160// helper class:
161
162template <class _Tp, _Tp __v>
163struct _LIBCPP_VISIBLE integral_constant
164{
165    static constexpr _Tp      value = __v;
166    typedef _Tp               value_type;
167    typedef integral_constant type;
168    _LIBCPP_INLINE_VISIBILITY
169#ifndef _LIBCPP_HAS_NO_CONSTEXPR
170    constexpr
171#endif
172         operator value_type() const {return value;}
173};
174
175template <class _Tp, _Tp __v>
176const _Tp integral_constant<_Tp, __v>::value;
177
178typedef integral_constant<bool, true>  true_type;
179typedef integral_constant<bool, false> false_type;
180
181// is_const
182
183template <class _Tp> struct _LIBCPP_VISIBLE is_const            : public false_type {};
184template <class _Tp> struct _LIBCPP_VISIBLE is_const<_Tp const> : public true_type {};
185
186// is_volatile
187
188template <class _Tp> struct _LIBCPP_VISIBLE is_volatile               : public false_type {};
189template <class _Tp> struct _LIBCPP_VISIBLE is_volatile<_Tp volatile> : public true_type {};
190
191// remove_const
192
193template <class _Tp> struct _LIBCPP_VISIBLE remove_const            {typedef _Tp type;};
194template <class _Tp> struct _LIBCPP_VISIBLE remove_const<const _Tp> {typedef _Tp type;};
195
196// remove_volatile
197
198template <class _Tp> struct _LIBCPP_VISIBLE remove_volatile               {typedef _Tp type;};
199template <class _Tp> struct _LIBCPP_VISIBLE remove_volatile<volatile _Tp> {typedef _Tp type;};
200
201// remove_cv
202
203template <class _Tp> struct _LIBCPP_VISIBLE remove_cv
204{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
205
206// is_void
207
208template <class _Tp> struct __is_void       : public false_type {};
209template <>          struct __is_void<void> : public true_type {};
210
211template <class _Tp> struct _LIBCPP_VISIBLE is_void
212    : public __is_void<typename remove_cv<_Tp>::type> {};
213
214// is_integral
215
216template <class _Tp> struct __is_integral                     : public false_type {};
217template <>          struct __is_integral<bool>               : public true_type {};
218template <>          struct __is_integral<char>               : public true_type {};
219template <>          struct __is_integral<signed char>        : public true_type {};
220template <>          struct __is_integral<unsigned char>      : public true_type {};
221template <>          struct __is_integral<wchar_t>            : public true_type {};
222#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
223template <>          struct __is_integral<char16_t>           : public true_type {};
224template <>          struct __is_integral<char32_t>           : public true_type {};
225#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
226template <>          struct __is_integral<short>              : public true_type {};
227template <>          struct __is_integral<unsigned short>     : public true_type {};
228template <>          struct __is_integral<int>                : public true_type {};
229template <>          struct __is_integral<unsigned int>       : public true_type {};
230template <>          struct __is_integral<long>               : public true_type {};
231template <>          struct __is_integral<unsigned long>      : public true_type {};
232template <>          struct __is_integral<long long>          : public true_type {};
233template <>          struct __is_integral<unsigned long long> : public true_type {};
234
235template <class _Tp> struct _LIBCPP_VISIBLE is_integral
236    : public __is_integral<typename remove_cv<_Tp>::type> {};
237
238// is_floating_point
239
240template <class _Tp> struct __is_floating_point              : public false_type {};
241template <>          struct __is_floating_point<float>       : public true_type {};
242template <>          struct __is_floating_point<double>      : public true_type {};
243template <>          struct __is_floating_point<long double> : public true_type {};
244
245template <class _Tp> struct _LIBCPP_VISIBLE is_floating_point
246    : public __is_floating_point<typename remove_cv<_Tp>::type> {};
247
248// is_array
249
250template <class _Tp> struct _LIBCPP_VISIBLE is_array
251    : public false_type {};
252template <class _Tp> struct _LIBCPP_VISIBLE is_array<_Tp[]>
253    : public true_type {};
254template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE is_array<_Tp[_Np]>
255    : public true_type {};
256
257// is_pointer
258
259template <class _Tp> struct __is_pointer       : public false_type {};
260template <class _Tp> struct __is_pointer<_Tp*> : public true_type {};
261
262template <class _Tp> struct _LIBCPP_VISIBLE is_pointer
263    : public __is_pointer<typename remove_cv<_Tp>::type> {};
264
265// is_reference
266
267template <class _Tp> struct _LIBCPP_VISIBLE is_lvalue_reference       : public false_type {};
268template <class _Tp> struct _LIBCPP_VISIBLE is_lvalue_reference<_Tp&> : public true_type {};
269
270template <class _Tp> struct _LIBCPP_VISIBLE is_rvalue_reference        : public false_type {};
271#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
272template <class _Tp> struct _LIBCPP_VISIBLE is_rvalue_reference<_Tp&&> : public true_type {};
273#endif
274
275template <class _Tp> struct _LIBCPP_VISIBLE is_reference        : public false_type {};
276template <class _Tp> struct _LIBCPP_VISIBLE is_reference<_Tp&>  : public true_type {};
277#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
278template <class _Tp> struct _LIBCPP_VISIBLE is_reference<_Tp&&> : public true_type {};
279#endif
280
281#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
282#define _LIBCPP_HAS_TYPE_TRAITS
283#endif
284
285// is_union
286
287#ifdef _LIBCPP_HAS_TYPE_TRAITS
288
289template <class _Tp> struct _LIBCPP_VISIBLE is_union
290    : public integral_constant<bool, __is_union(_Tp)> {};
291
292#else  // _LIBCPP_HAS_TYPE_TRAITS
293
294template <class _Tp> struct __libcpp_union : public false_type {};
295template <class _Tp> struct _LIBCPP_VISIBLE is_union
296    : public __libcpp_union<typename remove_cv<_Tp>::type> {};
297
298#endif  // _LIBCPP_HAS_TYPE_TRAITS
299
300// is_class
301
302#ifdef _LIBCPP_HAS_TYPE_TRAITS
303
304template <class _Tp> struct _LIBCPP_VISIBLE is_class
305    : public integral_constant<bool, __is_class(_Tp)> {};
306
307#else  // _LIBCPP_HAS_TYPE_TRAITS
308
309namespace __is_class_imp
310{
311template <class _Tp> char  __test(int _Tp::*);
312template <class _Tp> __two __test(...);
313}
314
315template <class _Tp> struct _LIBCPP_VISIBLE is_class
316    : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
317
318#endif  // _LIBCPP_HAS_TYPE_TRAITS
319
320// is_function
321
322namespace __is_function_imp
323{
324template <class _Tp> char  __test(_Tp*);
325template <class _Tp> __two __test(...);
326template <class _Tp> _Tp&  __source();
327}
328
329template <class _Tp, bool = is_class<_Tp>::value ||
330                            is_union<_Tp>::value ||
331                            is_void<_Tp>::value  ||
332                            is_reference<_Tp>::value>
333struct __is_function
334    : public integral_constant<bool, sizeof(__is_function_imp::__test<_Tp>(__is_function_imp::__source<_Tp>())) == 1>
335    {};
336template <class _Tp> struct __is_function<_Tp, true> : public false_type {};
337
338template <class _Tp> struct _LIBCPP_VISIBLE is_function
339    : public __is_function<_Tp> {};
340
341// is_member_function_pointer
342
343template <class _Tp> struct            __is_member_function_pointer             : public false_type {};
344template <class _Tp, class _Up> struct __is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
345
346template <class _Tp> struct _LIBCPP_VISIBLE is_member_function_pointer
347    : public __is_member_function_pointer<typename remove_cv<_Tp>::type> {};
348
349// is_member_pointer
350
351template <class _Tp>            struct __is_member_pointer             : public false_type {};
352template <class _Tp, class _Up> struct __is_member_pointer<_Tp _Up::*> : public true_type {};
353
354template <class _Tp> struct _LIBCPP_VISIBLE is_member_pointer
355    : public __is_member_pointer<typename remove_cv<_Tp>::type> {};
356
357// is_member_object_pointer
358
359template <class _Tp> struct _LIBCPP_VISIBLE is_member_object_pointer
360    : public integral_constant<bool, is_member_pointer<_Tp>::value &&
361                                    !is_member_function_pointer<_Tp>::value> {};
362
363// is_enum
364
365#ifdef _LIBCPP_HAS_TYPE_TRAITS
366
367template <class _Tp> struct _LIBCPP_VISIBLE is_enum
368    : public integral_constant<bool, __is_enum(_Tp)> {};
369
370#else  // _LIBCPP_HAS_TYPE_TRAITS
371
372template <class _Tp> struct _LIBCPP_VISIBLE is_enum
373    : public integral_constant<bool, !is_void<_Tp>::value             &&
374                                     !is_integral<_Tp>::value         &&
375                                     !is_floating_point<_Tp>::value   &&
376                                     !is_array<_Tp>::value            &&
377                                     !is_pointer<_Tp>::value          &&
378                                     !is_reference<_Tp>::value        &&
379                                     !is_member_pointer<_Tp>::value   &&
380                                     !is_union<_Tp>::value            &&
381                                     !is_class<_Tp>::value            &&
382                                     !is_function<_Tp>::value         > {};
383
384#endif  // _LIBCPP_HAS_TYPE_TRAITS
385
386// is_arithmetic
387
388template <class _Tp> struct _LIBCPP_VISIBLE is_arithmetic
389    : public integral_constant<bool, is_integral<_Tp>::value      ||
390                                     is_floating_point<_Tp>::value> {};
391
392// is_fundamental
393
394template <class _Tp> struct _LIBCPP_VISIBLE is_fundamental
395    : public integral_constant<bool, is_void<_Tp>::value      ||
396                                     is_arithmetic<_Tp>::value> {};
397
398// is_scalar
399
400template <class _Tp> struct _LIBCPP_VISIBLE is_scalar
401    : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
402                                     is_member_pointer<_Tp>::value ||
403                                     is_pointer<_Tp>::value        ||
404                                     is_enum<_Tp>::value           > {};
405
406// is_object
407
408template <class _Tp> struct _LIBCPP_VISIBLE is_object
409    : public integral_constant<bool, is_scalar<_Tp>::value ||
410                                     is_array<_Tp>::value  ||
411                                     is_union<_Tp>::value  ||
412                                     is_class<_Tp>::value  > {};
413
414// is_compound
415
416template <class _Tp> struct _LIBCPP_VISIBLE is_compound
417    : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
418
419// add_const
420
421template <class _Tp, bool = is_reference<_Tp>::value ||
422                            is_function<_Tp>::value  ||
423                            is_const<_Tp>::value     >
424struct __add_const             {typedef _Tp type;};
425
426template <class _Tp>
427struct __add_const<_Tp, false> {typedef const _Tp type;};
428
429template <class _Tp> struct _LIBCPP_VISIBLE add_const
430    {typedef typename __add_const<_Tp>::type type;};
431
432// add_volatile
433
434template <class _Tp, bool = is_reference<_Tp>::value ||
435                            is_function<_Tp>::value  ||
436                            is_volatile<_Tp>::value  >
437struct __add_volatile             {typedef _Tp type;};
438
439template <class _Tp>
440struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
441
442template <class _Tp> struct _LIBCPP_VISIBLE add_volatile
443    {typedef typename __add_volatile<_Tp>::type type;};
444
445// add_cv
446
447template <class _Tp> struct _LIBCPP_VISIBLE add_cv
448    {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;};
449
450// remove_reference
451
452template <class _Tp> struct _LIBCPP_VISIBLE remove_reference        {typedef _Tp type;};
453template <class _Tp> struct _LIBCPP_VISIBLE remove_reference<_Tp&>  {typedef _Tp type;};
454#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
455template <class _Tp> struct _LIBCPP_VISIBLE remove_reference<_Tp&&> {typedef _Tp type;};
456#endif
457
458// add_lvalue_reference
459
460template <class _Tp> struct _LIBCPP_VISIBLE add_lvalue_reference                      {typedef _Tp& type;};
461template <class _Tp> struct _LIBCPP_VISIBLE add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
462template <>          struct _LIBCPP_VISIBLE add_lvalue_reference<void>                {typedef void type;};
463template <>          struct _LIBCPP_VISIBLE add_lvalue_reference<const void>          {typedef const void type;};
464template <>          struct _LIBCPP_VISIBLE add_lvalue_reference<volatile void>       {typedef volatile void type;};
465template <>          struct _LIBCPP_VISIBLE add_lvalue_reference<const volatile void> {typedef const volatile void type;};
466
467#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
468
469template <class _Tp> struct _LIBCPP_VISIBLE  add_rvalue_reference                     {typedef _Tp&& type;};
470template <>          struct _LIBCPP_VISIBLE add_rvalue_reference<void>                {typedef void type;};
471template <>          struct _LIBCPP_VISIBLE add_rvalue_reference<const void>          {typedef const void type;};
472template <>          struct _LIBCPP_VISIBLE add_rvalue_reference<volatile void>       {typedef volatile void type;};
473template <>          struct _LIBCPP_VISIBLE add_rvalue_reference<const volatile void> {typedef const volatile void type;};
474
475#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
476
477#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
478
479template <class _Tp>
480typename add_rvalue_reference<_Tp>::type
481declval();
482
483#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
484
485template <class _Tp>
486typename add_lvalue_reference<_Tp>::type
487declval();
488
489#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
490
491struct __any
492{
493    __any(...);
494};
495
496// remove_pointer
497
498template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer                      {typedef _Tp type;};
499template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp*>                {typedef _Tp type;};
500template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* const>          {typedef _Tp type;};
501template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* volatile>       {typedef _Tp type;};
502template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* const volatile> {typedef _Tp type;};
503
504// add_pointer
505
506template <class _Tp> struct _LIBCPP_VISIBLE add_pointer
507    {typedef typename remove_reference<_Tp>::type* type;};
508
509// is_signed
510
511template <class _Tp, bool = is_integral<_Tp>::value>
512struct ___is_signed : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};
513
514template <class _Tp>
515struct ___is_signed<_Tp, false> : public true_type {};  // floating point
516
517template <class _Tp, bool = is_arithmetic<_Tp>::value>
518struct __is_signed : public ___is_signed<_Tp> {};
519
520template <class _Tp> struct __is_signed<_Tp, false> : public false_type {};
521
522template <class _Tp> struct _LIBCPP_VISIBLE is_signed : public __is_signed<_Tp> {};
523
524// is_unsigned
525
526template <class _Tp, bool = is_integral<_Tp>::value>
527struct ___is_unsigned : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};
528
529template <class _Tp>
530struct ___is_unsigned<_Tp, false> : public false_type {};  // floating point
531
532template <class _Tp, bool = is_arithmetic<_Tp>::value>
533struct __is_unsigned : public ___is_unsigned<_Tp> {};
534
535template <class _Tp> struct __is_unsigned<_Tp, false> : public false_type {};
536
537template <class _Tp> struct _LIBCPP_VISIBLE is_unsigned : public __is_unsigned<_Tp> {};
538
539// rank
540
541template <class _Tp> struct _LIBCPP_VISIBLE rank
542    : public integral_constant<size_t, 0> {};
543template <class _Tp> struct _LIBCPP_VISIBLE rank<_Tp[]>
544    : public integral_constant<size_t, rank<_Tp>::value + 1> {};
545template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE rank<_Tp[_Np]>
546    : public integral_constant<size_t, rank<_Tp>::value + 1> {};
547
548// extent
549
550template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_VISIBLE extent
551    : public integral_constant<size_t, 0> {};
552template <class _Tp> struct _LIBCPP_VISIBLE extent<_Tp[], 0>
553    : public integral_constant<size_t, 0> {};
554template <class _Tp, unsigned _Ip> struct _LIBCPP_VISIBLE extent<_Tp[], _Ip>
555    : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
556template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE extent<_Tp[_Np], 0>
557    : public integral_constant<size_t, _Np> {};
558template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_VISIBLE extent<_Tp[_Np], _Ip>
559    : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
560
561// remove_extent
562
563template <class _Tp> struct _LIBCPP_VISIBLE remove_extent
564    {typedef _Tp type;};
565template <class _Tp> struct _LIBCPP_VISIBLE remove_extent<_Tp[]>
566    {typedef _Tp type;};
567template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE remove_extent<_Tp[_Np]>
568    {typedef _Tp type;};
569
570// remove_all_extents
571
572template <class _Tp> struct _LIBCPP_VISIBLE remove_all_extents
573    {typedef _Tp type;};
574template <class _Tp> struct _LIBCPP_VISIBLE remove_all_extents<_Tp[]>
575    {typedef typename remove_all_extents<_Tp>::type type;};
576template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE remove_all_extents<_Tp[_Np]>
577    {typedef typename remove_all_extents<_Tp>::type type;};
578
579// is_same
580
581template <class _Tp, class _Up> struct _LIBCPP_VISIBLE is_same           : public false_type {};
582template <class _Tp>            struct _LIBCPP_VISIBLE is_same<_Tp, _Tp> : public true_type {};
583
584// is_abstract
585
586namespace __is_abstract_imp
587{
588template <class _Tp> char  __test(_Tp (*)[1]);
589template <class _Tp> __two __test(...);
590}
591
592template <class _Tp, bool = is_class<_Tp>::value>
593struct __libcpp_abstract : public integral_constant<bool, sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
594
595template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {};
596
597template <class _Tp> struct _LIBCPP_VISIBLE is_abstract : public __libcpp_abstract<_Tp> {};
598
599// is_convertible
600
601namespace __is_convertible_imp
602{
603template <class _Tp> char  __test(_Tp);
604template <class _Tp> __two __test(...);
605#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
606template <class _Tp> _Tp&& __source();
607#else
608template <class _Tp> typename remove_reference<_Tp>::type& __source();
609#endif
610
611template <class _Tp, bool _IsArray =    is_array<_Tp>::value,
612                     bool _IsFunction = is_function<_Tp>::value,
613                     bool _IsVoid =     is_void<_Tp>::value>
614                     struct __is_array_function_or_void                          {enum {value = 0};};
615template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
616template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
617template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
618}
619
620template <class _Tp,
621    unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
622struct __is_convertible_check
623{
624    static const size_t __v = 0;
625};
626
627template <class _Tp>
628struct __is_convertible_check<_Tp, 0>
629{
630    static const size_t __v = sizeof(_Tp);
631};
632
633template <class _T1, class _T2,
634    unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
635    unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
636struct __is_convertible
637    : public integral_constant<bool,
638        sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
639    >
640{};
641
642template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 0> : false_type {};
643
644template <class _T1> struct __is_convertible<_T1, const _T1&, 1, 0> : true_type {};
645#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
646template <class _T1> struct __is_convertible<_T1, _T1&&, 1, 0> : true_type {};
647template <class _T1> struct __is_convertible<_T1, const _T1&&, 1, 0> : true_type {};
648template <class _T1> struct __is_convertible<_T1, volatile _T1&&, 1, 0> : true_type {};
649template <class _T1> struct __is_convertible<_T1, const volatile _T1&&, 1, 0> : true_type {};
650#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
651
652template <class _T1, class _T2> struct __is_convertible<_T1, _T2*, 1, 0>
653    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*>::value> {};
654
655template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const, 1, 0>
656    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const>::value> {};
657
658template <class _T1, class _T2> struct __is_convertible<_T1, _T2* volatile, 1, 0>
659    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*volatile>::value> {};
660
661template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const volatile, 1, 0>
662    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const volatile>::value> {};
663
664template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 0>                : public false_type {};
665#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
666template <class _T1>            struct __is_convertible<_T1, _T1&&, 2, 0>               : public true_type {};
667#endif
668template <class _T1>            struct __is_convertible<_T1, _T1*, 2, 0>               : public true_type {};
669template <class _T1>            struct __is_convertible<_T1, _T1*const, 2, 0>          : public true_type {};
670template <class _T1>            struct __is_convertible<_T1, _T1*volatile, 2, 0>       : public true_type {};
671template <class _T1>            struct __is_convertible<_T1, _T1*const volatile, 2, 0> : public true_type {};
672
673template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 0> : public false_type {};
674
675template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
676template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
677template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
678template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
679
680template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
681template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
682template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
683template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
684
685template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
686template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
687template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
688template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
689
690template <class _T1, class _T2> struct _LIBCPP_VISIBLE is_convertible
691    : public __is_convertible<_T1, _T2>
692{
693    static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
694    static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
695};
696
697// is_base_of
698
699//  (C) Copyright Rani Sharoni 2003.
700//  Use, modification and distribution are subject to the Boost Software License,
701//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
702//  http://www.boost.org/LICENSE_1_0.txt).
703//
704//  See http://www.boost.org/libs/type_traits for most recent version including documentation.
705
706template <class _Bp, class _Dp>
707struct __is_base_of_tests
708{
709    template <class _Tp>
710    static char  __test(const volatile _Dp*, _Tp);
711    static __two __test(const volatile _Bp*, int);
712};
713
714template <class _Bp, class _Dp>
715struct __is_base_of_imp
716{
717    struct __host
718    {
719        operator const volatile _Bp*() const;
720        operator const volatile _Dp*();
721    };
722
723    static const size_t __complete_check = sizeof(_Dp);
724    static const bool value = sizeof(__is_base_of_tests<_Bp, _Dp>::__test(__host(), 0)) == 1;
725};
726
727template <class _Bp, class _Dp, bool = is_class<_Bp>::value,
728                                bool = is_class<_Dp>::value,
729                                bool = is_same<_Bp, _Dp>::value>
730struct __libcpp_base_of : public false_type {};
731
732template <class _Bp, class _Dp>
733struct __libcpp_base_of<_Bp, _Dp, true, true, true> : public true_type {};
734
735template <class _Bp, class _Dp>
736struct __libcpp_base_of<_Bp, _Dp, true, true, false>
737    : public integral_constant<bool, __is_base_of_imp<_Bp, _Dp>::value> {};
738
739template <class _Bp, class _Dp>
740struct _LIBCPP_VISIBLE is_base_of
741    : public __libcpp_base_of<typename remove_cv<_Bp>::type, typename remove_cv<_Dp>::type>
742{
743};
744
745// is_empty
746
747template <class _Tp>
748struct __is_empty1
749    : public _Tp
750{
751    double _;
752};
753
754struct __is_empty2
755{
756    double _;
757};
758
759template <class _Tp, bool = is_class<_Tp>::value>
760struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
761
762template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
763
764template <class _Tp> struct _LIBCPP_VISIBLE is_empty : public __libcpp_empty<_Tp> {};
765
766// is_polymorphic
767
768template <class _Tp> struct __is_polymorphic1 : public _Tp {};
769template <class _Tp> struct __is_polymorphic2 : public _Tp {virtual ~__is_polymorphic2() throw();};
770
771template <class _Tp, bool = is_class<_Tp>::value>
772struct __libcpp_polymorphic
773    : public integral_constant<bool, sizeof(__is_polymorphic1<_Tp>) == sizeof(__is_polymorphic2<_Tp>)> {};
774
775template <class _Tp> struct __libcpp_polymorphic<_Tp, false> : public false_type {};
776
777template <class _Tp> struct _LIBCPP_VISIBLE is_polymorphic
778    : public __libcpp_polymorphic<_Tp> {};
779
780// has_virtual_destructor
781
782#ifdef _LIBCPP_HAS_TYPE_TRAITS
783
784template <class _Tp> struct _LIBCPP_VISIBLE has_virtual_destructor
785    : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
786
787#else  // _LIBCPP_HAS_TYPE_TRAITS
788
789template <class _Tp> struct _LIBCPP_VISIBLE has_virtual_destructor
790    : public false_type {};
791
792#endif  // _LIBCPP_HAS_TYPE_TRAITS
793
794// alignment_of
795
796template <class _Tp> struct __alignment_of {_Tp _;};
797
798template <class _Tp> struct _LIBCPP_VISIBLE alignment_of
799    : public integral_constant<size_t, __alignof__(__alignment_of<typename remove_all_extents<_Tp>::type>)> {};
800
801// aligned_storage
802
803template <class _Hp, class _Tp>
804struct __type_list
805{
806    typedef _Hp _Head;
807    typedef _Tp _Tail;
808};
809
810struct __nat {};
811
812template <class _Tp>
813struct __align_type
814{
815    static const size_t value = alignment_of<_Tp>::value;
816    typedef _Tp type;
817};
818
819struct __struct_double {long double _;};
820struct __struct_double4 {double _[4];};
821
822typedef
823    __type_list<__align_type<unsigned char>,
824    __type_list<__align_type<unsigned short>,
825    __type_list<__align_type<unsigned int>,
826    __type_list<__align_type<unsigned long>,
827    __type_list<__align_type<unsigned long long>,
828    __type_list<__align_type<double>,
829    __type_list<__align_type<long double>,
830    __type_list<__align_type<__struct_double>,
831    __type_list<__align_type<__struct_double4>,
832    __type_list<__align_type<int*>,
833    __nat
834    > > > > > > > > > > __all_types;
835
836template <class _TL, size_t _Align> struct __find_pod;
837
838template <class _Hp, size_t _Align>
839struct __find_pod<__type_list<_Hp, __nat>, _Align>
840{
841    typedef typename conditional<
842                             _Align == _Hp::value,
843                             typename _Hp::type,
844                             void
845                         >::type type;
846};
847
848template <class _Hp, class _Tp, size_t _Align>
849struct __find_pod<__type_list<_Hp, _Tp>, _Align>
850{
851    typedef typename conditional<
852                             _Align == _Hp::value,
853                             typename _Hp::type,
854                             typename __find_pod<_Tp, _Align>::type
855                         >::type type;
856};
857
858template <class _TL, size_t _Len> struct __find_max_align;
859
860template <class _Hp, size_t _Len>
861struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
862
863template <size_t _Len, size_t _A1, size_t _A2>
864struct __select_align
865{
866private:
867    static const size_t __min = _A2 < _A1 ? _A2 : _A1;
868    static const size_t __max = _A1 < _A2 ? _A2 : _A1;
869public:
870    static const size_t value = _Len < __max ? __min : __max;
871};
872
873template <class _Hp, class _Tp, size_t _Len>
874struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
875    : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
876
877template <size_t _Len, const size_t _Align = __find_max_align<__all_types, _Len>::value>
878struct _LIBCPP_VISIBLE aligned_storage
879{
880    typedef typename __find_pod<__all_types, _Align>::type _Aligner;
881    static_assert(!is_void<_Aligner>::value, "");
882    union type
883    {
884        _Aligner __align;
885        unsigned char __data[_Len];
886    };
887};
888
889#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
890template <size_t _Len>\
891struct __attribute__ ((__visibility__("default"))) aligned_storage<_Len, n>\
892{\
893    struct type\
894    {\
895        unsigned char _[_Len];\
896    } __attribute__((__aligned__(n)));\
897}
898
899_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
900_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
901_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
902_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
903_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
904_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
905_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
906_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
907_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
908_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
909_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
910_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
911_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
912_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
913_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
914
915#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
916
917// __promote
918
919template <class _A1, class _A2 = void, class _A3 = void,
920          bool = (is_arithmetic<_A1>::value || is_void<_A1>::value) &&
921                 (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
922                 (is_arithmetic<_A3>::value || is_void<_A3>::value)>
923class __promote {};
924
925template <class _A1, class _A2, class _A3>
926class __promote<_A1, _A2, _A3, true>
927{
928private:
929    typedef typename __promote<_A1>::type __type1;
930    typedef typename __promote<_A2>::type __type2;
931    typedef typename __promote<_A3>::type __type3;
932public:
933    typedef __typeof__(__type1() + __type2() + __type3()) type;
934};
935
936template <class _A1, class _A2>
937class __promote<_A1, _A2, void, true>
938{
939private:
940    typedef typename __promote<_A1>::type __type1;
941    typedef typename __promote<_A2>::type __type2;
942public:
943    typedef __typeof__(__type1() + __type2()) type;
944};
945
946template <class _A1>
947class __promote<_A1, void, void, true>
948{
949public:
950    typedef typename conditional<is_arithmetic<_A1>::value,
951                     typename conditional<is_integral<_A1>::value, double, _A1>::type,
952                     void
953            >::type type;
954};
955
956#ifdef _LIBCPP_STORE_AS_OPTIMIZATION
957
958// __transform
959
960template <class _Tp, size_t = sizeof(_Tp), bool = is_scalar<_Tp>::value> struct __transform {typedef _Tp type;};
961template <class _Tp> struct __transform<_Tp, 1, true> {typedef unsigned char      type;};
962template <class _Tp> struct __transform<_Tp, 2, true> {typedef unsigned short     type;};
963template <class _Tp> struct __transform<_Tp, 4, true> {typedef unsigned int       type;};
964template <class _Tp> struct __transform<_Tp, 8, true> {typedef unsigned long long type;};
965
966#endif  // _LIBCPP_STORE_AS_OPTIMIZATION
967
968// make_signed / make_unsigned
969
970typedef
971    __type_list<signed char,
972    __type_list<signed short,
973    __type_list<signed int,
974    __type_list<signed long,
975    __type_list<signed long long,
976    __nat
977    > > > > > __signed_types;
978
979typedef
980    __type_list<unsigned char,
981    __type_list<unsigned short,
982    __type_list<unsigned int,
983    __type_list<unsigned long,
984    __type_list<unsigned long long,
985    __nat
986    > > > > > __unsigned_types;
987
988template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
989
990template <class _Hp, class _Tp, size_t _Size>
991struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
992{
993    typedef _Hp type;
994};
995
996template <class _Hp, class _Tp, size_t _Size>
997struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
998{
999    typedef typename __find_first<_Tp, _Size>::type type;
1000};
1001
1002template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
1003                             bool = is_volatile<typename remove_reference<_Tp>::type>::value>
1004struct __apply_cv
1005{
1006    typedef _Up type;
1007};
1008
1009template <class _Tp, class _Up>
1010struct __apply_cv<_Tp, _Up, true, false>
1011{
1012    typedef const _Up type;
1013};
1014
1015template <class _Tp, class _Up>
1016struct __apply_cv<_Tp, _Up, false, true>
1017{
1018    typedef volatile _Up type;
1019};
1020
1021template <class _Tp, class _Up>
1022struct __apply_cv<_Tp, _Up, true, true>
1023{
1024    typedef const volatile _Up type;
1025};
1026
1027template <class _Tp, class _Up>
1028struct __apply_cv<_Tp&, _Up, false, false>
1029{
1030    typedef _Up& type;
1031};
1032
1033template <class _Tp, class _Up>
1034struct __apply_cv<_Tp&, _Up, true, false>
1035{
1036    typedef const _Up& type;
1037};
1038
1039template <class _Tp, class _Up>
1040struct __apply_cv<_Tp&, _Up, false, true>
1041{
1042    typedef volatile _Up& type;
1043};
1044
1045template <class _Tp, class _Up>
1046struct __apply_cv<_Tp&, _Up, true, true>
1047{
1048    typedef const volatile _Up& type;
1049};
1050
1051template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1052struct __make_signed {};
1053
1054template <class _Tp>
1055struct __make_signed<_Tp, true>
1056{
1057    typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
1058};
1059
1060template <> struct __make_signed<bool,               true> {};
1061template <> struct __make_signed<  signed short,     true> {typedef short     type;};
1062template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
1063template <> struct __make_signed<  signed int,       true> {typedef int       type;};
1064template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
1065template <> struct __make_signed<  signed long,      true> {typedef long      type;};
1066template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
1067template <> struct __make_signed<  signed long long, true> {typedef long long type;};
1068template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
1069
1070template <class _Tp>
1071struct _LIBCPP_VISIBLE make_signed
1072{
1073    typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
1074};
1075
1076template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1077struct __make_unsigned {};
1078
1079template <class _Tp>
1080struct __make_unsigned<_Tp, true>
1081{
1082    typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
1083};
1084
1085template <> struct __make_unsigned<bool,               true> {};
1086template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
1087template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
1088template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
1089template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
1090template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
1091template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
1092template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
1093template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
1094
1095template <class _Tp>
1096struct _LIBCPP_VISIBLE make_unsigned
1097{
1098    typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
1099};
1100
1101#ifdef _LIBCPP_HAS_NO_VARIADICS
1102
1103template <class _Tp, class _Up = void, class V = void>
1104struct _LIBCPP_VISIBLE common_type
1105{
1106public:
1107    typedef typename common_type<typename common_type<_Tp, _Up>::type, V>::type type;
1108};
1109
1110template <class _Tp>
1111struct _LIBCPP_VISIBLE common_type<_Tp, void, void>
1112{
1113public:
1114    typedef _Tp type;
1115};
1116
1117template <class _Tp, class _Up>
1118struct _LIBCPP_VISIBLE common_type<_Tp, _Up, void>
1119{
1120private:
1121#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1122    static _Tp&& __t();
1123    static _Up&& __u();
1124#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1125    static _Tp __t();
1126    static _Up __u();
1127#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1128public:
1129    typedef decltype(true ? __t() : __u()) type;
1130};
1131
1132#else  // _LIBCPP_HAS_NO_VARIADICS
1133
1134template <class ..._Tp> struct common_type;
1135
1136template <class _Tp>
1137struct _LIBCPP_VISIBLE common_type<_Tp>
1138{
1139    typedef _Tp type;
1140};
1141
1142template <class _Tp, class _Up>
1143struct _LIBCPP_VISIBLE common_type<_Tp, _Up>
1144{
1145private:
1146    static _Tp&& __t();
1147    static _Up&& __u();
1148    static bool __f();
1149public:
1150    typedef decltype(__f() ? __t() : __u()) type;
1151};
1152
1153template <class _Tp, class _Up, class ..._Vp>
1154struct _LIBCPP_VISIBLE common_type<_Tp, _Up, _Vp...>
1155{
1156    typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
1157};
1158
1159#endif  // _LIBCPP_HAS_NO_VARIADICS
1160
1161// is_assignable
1162
1163template <class _Tp, class _Arg>
1164decltype((_STD::declval<_Tp>() = _STD::declval<_Arg>(), true_type()))
1165#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1166__is_assignable_test(_Tp&&, _Arg&&);
1167#else
1168__is_assignable_test(_Tp&, _Arg&);
1169#endif
1170
1171template <class _Arg>
1172false_type
1173#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1174__is_assignable_test(__any, _Arg&&);
1175#else
1176__is_assignable_test(__any, _Arg&);
1177#endif
1178
1179template <class _Tp, class _Arg>
1180struct __is_assignable_imp
1181    : public common_type
1182        <
1183            decltype(__is_assignable_test(declval<_Tp>(), declval<_Arg>()))
1184        >::type {};
1185
1186template <class _Tp, class _Arg>
1187struct is_assignable
1188    : public __is_assignable_imp<_Tp, _Arg> {};
1189
1190// is_copy_assignable
1191
1192template <class _Tp> struct _LIBCPP_VISIBLE is_copy_assignable
1193    : public is_assignable<_Tp&, const _Tp&> {};
1194
1195// is_move_assignable
1196
1197template <class _Tp> struct _LIBCPP_VISIBLE is_move_assignable
1198#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1199    : public is_assignable<_Tp&, _Tp&&> {};
1200#else
1201    : public is_copy_assignable<_Tp> {};
1202#endif
1203
1204// is_destructible
1205
1206template <class _Tp>
1207struct __destructible_test
1208{
1209    _Tp __t;
1210};
1211
1212template <class _Tp>
1213decltype((_STD::declval<__destructible_test<_Tp> >().~__destructible_test<_Tp>(), true_type()))
1214#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1215__is_destructible_test(_Tp&&);
1216#else
1217__is_destructible_test(_Tp&);
1218#endif
1219
1220false_type
1221__is_destructible_test(__any);
1222
1223template <class _Tp, bool = is_void<_Tp>::value || is_abstract<_Tp>::value>
1224struct __destructible_imp
1225    : public common_type
1226        <
1227            decltype(__is_destructible_test(declval<_Tp>()))
1228        >::type {};
1229
1230template <class _Tp>
1231struct __destructible_imp<_Tp, true>
1232    : public false_type {};
1233
1234template <class _Tp>
1235struct is_destructible
1236    : public __destructible_imp<_Tp> {};
1237
1238// move
1239
1240#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1241
1242template <class _Tp>
1243inline _LIBCPP_INLINE_VISIBILITY
1244typename remove_reference<_Tp>::type&&
1245move(_Tp&& __t)
1246{
1247    typedef typename remove_reference<_Tp>::type _Up;
1248    return static_cast<_Up&&>(__t);
1249}
1250
1251template <class _Tp>
1252inline _LIBCPP_INLINE_VISIBILITY
1253_Tp&&
1254forward(typename std::remove_reference<_Tp>::type& __t)
1255{
1256    return static_cast<_Tp&&>(__t);
1257}
1258
1259template <class _Tp>
1260inline _LIBCPP_INLINE_VISIBILITY
1261_Tp&&
1262forward(typename std::remove_reference<_Tp>::type&& __t)
1263{
1264 	static_assert(!std::is_lvalue_reference<_Tp>::value,
1265 	              "Can not forward an rvalue as an lvalue.");
1266 	return static_cast<_Tp&&>(__t);
1267}
1268
1269#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1270
1271template <class _Tp>
1272class __rv
1273{
1274    typedef typename remove_reference<_Tp>::type _Trr;
1275    _Trr& t_;
1276public:
1277    _LIBCPP_INLINE_VISIBILITY
1278    _Trr* operator->() {return &t_;}
1279    _LIBCPP_INLINE_VISIBILITY
1280    explicit __rv(_Trr& __t) : t_(__t) {}
1281};
1282
1283template <class _Tp>
1284inline _LIBCPP_INLINE_VISIBILITY
1285typename enable_if
1286<
1287    !is_convertible<_Tp, __rv<_Tp> >::value,
1288    _Tp&
1289>::type
1290move(_Tp& __t)
1291{
1292    return __t;
1293}
1294
1295template <class _Tp>
1296inline _LIBCPP_INLINE_VISIBILITY
1297typename enable_if
1298<
1299    is_convertible<_Tp, __rv<_Tp> >::value,
1300    _Tp
1301>::type
1302move(_Tp& __t)
1303{
1304    return _Tp(__rv<_Tp>(__t));
1305}
1306
1307template <class _Tp, class _Up>
1308inline _LIBCPP_INLINE_VISIBILITY
1309typename enable_if
1310<
1311    !is_convertible<_Tp, __rv<_Tp> >::value,
1312    typename add_lvalue_reference<_Tp>::type
1313>::type
1314forward(_Up& __t)
1315{
1316    return __t;
1317}
1318
1319template <class _Tp, class _Up>
1320inline _LIBCPP_INLINE_VISIBILITY
1321typename enable_if
1322<
1323    !is_convertible<_Tp, __rv<_Tp> >::value,
1324    typename add_lvalue_reference<_Tp>::type
1325>::type
1326forward(const _Up& __t)
1327{
1328    return __t;
1329}
1330
1331template <class _Tp, class _Up>
1332inline _LIBCPP_INLINE_VISIBILITY
1333typename enable_if
1334<
1335    is_convertible<_Tp, __rv<_Tp> >::value,
1336    _Tp
1337>::type
1338forward(_Up& __t)
1339{
1340    return _Tp(__rv<_Tp>(__t));
1341}
1342
1343template <class _Tp, class _Up>
1344inline _LIBCPP_INLINE_VISIBILITY
1345typename enable_if
1346<
1347    is_convertible<_Tp, __rv<_Tp> >::value,
1348    _Tp
1349>::type
1350forward(const _Up& __t)
1351{
1352    return _Tp(__rv<_Tp>(__t));
1353}
1354
1355#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1356
1357template <class _Tp>
1358struct _LIBCPP_VISIBLE decay
1359{
1360private:
1361    typedef typename remove_reference<_Tp>::type _Up;
1362public:
1363    typedef typename conditional
1364                     <
1365                         is_array<_Up>::value,
1366                         typename remove_extent<_Up>::type*,
1367                         typename conditional
1368                         <
1369                              is_function<_Up>::value,
1370                              typename add_pointer<_Up>::type,
1371                              typename remove_cv<_Up>::type
1372                         >::type
1373                     >::type type;
1374};
1375
1376// result_of
1377
1378template <class> class result_of;
1379
1380template <class _Fn, bool>
1381class __result_of
1382{
1383};
1384
1385#ifndef _LIBCPP_HAS_NO_VARIADICS
1386
1387template <class _Fn, class ..._ArgTypes>
1388class __result_of<_Fn(_ArgTypes...), true>
1389{
1390public:
1391    typedef decltype(declval<_Fn>()(declval<_ArgTypes>()...)) type;
1392};
1393
1394template <class _MP, class _Tp, bool _IsMemberFunctionPtr, class ..._Args>
1395struct __result_of_mp {};
1396
1397// member function pointer
1398
1399template <class _R, class _Class, class _Tp, class ..._Params, class ..._Args>
1400struct __result_of_mp<_R (_Class::*)(_Params...), _Tp, true, _Args...>
1401{
1402    typedef _R type;
1403};
1404
1405template <class _R, class _Class, class _Tp, class ..._Params, class ..._Args>
1406struct __result_of_mp<_R (_Class::*)(_Params...) const, _Tp, true, _Args...>
1407{
1408    typedef _R type;
1409};
1410
1411template <class _R, class _Class, class _Tp, class ..._Params, class ..._Args>
1412struct __result_of_mp<_R (_Class::*)(_Params...) volatile, _Tp, true, _Args...>
1413{
1414    typedef _R type;
1415};
1416
1417template <class _R, class _Class, class _Tp, class ..._Params, class ..._Args>
1418struct __result_of_mp<_R (_Class::*)(_Params...) const volatile, _Tp, true, _Args...>
1419{
1420    typedef _R type;
1421};
1422
1423// member data pointer
1424
1425template <class _MP, class _Tp, bool>
1426struct __result_of_mdp;
1427
1428template <class _R, class _Class, class _Tp>
1429struct __result_of_mdp<_R _Class::*, _Tp, false>
1430{
1431    typedef typename __apply_cv<decltype(*_STD::declval<_Tp>()), _R>::type type;
1432};
1433
1434template <class _R, class _Class, class _Tp>
1435struct __result_of_mdp<_R _Class::*, _Tp, true>
1436{
1437    typedef typename __apply_cv<_Tp, _R>::type&& type;
1438};
1439
1440template <class _R, class _Class, class _Tp>
1441struct __result_of_mp<_R _Class::*, _Tp, false>
1442    : public __result_of_mdp<_R _Class::*, _Tp,
1443            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
1444{
1445};
1446
1447template <class _Fn, class _Tp, class ..._ArgTypes>
1448class __result_of<_Fn(_Tp, _ArgTypes...), false>  // _Fn must be member pointer
1449    : public __result_of_mp<_Fn, _Tp, is_member_function_pointer<_Fn>::value,
1450                            _ArgTypes...>
1451{
1452};
1453
1454// result_of
1455
1456template <class _Fn, class ..._ArgTypes>
1457class _LIBCPP_VISIBLE result_of<_Fn(_ArgTypes...)>
1458    : public __result_of<_Fn(_ArgTypes...),
1459                         is_class<typename remove_reference<_Fn>::type>::value ||
1460                         is_function<typename remove_pointer<
1461                                        typename remove_reference<_Fn>::type
1462                                                            >::type
1463                                    >::value
1464                        >
1465{
1466};
1467
1468#else  // _LIBCPP_HAS_NO_VARIADICS
1469
1470template <class _Fn>
1471class __result_of<_Fn(), true>
1472{
1473public:
1474    typedef decltype(declval<_Fn>()()) type;
1475};
1476
1477template <class _Fn, class _A0>
1478class __result_of<_Fn(_A0), true>
1479{
1480public:
1481    typedef decltype(declval<_Fn>()(declval<_A0>())) type;
1482};
1483
1484template <class _Fn, class _A0, class _A1>
1485class __result_of<_Fn(_A0, _A1), true>
1486{
1487public:
1488    typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
1489};
1490
1491template <class _Fn, class _A0, class _A1, class _A2>
1492class __result_of<_Fn(_A0, _A1, _A2), true>
1493{
1494public:
1495    typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
1496};
1497
1498template <class _Fn>
1499class _LIBCPP_VISIBLE result_of<_Fn()>
1500    : public __result_of<_Fn(),
1501                         is_class<typename remove_reference<_Fn>::type>::value ||
1502                         is_function<typename remove_pointer<
1503                                        typename remove_reference<_Fn>::type
1504                                                            >::type
1505                                    >::value
1506                        >
1507{
1508};
1509
1510template <class _Fn, class _A0>
1511class _LIBCPP_VISIBLE result_of<_Fn(_A0)>
1512    : public __result_of<_Fn(_A0),
1513                         is_class<typename remove_reference<_Fn>::type>::value ||
1514                         is_function<typename remove_pointer<
1515                                        typename remove_reference<_Fn>::type
1516                                                            >::type
1517                                    >::value
1518                        >
1519{
1520};
1521
1522template <class _Fn, class _A0, class _A1>
1523class _LIBCPP_VISIBLE result_of<_Fn(_A0, _A1)>
1524    : public __result_of<_Fn(_A0, _A1),
1525                         is_class<typename remove_reference<_Fn>::type>::value ||
1526                         is_function<typename remove_pointer<
1527                                        typename remove_reference<_Fn>::type
1528                                                            >::type
1529                                    >::value
1530                        >
1531{
1532};
1533
1534template <class _Fn, class _A0, class _A1, class _A2>
1535class _LIBCPP_VISIBLE result_of<_Fn(_A0, _A1, _A2)>
1536    : public __result_of<_Fn(_A0, _A1, _A2),
1537                         is_class<typename remove_reference<_Fn>::type>::value ||
1538                         is_function<typename remove_pointer<
1539                                        typename remove_reference<_Fn>::type
1540                                                            >::type
1541                                    >::value
1542                        >
1543{
1544};
1545
1546#endif  // _LIBCPP_HAS_NO_VARIADICS
1547
1548#ifndef _LIBCPP_HAS_NO_VARIADICS
1549
1550// template <class T, class... Args> struct is_constructible;
1551
1552//      main is_constructible test
1553
1554template <class _Tp, class ..._Args>
1555decltype(_STD::move(_Tp(_STD::declval<_Args>()...)), true_type())
1556__is_constructible_test(_Tp&&, _Args&& ...);
1557
1558template <class ..._Args>
1559false_type
1560__is_constructible_test(__any, _Args&& ...);
1561
1562template <bool, class _Tp, class... _Args>
1563struct __is_constructible // false, _Tp is not a scalar
1564    : public common_type
1565             <
1566                 decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...))
1567             >::type
1568    {};
1569
1570//      function types are not constructible
1571
1572template <class _R, class... _A1, class... _A2>
1573struct __is_constructible<false, _R(_A1...), _A2...>
1574    : public false_type
1575    {};
1576
1577//      handle scalars and reference types
1578
1579//      Scalars are default constructible, references are not
1580
1581template <class _Tp>
1582struct __is_constructible<true, _Tp>
1583    : public is_scalar<_Tp>
1584    {};
1585
1586//      Scalars and references are constructible from one arg if that arg is
1587//          implicitly convertible to the scalar or reference.
1588
1589template <class _Tp>
1590struct __is_constructible_ref
1591{
1592    true_type static __(_Tp);
1593    false_type static __(...);
1594};
1595
1596template <class _Tp, class _A0>
1597struct __is_constructible<true, _Tp, _A0>
1598    : public common_type
1599             <
1600                 decltype(__is_constructible_ref<_Tp>::__(declval<_A0>()))
1601             >::type
1602    {};
1603
1604//      Scalars and references are not constructible from multiple args.
1605
1606template <class _Tp, class _A0, class ..._Args>
1607struct __is_constructible<true, _Tp, _A0, _Args...>
1608    : public false_type
1609    {};
1610
1611//      Treat scalars and reference types separately
1612
1613template <bool, class _Tp, class... _Args>
1614struct __is_constructible_void_check
1615    : public __is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
1616                                _Tp, _Args...>
1617    {};
1618
1619//      If any of T or Args is void, is_constructible should be false
1620
1621template <class _Tp, class... _Args>
1622struct __is_constructible_void_check<true, _Tp, _Args...>
1623    : public false_type
1624    {};
1625
1626template <class ..._Args> struct __contains_void;
1627
1628template <> struct __contains_void<> : false_type {};
1629
1630template <class _A0, class ..._Args>
1631struct __contains_void<_A0, _Args...>
1632{
1633    static const bool value = is_void<_A0>::value ||
1634                              __contains_void<_Args...>::value;
1635};
1636
1637//      is_constructible entry point
1638
1639template <class _Tp, class... _Args>
1640struct _LIBCPP_VISIBLE is_constructible
1641    : public __is_constructible_void_check<__contains_void<_Tp, _Args...>::value
1642                                        || is_abstract<_Tp>::value,
1643                                           _Tp, _Args...>
1644    {};
1645
1646//      Array types are default constructible if their element type
1647//      is default constructible
1648
1649template <class _A, size_t _N>
1650struct __is_constructible<false, _A[_N]>
1651    : public is_constructible<typename remove_all_extents<_A>::type>
1652    {};
1653
1654//      Otherwise array types are not constructible by this syntax
1655
1656template <class _A, size_t _N, class ..._Args>
1657struct __is_constructible<false, _A[_N], _Args...>
1658    : public false_type
1659    {};
1660
1661//      Incomplete array types are not constructible
1662
1663template <class _A, class ..._Args>
1664struct __is_constructible<false, _A[], _Args...>
1665    : public false_type
1666    {};
1667
1668#else  // _LIBCPP_HAS_NO_VARIADICS
1669
1670// template <class T> struct is_constructible0;
1671
1672//      main is_constructible0 test
1673
1674template <class _Tp>
1675decltype((_Tp(), true_type()))
1676__is_constructible0_test(_Tp&);
1677
1678false_type
1679__is_constructible0_test(__any);
1680
1681template <class _Tp, class _A0>
1682decltype((_Tp(_STD::declval<_A0>()), true_type()))
1683__is_constructible1_test(_Tp&, _A0&);
1684
1685template <class _A0>
1686false_type
1687__is_constructible1_test(__any, _A0&);
1688
1689template <class _Tp, class _A0, class _A1>
1690decltype((_Tp(_STD::declval<_A0>(), _STD::declval<_A1>()), true_type()))
1691__is_constructible2_test(_Tp&, _A0&, _A1&);
1692
1693template <class _A0, class _A1>
1694false_type
1695__is_constructible2_test(__any, _A0&, _A1&);
1696
1697template <bool, class _Tp>
1698struct __is_constructible0_imp // false, _Tp is not a scalar
1699    : public common_type
1700             <
1701                 decltype(__is_constructible0_test(declval<_Tp&>()))
1702             >::type
1703    {};
1704
1705template <bool, class _Tp, class _A0>
1706struct __is_constructible1_imp // false, _Tp is not a scalar
1707    : public common_type
1708             <
1709                 decltype(__is_constructible1_test(declval<_Tp&>(), declval<_A0&>()))
1710             >::type
1711    {};
1712
1713template <bool, class _Tp, class _A0, class _A1>
1714struct __is_constructible2_imp // false, _Tp is not a scalar
1715    : public common_type
1716             <
1717                 decltype(__is_constructible2_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>()))
1718             >::type
1719    {};
1720
1721//      handle scalars and reference types
1722
1723//      Scalars are default constructible, references are not
1724
1725template <class _Tp>
1726struct __is_constructible0_imp<true, _Tp>
1727    : public is_scalar<_Tp>
1728    {};
1729
1730template <class _Tp, class _A0>
1731struct __is_constructible1_imp<true, _Tp, _A0>
1732    : public is_convertible<_A0, _Tp>
1733    {};
1734
1735template <class _Tp, class _A0, class _A1>
1736struct __is_constructible2_imp<true, _Tp, _A0, _A1>
1737    : public false_type
1738    {};
1739
1740//      Treat scalars and reference types separately
1741
1742template <bool, class _Tp>
1743struct __is_constructible0_void_check
1744    : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
1745                                _Tp>
1746    {};
1747
1748template <bool, class _Tp, class _A0>
1749struct __is_constructible1_void_check
1750    : public __is_constructible1_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
1751                                _Tp, _A0>
1752    {};
1753
1754template <bool, class _Tp, class _A0, class _A1>
1755struct __is_constructible2_void_check
1756    : public __is_constructible2_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
1757                                _Tp, _A0, _A1>
1758    {};
1759
1760//      If any of T or Args is void, is_constructible should be false
1761
1762template <class _Tp>
1763struct __is_constructible0_void_check<true, _Tp>
1764    : public false_type
1765    {};
1766
1767template <class _Tp, class _A0>
1768struct __is_constructible1_void_check<true, _Tp, _A0>
1769    : public false_type
1770    {};
1771
1772template <class _Tp, class _A0, class _A1>
1773struct __is_constructible2_void_check<true, _Tp, _A0, _A1>
1774    : public false_type
1775    {};
1776
1777//      is_constructible entry point
1778
1779namespace __is_construct
1780{
1781
1782struct __nat {};
1783
1784}
1785
1786template <class _Tp, class _A0 = __is_construct::__nat,
1787                     class _A1 = __is_construct::__nat>
1788struct _LIBCPP_VISIBLE is_constructible
1789    : public __is_constructible2_void_check<is_void<_Tp>::value
1790                                        || is_abstract<_Tp>::value
1791                                        || is_function<_Tp>::value
1792                                        || is_void<_A0>::value
1793                                        || is_void<_A1>::value,
1794                                           _Tp, _A0, _A1>
1795    {};
1796
1797template <class _Tp>
1798struct _LIBCPP_VISIBLE is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat>
1799    : public __is_constructible0_void_check<is_void<_Tp>::value
1800                                        || is_abstract<_Tp>::value
1801                                        || is_function<_Tp>::value,
1802                                           _Tp>
1803    {};
1804
1805template <class _Tp, class _A0>
1806struct _LIBCPP_VISIBLE is_constructible<_Tp, _A0, __is_construct::__nat>
1807    : public __is_constructible1_void_check<is_void<_Tp>::value
1808                                        || is_abstract<_Tp>::value
1809                                        || is_function<_Tp>::value
1810                                        || is_void<_A0>::value,
1811                                           _Tp, _A0>
1812    {};
1813
1814//      Array types are default constructible if their element type
1815//      is default constructible
1816
1817template <class _A, size_t _N>
1818struct __is_constructible0_imp<false, _A[_N]>
1819    : public is_constructible<typename remove_all_extents<_A>::type>
1820    {};
1821
1822template <class _A, size_t _N, class _A0>
1823struct __is_constructible1_imp<false, _A[_N], _A0>
1824    : public false_type
1825    {};
1826
1827template <class _A, size_t _N, class _A0, class _A1>
1828struct __is_constructible2_imp<false, _A[_N], _A0, _A1>
1829    : public false_type
1830    {};
1831
1832//      Incomplete array types are not constructible
1833
1834template <class _A>
1835struct __is_constructible0_imp<false, _A[]>
1836    : public false_type
1837    {};
1838
1839template <class _A, class _A0>
1840struct __is_constructible1_imp<false, _A[], _A0>
1841    : public false_type
1842    {};
1843
1844template <class _A, class _A0, class _A1>
1845struct __is_constructible2_imp<false, _A[], _A0, _A1>
1846    : public false_type
1847    {};
1848
1849#endif  // _LIBCPP_HAS_NO_VARIADICS
1850
1851// is_default_constructible
1852
1853template <class _Tp>
1854struct _LIBCPP_VISIBLE is_default_constructible
1855    : public is_constructible<_Tp>
1856    {};
1857
1858// is_copy_constructible
1859
1860template <class _Tp>
1861struct _LIBCPP_VISIBLE is_copy_constructible
1862    : public is_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
1863    {};
1864
1865// is_move_constructible
1866
1867template <class _Tp>
1868struct _LIBCPP_VISIBLE is_move_constructible
1869#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1870    : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
1871#else
1872    : public is_copy_constructible<_Tp>
1873#endif
1874    {};
1875
1876// is_trivially_constructible
1877
1878#ifndef _LIBCPP_HAS_NO_VARIADICS
1879
1880template <class _Tp, class... _Args>
1881struct _LIBCPP_VISIBLE is_trivially_constructible
1882    : false_type
1883{
1884};
1885
1886template <class _Tp>
1887struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp>
1888#ifdef _LIBCPP_HAS_TYPE_TRAITS
1889    : integral_constant<bool, __has_trivial_constructor(_Tp)>
1890#else
1891    : integral_constant<bool, is_scalar<_Tp>::value>
1892#endif
1893{
1894};
1895
1896template <class _Tp>
1897#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1898struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&&>
1899#else
1900struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp>
1901#endif
1902#ifdef _LIBCPP_HAS_TYPE_TRAITS
1903    : integral_constant<bool, __has_trivial_copy(_Tp)>
1904#else
1905    : integral_constant<bool, is_scalar<_Tp>::value>
1906#endif
1907{
1908};
1909
1910template <class _Tp>
1911struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&>
1912#ifdef _LIBCPP_HAS_TYPE_TRAITS
1913    : integral_constant<bool, __has_trivial_copy(_Tp)>
1914#else
1915    : integral_constant<bool, is_scalar<_Tp>::value>
1916#endif
1917{
1918};
1919
1920template <class _Tp>
1921struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&>
1922#ifdef _LIBCPP_HAS_TYPE_TRAITS
1923    : integral_constant<bool, __has_trivial_copy(_Tp)>
1924#else
1925    : integral_constant<bool, is_scalar<_Tp>::value>
1926#endif
1927{
1928};
1929
1930#else  // _LIBCPP_HAS_NO_VARIADICS
1931
1932template <class _Tp, class _A0 = __is_construct::__nat,
1933                     class _A1 = __is_construct::__nat>
1934struct _LIBCPP_VISIBLE is_trivially_constructible
1935    : false_type
1936{
1937};
1938
1939template <class _Tp>
1940struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat,
1941                                                       __is_construct::__nat>
1942#ifdef _LIBCPP_HAS_TYPE_TRAITS
1943    : integral_constant<bool, __has_trivial_constructor(_Tp)>
1944#else
1945    : integral_constant<bool, is_scalar<_Tp>::value>
1946#endif
1947{
1948};
1949
1950template <class _Tp>
1951struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp,
1952                                                       __is_construct::__nat>
1953#ifdef _LIBCPP_HAS_TYPE_TRAITS
1954    : integral_constant<bool, __has_trivial_copy(_Tp)>
1955#else
1956    : integral_constant<bool, is_scalar<_Tp>::value>
1957#endif
1958{
1959};
1960
1961template <class _Tp>
1962struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&,
1963                                                       __is_construct::__nat>
1964#ifdef _LIBCPP_HAS_TYPE_TRAITS
1965    : integral_constant<bool, __has_trivial_copy(_Tp)>
1966#else
1967    : integral_constant<bool, is_scalar<_Tp>::value>
1968#endif
1969{
1970};
1971
1972template <class _Tp>
1973struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&,
1974                                                       __is_construct::__nat>
1975#ifdef _LIBCPP_HAS_TYPE_TRAITS
1976    : integral_constant<bool, __has_trivial_copy(_Tp)>
1977#else
1978    : integral_constant<bool, is_scalar<_Tp>::value>
1979#endif
1980{
1981};
1982
1983#endif  // _LIBCPP_HAS_NO_VARIADICS
1984
1985// is_trivially_default_constructible
1986
1987template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_default_constructible
1988    : public is_trivially_constructible<_Tp>
1989    {};
1990
1991// is_trivially_copy_constructible
1992
1993template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_constructible
1994    : public is_trivially_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
1995    {};
1996
1997// is_trivially_move_constructible
1998
1999template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_move_constructible
2000#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2001    : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2002#else
2003    : public is_trivially_copy_constructible<_Tp>
2004#endif
2005    {};
2006
2007// is_trivially_assignable
2008
2009template <class _Tp, class _Arg>
2010struct is_trivially_assignable
2011    : public false_type {};
2012
2013template <class _Tp>
2014struct is_trivially_assignable<_Tp&, _Tp>
2015#ifdef _LIBCPP_HAS_TYPE_TRAITS
2016    : integral_constant<bool, __has_trivial_assign(_Tp)> {};
2017#else
2018    : integral_constant<bool, is_scalar<_Tp>::value> {};
2019#endif
2020
2021template <class _Tp>
2022struct is_trivially_assignable<_Tp&, _Tp&>
2023#ifdef _LIBCPP_HAS_TYPE_TRAITS
2024    : integral_constant<bool, __has_trivial_assign(_Tp)> {};
2025#else
2026    : integral_constant<bool, is_scalar<_Tp>::value> {};
2027#endif
2028
2029template <class _Tp>
2030struct is_trivially_assignable<_Tp&, const _Tp&>
2031#ifdef _LIBCPP_HAS_TYPE_TRAITS
2032    : integral_constant<bool, __has_trivial_assign(_Tp)> {};
2033#else
2034    : integral_constant<bool, is_scalar<_Tp>::value> {};
2035#endif
2036
2037#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2038
2039template <class _Tp>
2040struct is_trivially_assignable<_Tp&, _Tp&&>
2041#ifdef _LIBCPP_HAS_TYPE_TRAITS
2042    : integral_constant<bool, __has_trivial_assign(_Tp)> {};
2043#else
2044    : integral_constant<bool, is_scalar<_Tp>::value> {};
2045#endif
2046
2047#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2048
2049// is_trivially_copy_assignable
2050
2051template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_assignable
2052    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2053                               const typename add_lvalue_reference<_Tp>::type>
2054    {};
2055
2056// is_trivially_move_assignable
2057
2058template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_move_assignable
2059    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2060#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2061                                     typename add_rvalue_reference<_Tp>::type>
2062#else
2063                                     typename add_lvalue_reference<_Tp>::type>
2064#endif
2065    {};
2066
2067// is_trivially_destructible
2068
2069#ifdef _LIBCPP_HAS_TYPE_TRAITS
2070
2071template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_destructible
2072    : public integral_constant<bool, __has_trivial_destructor(_Tp)> {};
2073
2074#else  // _LIBCPP_HAS_TYPE_TRAITS
2075
2076template <class _Tp> struct __libcpp_trivial_destructor
2077    : public integral_constant<bool, is_scalar<_Tp>::value ||
2078                                     is_reference<_Tp>::value> {};
2079
2080template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_destructible
2081    : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
2082
2083#endif  // _LIBCPP_HAS_TYPE_TRAITS
2084
2085// is_nothrow_constructible
2086
2087#ifndef _LIBCPP_HAS_NO_VARIADICS
2088
2089template <class _Tp, class... _Args>
2090struct _LIBCPP_VISIBLE is_nothrow_constructible
2091    : false_type
2092{
2093};
2094
2095template <class _Tp>
2096struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp>
2097#ifdef _LIBCPP_HAS_TYPE_TRAITS
2098    : integral_constant<bool, __has_nothrow_constructor(_Tp)>
2099#else
2100    : integral_constant<bool, is_scalar<_Tp>::value>
2101#endif
2102{
2103};
2104
2105template <class _Tp>
2106#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2107struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&&>
2108#else
2109struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp>
2110#endif
2111#ifdef _LIBCPP_HAS_TYPE_TRAITS
2112    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2113#else
2114    : integral_constant<bool, is_scalar<_Tp>::value>
2115#endif
2116{
2117};
2118
2119template <class _Tp>
2120struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, const _Tp&>
2121#ifdef _LIBCPP_HAS_TYPE_TRAITS
2122    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2123#else
2124    : integral_constant<bool, is_scalar<_Tp>::value>
2125#endif
2126{
2127};
2128
2129template <class _Tp>
2130struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&>
2131#ifdef _LIBCPP_HAS_TYPE_TRAITS
2132    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2133#else
2134    : integral_constant<bool, is_scalar<_Tp>::value>
2135#endif
2136{
2137};
2138
2139#else  // _LIBCPP_HAS_NO_VARIADICS
2140
2141template <class _Tp, class _A0 = __is_construct::__nat,
2142                     class _A1 = __is_construct::__nat>
2143struct _LIBCPP_VISIBLE is_nothrow_constructible
2144    : false_type
2145{
2146};
2147
2148template <class _Tp>
2149struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, __is_construct::__nat,
2150                                                       __is_construct::__nat>
2151#ifdef _LIBCPP_HAS_TYPE_TRAITS
2152    : integral_constant<bool, __has_nothrow_constructor(_Tp)>
2153#else
2154    : integral_constant<bool, is_scalar<_Tp>::value>
2155#endif
2156{
2157};
2158
2159template <class _Tp>
2160struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp,
2161                                                       __is_construct::__nat>
2162#ifdef _LIBCPP_HAS_TYPE_TRAITS
2163    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2164#else
2165    : integral_constant<bool, is_scalar<_Tp>::value>
2166#endif
2167{
2168};
2169
2170template <class _Tp>
2171struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, const _Tp&,
2172                                                       __is_construct::__nat>
2173#ifdef _LIBCPP_HAS_TYPE_TRAITS
2174    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2175#else
2176    : integral_constant<bool, is_scalar<_Tp>::value>
2177#endif
2178{
2179};
2180
2181template <class _Tp>
2182struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&,
2183                                                       __is_construct::__nat>
2184#ifdef _LIBCPP_HAS_TYPE_TRAITS
2185    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2186#else
2187    : integral_constant<bool, is_scalar<_Tp>::value>
2188#endif
2189{
2190};
2191
2192#endif  // _LIBCPP_HAS_NO_VARIADICS
2193
2194// is_nothrow_default_constructible
2195
2196template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_default_constructible
2197    : public is_nothrow_constructible<_Tp>
2198    {};
2199
2200// is_nothrow_copy_constructible
2201
2202template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_copy_constructible
2203    : public is_nothrow_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
2204    {};
2205
2206// is_nothrow_move_constructible
2207
2208template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_move_constructible
2209#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2210    : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2211#else
2212    : public is_nothrow_copy_constructible<_Tp>
2213#endif
2214    {};
2215
2216// is_nothrow_assignable
2217
2218template <class _Tp, class _Arg>
2219struct is_nothrow_assignable
2220    : public false_type {};
2221
2222template <class _Tp>
2223struct is_nothrow_assignable<_Tp&, _Tp>
2224#ifdef _LIBCPP_HAS_TYPE_TRAITS
2225    : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2226#else
2227    : integral_constant<bool, is_scalar<_Tp>::value> {};
2228#endif
2229
2230template <class _Tp>
2231struct is_nothrow_assignable<_Tp&, _Tp&>
2232#ifdef _LIBCPP_HAS_TYPE_TRAITS
2233    : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2234#else
2235    : integral_constant<bool, is_scalar<_Tp>::value> {};
2236#endif
2237
2238template <class _Tp>
2239struct is_nothrow_assignable<_Tp&, const _Tp&>
2240#ifdef _LIBCPP_HAS_TYPE_TRAITS
2241    : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2242#else
2243    : integral_constant<bool, is_scalar<_Tp>::value> {};
2244#endif
2245
2246#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2247
2248template <class _Tp>
2249struct is_nothrow_assignable<_Tp&, _Tp&&>
2250#ifdef _LIBCPP_HAS_TYPE_TRAITS
2251    : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2252#else
2253    : integral_constant<bool, is_scalar<_Tp>::value> {};
2254#endif
2255
2256#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2257
2258// is_nothrow_copy_assignable
2259
2260template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_copy_assignable
2261    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
2262                               const typename add_lvalue_reference<_Tp>::type>
2263    {};
2264
2265// is_nothrow_move_assignable
2266
2267template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_move_assignable
2268    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
2269#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2270                                     typename add_rvalue_reference<_Tp>::type>
2271#else
2272                                     typename add_lvalue_reference<_Tp>::type>
2273#endif
2274    {};
2275
2276// is_nothrow_destructible
2277
2278template <class _Tp> struct __libcpp_nothrow_destructor
2279    : public integral_constant<bool, is_scalar<_Tp>::value ||
2280                                     is_reference<_Tp>::value> {};
2281
2282template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_destructible
2283    : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
2284
2285// is_pod
2286
2287#ifdef _LIBCPP_HAS_TYPE_TRAITS
2288
2289template <class _Tp> struct _LIBCPP_VISIBLE is_pod
2290    : public integral_constant<bool, __is_pod(_Tp)> {};
2291
2292#else  // _LIBCPP_HAS_TYPE_TRAITS
2293
2294template <class _Tp> struct _LIBCPP_VISIBLE is_pod
2295    : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
2296                                     is_trivially_copy_constructible<_Tp>::value      &&
2297                                     is_trivially_copy_assignable<_Tp>::value    &&
2298                                     is_trivially_destructible<_Tp>::value> {};
2299
2300#endif  // _LIBCPP_HAS_TYPE_TRAITS
2301
2302template <class _Tp>
2303inline _LIBCPP_INLINE_VISIBILITY
2304void
2305swap(_Tp& __x, _Tp& __y)
2306{
2307    _Tp __t(_STD::move(__x));
2308    __x = _STD::move(__y);
2309    __y = _STD::move(__t);
2310}
2311
2312_LIBCPP_END_NAMESPACE_STD
2313
2314#endif  // _LIBCPP_TYPE_TRAITS
2315