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