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