blob: e7bb1eb34cbe9cb230f10c91f5b9068f52ceb914 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ type_traits ---------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_TYPE_TRAITS
12#define _LIBCPP_TYPE_TRAITS
13
14/*
15 type_traits synopsis
16
17namespace std
18{
19
20 // helper class:
21 template <class T, T v> struct integral_constant;
22 typedef integral_constant<bool, true> true_type;
23 typedef integral_constant<bool, false> false_type;
24
25 // helper traits
26 template <bool, class T = void> struct enable_if;
27 template <bool, class T, class F> struct conditional;
28
29 // Primary classification traits:
30 template <class T> struct is_void;
31 template <class T> struct is_integral;
32 template <class T> struct is_floating_point;
33 template <class T> struct is_array;
34 template <class T> struct is_pointer;
35 template <class T> struct is_lvalue_reference;
36 template <class T> struct is_rvalue_reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037 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;
Howard Hinnant324bb032010-08-22 00:02:43 +000043
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000044 // 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;
Howard Hinnant324bb032010-08-22 00:02:43 +000052
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000053 // 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;
Howard Hinnant324bb032010-08-22 00:02:43 +000062
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063 // 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;
Howard Hinnant324bb032010-08-22 00:02:43 +000067
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000068 // Pointer transformations:
69 template <class T> struct remove_pointer;
70 template <class T> struct add_pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +000071
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072 // 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;
Howard Hinnant324bb032010-08-22 00:02:43 +000077
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078 // 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;
Howard Hinnant324bb032010-08-22 00:02:43 +000083
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084 // 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;
Howard Hinnant745d4732010-09-08 17:55:32 +000093
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000094 template <class T, class... Args> struct is_constructible;
Howard Hinnant1468b662010-11-19 22:17:28 +000095 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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000112 template <class T, class... Args> struct is_nothrow_constructible;
Howard Hinnant1468b662010-11-19 22:17:28 +0000113 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;
Howard Hinnant745d4732010-09-08 17:55:32 +0000120
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000121 template <class T> struct has_virtual_destructor;
Howard Hinnant324bb032010-08-22 00:02:43 +0000122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123 // 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;
Howard Hinnant324bb032010-08-22 00:02:43 +0000127
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128 // 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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000132
133 template <class T> struct decay;
134 template <class... T> struct common_type;
135 template <class T> struct underlying_type;
136 template <class> class result_of; // undefined
137 template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
138
139} // std
140
141*/
142#include <__config>
143#include <cstddef>
144
145#pragma GCC system_header
146
147_LIBCPP_BEGIN_NAMESPACE_STD
148
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000149template <bool _B, class _If, class _Then>
150 struct _LIBCPP_VISIBLE conditional {typedef _If type;};
151template <class _If, class _Then>
152 struct _LIBCPP_VISIBLE conditional<false, _If, _Then> {typedef _Then type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000154template <bool, class _Tp = void> struct _LIBCPP_VISIBLE enable_if {};
155template <class _Tp> struct _LIBCPP_VISIBLE enable_if<true, _Tp> {typedef _Tp type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000156
157struct __two {char _[2];};
158
159// helper class:
160
161template <class _Tp, _Tp __v>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000162struct _LIBCPP_VISIBLE integral_constant
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000163{
Howard Hinnant13870382010-09-06 19:10:31 +0000164 static constexpr _Tp value = __v;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000165 typedef _Tp value_type;
166 typedef integral_constant type;
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant52c4eb22011-01-08 20:00:48 +0000168#ifndef _LIBCPP_HAS_NO_CONSTEXPR
169 constexpr
Howard Hinnant13870382010-09-06 19:10:31 +0000170#endif
Howard Hinnant6063ec12011-05-13 14:08:16 +0000171 operator value_type()
172#ifdef _LIBCPP_HAS_NO_CONSTEXPR
173 const
174#endif
175 {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176};
177
178template <class _Tp, _Tp __v>
Howard Hinnant6063ec12011-05-13 14:08:16 +0000179constexpr _Tp integral_constant<_Tp, __v>::value;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180
181typedef integral_constant<bool, true> true_type;
182typedef integral_constant<bool, false> false_type;
183
184// is_const
185
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000186template <class _Tp> struct _LIBCPP_VISIBLE is_const : public false_type {};
187template <class _Tp> struct _LIBCPP_VISIBLE is_const<_Tp const> : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000188
189// is_volatile
190
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000191template <class _Tp> struct _LIBCPP_VISIBLE is_volatile : public false_type {};
192template <class _Tp> struct _LIBCPP_VISIBLE is_volatile<_Tp volatile> : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193
194// remove_const
195
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000196template <class _Tp> struct _LIBCPP_VISIBLE remove_const {typedef _Tp type;};
197template <class _Tp> struct _LIBCPP_VISIBLE remove_const<const _Tp> {typedef _Tp type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198
199// remove_volatile
200
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000201template <class _Tp> struct _LIBCPP_VISIBLE remove_volatile {typedef _Tp type;};
202template <class _Tp> struct _LIBCPP_VISIBLE remove_volatile<volatile _Tp> {typedef _Tp type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000203
204// remove_cv
205
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000206template <class _Tp> struct _LIBCPP_VISIBLE remove_cv
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
208
209// is_void
210
211template <class _Tp> struct __is_void : public false_type {};
212template <> struct __is_void<void> : public true_type {};
213
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000214template <class _Tp> struct _LIBCPP_VISIBLE is_void
215 : public __is_void<typename remove_cv<_Tp>::type> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000216
Howard Hinnant6e5e7e72011-03-09 17:17:06 +0000217// __is_nullptr_t
218
219template <class _Tp> struct ____is_nullptr_t : public false_type {};
220template <> struct ____is_nullptr_t<nullptr_t> : public true_type {};
221
222template <class _Tp> struct _LIBCPP_VISIBLE __is_nullptr_t
223 : public ____is_nullptr_t<typename remove_cv<_Tp>::type> {};
224
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225// is_integral
226
227template <class _Tp> struct __is_integral : public false_type {};
228template <> struct __is_integral<bool> : public true_type {};
229template <> struct __is_integral<char> : public true_type {};
230template <> struct __is_integral<signed char> : public true_type {};
231template <> struct __is_integral<unsigned char> : public true_type {};
232template <> struct __is_integral<wchar_t> : public true_type {};
233#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
234template <> struct __is_integral<char16_t> : public true_type {};
235template <> struct __is_integral<char32_t> : public true_type {};
Howard Hinnant324bb032010-08-22 00:02:43 +0000236#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000237template <> struct __is_integral<short> : public true_type {};
238template <> struct __is_integral<unsigned short> : public true_type {};
239template <> struct __is_integral<int> : public true_type {};
240template <> struct __is_integral<unsigned int> : public true_type {};
241template <> struct __is_integral<long> : public true_type {};
242template <> struct __is_integral<unsigned long> : public true_type {};
243template <> struct __is_integral<long long> : public true_type {};
244template <> struct __is_integral<unsigned long long> : public true_type {};
245
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000246template <class _Tp> struct _LIBCPP_VISIBLE is_integral
247 : public __is_integral<typename remove_cv<_Tp>::type> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000248
249// is_floating_point
250
251template <class _Tp> struct __is_floating_point : public false_type {};
252template <> struct __is_floating_point<float> : public true_type {};
253template <> struct __is_floating_point<double> : public true_type {};
254template <> struct __is_floating_point<long double> : public true_type {};
255
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000256template <class _Tp> struct _LIBCPP_VISIBLE is_floating_point
257 : public __is_floating_point<typename remove_cv<_Tp>::type> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258
259// is_array
260
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000261template <class _Tp> struct _LIBCPP_VISIBLE is_array
262 : public false_type {};
263template <class _Tp> struct _LIBCPP_VISIBLE is_array<_Tp[]>
264 : public true_type {};
265template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE is_array<_Tp[_Np]>
266 : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267
268// is_pointer
269
270template <class _Tp> struct __is_pointer : public false_type {};
271template <class _Tp> struct __is_pointer<_Tp*> : public true_type {};
272
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000273template <class _Tp> struct _LIBCPP_VISIBLE is_pointer
274 : public __is_pointer<typename remove_cv<_Tp>::type> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000275
276// is_reference
277
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000278template <class _Tp> struct _LIBCPP_VISIBLE is_lvalue_reference : public false_type {};
279template <class _Tp> struct _LIBCPP_VISIBLE is_lvalue_reference<_Tp&> : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000281template <class _Tp> struct _LIBCPP_VISIBLE is_rvalue_reference : public false_type {};
Howard Hinnant73d21a42010-09-04 23:28:19 +0000282#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000283template <class _Tp> struct _LIBCPP_VISIBLE is_rvalue_reference<_Tp&&> : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000284#endif
285
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000286template <class _Tp> struct _LIBCPP_VISIBLE is_reference : public false_type {};
287template <class _Tp> struct _LIBCPP_VISIBLE is_reference<_Tp&> : public true_type {};
Howard Hinnant73d21a42010-09-04 23:28:19 +0000288#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000289template <class _Tp> struct _LIBCPP_VISIBLE is_reference<_Tp&&> : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290#endif
291
Howard Hinnantcb2deb22010-09-09 13:58:34 +0000292#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
293#define _LIBCPP_HAS_TYPE_TRAITS
294#endif
295
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296// is_union
297
Howard Hinnant36666952011-05-09 19:21:17 +0000298#if __has_feature(is_union) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000300template <class _Tp> struct _LIBCPP_VISIBLE is_union
Howard Hinnant745d4732010-09-08 17:55:32 +0000301 : public integral_constant<bool, __is_union(_Tp)> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
Howard Hinnant36666952011-05-09 19:21:17 +0000303#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304
305template <class _Tp> struct __libcpp_union : public false_type {};
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000306template <class _Tp> struct _LIBCPP_VISIBLE is_union
307 : public __libcpp_union<typename remove_cv<_Tp>::type> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308
Howard Hinnant36666952011-05-09 19:21:17 +0000309#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000310
311// is_class
312
Howard Hinnant36666952011-05-09 19:21:17 +0000313#if __has_feature(is_class) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant745d4732010-09-08 17:55:32 +0000314
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000315template <class _Tp> struct _LIBCPP_VISIBLE is_class
Howard Hinnant745d4732010-09-08 17:55:32 +0000316 : public integral_constant<bool, __is_class(_Tp)> {};
317
Howard Hinnant36666952011-05-09 19:21:17 +0000318#else
Howard Hinnant745d4732010-09-08 17:55:32 +0000319
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320namespace __is_class_imp
321{
322template <class _Tp> char __test(int _Tp::*);
323template <class _Tp> __two __test(...);
324}
325
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000326template <class _Tp> struct _LIBCPP_VISIBLE is_class
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
328
Howard Hinnant36666952011-05-09 19:21:17 +0000329#endif
Howard Hinnant745d4732010-09-08 17:55:32 +0000330
Howard Hinnantd7373822011-06-01 17:25:11 +0000331// is_same
332
333template <class _Tp, class _Up> struct _LIBCPP_VISIBLE is_same : public false_type {};
334template <class _Tp> struct _LIBCPP_VISIBLE is_same<_Tp, _Tp> : public true_type {};
335
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336// is_function
337
338namespace __is_function_imp
339{
340template <class _Tp> char __test(_Tp*);
341template <class _Tp> __two __test(...);
342template <class _Tp> _Tp& __source();
343}
344
345template <class _Tp, bool = is_class<_Tp>::value ||
346 is_union<_Tp>::value ||
347 is_void<_Tp>::value ||
Howard Hinnantd7373822011-06-01 17:25:11 +0000348 is_reference<_Tp>::value ||
349 is_same<_Tp, nullptr_t>::value >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350struct __is_function
351 : public integral_constant<bool, sizeof(__is_function_imp::__test<_Tp>(__is_function_imp::__source<_Tp>())) == 1>
352 {};
353template <class _Tp> struct __is_function<_Tp, true> : public false_type {};
354
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000355template <class _Tp> struct _LIBCPP_VISIBLE is_function
356 : public __is_function<_Tp> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
358// is_member_function_pointer
359
360template <class _Tp> struct __is_member_function_pointer : public false_type {};
361template <class _Tp, class _Up> struct __is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
362
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000363template <class _Tp> struct _LIBCPP_VISIBLE is_member_function_pointer
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364 : public __is_member_function_pointer<typename remove_cv<_Tp>::type> {};
365
366// is_member_pointer
367
368template <class _Tp> struct __is_member_pointer : public false_type {};
369template <class _Tp, class _Up> struct __is_member_pointer<_Tp _Up::*> : public true_type {};
370
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000371template <class _Tp> struct _LIBCPP_VISIBLE is_member_pointer
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372 : public __is_member_pointer<typename remove_cv<_Tp>::type> {};
373
374// is_member_object_pointer
375
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000376template <class _Tp> struct _LIBCPP_VISIBLE is_member_object_pointer
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377 : public integral_constant<bool, is_member_pointer<_Tp>::value &&
378 !is_member_function_pointer<_Tp>::value> {};
379
380// is_enum
381
Howard Hinnant36666952011-05-09 19:21:17 +0000382#if __has_feature(is_enum) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant745d4732010-09-08 17:55:32 +0000383
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000384template <class _Tp> struct _LIBCPP_VISIBLE is_enum
Howard Hinnant745d4732010-09-08 17:55:32 +0000385 : public integral_constant<bool, __is_enum(_Tp)> {};
386
Howard Hinnant36666952011-05-09 19:21:17 +0000387#else
Howard Hinnant745d4732010-09-08 17:55:32 +0000388
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000389template <class _Tp> struct _LIBCPP_VISIBLE is_enum
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 : public integral_constant<bool, !is_void<_Tp>::value &&
391 !is_integral<_Tp>::value &&
392 !is_floating_point<_Tp>::value &&
393 !is_array<_Tp>::value &&
394 !is_pointer<_Tp>::value &&
395 !is_reference<_Tp>::value &&
396 !is_member_pointer<_Tp>::value &&
397 !is_union<_Tp>::value &&
398 !is_class<_Tp>::value &&
399 !is_function<_Tp>::value > {};
400
Howard Hinnant36666952011-05-09 19:21:17 +0000401#endif
Howard Hinnant745d4732010-09-08 17:55:32 +0000402
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403// is_arithmetic
404
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000405template <class _Tp> struct _LIBCPP_VISIBLE is_arithmetic
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406 : public integral_constant<bool, is_integral<_Tp>::value ||
407 is_floating_point<_Tp>::value> {};
408
409// is_fundamental
410
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000411template <class _Tp> struct _LIBCPP_VISIBLE is_fundamental
Howard Hinnant6e5e7e72011-03-09 17:17:06 +0000412 : public integral_constant<bool, is_void<_Tp>::value ||
413 __is_nullptr_t<_Tp>::value ||
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414 is_arithmetic<_Tp>::value> {};
415
416// is_scalar
417
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000418template <class _Tp> struct _LIBCPP_VISIBLE is_scalar
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419 : public integral_constant<bool, is_arithmetic<_Tp>::value ||
420 is_member_pointer<_Tp>::value ||
421 is_pointer<_Tp>::value ||
Howard Hinnant6e5e7e72011-03-09 17:17:06 +0000422 __is_nullptr_t<_Tp>::value ||
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 is_enum<_Tp>::value > {};
424
Howard Hinnant5885da32011-03-09 15:10:51 +0000425template <> struct _LIBCPP_VISIBLE is_scalar<nullptr_t> : public true_type {};
426
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427// is_object
428
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000429template <class _Tp> struct _LIBCPP_VISIBLE is_object
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430 : public integral_constant<bool, is_scalar<_Tp>::value ||
431 is_array<_Tp>::value ||
432 is_union<_Tp>::value ||
433 is_class<_Tp>::value > {};
434
435// is_compound
436
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000437template <class _Tp> struct _LIBCPP_VISIBLE is_compound
438 : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439
440// add_const
441
442template <class _Tp, bool = is_reference<_Tp>::value ||
443 is_function<_Tp>::value ||
444 is_const<_Tp>::value >
445struct __add_const {typedef _Tp type;};
446
447template <class _Tp>
448struct __add_const<_Tp, false> {typedef const _Tp type;};
449
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000450template <class _Tp> struct _LIBCPP_VISIBLE add_const
451 {typedef typename __add_const<_Tp>::type type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452
453// add_volatile
454
455template <class _Tp, bool = is_reference<_Tp>::value ||
456 is_function<_Tp>::value ||
457 is_volatile<_Tp>::value >
458struct __add_volatile {typedef _Tp type;};
459
460template <class _Tp>
461struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
462
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000463template <class _Tp> struct _LIBCPP_VISIBLE add_volatile
464 {typedef typename __add_volatile<_Tp>::type type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465
466// add_cv
467
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000468template <class _Tp> struct _LIBCPP_VISIBLE add_cv
469 {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470
471// remove_reference
472
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000473template <class _Tp> struct _LIBCPP_VISIBLE remove_reference {typedef _Tp type;};
474template <class _Tp> struct _LIBCPP_VISIBLE remove_reference<_Tp&> {typedef _Tp type;};
Howard Hinnant73d21a42010-09-04 23:28:19 +0000475#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000476template <class _Tp> struct _LIBCPP_VISIBLE remove_reference<_Tp&&> {typedef _Tp type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000477#endif
478
479// add_lvalue_reference
480
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000481template <class _Tp> struct _LIBCPP_VISIBLE add_lvalue_reference {typedef _Tp& type;};
482template <class _Tp> struct _LIBCPP_VISIBLE add_lvalue_reference<_Tp&> {typedef _Tp& type;}; // for older compiler
483template <> struct _LIBCPP_VISIBLE add_lvalue_reference<void> {typedef void type;};
484template <> struct _LIBCPP_VISIBLE add_lvalue_reference<const void> {typedef const void type;};
485template <> struct _LIBCPP_VISIBLE add_lvalue_reference<volatile void> {typedef volatile void type;};
486template <> struct _LIBCPP_VISIBLE add_lvalue_reference<const volatile void> {typedef const volatile void type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487
Howard Hinnant73d21a42010-09-04 23:28:19 +0000488#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000490template <class _Tp> struct _LIBCPP_VISIBLE add_rvalue_reference {typedef _Tp&& type;};
491template <> struct _LIBCPP_VISIBLE add_rvalue_reference<void> {typedef void type;};
492template <> struct _LIBCPP_VISIBLE add_rvalue_reference<const void> {typedef const void type;};
493template <> struct _LIBCPP_VISIBLE add_rvalue_reference<volatile void> {typedef volatile void type;};
494template <> struct _LIBCPP_VISIBLE add_rvalue_reference<const volatile void> {typedef const volatile void type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495
Howard Hinnant73d21a42010-09-04 23:28:19 +0000496#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497
Howard Hinnant745d4732010-09-08 17:55:32 +0000498#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
499
500template <class _Tp>
501typename add_rvalue_reference<_Tp>::type
Howard Hinnant5d37fb32011-05-11 20:19:40 +0000502declval() _NOEXCEPT;
Howard Hinnant745d4732010-09-08 17:55:32 +0000503
504#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
505
506template <class _Tp>
507typename add_lvalue_reference<_Tp>::type
508declval();
509
510#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
511
512struct __any
513{
514 __any(...);
515};
516
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517// remove_pointer
518
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000519template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer {typedef _Tp type;};
520template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp*> {typedef _Tp type;};
521template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* const> {typedef _Tp type;};
522template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* volatile> {typedef _Tp type;};
523template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* const volatile> {typedef _Tp type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524
525// add_pointer
526
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000527template <class _Tp> struct _LIBCPP_VISIBLE add_pointer
528 {typedef typename remove_reference<_Tp>::type* type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529
530// is_signed
531
532template <class _Tp, bool = is_integral<_Tp>::value>
533struct ___is_signed : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};
534
535template <class _Tp>
536struct ___is_signed<_Tp, false> : public true_type {}; // floating point
537
538template <class _Tp, bool = is_arithmetic<_Tp>::value>
539struct __is_signed : public ___is_signed<_Tp> {};
540
541template <class _Tp> struct __is_signed<_Tp, false> : public false_type {};
542
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000543template <class _Tp> struct _LIBCPP_VISIBLE is_signed : public __is_signed<_Tp> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544
545// is_unsigned
546
547template <class _Tp, bool = is_integral<_Tp>::value>
548struct ___is_unsigned : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};
549
550template <class _Tp>
551struct ___is_unsigned<_Tp, false> : public false_type {}; // floating point
552
553template <class _Tp, bool = is_arithmetic<_Tp>::value>
554struct __is_unsigned : public ___is_unsigned<_Tp> {};
555
556template <class _Tp> struct __is_unsigned<_Tp, false> : public false_type {};
557
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000558template <class _Tp> struct _LIBCPP_VISIBLE is_unsigned : public __is_unsigned<_Tp> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559
560// rank
561
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000562template <class _Tp> struct _LIBCPP_VISIBLE rank
563 : public integral_constant<size_t, 0> {};
564template <class _Tp> struct _LIBCPP_VISIBLE rank<_Tp[]>
565 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
566template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE rank<_Tp[_Np]>
567 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568
569// extent
570
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000571template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_VISIBLE extent
572 : public integral_constant<size_t, 0> {};
573template <class _Tp> struct _LIBCPP_VISIBLE extent<_Tp[], 0>
574 : public integral_constant<size_t, 0> {};
575template <class _Tp, unsigned _Ip> struct _LIBCPP_VISIBLE extent<_Tp[], _Ip>
576 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
577template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE extent<_Tp[_Np], 0>
578 : public integral_constant<size_t, _Np> {};
579template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_VISIBLE extent<_Tp[_Np], _Ip>
580 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581
582// remove_extent
583
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000584template <class _Tp> struct _LIBCPP_VISIBLE remove_extent
585 {typedef _Tp type;};
586template <class _Tp> struct _LIBCPP_VISIBLE remove_extent<_Tp[]>
587 {typedef _Tp type;};
588template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE remove_extent<_Tp[_Np]>
589 {typedef _Tp type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590
591// remove_all_extents
592
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000593template <class _Tp> struct _LIBCPP_VISIBLE remove_all_extents
594 {typedef _Tp type;};
595template <class _Tp> struct _LIBCPP_VISIBLE remove_all_extents<_Tp[]>
596 {typedef typename remove_all_extents<_Tp>::type type;};
597template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE remove_all_extents<_Tp[_Np]>
598 {typedef typename remove_all_extents<_Tp>::type type;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600// is_abstract
601
602namespace __is_abstract_imp
603{
604template <class _Tp> char __test(_Tp (*)[1]);
605template <class _Tp> __two __test(...);
606}
607
608template <class _Tp, bool = is_class<_Tp>::value>
609struct __libcpp_abstract : public integral_constant<bool, sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
610
611template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {};
612
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000613template <class _Tp> struct _LIBCPP_VISIBLE is_abstract : public __libcpp_abstract<_Tp> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000614
615// is_convertible
616
Howard Hinnant31b8e612011-02-10 17:46:03 +0000617#if __has_feature(is_convertible_to)
Howard Hinnant091c5ac2011-01-27 21:00:00 +0000618
619template <class _T1, class _T2> struct _LIBCPP_VISIBLE is_convertible
620 : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
Howard Hinnant091c5ac2011-01-27 21:00:00 +0000621
Howard Hinnant31b8e612011-02-10 17:46:03 +0000622#else // __has_feature(is_convertible_to)
Howard Hinnant091c5ac2011-01-27 21:00:00 +0000623
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624namespace __is_convertible_imp
625{
Howard Hinnant091c5ac2011-01-27 21:00:00 +0000626#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
627template <class _Tp> char __test(const volatile typename remove_reference<_Tp>::type&&);
628#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629template <class _Tp> char __test(_Tp);
Howard Hinnant091c5ac2011-01-27 21:00:00 +0000630#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631template <class _Tp> __two __test(...);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000632#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633template <class _Tp> _Tp&& __source();
634#else
635template <class _Tp> typename remove_reference<_Tp>::type& __source();
636#endif
637
638template <class _Tp, bool _IsArray = is_array<_Tp>::value,
639 bool _IsFunction = is_function<_Tp>::value,
640 bool _IsVoid = is_void<_Tp>::value>
641 struct __is_array_function_or_void {enum {value = 0};};
642template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
643template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
644template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
645}
646
647template <class _Tp,
648 unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
649struct __is_convertible_check
650{
651 static const size_t __v = 0;
652};
653
654template <class _Tp>
655struct __is_convertible_check<_Tp, 0>
656{
657 static const size_t __v = sizeof(_Tp);
658};
659
660template <class _T1, class _T2,
661 unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
662 unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
663struct __is_convertible
664 : public integral_constant<bool,
665 sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
666 >
667{};
668
669template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 0> : false_type {};
670
671template <class _T1> struct __is_convertible<_T1, const _T1&, 1, 0> : true_type {};
Howard Hinnant73d21a42010-09-04 23:28:19 +0000672#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673template <class _T1> struct __is_convertible<_T1, _T1&&, 1, 0> : true_type {};
674template <class _T1> struct __is_convertible<_T1, const _T1&&, 1, 0> : true_type {};
675template <class _T1> struct __is_convertible<_T1, volatile _T1&&, 1, 0> : true_type {};
676template <class _T1> struct __is_convertible<_T1, const volatile _T1&&, 1, 0> : true_type {};
Howard Hinnant73d21a42010-09-04 23:28:19 +0000677#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678
679template <class _T1, class _T2> struct __is_convertible<_T1, _T2*, 1, 0>
680 : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*>::value> {};
681
682template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const, 1, 0>
683 : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const>::value> {};
684
685template <class _T1, class _T2> struct __is_convertible<_T1, _T2* volatile, 1, 0>
686 : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*volatile>::value> {};
687
688template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const volatile, 1, 0>
689 : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const volatile>::value> {};
690
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 0> : public false_type {};
Howard Hinnant73d21a42010-09-04 23:28:19 +0000692#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693template <class _T1> struct __is_convertible<_T1, _T1&&, 2, 0> : public true_type {};
694#endif
695template <class _T1> struct __is_convertible<_T1, _T1*, 2, 0> : public true_type {};
696template <class _T1> struct __is_convertible<_T1, _T1*const, 2, 0> : public true_type {};
697template <class _T1> struct __is_convertible<_T1, _T1*volatile, 2, 0> : public true_type {};
698template <class _T1> struct __is_convertible<_T1, _T1*const volatile, 2, 0> : public true_type {};
699
700template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 0> : public false_type {};
701
702template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
703template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
704template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
705template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
706
707template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
708template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
709template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
710template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
711
712template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
713template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
714template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
715template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
716
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000717template <class _T1, class _T2> struct _LIBCPP_VISIBLE is_convertible
718 : public __is_convertible<_T1, _T2>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000719{
720 static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
721 static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
722};
723
Howard Hinnant31b8e612011-02-10 17:46:03 +0000724#endif // __has_feature(is_convertible_to)
Howard Hinnant091c5ac2011-01-27 21:00:00 +0000725
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726// is_base_of
727
Howard Hinnant621ee222011-02-10 21:34:42 +0000728#if __has_feature(is_base_of)
Howard Hinnant80f91802011-01-28 20:00:37 +0000729
730template <class _Bp, class _Dp>
731struct _LIBCPP_VISIBLE is_base_of
732 : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
733
Howard Hinnant31b8e612011-02-10 17:46:03 +0000734#else // __has_feature(is_base_of)
Howard Hinnant80f91802011-01-28 20:00:37 +0000735
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736// (C) Copyright Rani Sharoni 2003.
737// Use, modification and distribution are subject to the Boost Software License,
738// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
739// http://www.boost.org/LICENSE_1_0.txt).
740//
741// See http://www.boost.org/libs/type_traits for most recent version including documentation.
742
743template <class _Bp, class _Dp>
744struct __is_base_of_tests
745{
746 template <class _Tp>
747 static char __test(const volatile _Dp*, _Tp);
748 static __two __test(const volatile _Bp*, int);
749};
750
751template <class _Bp, class _Dp>
752struct __is_base_of_imp
753{
754 struct __host
755 {
756 operator const volatile _Bp*() const;
757 operator const volatile _Dp*();
758 };
759
760 static const size_t __complete_check = sizeof(_Dp);
761 static const bool value = sizeof(__is_base_of_tests<_Bp, _Dp>::__test(__host(), 0)) == 1;
762};
763
764template <class _Bp, class _Dp, bool = is_class<_Bp>::value,
765 bool = is_class<_Dp>::value,
766 bool = is_same<_Bp, _Dp>::value>
767struct __libcpp_base_of : public false_type {};
768
769template <class _Bp, class _Dp>
770struct __libcpp_base_of<_Bp, _Dp, true, true, true> : public true_type {};
771
772template <class _Bp, class _Dp>
773struct __libcpp_base_of<_Bp, _Dp, true, true, false>
774 : public integral_constant<bool, __is_base_of_imp<_Bp, _Dp>::value> {};
775
776template <class _Bp, class _Dp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000777struct _LIBCPP_VISIBLE is_base_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778 : public __libcpp_base_of<typename remove_cv<_Bp>::type, typename remove_cv<_Dp>::type>
779{
780};
781
Howard Hinnant31b8e612011-02-10 17:46:03 +0000782#endif // __has_feature(is_base_of)
Howard Hinnant80f91802011-01-28 20:00:37 +0000783
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784// is_empty
785
786template <class _Tp>
787struct __is_empty1
788 : public _Tp
789{
790 double _;
791};
792
793struct __is_empty2
794{
795 double _;
796};
797
798template <class _Tp, bool = is_class<_Tp>::value>
799struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
800
801template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
802
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000803template <class _Tp> struct _LIBCPP_VISIBLE is_empty : public __libcpp_empty<_Tp> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804
805// is_polymorphic
806
807template <class _Tp> struct __is_polymorphic1 : public _Tp {};
808template <class _Tp> struct __is_polymorphic2 : public _Tp {virtual ~__is_polymorphic2() throw();};
809
810template <class _Tp, bool = is_class<_Tp>::value>
811struct __libcpp_polymorphic
812 : public integral_constant<bool, sizeof(__is_polymorphic1<_Tp>) == sizeof(__is_polymorphic2<_Tp>)> {};
813
814template <class _Tp> struct __libcpp_polymorphic<_Tp, false> : public false_type {};
815
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000816template <class _Tp> struct _LIBCPP_VISIBLE is_polymorphic
817 : public __libcpp_polymorphic<_Tp> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819// has_virtual_destructor
820
Howard Hinnant36666952011-05-09 19:21:17 +0000821#ifdef __has_feature(has_virtual_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant745d4732010-09-08 17:55:32 +0000822
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000823template <class _Tp> struct _LIBCPP_VISIBLE has_virtual_destructor
Howard Hinnant745d4732010-09-08 17:55:32 +0000824 : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
825
Howard Hinnantcb2deb22010-09-09 13:58:34 +0000826#else // _LIBCPP_HAS_TYPE_TRAITS
Howard Hinnant745d4732010-09-08 17:55:32 +0000827
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000828template <class _Tp> struct _LIBCPP_VISIBLE has_virtual_destructor
829 : public false_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830
Howard Hinnantcb2deb22010-09-09 13:58:34 +0000831#endif // _LIBCPP_HAS_TYPE_TRAITS
Howard Hinnant745d4732010-09-08 17:55:32 +0000832
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833// alignment_of
834
835template <class _Tp> struct __alignment_of {_Tp _;};
836
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000837template <class _Tp> struct _LIBCPP_VISIBLE alignment_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 : public integral_constant<size_t, __alignof__(__alignment_of<typename remove_all_extents<_Tp>::type>)> {};
839
840// aligned_storage
841
842template <class _Hp, class _Tp>
843struct __type_list
844{
845 typedef _Hp _Head;
846 typedef _Tp _Tail;
847};
848
Howard Hinnante003ce42011-05-22 00:09:02 +0000849struct __nat
850{
851#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
852 __nat() = delete;
853 __nat(const __nat&) = delete;
854 __nat& operator=(const __nat&) = delete;
855 ~__nat() = delete;
856#endif
857};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858
859template <class _Tp>
860struct __align_type
861{
862 static const size_t value = alignment_of<_Tp>::value;
863 typedef _Tp type;
864};
865
866struct __struct_double {long double _;};
867struct __struct_double4 {double _[4];};
868
869typedef
870 __type_list<__align_type<unsigned char>,
871 __type_list<__align_type<unsigned short>,
872 __type_list<__align_type<unsigned int>,
873 __type_list<__align_type<unsigned long>,
874 __type_list<__align_type<unsigned long long>,
875 __type_list<__align_type<double>,
876 __type_list<__align_type<long double>,
877 __type_list<__align_type<__struct_double>,
878 __type_list<__align_type<__struct_double4>,
879 __type_list<__align_type<int*>,
880 __nat
881 > > > > > > > > > > __all_types;
882
883template <class _TL, size_t _Align> struct __find_pod;
884
885template <class _Hp, size_t _Align>
886struct __find_pod<__type_list<_Hp, __nat>, _Align>
887{
888 typedef typename conditional<
889 _Align == _Hp::value,
890 typename _Hp::type,
891 void
892 >::type type;
893};
894
895template <class _Hp, class _Tp, size_t _Align>
896struct __find_pod<__type_list<_Hp, _Tp>, _Align>
897{
898 typedef typename conditional<
899 _Align == _Hp::value,
900 typename _Hp::type,
901 typename __find_pod<_Tp, _Align>::type
902 >::type type;
903};
904
905template <class _TL, size_t _Len> struct __find_max_align;
906
907template <class _Hp, size_t _Len>
908struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
909
910template <size_t _Len, size_t _A1, size_t _A2>
911struct __select_align
912{
913private:
914 static const size_t __min = _A2 < _A1 ? _A2 : _A1;
915 static const size_t __max = _A1 < _A2 ? _A2 : _A1;
916public:
917 static const size_t value = _Len < __max ? __min : __max;
918};
919
920template <class _Hp, class _Tp, size_t _Len>
921struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
922 : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
923
924template <size_t _Len, const size_t _Align = __find_max_align<__all_types, _Len>::value>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000925struct _LIBCPP_VISIBLE aligned_storage
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000926{
927 typedef typename __find_pod<__all_types, _Align>::type _Aligner;
928 static_assert(!is_void<_Aligner>::value, "");
929 union type
930 {
931 _Aligner __align;
932 unsigned char __data[_Len];
933 };
934};
935
936#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
937template <size_t _Len>\
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000938struct __attribute__ ((__visibility__("default"))) aligned_storage<_Len, n>\
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939{\
940 struct type\
941 {\
942 unsigned char _[_Len];\
943 } __attribute__((__aligned__(n)));\
944}
945
946_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
947_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
948_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
949_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
950_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
951_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
952_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
953_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
954_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
955_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
956_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
957_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
958_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
959_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
960_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
961
962#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
963
964// __promote
965
966template <class _A1, class _A2 = void, class _A3 = void,
967 bool = (is_arithmetic<_A1>::value || is_void<_A1>::value) &&
968 (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
969 (is_arithmetic<_A3>::value || is_void<_A3>::value)>
970class __promote {};
971
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972template <class _A1, class _A2, class _A3>
973class __promote<_A1, _A2, _A3, true>
974{
975private:
976 typedef typename __promote<_A1>::type __type1;
977 typedef typename __promote<_A2>::type __type2;
978 typedef typename __promote<_A3>::type __type3;
979public:
980 typedef __typeof__(__type1() + __type2() + __type3()) type;
981};
982
983template <class _A1, class _A2>
984class __promote<_A1, _A2, void, true>
985{
986private:
987 typedef typename __promote<_A1>::type __type1;
988 typedef typename __promote<_A2>::type __type2;
989public:
990 typedef __typeof__(__type1() + __type2()) type;
991};
992
993template <class _A1>
994class __promote<_A1, void, void, true>
995{
996public:
997 typedef typename conditional<is_arithmetic<_A1>::value,
998 typename conditional<is_integral<_A1>::value, double, _A1>::type,
999 void
1000 >::type type;
1001};
1002
1003#ifdef _LIBCPP_STORE_AS_OPTIMIZATION
1004
1005// __transform
1006
1007template <class _Tp, size_t = sizeof(_Tp), bool = is_scalar<_Tp>::value> struct __transform {typedef _Tp type;};
1008template <class _Tp> struct __transform<_Tp, 1, true> {typedef unsigned char type;};
1009template <class _Tp> struct __transform<_Tp, 2, true> {typedef unsigned short type;};
1010template <class _Tp> struct __transform<_Tp, 4, true> {typedef unsigned int type;};
1011template <class _Tp> struct __transform<_Tp, 8, true> {typedef unsigned long long type;};
1012
1013#endif // _LIBCPP_STORE_AS_OPTIMIZATION
1014
1015// make_signed / make_unsigned
1016
1017typedef
1018 __type_list<signed char,
1019 __type_list<signed short,
1020 __type_list<signed int,
1021 __type_list<signed long,
1022 __type_list<signed long long,
1023 __nat
1024 > > > > > __signed_types;
1025
1026typedef
1027 __type_list<unsigned char,
1028 __type_list<unsigned short,
1029 __type_list<unsigned int,
1030 __type_list<unsigned long,
1031 __type_list<unsigned long long,
1032 __nat
1033 > > > > > __unsigned_types;
1034
1035template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
1036
1037template <class _Hp, class _Tp, size_t _Size>
1038struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
1039{
1040 typedef _Hp type;
1041};
1042
1043template <class _Hp, class _Tp, size_t _Size>
1044struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
1045{
1046 typedef typename __find_first<_Tp, _Size>::type type;
1047};
1048
1049template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
1050 bool = is_volatile<typename remove_reference<_Tp>::type>::value>
1051struct __apply_cv
1052{
1053 typedef _Up type;
1054};
1055
1056template <class _Tp, class _Up>
1057struct __apply_cv<_Tp, _Up, true, false>
1058{
1059 typedef const _Up type;
1060};
1061
1062template <class _Tp, class _Up>
1063struct __apply_cv<_Tp, _Up, false, true>
1064{
1065 typedef volatile _Up type;
1066};
1067
1068template <class _Tp, class _Up>
1069struct __apply_cv<_Tp, _Up, true, true>
1070{
1071 typedef const volatile _Up type;
1072};
1073
1074template <class _Tp, class _Up>
1075struct __apply_cv<_Tp&, _Up, false, false>
1076{
1077 typedef _Up& type;
1078};
1079
1080template <class _Tp, class _Up>
1081struct __apply_cv<_Tp&, _Up, true, false>
1082{
1083 typedef const _Up& type;
1084};
1085
1086template <class _Tp, class _Up>
1087struct __apply_cv<_Tp&, _Up, false, true>
1088{
1089 typedef volatile _Up& type;
1090};
1091
1092template <class _Tp, class _Up>
1093struct __apply_cv<_Tp&, _Up, true, true>
1094{
1095 typedef const volatile _Up& type;
1096};
1097
1098template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1099struct __make_signed {};
1100
1101template <class _Tp>
1102struct __make_signed<_Tp, true>
1103{
1104 typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
1105};
1106
1107template <> struct __make_signed<bool, true> {};
1108template <> struct __make_signed< signed short, true> {typedef short type;};
1109template <> struct __make_signed<unsigned short, true> {typedef short type;};
1110template <> struct __make_signed< signed int, true> {typedef int type;};
1111template <> struct __make_signed<unsigned int, true> {typedef int type;};
1112template <> struct __make_signed< signed long, true> {typedef long type;};
1113template <> struct __make_signed<unsigned long, true> {typedef long type;};
1114template <> struct __make_signed< signed long long, true> {typedef long long type;};
1115template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
1116
1117template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001118struct _LIBCPP_VISIBLE make_signed
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119{
1120 typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
1121};
1122
1123template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1124struct __make_unsigned {};
1125
1126template <class _Tp>
1127struct __make_unsigned<_Tp, true>
1128{
1129 typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
1130};
1131
1132template <> struct __make_unsigned<bool, true> {};
1133template <> struct __make_unsigned< signed short, true> {typedef unsigned short type;};
1134template <> struct __make_unsigned<unsigned short, true> {typedef unsigned short type;};
1135template <> struct __make_unsigned< signed int, true> {typedef unsigned int type;};
1136template <> struct __make_unsigned<unsigned int, true> {typedef unsigned int type;};
1137template <> struct __make_unsigned< signed long, true> {typedef unsigned long type;};
1138template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;};
1139template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;};
1140template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
1141
1142template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001143struct _LIBCPP_VISIBLE make_unsigned
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144{
1145 typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
1146};
1147
1148#ifdef _LIBCPP_HAS_NO_VARIADICS
1149
1150template <class _Tp, class _Up = void, class V = void>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001151struct _LIBCPP_VISIBLE common_type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152{
1153public:
1154 typedef typename common_type<typename common_type<_Tp, _Up>::type, V>::type type;
1155};
1156
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001158struct _LIBCPP_VISIBLE common_type<_Tp, void, void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159{
1160public:
1161 typedef _Tp type;
1162};
1163
1164template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001165struct _LIBCPP_VISIBLE common_type<_Tp, _Up, void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166{
1167private:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001168#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 static _Tp&& __t();
1170 static _Up&& __u();
Howard Hinnant73d21a42010-09-04 23:28:19 +00001171#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172 static _Tp __t();
1173 static _Up __u();
Howard Hinnant73d21a42010-09-04 23:28:19 +00001174#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001175public:
Howard Hinnant726a76f2010-11-16 21:10:23 +00001176 typedef decltype(true ? __t() : __u()) type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001177};
1178
Howard Hinnant324bb032010-08-22 00:02:43 +00001179#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001180
1181template <class ..._Tp> struct common_type;
1182
1183template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001184struct _LIBCPP_VISIBLE common_type<_Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185{
1186 typedef _Tp type;
1187};
1188
1189template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001190struct _LIBCPP_VISIBLE common_type<_Tp, _Up>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191{
1192private:
1193 static _Tp&& __t();
1194 static _Up&& __u();
1195 static bool __f();
1196public:
1197 typedef decltype(__f() ? __t() : __u()) type;
1198};
1199
1200template <class _Tp, class _Up, class ..._Vp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001201struct _LIBCPP_VISIBLE common_type<_Tp, _Up, _Vp...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001202{
1203 typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
1204};
1205
Howard Hinnant324bb032010-08-22 00:02:43 +00001206#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001207
Howard Hinnant1468b662010-11-19 22:17:28 +00001208// is_assignable
1209
Howard Hinnant745d4732010-09-08 17:55:32 +00001210template <class _Tp, class _Arg>
1211decltype((_STD::declval<_Tp>() = _STD::declval<_Arg>(), true_type()))
1212#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1213__is_assignable_test(_Tp&&, _Arg&&);
1214#else
Howard Hinnant6063ec12011-05-13 14:08:16 +00001215__is_assignable_test(_Tp, _Arg&);
Howard Hinnant745d4732010-09-08 17:55:32 +00001216#endif
1217
1218template <class _Arg>
1219false_type
1220#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1221__is_assignable_test(__any, _Arg&&);
1222#else
1223__is_assignable_test(__any, _Arg&);
1224#endif
1225
Howard Hinnant6063ec12011-05-13 14:08:16 +00001226template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
Howard Hinnant745d4732010-09-08 17:55:32 +00001227struct __is_assignable_imp
1228 : public common_type
1229 <
1230 decltype(__is_assignable_test(declval<_Tp>(), declval<_Arg>()))
1231 >::type {};
1232
1233template <class _Tp, class _Arg>
Howard Hinnant6063ec12011-05-13 14:08:16 +00001234struct __is_assignable_imp<_Tp, _Arg, true>
1235 : public false_type
1236{
1237};
1238
1239template <class _Tp, class _Arg>
Howard Hinnant1468b662010-11-19 22:17:28 +00001240struct is_assignable
Howard Hinnant745d4732010-09-08 17:55:32 +00001241 : public __is_assignable_imp<_Tp, _Arg> {};
1242
Howard Hinnant1468b662010-11-19 22:17:28 +00001243// is_copy_assignable
Howard Hinnant745d4732010-09-08 17:55:32 +00001244
Howard Hinnant1468b662010-11-19 22:17:28 +00001245template <class _Tp> struct _LIBCPP_VISIBLE is_copy_assignable
Howard Hinnant6063ec12011-05-13 14:08:16 +00001246 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
1247 const typename add_lvalue_reference<_Tp>::type> {};
Howard Hinnant745d4732010-09-08 17:55:32 +00001248
Howard Hinnant1468b662010-11-19 22:17:28 +00001249// is_move_assignable
1250
1251template <class _Tp> struct _LIBCPP_VISIBLE is_move_assignable
1252#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant6063ec12011-05-13 14:08:16 +00001253 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
1254 const typename add_rvalue_reference<_Tp>::type> {};
Howard Hinnant1468b662010-11-19 22:17:28 +00001255#else
1256 : public is_copy_assignable<_Tp> {};
1257#endif
1258
1259// is_destructible
1260
1261template <class _Tp>
1262struct __destructible_test
1263{
1264 _Tp __t;
1265};
1266
1267template <class _Tp>
1268decltype((_STD::declval<__destructible_test<_Tp> >().~__destructible_test<_Tp>(), true_type()))
1269#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1270__is_destructible_test(_Tp&&);
1271#else
1272__is_destructible_test(_Tp&);
1273#endif
1274
1275false_type
1276__is_destructible_test(__any);
1277
1278template <class _Tp, bool = is_void<_Tp>::value || is_abstract<_Tp>::value>
1279struct __destructible_imp
1280 : public common_type
1281 <
1282 decltype(__is_destructible_test(declval<_Tp>()))
1283 >::type {};
1284
1285template <class _Tp>
1286struct __destructible_imp<_Tp, true>
Howard Hinnant745d4732010-09-08 17:55:32 +00001287 : public false_type {};
1288
Howard Hinnant1468b662010-11-19 22:17:28 +00001289template <class _Tp>
1290struct is_destructible
1291 : public __destructible_imp<_Tp> {};
Howard Hinnant745d4732010-09-08 17:55:32 +00001292
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293// move
1294
Howard Hinnant73d21a42010-09-04 23:28:19 +00001295#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001296
1297template <class _Tp>
1298inline _LIBCPP_INLINE_VISIBILITY
1299typename remove_reference<_Tp>::type&&
Howard Hinnante9b2c2d2011-05-27 15:04:19 +00001300move(_Tp&& __t) _NOEXCEPT
Howard Hinnant60a0a8e2010-08-10 20:48:29 +00001301{
Howard Hinnant726a76f2010-11-16 21:10:23 +00001302 typedef typename remove_reference<_Tp>::type _Up;
1303 return static_cast<_Up&&>(__t);
Howard Hinnant60a0a8e2010-08-10 20:48:29 +00001304}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305
Howard Hinnantd2a92512010-09-13 01:43:27 +00001306template <class _Tp>
1307inline _LIBCPP_INLINE_VISIBILITY
1308_Tp&&
Howard Hinnante9b2c2d2011-05-27 15:04:19 +00001309forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
Howard Hinnantd2a92512010-09-13 01:43:27 +00001310{
1311 return static_cast<_Tp&&>(__t);
1312}
1313
1314template <class _Tp>
1315inline _LIBCPP_INLINE_VISIBILITY
1316_Tp&&
Howard Hinnante9b2c2d2011-05-27 15:04:19 +00001317forward(typename std::remove_reference<_Tp>::type&& __t) _NOEXCEPT
Howard Hinnantd2a92512010-09-13 01:43:27 +00001318{
1319 static_assert(!std::is_lvalue_reference<_Tp>::value,
1320 "Can not forward an rvalue as an lvalue.");
1321 return static_cast<_Tp&&>(__t);
1322}
1323
Howard Hinnant73d21a42010-09-04 23:28:19 +00001324#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001325
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001326template <class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327class __rv
1328{
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001329 typedef typename remove_reference<_Tp>::type _Trr;
1330 _Trr& t_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001333 _Trr* operator->() {return &t_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001335 explicit __rv(_Trr& __t) : t_(__t) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336};
1337
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001338template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001339inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340typename enable_if
1341<
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001342 !is_convertible<_Tp, __rv<_Tp> >::value,
1343 _Tp&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001344>::type
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001345move(_Tp& __t)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001346{
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001347 return __t;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001348}
1349
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001350template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001351inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352typename enable_if
1353<
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001354 is_convertible<_Tp, __rv<_Tp> >::value,
1355 _Tp
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001356>::type
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001357move(_Tp& __t)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001358{
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001359 return _Tp(__rv<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360}
1361
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001362template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364typename enable_if
1365<
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001366 !is_convertible<_Tp, __rv<_Tp> >::value,
1367 typename add_lvalue_reference<_Tp>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001368>::type
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001369forward(_Up& __t)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370{
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001371 return __t;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001372}
1373
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001374template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001375inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376typename enable_if
1377<
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001378 !is_convertible<_Tp, __rv<_Tp> >::value,
1379 typename add_lvalue_reference<_Tp>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380>::type
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001381forward(const _Up& __t)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382{
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001383 return __t;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001384}
1385
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001386template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001387inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388typename enable_if
1389<
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001390 is_convertible<_Tp, __rv<_Tp> >::value,
1391 _Tp
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001392>::type
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001393forward(_Up& __t)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394{
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001395 return _Tp(__rv<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396}
1397
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001398template <class _Tp, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001399inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400typename enable_if
1401<
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001402 is_convertible<_Tp, __rv<_Tp> >::value,
1403 _Tp
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404>::type
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001405forward(const _Up& __t)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406{
Howard Hinnantd8bc09b2010-05-18 17:32:30 +00001407 return _Tp(__rv<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408}
1409
Howard Hinnant73d21a42010-09-04 23:28:19 +00001410#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001413struct _LIBCPP_VISIBLE decay
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414{
1415private:
1416 typedef typename remove_reference<_Tp>::type _Up;
1417public:
1418 typedef typename conditional
1419 <
1420 is_array<_Up>::value,
1421 typename remove_extent<_Up>::type*,
1422 typename conditional
1423 <
1424 is_function<_Up>::value,
1425 typename add_pointer<_Up>::type,
1426 typename remove_cv<_Up>::type
1427 >::type
1428 >::type type;
1429};
1430
Howard Hinnant656bdc32011-05-16 18:40:35 +00001431template <class _Tp>
1432inline _LIBCPP_INLINE_VISIBILITY
1433typename decay<_Tp>::type
1434__decay_copy(_Tp&& __t)
1435{
1436 return _STD::forward<_Tp>(__t);
1437}
1438
Howard Hinnant37c53b62011-05-16 16:17:21 +00001439template <class _MP, bool _IsMemberFuctionPtr, bool _IsMemberObjectPtr>
1440struct __member_pointer_traits_imp
1441{
1442};
1443
1444#ifndef _LIBCPP_HAS_NO_VARIADICS
1445
1446template <class _R, class _Class, class ..._Param>
1447struct __member_pointer_traits_imp<_R (_Class::*)(_Param...), true, false>
1448{
1449 typedef _Class _ClassType;
1450 typedef _R _ReturnType;
1451};
1452
1453template <class _R, class _Class, class ..._Param>
1454struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) const, true, false>
1455{
1456 typedef _Class const _ClassType;
1457 typedef _R _ReturnType;
1458};
1459
1460template <class _R, class _Class, class ..._Param>
1461struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) volatile, true, false>
1462{
1463 typedef _Class volatile _ClassType;
1464 typedef _R _ReturnType;
1465};
1466
1467template <class _R, class _Class, class ..._Param>
1468struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) const volatile, true, false>
1469{
1470 typedef _Class const volatile _ClassType;
1471 typedef _R _ReturnType;
1472};
1473
1474#if __has_feature(cxx_reference_qualified_functions)
1475
1476template <class _R, class _Class, class ..._Param>
1477struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) &, true, false>
1478{
1479 typedef _Class& _ClassType;
1480 typedef _R _ReturnType;
1481};
1482
1483template <class _R, class _Class, class ..._Param>
1484struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) const&, true, false>
1485{
1486 typedef _Class const& _ClassType;
1487 typedef _R _ReturnType;
1488};
1489
1490template <class _R, class _Class, class ..._Param>
1491struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) volatile&, true, false>
1492{
1493 typedef _Class volatile& _ClassType;
1494 typedef _R _ReturnType;
1495};
1496
1497template <class _R, class _Class, class ..._Param>
1498struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) const volatile&, true, false>
1499{
1500 typedef _Class const volatile& _ClassType;
1501 typedef _R _ReturnType;
1502};
1503
1504template <class _R, class _Class, class ..._Param>
1505struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) &&, true, false>
1506{
1507 typedef _Class&& _ClassType;
1508 typedef _R _ReturnType;
1509};
1510
1511template <class _R, class _Class, class ..._Param>
1512struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) const&&, true, false>
1513{
1514 typedef _Class const&& _ClassType;
1515 typedef _R _ReturnType;
1516};
1517
1518template <class _R, class _Class, class ..._Param>
1519struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) volatile&&, true, false>
1520{
1521 typedef _Class volatile&& _ClassType;
1522 typedef _R _ReturnType;
1523};
1524
1525template <class _R, class _Class, class ..._Param>
1526struct __member_pointer_traits_imp<_R (_Class::*)(_Param...) const volatile&&, true, false>
1527{
1528 typedef _Class const volatile&& _ClassType;
1529 typedef _R _ReturnType;
1530};
1531
1532#endif // __has_feature(cxx_reference_qualified_functions)
1533
1534#else // _LIBCPP_HAS_NO_VARIADICS
1535
1536template <class _R, class _Class>
1537struct __member_pointer_traits_imp<_R (_Class::*)(), true, false>
1538{
1539 typedef _Class _ClassType;
1540 typedef _R _ReturnType;
1541};
1542
1543template <class _R, class _Class, class _P0>
1544struct __member_pointer_traits_imp<_R (_Class::*)(_P0), true, false>
1545{
1546 typedef _Class _ClassType;
1547 typedef _R _ReturnType;
1548};
1549
1550template <class _R, class _Class, class _P0, class _P1>
1551struct __member_pointer_traits_imp<_R (_Class::*)(_P0, _P1), true, false>
1552{
1553 typedef _Class _ClassType;
1554 typedef _R _ReturnType;
1555};
1556
1557template <class _R, class _Class, class _P0, class _P1, class _P2>
1558struct __member_pointer_traits_imp<_R (_Class::*)(_P0, _P1, _P2), true, false>
1559{
1560 typedef _Class _ClassType;
1561 typedef _R _ReturnType;
1562};
1563
1564template <class _R, class _Class>
1565struct __member_pointer_traits_imp<_R (_Class::*)() const, true, false>
1566{
1567 typedef _Class const _ClassType;
1568 typedef _R _ReturnType;
1569};
1570
1571template <class _R, class _Class, class _P0>
1572struct __member_pointer_traits_imp<_R (_Class::*)(_P0) const, true, false>
1573{
1574 typedef _Class const _ClassType;
1575 typedef _R _ReturnType;
1576};
1577
1578template <class _R, class _Class, class _P0, class _P1>
1579struct __member_pointer_traits_imp<_R (_Class::*)(_P0, _P1) const, true, false>
1580{
1581 typedef _Class const _ClassType;
1582 typedef _R _ReturnType;
1583};
1584
1585template <class _R, class _Class, class _P0, class _P1, class _P2>
1586struct __member_pointer_traits_imp<_R (_Class::*)(_P0, _P1, _P2) const, true, false>
1587{
1588 typedef _Class const _ClassType;
1589 typedef _R _ReturnType;
1590};
1591
1592template <class _R, class _Class>
1593struct __member_pointer_traits_imp<_R (_Class::*)() volatile, true, false>
1594{
1595 typedef _Class volatile _ClassType;
1596 typedef _R _ReturnType;
1597};
1598
1599template <class _R, class _Class, class _P0>
1600struct __member_pointer_traits_imp<_R (_Class::*)(_P0) volatile, true, false>
1601{
1602 typedef _Class volatile _ClassType;
1603 typedef _R _ReturnType;
1604};
1605
1606template <class _R, class _Class, class _P0, class _P1>
1607struct __member_pointer_traits_imp<_R (_Class::*)(_P0, _P1) volatile, true, false>
1608{
1609 typedef _Class volatile _ClassType;
1610 typedef _R _ReturnType;
1611};
1612
1613template <class _R, class _Class, class _P0, class _P1, class _P2>
1614struct __member_pointer_traits_imp<_R (_Class::*)(_P0, _P1, _P2) volatile, true, false>
1615{
1616 typedef _Class volatile _ClassType;
1617 typedef _R _ReturnType;
1618};
1619
1620template <class _R, class _Class>
1621struct __member_pointer_traits_imp<_R (_Class::*)() const volatile, true, false>
1622{
1623 typedef _Class const volatile _ClassType;
1624 typedef _R _ReturnType;
1625};
1626
1627template <class _R, class _Class, class _P0>
1628struct __member_pointer_traits_imp<_R (_Class::*)(_P0) const volatile, true, false>
1629{
1630 typedef _Class const volatile _ClassType;
1631 typedef _R _ReturnType;
1632};
1633
1634template <class _R, class _Class, class _P0, class _P1>
1635struct __member_pointer_traits_imp<_R (_Class::*)(_P0, _P1) const volatile, true, false>
1636{
1637 typedef _Class const volatile _ClassType;
1638 typedef _R _ReturnType;
1639};
1640
1641template <class _R, class _Class, class _P0, class _P1, class _P2>
1642struct __member_pointer_traits_imp<_R (_Class::*)(_P0, _P1, _P2) const volatile, true, false>
1643{
1644 typedef _Class const volatile _ClassType;
1645 typedef _R _ReturnType;
1646};
1647
1648#endif // _LIBCPP_HAS_NO_VARIADICS
1649
1650template <class _R, class _Class>
1651struct __member_pointer_traits_imp<_R _Class::*, false, true>
1652{
1653 typedef _Class _ClassType;
1654 typedef _R _ReturnType;
1655};
1656
1657template <class _MP>
1658struct __member_pointer_traits
1659 : public __member_pointer_traits_imp<_MP,
1660 is_member_function_pointer<_MP>::value,
1661 is_member_object_pointer<_MP>::value>
1662{
1663// typedef ... _ClassType;
1664// typedef ... _ReturnType;
1665};
1666
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667// result_of
1668
1669template <class> class result_of;
1670
Howard Hinnant37c53b62011-05-16 16:17:21 +00001671template <class _Fn, bool, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672class __result_of
1673{
1674};
1675
1676#ifndef _LIBCPP_HAS_NO_VARIADICS
1677
1678template <class _Fn, class ..._ArgTypes>
Howard Hinnant37c53b62011-05-16 16:17:21 +00001679class __result_of<_Fn(_ArgTypes...), true, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680{
1681public:
1682 typedef decltype(declval<_Fn>()(declval<_ArgTypes>()...)) type;
1683};
1684
Howard Hinnant37c53b62011-05-16 16:17:21 +00001685template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
1686struct __result_of_mp;
Howard Hinnant4a23e1e2010-08-18 18:52:04 +00001687
1688// member function pointer
1689
Howard Hinnant37c53b62011-05-16 16:17:21 +00001690template <class _MP, class _Tp>
1691struct __result_of_mp<_MP, _Tp, true>
1692 : public common_type<typename __member_pointer_traits<_MP>::_ReturnType>
Howard Hinnant4a23e1e2010-08-18 18:52:04 +00001693{
Howard Hinnant4a23e1e2010-08-18 18:52:04 +00001694};
1695
1696// member data pointer
1697
1698template <class _MP, class _Tp, bool>
1699struct __result_of_mdp;
1700
1701template <class _R, class _Class, class _Tp>
1702struct __result_of_mdp<_R _Class::*, _Tp, false>
1703{
Howard Hinnant37c53b62011-05-16 16:17:21 +00001704 typedef typename __apply_cv<decltype(*_STD::declval<_Tp>()), _R>::type&& type;
Howard Hinnant4a23e1e2010-08-18 18:52:04 +00001705};
1706
1707template <class _R, class _Class, class _Tp>
1708struct __result_of_mdp<_R _Class::*, _Tp, true>
1709{
1710 typedef typename __apply_cv<_Tp, _R>::type&& type;
1711};
1712
1713template <class _R, class _Class, class _Tp>
Howard Hinnanteee76982010-12-11 00:05:19 +00001714struct __result_of_mp<_R _Class::*, _Tp, false>
Howard Hinnant4a23e1e2010-08-18 18:52:04 +00001715 : public __result_of_mdp<_R _Class::*, _Tp,
1716 is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
1717{
1718};
1719
1720template <class _Fn, class _Tp, class ..._ArgTypes>
Howard Hinnant37c53b62011-05-16 16:17:21 +00001721class __result_of<_Fn(_Tp, _ArgTypes...), false, true> // _Fn must be member pointer
1722 : public __result_of_mp<typename remove_reference<_Fn>::type,
1723 _Tp,
1724 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
Howard Hinnant4a23e1e2010-08-18 18:52:04 +00001725{
1726};
1727
Howard Hinnant4a23e1e2010-08-18 18:52:04 +00001728// result_of
1729
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730template <class _Fn, class ..._ArgTypes>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001731class _LIBCPP_VISIBLE result_of<_Fn(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001732 : public __result_of<_Fn(_ArgTypes...),
1733 is_class<typename remove_reference<_Fn>::type>::value ||
Howard Hinnant37c53b62011-05-16 16:17:21 +00001734 is_function<typename remove_reference<_Fn>::type>::value,
1735 is_member_pointer<typename remove_reference<_Fn>::type>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736 >
1737{
1738};
1739
Howard Hinnant324bb032010-08-22 00:02:43 +00001740#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741
1742template <class _Fn>
Howard Hinnant37c53b62011-05-16 16:17:21 +00001743class __result_of<_Fn(), true, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744{
1745public:
1746 typedef decltype(declval<_Fn>()()) type;
1747};
1748
1749template <class _Fn, class _A0>
Howard Hinnant37c53b62011-05-16 16:17:21 +00001750class __result_of<_Fn(_A0), true, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751{
1752public:
1753 typedef decltype(declval<_Fn>()(declval<_A0>())) type;
1754};
1755
1756template <class _Fn, class _A0, class _A1>
Howard Hinnant37c53b62011-05-16 16:17:21 +00001757class __result_of<_Fn(_A0, _A1), true, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001758{
1759public:
1760 typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
1761};
1762
1763template <class _Fn, class _A0, class _A1, class _A2>
Howard Hinnant37c53b62011-05-16 16:17:21 +00001764class __result_of<_Fn(_A0, _A1, _A2), true, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001765{
1766public:
1767 typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
1768};
1769
Howard Hinnant37c53b62011-05-16 16:17:21 +00001770template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
1771struct __result_of_mp;
1772
1773// member function pointer
1774
1775template <class _MP, class _Tp>
1776struct __result_of_mp<_MP, _Tp, true>
1777 : public common_type<typename __member_pointer_traits<_MP>::_ReturnType>
1778{
1779};
1780
1781// member data pointer
1782
1783template <class _MP, class _Tp, bool>
1784struct __result_of_mdp;
1785
1786template <class _R, class _Class, class _Tp>
1787struct __result_of_mdp<_R _Class::*, _Tp, false>
1788{
1789 typedef typename __apply_cv<decltype(*_STD::declval<_Tp>()), _R>::type& type;
1790};
1791
1792template <class _R, class _Class, class _Tp>
1793struct __result_of_mdp<_R _Class::*, _Tp, true>
1794{
1795 typedef typename __apply_cv<_Tp, _R>::type& type;
1796};
1797
1798template <class _R, class _Class, class _Tp>
1799struct __result_of_mp<_R _Class::*, _Tp, false>
1800 : public __result_of_mdp<_R _Class::*, _Tp,
1801 is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
1802{
1803};
1804
1805
1806
1807template <class _Fn, class _Tp>
1808class __result_of<_Fn(_Tp), false, true> // _Fn must be member pointer
1809 : public __result_of_mp<typename remove_reference<_Fn>::type,
1810 _Tp,
1811 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1812{
1813};
1814
1815template <class _Fn, class _Tp, class _A0>
1816class __result_of<_Fn(_Tp, _A0), false, true> // _Fn must be member pointer
1817 : public __result_of_mp<typename remove_reference<_Fn>::type,
1818 _Tp,
1819 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1820{
1821};
1822
1823template <class _Fn, class _Tp, class _A0, class _A1>
1824class __result_of<_Fn(_Tp, _A0, _A1), false, true> // _Fn must be member pointer
1825 : public __result_of_mp<typename remove_reference<_Fn>::type,
1826 _Tp,
1827 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1828{
1829};
1830
1831template <class _Fn, class _Tp, class _A0, class _A1, class _A2>
1832class __result_of<_Fn(_Tp, _A0, _A1, _A2), false, true> // _Fn must be member pointer
1833 : public __result_of_mp<typename remove_reference<_Fn>::type,
1834 _Tp,
1835 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
1836{
1837};
1838
1839// result_of
1840
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001841template <class _Fn>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001842class _LIBCPP_VISIBLE result_of<_Fn()>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843 : public __result_of<_Fn(),
1844 is_class<typename remove_reference<_Fn>::type>::value ||
Howard Hinnant37c53b62011-05-16 16:17:21 +00001845 is_function<typename remove_reference<_Fn>::type>::value,
1846 is_member_pointer<typename remove_reference<_Fn>::type>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847 >
1848{
1849};
1850
1851template <class _Fn, class _A0>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001852class _LIBCPP_VISIBLE result_of<_Fn(_A0)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853 : public __result_of<_Fn(_A0),
1854 is_class<typename remove_reference<_Fn>::type>::value ||
Howard Hinnant37c53b62011-05-16 16:17:21 +00001855 is_function<typename remove_reference<_Fn>::type>::value,
1856 is_member_pointer<typename remove_reference<_Fn>::type>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857 >
1858{
1859};
1860
1861template <class _Fn, class _A0, class _A1>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001862class _LIBCPP_VISIBLE result_of<_Fn(_A0, _A1)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863 : public __result_of<_Fn(_A0, _A1),
1864 is_class<typename remove_reference<_Fn>::type>::value ||
Howard Hinnant37c53b62011-05-16 16:17:21 +00001865 is_function<typename remove_reference<_Fn>::type>::value,
1866 is_member_pointer<typename remove_reference<_Fn>::type>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001867 >
1868{
1869};
1870
1871template <class _Fn, class _A0, class _A1, class _A2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001872class _LIBCPP_VISIBLE result_of<_Fn(_A0, _A1, _A2)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873 : public __result_of<_Fn(_A0, _A1, _A2),
1874 is_class<typename remove_reference<_Fn>::type>::value ||
Howard Hinnant37c53b62011-05-16 16:17:21 +00001875 is_function<typename remove_reference<_Fn>::type>::value,
1876 is_member_pointer<typename remove_reference<_Fn>::type>::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877 >
1878{
1879};
1880
Howard Hinnant324bb032010-08-22 00:02:43 +00001881#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882
Howard Hinnant1468b662010-11-19 22:17:28 +00001883#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884
1885// template <class T, class... Args> struct is_constructible;
1886
1887// main is_constructible test
1888
1889template <class _Tp, class ..._Args>
1890decltype(_STD::move(_Tp(_STD::declval<_Args>()...)), true_type())
1891__is_constructible_test(_Tp&&, _Args&& ...);
1892
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001893template <class ..._Args>
1894false_type
1895__is_constructible_test(__any, _Args&& ...);
1896
1897template <bool, class _Tp, class... _Args>
1898struct __is_constructible // false, _Tp is not a scalar
1899 : public common_type
1900 <
1901 decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...))
1902 >::type
1903 {};
1904
1905// function types are not constructible
1906
1907template <class _R, class... _A1, class... _A2>
1908struct __is_constructible<false, _R(_A1...), _A2...>
1909 : public false_type
1910 {};
1911
1912// handle scalars and reference types
1913
1914// Scalars are default constructible, references are not
1915
1916template <class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00001917struct __is_constructible<true, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918 : public is_scalar<_Tp>
1919 {};
1920
1921// Scalars and references are constructible from one arg if that arg is
1922// implicitly convertible to the scalar or reference.
1923
1924template <class _Tp>
1925struct __is_constructible_ref
1926{
1927 true_type static __(_Tp);
1928 false_type static __(...);
1929};
1930
1931template <class _Tp, class _A0>
Howard Hinnant324bb032010-08-22 00:02:43 +00001932struct __is_constructible<true, _Tp, _A0>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933 : public common_type
1934 <
1935 decltype(__is_constructible_ref<_Tp>::__(declval<_A0>()))
1936 >::type
1937 {};
1938
1939// Scalars and references are not constructible from multiple args.
1940
1941template <class _Tp, class _A0, class ..._Args>
Howard Hinnant324bb032010-08-22 00:02:43 +00001942struct __is_constructible<true, _Tp, _A0, _Args...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943 : public false_type
1944 {};
1945
1946// Treat scalars and reference types separately
1947
1948template <bool, class _Tp, class... _Args>
1949struct __is_constructible_void_check
1950 : public __is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
1951 _Tp, _Args...>
1952 {};
1953
1954// If any of T or Args is void, is_constructible should be false
1955
1956template <class _Tp, class... _Args>
1957struct __is_constructible_void_check<true, _Tp, _Args...>
1958 : public false_type
1959 {};
1960
Howard Hinnant17615b02010-07-27 01:25:38 +00001961template <class ..._Args> struct __contains_void;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962
Howard Hinnant17615b02010-07-27 01:25:38 +00001963template <> struct __contains_void<> : false_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964
1965template <class _A0, class ..._Args>
Howard Hinnant17615b02010-07-27 01:25:38 +00001966struct __contains_void<_A0, _Args...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001967{
1968 static const bool value = is_void<_A0>::value ||
Howard Hinnant17615b02010-07-27 01:25:38 +00001969 __contains_void<_Args...>::value;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970};
1971
1972// is_constructible entry point
1973
1974template <class _Tp, class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001975struct _LIBCPP_VISIBLE is_constructible
Howard Hinnant17615b02010-07-27 01:25:38 +00001976 : public __is_constructible_void_check<__contains_void<_Tp, _Args...>::value
1977 || is_abstract<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001978 _Tp, _Args...>
1979 {};
1980
1981// Array types are default constructible if their element type
1982// is default constructible
1983
1984template <class _A, size_t _N>
1985struct __is_constructible<false, _A[_N]>
1986 : public is_constructible<typename remove_all_extents<_A>::type>
1987 {};
1988
1989// Otherwise array types are not constructible by this syntax
1990
1991template <class _A, size_t _N, class ..._Args>
1992struct __is_constructible<false, _A[_N], _Args...>
1993 : public false_type
1994 {};
1995
1996// Incomplete array types are not constructible
1997
1998template <class _A, class ..._Args>
1999struct __is_constructible<false, _A[], _Args...>
2000 : public false_type
2001 {};
2002
Howard Hinnant1468b662010-11-19 22:17:28 +00002003#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbb73d762010-09-07 17:47:31 +00002004
2005// template <class T> struct is_constructible0;
2006
2007// main is_constructible0 test
2008
2009template <class _Tp>
Howard Hinnant1468b662010-11-19 22:17:28 +00002010decltype((_Tp(), true_type()))
Howard Hinnantbb73d762010-09-07 17:47:31 +00002011__is_constructible0_test(_Tp&);
2012
2013false_type
2014__is_constructible0_test(__any);
2015
Howard Hinnant1468b662010-11-19 22:17:28 +00002016template <class _Tp, class _A0>
2017decltype((_Tp(_STD::declval<_A0>()), true_type()))
2018__is_constructible1_test(_Tp&, _A0&);
2019
2020template <class _A0>
2021false_type
2022__is_constructible1_test(__any, _A0&);
2023
2024template <class _Tp, class _A0, class _A1>
2025decltype((_Tp(_STD::declval<_A0>(), _STD::declval<_A1>()), true_type()))
2026__is_constructible2_test(_Tp&, _A0&, _A1&);
2027
2028template <class _A0, class _A1>
2029false_type
2030__is_constructible2_test(__any, _A0&, _A1&);
2031
Howard Hinnantbb73d762010-09-07 17:47:31 +00002032template <bool, class _Tp>
2033struct __is_constructible0_imp // false, _Tp is not a scalar
2034 : public common_type
2035 <
2036 decltype(__is_constructible0_test(declval<_Tp&>()))
2037 >::type
2038 {};
2039
Howard Hinnant1468b662010-11-19 22:17:28 +00002040template <bool, class _Tp, class _A0>
2041struct __is_constructible1_imp // false, _Tp is not a scalar
2042 : public common_type
2043 <
2044 decltype(__is_constructible1_test(declval<_Tp&>(), declval<_A0&>()))
2045 >::type
2046 {};
2047
2048template <bool, class _Tp, class _A0, class _A1>
2049struct __is_constructible2_imp // false, _Tp is not a scalar
2050 : public common_type
2051 <
2052 decltype(__is_constructible2_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>()))
2053 >::type
2054 {};
2055
Howard Hinnantbb73d762010-09-07 17:47:31 +00002056// handle scalars and reference types
2057
2058// Scalars are default constructible, references are not
2059
2060template <class _Tp>
2061struct __is_constructible0_imp<true, _Tp>
2062 : public is_scalar<_Tp>
2063 {};
2064
Howard Hinnant1468b662010-11-19 22:17:28 +00002065template <class _Tp, class _A0>
2066struct __is_constructible1_imp<true, _Tp, _A0>
2067 : public is_convertible<_A0, _Tp>
2068 {};
2069
2070template <class _Tp, class _A0, class _A1>
2071struct __is_constructible2_imp<true, _Tp, _A0, _A1>
2072 : public false_type
2073 {};
2074
Howard Hinnantbb73d762010-09-07 17:47:31 +00002075// Treat scalars and reference types separately
2076
2077template <bool, class _Tp>
2078struct __is_constructible0_void_check
2079 : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2080 _Tp>
2081 {};
2082
Howard Hinnant1468b662010-11-19 22:17:28 +00002083template <bool, class _Tp, class _A0>
2084struct __is_constructible1_void_check
2085 : public __is_constructible1_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2086 _Tp, _A0>
2087 {};
2088
2089template <bool, class _Tp, class _A0, class _A1>
2090struct __is_constructible2_void_check
2091 : public __is_constructible2_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2092 _Tp, _A0, _A1>
2093 {};
2094
Howard Hinnantbb73d762010-09-07 17:47:31 +00002095// If any of T or Args is void, is_constructible should be false
2096
2097template <class _Tp>
2098struct __is_constructible0_void_check<true, _Tp>
2099 : public false_type
2100 {};
2101
Howard Hinnant1468b662010-11-19 22:17:28 +00002102template <class _Tp, class _A0>
2103struct __is_constructible1_void_check<true, _Tp, _A0>
2104 : public false_type
2105 {};
2106
2107template <class _Tp, class _A0, class _A1>
2108struct __is_constructible2_void_check<true, _Tp, _A0, _A1>
2109 : public false_type
2110 {};
2111
2112// is_constructible entry point
2113
2114namespace __is_construct
2115{
2116
2117struct __nat {};
2118
2119}
2120
2121template <class _Tp, class _A0 = __is_construct::__nat,
2122 class _A1 = __is_construct::__nat>
2123struct _LIBCPP_VISIBLE is_constructible
2124 : public __is_constructible2_void_check<is_void<_Tp>::value
2125 || is_abstract<_Tp>::value
2126 || is_function<_Tp>::value
2127 || is_void<_A0>::value
2128 || is_void<_A1>::value,
2129 _Tp, _A0, _A1>
2130 {};
Howard Hinnantbb73d762010-09-07 17:47:31 +00002131
2132template <class _Tp>
Howard Hinnant1468b662010-11-19 22:17:28 +00002133struct _LIBCPP_VISIBLE is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat>
Howard Hinnantbb73d762010-09-07 17:47:31 +00002134 : public __is_constructible0_void_check<is_void<_Tp>::value
Howard Hinnant1468b662010-11-19 22:17:28 +00002135 || is_abstract<_Tp>::value
2136 || is_function<_Tp>::value,
Howard Hinnantbb73d762010-09-07 17:47:31 +00002137 _Tp>
2138 {};
2139
Howard Hinnant1468b662010-11-19 22:17:28 +00002140template <class _Tp, class _A0>
2141struct _LIBCPP_VISIBLE is_constructible<_Tp, _A0, __is_construct::__nat>
2142 : public __is_constructible1_void_check<is_void<_Tp>::value
2143 || is_abstract<_Tp>::value
2144 || is_function<_Tp>::value
2145 || is_void<_A0>::value,
2146 _Tp, _A0>
2147 {};
2148
Howard Hinnantbb73d762010-09-07 17:47:31 +00002149// Array types are default constructible if their element type
2150// is default constructible
2151
2152template <class _A, size_t _N>
2153struct __is_constructible0_imp<false, _A[_N]>
Howard Hinnant1468b662010-11-19 22:17:28 +00002154 : public is_constructible<typename remove_all_extents<_A>::type>
2155 {};
2156
2157template <class _A, size_t _N, class _A0>
2158struct __is_constructible1_imp<false, _A[_N], _A0>
2159 : public false_type
2160 {};
2161
2162template <class _A, size_t _N, class _A0, class _A1>
2163struct __is_constructible2_imp<false, _A[_N], _A0, _A1>
2164 : public false_type
Howard Hinnantbb73d762010-09-07 17:47:31 +00002165 {};
2166
2167// Incomplete array types are not constructible
2168
2169template <class _A>
2170struct __is_constructible0_imp<false, _A[]>
2171 : public false_type
2172 {};
2173
Howard Hinnant1468b662010-11-19 22:17:28 +00002174template <class _A, class _A0>
2175struct __is_constructible1_imp<false, _A[], _A0>
2176 : public false_type
Howard Hinnant954b3662010-09-07 23:11:28 +00002177 {};
2178
Howard Hinnant1468b662010-11-19 22:17:28 +00002179template <class _A, class _A0, class _A1>
2180struct __is_constructible2_imp<false, _A[], _A0, _A1>
2181 : public false_type
Howard Hinnant954b3662010-09-07 23:11:28 +00002182 {};
2183
Howard Hinnant1468b662010-11-19 22:17:28 +00002184#endif // _LIBCPP_HAS_NO_VARIADICS
2185
2186// is_default_constructible
2187
2188template <class _Tp>
2189struct _LIBCPP_VISIBLE is_default_constructible
2190 : public is_constructible<_Tp>
2191 {};
2192
2193// is_copy_constructible
2194
2195template <class _Tp>
2196struct _LIBCPP_VISIBLE is_copy_constructible
2197 : public is_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
2198 {};
2199
2200// is_move_constructible
2201
2202template <class _Tp>
2203struct _LIBCPP_VISIBLE is_move_constructible
2204#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2205 : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2206#else
2207 : public is_copy_constructible<_Tp>
2208#endif
2209 {};
2210
2211// is_trivially_constructible
2212
2213#ifndef _LIBCPP_HAS_NO_VARIADICS
2214
2215template <class _Tp, class... _Args>
2216struct _LIBCPP_VISIBLE is_trivially_constructible
2217 : false_type
2218{
2219};
2220
2221template <class _Tp>
2222struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp>
Howard Hinnant36666952011-05-09 19:21:17 +00002223#if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002224 : integral_constant<bool, __has_trivial_constructor(_Tp)>
2225#else
2226 : integral_constant<bool, is_scalar<_Tp>::value>
2227#endif
2228{
2229};
2230
2231template <class _Tp>
2232#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2233struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&&>
2234#else
2235struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp>
2236#endif
Howard Hinnant36666952011-05-09 19:21:17 +00002237#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002238 : integral_constant<bool, __has_trivial_copy(_Tp)>
2239#else
2240 : integral_constant<bool, is_scalar<_Tp>::value>
2241#endif
2242{
2243};
2244
2245template <class _Tp>
2246struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&>
Howard Hinnant36666952011-05-09 19:21:17 +00002247#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002248 : integral_constant<bool, __has_trivial_copy(_Tp)>
2249#else
2250 : integral_constant<bool, is_scalar<_Tp>::value>
2251#endif
2252{
2253};
2254
2255template <class _Tp>
2256struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&>
Howard Hinnant36666952011-05-09 19:21:17 +00002257#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002258 : integral_constant<bool, __has_trivial_copy(_Tp)>
2259#else
2260 : integral_constant<bool, is_scalar<_Tp>::value>
2261#endif
2262{
2263};
2264
2265#else // _LIBCPP_HAS_NO_VARIADICS
2266
2267template <class _Tp, class _A0 = __is_construct::__nat,
2268 class _A1 = __is_construct::__nat>
2269struct _LIBCPP_VISIBLE is_trivially_constructible
2270 : false_type
2271{
2272};
2273
2274template <class _Tp>
2275struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat,
2276 __is_construct::__nat>
Howard Hinnant36666952011-05-09 19:21:17 +00002277#if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002278 : integral_constant<bool, __has_trivial_constructor(_Tp)>
2279#else
2280 : integral_constant<bool, is_scalar<_Tp>::value>
2281#endif
2282{
2283};
2284
2285template <class _Tp>
2286struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp,
2287 __is_construct::__nat>
Howard Hinnant36666952011-05-09 19:21:17 +00002288#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002289 : integral_constant<bool, __has_trivial_copy(_Tp)>
2290#else
2291 : integral_constant<bool, is_scalar<_Tp>::value>
2292#endif
2293{
2294};
2295
2296template <class _Tp>
2297struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&,
2298 __is_construct::__nat>
Howard Hinnant36666952011-05-09 19:21:17 +00002299#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002300 : integral_constant<bool, __has_trivial_copy(_Tp)>
2301#else
2302 : integral_constant<bool, is_scalar<_Tp>::value>
2303#endif
2304{
2305};
2306
2307template <class _Tp>
2308struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&,
2309 __is_construct::__nat>
Howard Hinnant36666952011-05-09 19:21:17 +00002310#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002311 : integral_constant<bool, __has_trivial_copy(_Tp)>
2312#else
2313 : integral_constant<bool, is_scalar<_Tp>::value>
2314#endif
2315{
2316};
2317
2318#endif // _LIBCPP_HAS_NO_VARIADICS
2319
2320// is_trivially_default_constructible
2321
2322template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_default_constructible
2323 : public is_trivially_constructible<_Tp>
2324 {};
2325
2326// is_trivially_copy_constructible
2327
2328template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_constructible
2329 : public is_trivially_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
2330 {};
2331
2332// is_trivially_move_constructible
2333
2334template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_move_constructible
2335#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2336 : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2337#else
2338 : public is_trivially_copy_constructible<_Tp>
2339#endif
2340 {};
2341
2342// is_trivially_assignable
2343
2344template <class _Tp, class _Arg>
2345struct is_trivially_assignable
2346 : public false_type {};
2347
2348template <class _Tp>
2349struct is_trivially_assignable<_Tp&, _Tp>
Howard Hinnant36666952011-05-09 19:21:17 +00002350#if __has_feature(has_trivial_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002351 : integral_constant<bool, __has_trivial_assign(_Tp)> {};
2352#else
2353 : integral_constant<bool, is_scalar<_Tp>::value> {};
2354#endif
2355
2356template <class _Tp>
2357struct is_trivially_assignable<_Tp&, _Tp&>
Howard Hinnant36666952011-05-09 19:21:17 +00002358#if __has_feature(has_trivial_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002359 : integral_constant<bool, __has_trivial_assign(_Tp)> {};
2360#else
2361 : integral_constant<bool, is_scalar<_Tp>::value> {};
2362#endif
2363
2364template <class _Tp>
2365struct is_trivially_assignable<_Tp&, const _Tp&>
Howard Hinnant36666952011-05-09 19:21:17 +00002366#if __has_feature(has_trivial_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002367 : integral_constant<bool, __has_trivial_assign(_Tp)> {};
2368#else
2369 : integral_constant<bool, is_scalar<_Tp>::value> {};
2370#endif
2371
2372#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2373
2374template <class _Tp>
2375struct is_trivially_assignable<_Tp&, _Tp&&>
Howard Hinnant36666952011-05-09 19:21:17 +00002376#if __has_feature(has_trivial_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002377 : integral_constant<bool, __has_trivial_assign(_Tp)> {};
2378#else
2379 : integral_constant<bool, is_scalar<_Tp>::value> {};
2380#endif
2381
2382#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2383
2384// is_trivially_copy_assignable
2385
2386template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_assignable
2387 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2388 const typename add_lvalue_reference<_Tp>::type>
2389 {};
2390
2391// is_trivially_move_assignable
2392
2393template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_move_assignable
2394 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2395#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2396 typename add_rvalue_reference<_Tp>::type>
2397#else
2398 typename add_lvalue_reference<_Tp>::type>
2399#endif
2400 {};
2401
2402// is_trivially_destructible
2403
Howard Hinnant36666952011-05-09 19:21:17 +00002404#if __has_feature(has_trivial_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002405
2406template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_destructible
2407 : public integral_constant<bool, __has_trivial_destructor(_Tp)> {};
2408
2409#else // _LIBCPP_HAS_TYPE_TRAITS
2410
2411template <class _Tp> struct __libcpp_trivial_destructor
2412 : public integral_constant<bool, is_scalar<_Tp>::value ||
2413 is_reference<_Tp>::value> {};
2414
2415template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_destructible
2416 : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
2417
2418#endif // _LIBCPP_HAS_TYPE_TRAITS
2419
2420// is_nothrow_constructible
2421
2422#ifndef _LIBCPP_HAS_NO_VARIADICS
2423
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002424#if __has_feature(cxx_noexcept)
2425
2426template <bool, class _Tp, class... _Args> struct __is_nothrow_constructible;
2427
2428template <class _Tp, class... _Args>
2429struct __is_nothrow_constructible<true, _Tp, _Args...>
2430 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
2431{
2432};
2433
2434template <class _Tp, class... _Args>
2435struct __is_nothrow_constructible<false, _Tp, _Args...>
2436 : public false_type
2437{
2438};
2439
2440template <class _Tp, class... _Args>
2441struct _LIBCPP_VISIBLE is_nothrow_constructible
2442 : __is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, _Tp, _Args...>
2443{
2444};
2445
Howard Hinnant6063ec12011-05-13 14:08:16 +00002446template <class _Tp, size_t _Ns>
2447struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp[_Ns]>
2448 : __is_nothrow_constructible<is_constructible<_Tp>::value, _Tp>
2449{
2450};
2451
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002452#else // __has_feature(cxx_noexcept)
2453
Howard Hinnant1468b662010-11-19 22:17:28 +00002454template <class _Tp, class... _Args>
2455struct _LIBCPP_VISIBLE is_nothrow_constructible
2456 : false_type
2457{
2458};
2459
2460template <class _Tp>
2461struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp>
Howard Hinnant36666952011-05-09 19:21:17 +00002462#if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002463 : integral_constant<bool, __has_nothrow_constructor(_Tp)>
2464#else
2465 : integral_constant<bool, is_scalar<_Tp>::value>
2466#endif
2467{
2468};
2469
2470template <class _Tp>
2471#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2472struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&&>
2473#else
2474struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp>
2475#endif
Howard Hinnant36666952011-05-09 19:21:17 +00002476#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002477 : integral_constant<bool, __has_nothrow_copy(_Tp)>
2478#else
2479 : integral_constant<bool, is_scalar<_Tp>::value>
2480#endif
2481{
2482};
2483
2484template <class _Tp>
2485struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, const _Tp&>
Howard Hinnant36666952011-05-09 19:21:17 +00002486#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002487 : integral_constant<bool, __has_nothrow_copy(_Tp)>
2488#else
2489 : integral_constant<bool, is_scalar<_Tp>::value>
2490#endif
2491{
2492};
2493
2494template <class _Tp>
2495struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&>
Howard Hinnant36666952011-05-09 19:21:17 +00002496#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002497 : integral_constant<bool, __has_nothrow_copy(_Tp)>
2498#else
2499 : integral_constant<bool, is_scalar<_Tp>::value>
2500#endif
2501{
2502};
2503
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002504#endif // __has_feature(cxx_noexcept)
2505
Howard Hinnant1468b662010-11-19 22:17:28 +00002506#else // _LIBCPP_HAS_NO_VARIADICS
2507
2508template <class _Tp, class _A0 = __is_construct::__nat,
2509 class _A1 = __is_construct::__nat>
2510struct _LIBCPP_VISIBLE is_nothrow_constructible
2511 : false_type
2512{
2513};
2514
2515template <class _Tp>
2516struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, __is_construct::__nat,
2517 __is_construct::__nat>
Howard Hinnant36666952011-05-09 19:21:17 +00002518#if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002519 : integral_constant<bool, __has_nothrow_constructor(_Tp)>
2520#else
2521 : integral_constant<bool, is_scalar<_Tp>::value>
2522#endif
2523{
2524};
2525
2526template <class _Tp>
2527struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp,
2528 __is_construct::__nat>
Howard Hinnant36666952011-05-09 19:21:17 +00002529#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002530 : integral_constant<bool, __has_nothrow_copy(_Tp)>
2531#else
2532 : integral_constant<bool, is_scalar<_Tp>::value>
2533#endif
2534{
2535};
2536
2537template <class _Tp>
2538struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, const _Tp&,
2539 __is_construct::__nat>
Howard Hinnant36666952011-05-09 19:21:17 +00002540#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002541 : integral_constant<bool, __has_nothrow_copy(_Tp)>
2542#else
2543 : integral_constant<bool, is_scalar<_Tp>::value>
2544#endif
2545{
2546};
2547
2548template <class _Tp>
2549struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&,
2550 __is_construct::__nat>
Howard Hinnant36666952011-05-09 19:21:17 +00002551#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002552 : integral_constant<bool, __has_nothrow_copy(_Tp)>
2553#else
2554 : integral_constant<bool, is_scalar<_Tp>::value>
2555#endif
2556{
2557};
2558
2559#endif // _LIBCPP_HAS_NO_VARIADICS
2560
2561// is_nothrow_default_constructible
2562
2563template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_default_constructible
2564 : public is_nothrow_constructible<_Tp>
2565 {};
2566
2567// is_nothrow_copy_constructible
2568
2569template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_copy_constructible
2570 : public is_nothrow_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
2571 {};
2572
2573// is_nothrow_move_constructible
2574
2575template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_move_constructible
2576#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2577 : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2578#else
2579 : public is_nothrow_copy_constructible<_Tp>
2580#endif
2581 {};
2582
2583// is_nothrow_assignable
2584
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002585#if __has_feature(cxx_noexcept)
2586
2587template <bool, class _Tp, class _Arg> struct __is_nothrow_assignable;
2588
Howard Hinnant1468b662010-11-19 22:17:28 +00002589template <class _Tp, class _Arg>
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002590struct __is_nothrow_assignable<false, _Tp, _Arg>
2591 : public false_type
2592{
2593};
2594
2595template <class _Tp, class _Arg>
2596struct __is_nothrow_assignable<true, _Tp, _Arg>
2597 : public integral_constant<bool, noexcept(_STD::declval<_Tp>() = _STD::declval<_Arg>()) >
2598{
2599};
2600
2601template <class _Tp, class _Arg>
2602struct _LIBCPP_VISIBLE is_nothrow_assignable
2603 : public __is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
2604{
2605};
2606
2607#else // __has_feature(cxx_noexcept)
2608
2609template <class _Tp, class _Arg>
2610struct _LIBCPP_VISIBLE is_nothrow_assignable
Howard Hinnant1468b662010-11-19 22:17:28 +00002611 : public false_type {};
2612
2613template <class _Tp>
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002614struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, _Tp>
Howard Hinnant36666952011-05-09 19:21:17 +00002615#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002616 : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2617#else
2618 : integral_constant<bool, is_scalar<_Tp>::value> {};
2619#endif
2620
2621template <class _Tp>
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002622struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, _Tp&>
Howard Hinnant36666952011-05-09 19:21:17 +00002623#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002624 : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2625#else
2626 : integral_constant<bool, is_scalar<_Tp>::value> {};
2627#endif
2628
2629template <class _Tp>
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002630struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, const _Tp&>
Howard Hinnant36666952011-05-09 19:21:17 +00002631#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002632 : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2633#else
2634 : integral_constant<bool, is_scalar<_Tp>::value> {};
2635#endif
2636
2637#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2638
2639template <class _Tp>
2640struct is_nothrow_assignable<_Tp&, _Tp&&>
Howard Hinnant36666952011-05-09 19:21:17 +00002641#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002642 : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
2643#else
2644 : integral_constant<bool, is_scalar<_Tp>::value> {};
2645#endif
2646
2647#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2648
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002649#endif // __has_feature(cxx_noexcept)
2650
Howard Hinnant1468b662010-11-19 22:17:28 +00002651// is_nothrow_copy_assignable
2652
2653template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_copy_assignable
2654 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
2655 const typename add_lvalue_reference<_Tp>::type>
2656 {};
2657
2658// is_nothrow_move_assignable
2659
2660template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_move_assignable
2661 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
2662#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2663 typename add_rvalue_reference<_Tp>::type>
2664#else
2665 typename add_lvalue_reference<_Tp>::type>
2666#endif
2667 {};
2668
2669// is_nothrow_destructible
2670
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002671#if __has_feature(cxx_noexcept)
2672
2673template <bool, class _Tp> struct __is_nothrow_destructible;
2674
2675template <class _Tp>
2676struct __is_nothrow_destructible<false, _Tp>
2677 : public false_type
2678{
2679};
2680
2681template <class _Tp>
2682struct __is_nothrow_destructible<true, _Tp>
2683 : public integral_constant<bool, noexcept(_STD::declval<_Tp>().~_Tp()) >
2684{
2685};
2686
2687template <class _Tp>
2688struct _LIBCPP_VISIBLE is_nothrow_destructible
2689 : public __is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
2690{
2691};
2692
Howard Hinnant6063ec12011-05-13 14:08:16 +00002693template <class _Tp, size_t _Ns>
2694struct _LIBCPP_VISIBLE is_nothrow_destructible<_Tp[_Ns]>
2695 : public is_nothrow_destructible<_Tp>
2696{
2697};
2698
2699template <class _Tp>
2700struct _LIBCPP_VISIBLE is_nothrow_destructible<_Tp&>
2701 : public true_type
2702{
2703};
2704
2705#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2706
2707template <class _Tp>
2708struct _LIBCPP_VISIBLE is_nothrow_destructible<_Tp&&>
2709 : public true_type
2710{
2711};
2712
2713#endif
2714
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002715#else
2716
Howard Hinnant1468b662010-11-19 22:17:28 +00002717template <class _Tp> struct __libcpp_nothrow_destructor
2718 : public integral_constant<bool, is_scalar<_Tp>::value ||
2719 is_reference<_Tp>::value> {};
2720
2721template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_destructible
2722 : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
2723
Howard Hinnant5d37fb32011-05-11 20:19:40 +00002724#endif
2725
Howard Hinnant1468b662010-11-19 22:17:28 +00002726// is_pod
2727
Howard Hinnant36666952011-05-09 19:21:17 +00002728#if __has_feature(is_pod) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
Howard Hinnant1468b662010-11-19 22:17:28 +00002729
2730template <class _Tp> struct _LIBCPP_VISIBLE is_pod
2731 : public integral_constant<bool, __is_pod(_Tp)> {};
2732
2733#else // _LIBCPP_HAS_TYPE_TRAITS
2734
2735template <class _Tp> struct _LIBCPP_VISIBLE is_pod
2736 : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value &&
2737 is_trivially_copy_constructible<_Tp>::value &&
2738 is_trivially_copy_assignable<_Tp>::value &&
2739 is_trivially_destructible<_Tp>::value> {};
2740
2741#endif // _LIBCPP_HAS_TYPE_TRAITS
Howard Hinnant954b3662010-09-07 23:11:28 +00002742
Howard Hinnant36666952011-05-09 19:21:17 +00002743// is_literal_type;
2744
2745template <class _Tp> struct _LIBCPP_VISIBLE is_literal_type
2746#if __has_feature(is_literal)
2747 : public integral_constant<bool, __is_literal(_Tp)>
2748#else
2749 : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value ||
2750 is_reference<typename remove_all_extents<_Tp>::type>::value>
2751#endif
2752 {};
2753
Howard Hinnant6063ec12011-05-13 14:08:16 +00002754// is_standard_layout;
2755
2756template <class _Tp> struct _LIBCPP_VISIBLE is_standard_layout
2757#if __has_feature(is_standard_layout)
2758 : public integral_constant<bool, __is_standard_layout(_Tp)>
2759#else
2760 : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
2761#endif
2762 {};
2763
2764// is_trivially_copyable;
2765
2766template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copyable
2767#if __has_feature(is_trivially_copyable)
2768 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
2769#else
2770 : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
2771#endif
2772 {};
2773
2774// is_trivial;
2775
2776template <class _Tp> struct _LIBCPP_VISIBLE is_trivial
2777#if __has_feature(is_trivial)
2778 : public integral_constant<bool, __is_trivial(_Tp)>
2779#else
2780 : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
Howard Hinnant5ec7f5a2011-05-14 18:20:45 +00002781 is_trivially_default_constructible<_Tp>::value>
Howard Hinnant6063ec12011-05-13 14:08:16 +00002782#endif
2783 {};
Howard Hinnant57cff292011-05-19 15:05:04 +00002784
2785#ifndef _LIBCPP_HAS_NO_VARIADICS
2786
Howard Hinnante003ce42011-05-22 00:09:02 +00002787// Check for complete types
2788
2789template <class ..._T> struct __check_complete;
2790
2791template <>
2792struct __check_complete<>
2793{
2794};
2795
2796template <class _H, class _T0, class ..._T>
2797struct __check_complete<_H, _T0, _T...>
2798 : private __check_complete<_H>,
2799 private __check_complete<_T0, _T...>
2800{
2801};
2802
2803template <class _H>
2804struct __check_complete<_H, _H>
2805 : private __check_complete<_H>
2806{
2807};
2808
2809template <class _T>
2810struct __check_complete<_T>
2811{
2812 static_assert(sizeof(_T) > 0, "Type must be complete.");
2813};
2814
2815template <class _T>
2816struct __check_complete<_T&>
2817 : private __check_complete<_T>
2818{
2819};
2820
2821template <class _T>
2822struct __check_complete<_T&&>
2823 : private __check_complete<_T>
2824{
2825};
2826
2827template <class _R, class ..._Param>
2828struct __check_complete<_R (*)(_Param...)>
2829 : private __check_complete<_Param...>
2830{
2831};
2832
2833template <class _R, class ..._Param>
2834struct __check_complete<_R (_Param...)>
2835 : private __check_complete<_Param...>
2836{
2837};
2838
2839template <class _R, class _Class, class ..._Param>
2840struct __check_complete<_R (_Class::*)(_Param...)>
2841 : private __check_complete<_Class, _Param...>
2842{
2843};
2844
2845template <class _R, class _Class, class ..._Param>
2846struct __check_complete<_R (_Class::*)(_Param...) const>
2847 : private __check_complete<_Class, _Param...>
2848{
2849};
2850
2851template <class _R, class _Class, class ..._Param>
2852struct __check_complete<_R (_Class::*)(_Param...) volatile>
2853 : private __check_complete<_Class, _Param...>
2854{
2855};
2856
2857template <class _R, class _Class, class ..._Param>
2858struct __check_complete<_R (_Class::*)(_Param...) const volatile>
2859 : private __check_complete<_Class, _Param...>
2860{
2861};
2862
2863#if __has_feature(cxx_reference_qualified_functions)
2864
2865template <class _R, class _Class, class ..._Param>
2866struct __check_complete<_R (_Class::*)(_Param...) &>
2867 : private __check_complete<_Class, _Param...>
2868{
2869};
2870
2871template <class _R, class _Class, class ..._Param>
2872struct __check_complete<_R (_Class::*)(_Param...) const&>
2873 : private __check_complete<_Class, _Param...>
2874{
2875};
2876
2877template <class _R, class _Class, class ..._Param>
2878struct __check_complete<_R (_Class::*)(_Param...) volatile&>
2879 : private __check_complete<_Class, _Param...>
2880{
2881};
2882
2883template <class _R, class _Class, class ..._Param>
2884struct __check_complete<_R (_Class::*)(_Param...) const volatile&>
2885 : private __check_complete<_Class, _Param...>
2886{
2887};
2888
2889template <class _R, class _Class, class ..._Param>
2890struct __check_complete<_R (_Class::*)(_Param...) &&>
2891 : private __check_complete<_Class, _Param...>
2892{
2893};
2894
2895template <class _R, class _Class, class ..._Param>
2896struct __check_complete<_R (_Class::*)(_Param...) const&&>
2897 : private __check_complete<_Class, _Param...>
2898{
2899};
2900
2901template <class _R, class _Class, class ..._Param>
2902struct __check_complete<_R (_Class::*)(_Param...) volatile&&>
2903 : private __check_complete<_Class, _Param...>
2904{
2905};
2906
2907template <class _R, class _Class, class ..._Param>
2908struct __check_complete<_R (_Class::*)(_Param...) const volatile&&>
2909 : private __check_complete<_Class, _Param...>
2910{
2911};
2912
2913#endif
2914
2915template <class _R, class _Class>
2916struct __check_complete<_R _Class::*>
2917 : private __check_complete<_Class>
2918{
2919};
2920
Howard Hinnantbd89e4b2011-05-20 22:02:53 +00002921// __invoke forward declarations
Howard Hinnant57cff292011-05-19 15:05:04 +00002922
Howard Hinnantbd89e4b2011-05-20 22:02:53 +00002923// fall back - none of the bullets
Howard Hinnant57cff292011-05-19 15:05:04 +00002924
2925template <class ..._Args>
2926auto
Howard Hinnantbd89e4b2011-05-20 22:02:53 +00002927__invoke(__any, _Args&& ...__args)
Howard Hinnant57cff292011-05-19 15:05:04 +00002928 -> __nat;
2929
Howard Hinnantbd89e4b2011-05-20 22:02:53 +00002930// bullets 1 and 2
2931
2932template <class _F, class _A0, class ..._Args>
2933auto
2934__invoke(_F&& __f, _A0&& __a0, _Args&& ...__args)
2935 -> decltype((_STD::forward<_A0>(__a0).*__f)(_STD::forward<_Args>(__args)...));
2936
2937template <class _F, class _A0, class ..._Args>
2938auto
2939__invoke(_F&& __f, _A0&& __a0, _Args&& ...__args)
2940 -> decltype(((*_STD::forward<_A0>(__a0)).*__f)(_STD::forward<_Args>(__args)...));
2941
2942// bullets 3 and 4
2943
2944template <class _F, class _A0>
2945auto
2946__invoke(_F&& __f, _A0&& __a0)
2947 -> decltype(_STD::forward<_A0>(__a0).*__f);
2948
2949template <class _F, class _A0>
2950auto
2951__invoke(_F&& __f, _A0&& __a0)
2952 -> decltype((*_STD::forward<_A0>(__a0)).*__f);
2953
2954// bullet 5
2955
Howard Hinnant57cff292011-05-19 15:05:04 +00002956template <class _F, class ..._Args>
Howard Hinnantbd89e4b2011-05-20 22:02:53 +00002957auto
2958__invoke(_F&& __f, _Args&& ...__args)
2959 -> decltype(_STD::forward<_F>(__f)(_STD::forward<_Args>(__args)...));
2960
2961// __invokable
2962
2963template <class _F, class ..._Args>
2964struct __invokable_imp
Howard Hinnante003ce42011-05-22 00:09:02 +00002965 : private __check_complete<_F, _Args...>
Howard Hinnant57cff292011-05-19 15:05:04 +00002966{
2967 typedef decltype(
Howard Hinnantbd89e4b2011-05-20 22:02:53 +00002968 __invoke(_STD::declval<_F>(), _STD::declval<_Args>()...)
Howard Hinnant57cff292011-05-19 15:05:04 +00002969 ) type;
2970 static const bool value = !is_same<type, __nat>::value;
2971};
2972
Howard Hinnant57cff292011-05-19 15:05:04 +00002973template <class _F, class ..._Args>
2974struct __invokable
2975 : public integral_constant<bool,
Howard Hinnantbd89e4b2011-05-20 22:02:53 +00002976 __invokable_imp<_F, _Args...>::value>
Howard Hinnant57cff292011-05-19 15:05:04 +00002977{
2978};
2979
2980// __invoke_of
2981
2982template <bool _Invokable, class _F, class ..._Args>
2983struct __invoke_of_imp // false
2984{
2985};
2986
2987template <class _F, class ..._Args>
2988struct __invoke_of_imp<true, _F, _Args...>
2989{
Howard Hinnantbd89e4b2011-05-20 22:02:53 +00002990 typedef typename __invokable_imp<_F, _Args...>::type type;
Howard Hinnant57cff292011-05-19 15:05:04 +00002991};
2992
2993template <class _F, class ..._Args>
2994struct __invoke_of
2995 : public __invoke_of_imp<__invokable<_F, _Args...>::value, _F, _Args...>
2996{
2997};
2998
2999#endif // _LIBCPP_HAS_NO_VARIADICS
3000
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003001template <class _Tp>
3002inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003003typename enable_if
3004<
3005 is_move_constructible<_Tp>::value &&
3006 is_move_assignable<_Tp>::value
3007>::type
Howard Hinnante9b2c2d2011-05-27 15:04:19 +00003008swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
3009 is_nothrow_move_assignable<_Tp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003010{
3011 _Tp __t(_STD::move(__x));
3012 __x = _STD::move(__y);
3013 __y = _STD::move(__t);
3014}
3015
Howard Hinnante9b2c2d2011-05-27 15:04:19 +00003016template <class _ForwardIterator1, class _ForwardIterator2>
3017inline _LIBCPP_INLINE_VISIBILITY
3018void
3019iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
3020 // _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
3021 _NOEXCEPT_(_NOEXCEPT_(swap(*_STD::declval<_ForwardIterator1>(),
3022 *_STD::declval<_ForwardIterator2>())))
3023{
3024 swap(*__a, *__b);
3025}
3026
Howard Hinnanta5e01212011-05-27 19:08:18 +00003027// __swappable
3028
Howard Hinnant1694d232011-05-28 14:41:13 +00003029namespace __detail
3030{
3031
3032using _STD::swap;
Howard Hinnanta5e01212011-05-27 19:08:18 +00003033__nat swap(__any, __any);
3034
3035template <class _Tp>
3036struct __swappable
3037{
3038 typedef decltype(swap(_STD::declval<_Tp&>(), _STD::declval<_Tp&>())) type;
3039 static const bool value = !is_same<type, __nat>::value;
3040};
3041
Howard Hinnant1694d232011-05-28 14:41:13 +00003042} // __detail
3043
Howard Hinnanta5e01212011-05-27 19:08:18 +00003044template <class _Tp>
3045struct __is_swappable
Howard Hinnant1694d232011-05-28 14:41:13 +00003046 : public integral_constant<bool, __detail::__swappable<_Tp>::value>
Howard Hinnanta5e01212011-05-27 19:08:18 +00003047{
3048};
3049
3050#if __has_feature(cxx_noexcept)
3051
3052template <bool, class _Tp>
3053struct __is_nothrow_swappable_imp
3054 : public integral_constant<bool, noexcept(swap(_STD::declval<_Tp&>(),
3055 _STD::declval<_Tp&>()))>
3056{
3057};
3058
3059template <class _Tp>
3060struct __is_nothrow_swappable_imp<false, _Tp>
3061 : public false_type
3062{
3063};
3064
3065template <class _Tp>
3066struct __is_nothrow_swappable
3067 : public __is_nothrow_swappable_imp<__is_swappable<_Tp>::value, _Tp>
3068{
3069};
3070
3071#else // __has_feature(cxx_noexcept)
3072
3073template <class _Tp>
3074struct __is_nothrow_swappable
3075 : public false_type
3076{
3077};
3078
3079#endif // __has_feature(cxx_noexcept)
3080
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003081_LIBCPP_END_NAMESPACE_STD
3082
3083#endif // _LIBCPP_TYPE_TRAITS