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