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