Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- memory ------------------------------------===// |
| 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_MEMORY |
| 12 | #define _LIBCPP_MEMORY |
| 13 | |
| 14 | /* |
| 15 | memory synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | struct allocator_arg_t { }; |
| 21 | constexpr allocator_arg_t allocator_arg = allocator_arg_t(); |
| 22 | |
| 23 | template <class T, class Alloc> struct uses_allocator; |
| 24 | |
| 25 | template <class Ptr> |
| 26 | struct pointer_traits |
| 27 | { |
| 28 | typedef Ptr pointer; |
| 29 | typedef <details> element_type; |
| 30 | typedef <details> difference_type; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 31 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | template <class U> using rebind = <details>; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 33 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | static pointer pointer_to(<details>); |
| 35 | }; |
| 36 | |
| 37 | template <class Alloc> |
| 38 | struct allocator_traits |
| 39 | { |
| 40 | typedef Alloc allocator_type; |
| 41 | typedef typename allocator_type::value_type |
| 42 | value_type; |
| 43 | |
| 44 | typedef Alloc::pointer | value_type* pointer; |
| 45 | typedef Alloc::const_pointer |
| 46 | | pointer_traits<pointer>::rebind<const value_type> |
| 47 | const_pointer; |
| 48 | typedef Alloc::void_pointer |
| 49 | | pointer_traits<pointer>::rebind<void> |
| 50 | void_pointer; |
| 51 | typedef Alloc::const_void_pointer |
| 52 | | pointer_traits<pointer>::rebind<const void> |
| 53 | const_void_pointer; |
| 54 | typedef Alloc::difference_type |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 55 | | pointer_traits<pointer>::difference_type |
| 56 | difference_type; |
| 57 | typedef Alloc::size_type |
| 58 | | make_unsigned<difference_type>::type |
| 59 | size_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | typedef Alloc::propagate_on_container_copy_assignment |
| 61 | | false_type propagate_on_container_copy_assignment; |
| 62 | typedef Alloc::propagate_on_container_move_assignment |
| 63 | | false_type propagate_on_container_move_assignment; |
| 64 | typedef Alloc::propagate_on_container_swap |
| 65 | | false_type propagate_on_container_swap; |
| 66 | |
| 67 | template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>; |
| 68 | template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; |
| 69 | |
| 70 | static pointer allocate(allocator_type& a, size_type n); |
| 71 | static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); |
| 72 | |
| 73 | static void deallocate(allocator_type& a, pointer p, size_type n); |
| 74 | |
| 75 | template <class T, class... Args> |
| 76 | static void construct(allocator_type& a, T* p, Args&&... args); |
| 77 | |
| 78 | template <class T> |
| 79 | static void destroy(allocator_type& a, T* p); |
| 80 | |
| 81 | static size_type max_size(const allocator_type& a); |
| 82 | |
| 83 | static allocator_type |
| 84 | select_on_container_copy_construction(const allocator_type& a); |
| 85 | }; |
| 86 | |
| 87 | template <> |
| 88 | class allocator<void> |
| 89 | { |
| 90 | public: |
| 91 | typedef void* pointer; |
| 92 | typedef const void* const_pointer; |
| 93 | typedef void value_type; |
| 94 | |
| 95 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 96 | }; |
| 97 | |
| 98 | template <class T> |
| 99 | class allocator |
| 100 | { |
| 101 | public: |
| 102 | typedef size_t size_type; |
| 103 | typedef ptrdiff_t difference_type; |
| 104 | typedef T* pointer; |
| 105 | typedef const T* const_pointer; |
| 106 | typedef typename add_lvalue_reference<T>::type reference; |
| 107 | typedef typename add_lvalue_reference<const T>::type const_reference; |
| 108 | typedef T value_type; |
| 109 | |
| 110 | template <class U> struct rebind {typedef allocator<U> other;}; |
| 111 | |
| 112 | allocator() throw(); |
| 113 | allocator(const allocator&) throw(); |
| 114 | template <class U> allocator(const allocator<U>&) throw(); |
| 115 | ~allocator() throw(); |
| 116 | pointer address(reference x) const; |
| 117 | const_pointer address(const_reference x) const; |
| 118 | pointer allocate(size_type, allocator<void>::const_pointer hint = 0); |
| 119 | void deallocate(pointer p, size_type n); |
| 120 | size_type max_size() const throw(); |
| 121 | void construct(pointer p, const T& val); |
| 122 | void destroy(pointer p); |
| 123 | }; |
| 124 | |
| 125 | template <class T, class U> |
| 126 | bool operator==(const allocator<T>&, const allocator<U>&) throw(); |
| 127 | |
| 128 | template <class T, class U> |
| 129 | bool operator!=(const allocator<T>&, const allocator<U>&) throw(); |
| 130 | |
| 131 | template <class OutputIterator, class T> |
| 132 | class raw_storage_iterator |
| 133 | : public iterator<output_iterator_tag, |
| 134 | T, // purposefully not C++03 |
| 135 | ptrdiff_t, // purposefully not C++03 |
| 136 | T*, // purposefully not C++03 |
| 137 | raw_storage_iterator&> // purposefully not C++03 |
| 138 | { |
| 139 | public: |
| 140 | explicit raw_storage_iterator(OutputIterator x); |
| 141 | raw_storage_iterator& operator*(); |
| 142 | raw_storage_iterator& operator=(const T& element); |
| 143 | raw_storage_iterator& operator++(); |
| 144 | raw_storage_iterator operator++(int); |
| 145 | }; |
| 146 | |
| 147 | template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n); |
| 148 | template <class T> void return_temporary_buffer(T* p); |
| 149 | |
| 150 | template <class InputIterator, class ForwardIterator> |
| 151 | ForwardIterator |
| 152 | uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); |
| 153 | |
| 154 | template <class ForwardIterator, class T> |
| 155 | void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); |
| 156 | |
| 157 | template <class ForwardIterator, class Size, class T> |
Howard Hinnant | 2f6a627 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 158 | ForwardIterator |
| 159 | uninitialized_fill_n(ForwardIterator first, Size n, const T& x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 160 | |
| 161 | template <class Y> struct auto_ptr_ref {}; |
| 162 | |
| 163 | template<class X> |
| 164 | class auto_ptr |
| 165 | { |
| 166 | public: |
| 167 | typedef X element_type; |
| 168 | |
| 169 | explicit auto_ptr(X* p =0) throw(); |
| 170 | auto_ptr(auto_ptr&) throw(); |
| 171 | template<class Y> auto_ptr(auto_ptr<Y>&) throw(); |
| 172 | auto_ptr& operator=(auto_ptr&) throw(); |
| 173 | template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw(); |
| 174 | auto_ptr& operator=(auto_ptr_ref<X> r) throw(); |
| 175 | ~auto_ptr() throw(); |
| 176 | |
| 177 | typename add_lvalue_reference<X>::type operator*() const throw(); |
| 178 | X* operator->() const throw(); |
| 179 | X* get() const throw(); |
| 180 | X* release() throw(); |
| 181 | void reset(X* p =0) throw(); |
| 182 | |
| 183 | auto_ptr(auto_ptr_ref<X>) throw(); |
| 184 | template<class Y> operator auto_ptr_ref<Y>() throw(); |
| 185 | template<class Y> operator auto_ptr<Y>() throw(); |
| 186 | }; |
| 187 | |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 188 | template <class T> |
| 189 | struct default_delete |
| 190 | { |
| 191 | constexpr default_delete(); |
| 192 | template <class U> default_delete(const default_delete<U>&); |
| 193 | |
| 194 | void operator()(T*) const; |
| 195 | }; |
| 196 | |
| 197 | template <class T> |
| 198 | struct default_delete<T[]> |
| 199 | { |
| 200 | constexpr default_delete(); |
| 201 | void operator()(T*) const; |
| 202 | template <class U> void operator()(U*) const = delete; |
| 203 | }; |
| 204 | |
| 205 | template <class T, class D = default_delete<T>> class unique_ptr; |
| 206 | |
| 207 | template <class T, class D = default_delete<T>> |
| 208 | class unique_ptr |
| 209 | { |
| 210 | public: |
| 211 | typedef see below pointer; |
| 212 | typedef T element_type; |
| 213 | typedef D deleter_type; |
| 214 | |
| 215 | // constructors |
| 216 | constexpr unique_ptr(); |
| 217 | explicit unique_ptr(pointer p); |
| 218 | unique_ptr(pointer p, implementation-defined d1); |
| 219 | unique_ptr(pointer p, implementation-defined d2); |
| 220 | unique_ptr(unique_ptr&& u); |
| 221 | unique_ptr(nullptr_t) : unique_ptr() { } |
| 222 | template <class U, class E> |
| 223 | unique_ptr(unique_ptr<U, E>&& u); |
| 224 | template <class U> |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 225 | unique_ptr(auto_ptr<U>&& u); |
| 226 | |
| 227 | // destructor |
| 228 | ~unique_ptr(); |
| 229 | |
| 230 | // assignment |
| 231 | unique_ptr& operator=(unique_ptr&& u); |
| 232 | template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u); |
| 233 | unique_ptr& operator=(nullptr_t); |
| 234 | |
| 235 | // observers |
| 236 | typename add_lvalue_reference<T>::type operator*() const; |
| 237 | pointer operator->() const; |
| 238 | pointer get() const; |
| 239 | deleter_type& get_deleter(); |
| 240 | const deleter_type& get_deleter() const; |
| 241 | explicit operator bool() const; |
| 242 | |
| 243 | // modifiers |
| 244 | pointer release(); |
| 245 | void reset(pointer p = pointer()); |
| 246 | void swap(unique_ptr& u); |
| 247 | }; |
| 248 | |
| 249 | template <class T, class D> |
| 250 | class unique_ptr<T[], D> |
| 251 | { |
| 252 | public: |
| 253 | typedef implementation-defined pointer; |
| 254 | typedef T element_type; |
| 255 | typedef D deleter_type; |
| 256 | |
| 257 | // constructors |
| 258 | constexpr unique_ptr(); |
| 259 | explicit unique_ptr(pointer p); |
| 260 | unique_ptr(pointer p, implementation-defined d); |
| 261 | unique_ptr(pointer p, implementation-defined d); |
| 262 | unique_ptr(unique_ptr&& u); |
| 263 | unique_ptr(nullptr_t) : unique_ptr() { } |
| 264 | |
| 265 | // destructor |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 266 | ~unique_ptr(); |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 267 | |
| 268 | // assignment |
| 269 | unique_ptr& operator=(unique_ptr&& u); |
| 270 | unique_ptr& operator=(nullptr_t); |
| 271 | |
| 272 | // observers |
| 273 | T& operator[](size_t i) const; |
| 274 | pointer get() const; |
| 275 | deleter_type& get_deleter(); |
| 276 | const deleter_type& get_deleter() const; |
| 277 | explicit operator bool() const; |
| 278 | |
| 279 | // modifiers |
| 280 | pointer release(); |
| 281 | void reset(pointer p = pointer()); |
| 282 | void reset(nullptr_t); |
| 283 | template <class U> void reset(U) = delete; |
| 284 | void swap(unique_ptr& u); |
| 285 | }; |
| 286 | |
| 287 | template <class T, class D> |
| 288 | void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y); |
| 289 | |
| 290 | template <class T1, class D1, class T2, class D2> |
| 291 | bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 292 | template <class T1, class D1, class T2, class D2> |
| 293 | bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 294 | template <class T1, class D1, class T2, class D2> |
| 295 | bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 296 | template <class T1, class D1, class T2, class D2> |
| 297 | bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 298 | template <class T1, class D1, class T2, class D2> |
| 299 | bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 300 | template <class T1, class D1, class T2, class D2> |
| 301 | bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 302 | |
| 303 | class bad_weak_ptr |
| 304 | : public std::exception |
| 305 | { |
| 306 | bad_weak_ptr(); |
| 307 | }; |
| 308 | |
| 309 | template<class T> |
| 310 | class shared_ptr |
| 311 | { |
| 312 | public: |
| 313 | typedef T element_type; |
| 314 | |
| 315 | // constructors: |
| 316 | constexpr shared_ptr(); |
| 317 | template<class Y> explicit shared_ptr(Y* p); |
| 318 | template<class Y, class D> shared_ptr(Y* p, D d); |
| 319 | template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); |
| 320 | template <class D> shared_ptr(nullptr_t p, D d); |
| 321 | template <class D, class A> shared_ptr(nullptr_t p, D d, A a); |
| 322 | template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p); |
| 323 | shared_ptr(const shared_ptr& r); |
| 324 | template<class Y> shared_ptr(const shared_ptr<Y>& r); |
| 325 | shared_ptr(shared_ptr&& r); |
| 326 | template<class Y> shared_ptr(shared_ptr<Y>&& r); |
| 327 | template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); |
| 328 | template<class Y> shared_ptr(auto_ptr<Y>&& r); |
| 329 | template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); |
| 330 | shared_ptr(nullptr_t) : shared_ptr() { } |
| 331 | |
| 332 | // destructor: |
| 333 | ~shared_ptr(); |
| 334 | |
| 335 | // assignment: |
| 336 | shared_ptr& operator=(const shared_ptr& r); |
| 337 | template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r); |
| 338 | shared_ptr& operator=(shared_ptr&& r); |
| 339 | template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); |
| 340 | template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); |
| 341 | template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); |
| 342 | |
| 343 | // modifiers: |
| 344 | void swap(shared_ptr& r); |
| 345 | void reset(); |
| 346 | template<class Y> void reset(Y* p); |
| 347 | template<class Y, class D> void reset(Y* p, D d); |
| 348 | template<class Y, class D, class A> void reset(Y* p, D d, A a); |
| 349 | |
| 350 | // observers: T* get() const; |
| 351 | T& operator*() const; |
| 352 | T* operator->() const; |
| 353 | long use_count() const; |
| 354 | bool unique() const; |
| 355 | explicit operator bool() const; |
| 356 | template<class U> bool owner_before(shared_ptr<U> const& b) const; |
| 357 | template<class U> bool owner_before(weak_ptr<U> const& b) const; |
| 358 | }; |
| 359 | |
| 360 | // shared_ptr comparisons: |
| 361 | template<class T, class U> |
| 362 | bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b); |
| 363 | template<class T, class U> |
| 364 | bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b); |
| 365 | template<class T, class U> |
| 366 | bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b); |
| 367 | template<class T, class U> |
| 368 | bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b); |
| 369 | template<class T, class U> |
| 370 | bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b); |
| 371 | template<class T, class U> |
| 372 | bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b); |
| 373 | |
| 374 | // shared_ptr specialized algorithms: |
| 375 | template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b); |
| 376 | |
| 377 | // shared_ptr casts: |
| 378 | template<class T, class U> |
| 379 | shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r); |
| 380 | template<class T, class U> |
| 381 | shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r); |
| 382 | template<class T, class U> |
| 383 | shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r); |
| 384 | |
| 385 | // shared_ptr I/O: |
| 386 | template<class E, class T, class Y> |
| 387 | basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p); |
| 388 | |
| 389 | // shared_ptr get_deleter: |
| 390 | template<class D, class T> D* get_deleter(shared_ptr<T> const& p); |
| 391 | |
| 392 | template<class T, class... Args> |
| 393 | shared_ptr<T> make_shared(Args&&... args); |
| 394 | template<class T, class A, class... Args> |
| 395 | shared_ptr<T> allocate_shared(const A& a, Args&&... args); |
| 396 | |
| 397 | template<class T> |
| 398 | class weak_ptr |
| 399 | { |
| 400 | public: |
| 401 | typedef T element_type; |
| 402 | |
| 403 | // constructors |
| 404 | constexpr weak_ptr(); |
| 405 | template<class Y> weak_ptr(shared_ptr<Y> const& r); |
| 406 | weak_ptr(weak_ptr const& r); |
| 407 | template<class Y> weak_ptr(weak_ptr<Y> const& r); |
| 408 | |
| 409 | // destructor |
| 410 | ~weak_ptr(); |
| 411 | |
| 412 | // assignment |
| 413 | weak_ptr& operator=(weak_ptr const& r); |
| 414 | template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r); |
| 415 | template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r); |
| 416 | |
| 417 | // modifiers |
| 418 | void swap(weak_ptr& r); |
| 419 | void reset(); |
| 420 | |
| 421 | // observers |
| 422 | long use_count() const; |
| 423 | bool expired() const; |
| 424 | shared_ptr<T> lock() const; |
| 425 | template<class U> bool owner_before(shared_ptr<U> const& b); |
| 426 | template<class U> bool owner_before(weak_ptr<U> const& b); |
| 427 | }; |
| 428 | |
| 429 | // weak_ptr specialized algorithms: |
| 430 | template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b); |
| 431 | |
| 432 | // class owner_less: |
| 433 | template<class T> struct owner_less; |
| 434 | |
| 435 | template<class T> |
| 436 | struct owner_less<shared_ptr<T>> |
| 437 | : binary_function<shared_ptr<T>, shared_ptr<T>, bool> |
| 438 | { |
| 439 | typedef bool result_type; |
| 440 | bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const; |
| 441 | bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; |
| 442 | bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; |
| 443 | }; |
| 444 | |
| 445 | template<class T> |
| 446 | struct owner_less<weak_ptr<T>> |
| 447 | : binary_function<weak_ptr<T>, weak_ptr<T>, bool> |
| 448 | { |
| 449 | typedef bool result_type; |
| 450 | bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const; |
| 451 | bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; |
| 452 | bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; |
| 453 | }; |
| 454 | |
| 455 | template<class T> |
| 456 | class enable_shared_from_this |
| 457 | { |
| 458 | protected: |
| 459 | constexpr enable_shared_from_this(); |
| 460 | enable_shared_from_this(enable_shared_from_this const&); |
| 461 | enable_shared_from_this& operator=(enable_shared_from_this const&); |
| 462 | ~enable_shared_from_this(); |
| 463 | public: |
| 464 | shared_ptr<T> shared_from_this(); |
| 465 | shared_ptr<T const> shared_from_this() const; |
| 466 | }; |
| 467 | |
| 468 | template<class T> |
| 469 | bool atomic_is_lock_free(const shared_ptr<T>* p); |
| 470 | template<class T> |
| 471 | shared_ptr<T> atomic_load(const shared_ptr<T>* p); |
| 472 | template<class T> |
| 473 | shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo); |
| 474 | template<class T> |
| 475 | void atomic_store(shared_ptr<T>* p, shared_ptr<T> r); |
| 476 | template<class T> |
| 477 | void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); |
| 478 | template<class T> |
| 479 | shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r); |
| 480 | template<class T> |
| 481 | shared_ptr<T> |
| 482 | atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); |
| 483 | template<class T> |
| 484 | bool |
| 485 | atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); |
| 486 | template<class T> |
| 487 | bool |
| 488 | atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); |
| 489 | template<class T> |
| 490 | bool |
| 491 | atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, |
| 492 | shared_ptr<T> w, memory_order success, |
| 493 | memory_order failure); |
| 494 | template<class T> |
| 495 | bool |
| 496 | atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, |
| 497 | shared_ptr<T> w, memory_order success, |
| 498 | memory_order failure); |
| 499 | // Hash support |
| 500 | template <class T> struct hash; |
| 501 | template <class T, class D> struct hash<unique_ptr<T, D> >; |
| 502 | template <class T> struct hash<shared_ptr<T> >; |
| 503 | |
| 504 | // Pointer safety |
| 505 | enum class pointer_safety { relaxed, preferred, strict }; |
| 506 | void declare_reachable(void *p); |
| 507 | template <class T> T *undeclare_reachable(T *p); |
| 508 | void declare_no_pointers(char *p, size_t n); |
| 509 | void undeclare_no_pointers(char *p, size_t n); |
| 510 | pointer_safety get_pointer_safety(); |
| 511 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 512 | void* align(size_t alignment, size_t size, void*& ptr, size_t& space); |
| 513 | |
| 514 | } // std |
| 515 | |
| 516 | */ |
| 517 | |
| 518 | #include <__config> |
| 519 | #include <type_traits> |
| 520 | #include <typeinfo> |
| 521 | #include <cstddef> |
| 522 | #include <cstdint> |
| 523 | #include <new> |
| 524 | #include <utility> |
| 525 | #include <limits> |
| 526 | #include <iterator> |
| 527 | #include <__functional_base> |
| 528 | #if defined(_LIBCPP_NO_EXCEPTIONS) |
| 529 | #include <cassert> |
| 530 | #endif |
| 531 | |
| 532 | #pragma GCC system_header |
| 533 | |
| 534 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 535 | |
| 536 | // allocator_arg_t |
| 537 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 538 | struct _LIBCPP_VISIBLE allocator_arg_t { }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | |
| 540 | extern const allocator_arg_t allocator_arg; |
| 541 | |
| 542 | // addressof |
| 543 | |
| 544 | template <class _Tp> |
| 545 | inline _LIBCPP_INLINE_VISIBILITY |
| 546 | _Tp* |
| 547 | addressof(_Tp& __x) |
| 548 | { |
| 549 | return (_Tp*)&(char&)__x; |
| 550 | } |
| 551 | |
| 552 | template <class _Tp> class allocator; |
| 553 | |
| 554 | template <> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 555 | class _LIBCPP_VISIBLE allocator<void> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 556 | { |
| 557 | public: |
| 558 | typedef void* pointer; |
| 559 | typedef const void* const_pointer; |
| 560 | typedef void value_type; |
| 561 | |
| 562 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 563 | }; |
| 564 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 565 | // pointer_traits |
| 566 | |
| 567 | template <class _Tp> |
| 568 | struct __has_element_type |
| 569 | { |
| 570 | private: |
| 571 | struct __two {char _; char __;}; |
| 572 | template <class _Up> static __two __test(...); |
| 573 | template <class _Up> static char __test(typename _Up::element_type* = 0); |
| 574 | public: |
| 575 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 576 | }; |
| 577 | |
| 578 | template <class _Ptr, bool = __has_element_type<_Ptr>::value> |
| 579 | struct __pointer_traits_element_type; |
| 580 | |
| 581 | template <class _Ptr> |
| 582 | struct __pointer_traits_element_type<_Ptr, true> |
| 583 | { |
| 584 | typedef typename _Ptr::element_type type; |
| 585 | }; |
| 586 | |
| 587 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 588 | |
| 589 | template <template <class, class...> class _Sp, class _Tp, class ..._Args> |
| 590 | struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> |
| 591 | { |
| 592 | typedef typename _Sp<_Tp, _Args...>::element_type type; |
| 593 | }; |
| 594 | |
| 595 | template <template <class, class...> class _Sp, class _Tp, class ..._Args> |
| 596 | struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> |
| 597 | { |
| 598 | typedef _Tp type; |
| 599 | }; |
| 600 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 601 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 602 | |
| 603 | template <template <class> class _Sp, class _Tp> |
| 604 | struct __pointer_traits_element_type<_Sp<_Tp>, true> |
| 605 | { |
| 606 | typedef typename _Sp<_Tp>::element_type type; |
| 607 | }; |
| 608 | |
| 609 | template <template <class> class _Sp, class _Tp> |
| 610 | struct __pointer_traits_element_type<_Sp<_Tp>, false> |
| 611 | { |
| 612 | typedef _Tp type; |
| 613 | }; |
| 614 | |
| 615 | template <template <class, class> class _Sp, class _Tp, class _A0> |
| 616 | struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true> |
| 617 | { |
| 618 | typedef typename _Sp<_Tp, _A0>::element_type type; |
| 619 | }; |
| 620 | |
| 621 | template <template <class, class> class _Sp, class _Tp, class _A0> |
| 622 | struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false> |
| 623 | { |
| 624 | typedef _Tp type; |
| 625 | }; |
| 626 | |
| 627 | template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> |
| 628 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true> |
| 629 | { |
| 630 | typedef typename _Sp<_Tp, _A0, _A1>::element_type type; |
| 631 | }; |
| 632 | |
| 633 | template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> |
| 634 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false> |
| 635 | { |
| 636 | typedef _Tp type; |
| 637 | }; |
| 638 | |
| 639 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 640 | class _A1, class _A2> |
| 641 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true> |
| 642 | { |
| 643 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type; |
| 644 | }; |
| 645 | |
| 646 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 647 | class _A1, class _A2> |
| 648 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false> |
| 649 | { |
| 650 | typedef _Tp type; |
| 651 | }; |
| 652 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 653 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 654 | |
| 655 | template <class _Tp> |
| 656 | struct __has_difference_type |
| 657 | { |
| 658 | private: |
| 659 | struct __two {char _; char __;}; |
| 660 | template <class _Up> static __two __test(...); |
| 661 | template <class _Up> static char __test(typename _Up::difference_type* = 0); |
| 662 | public: |
| 663 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 664 | }; |
| 665 | |
| 666 | template <class _Ptr, bool = __has_difference_type<_Ptr>::value> |
| 667 | struct __pointer_traits_difference_type |
| 668 | { |
| 669 | typedef ptrdiff_t type; |
| 670 | }; |
| 671 | |
| 672 | template <class _Ptr> |
| 673 | struct __pointer_traits_difference_type<_Ptr, true> |
| 674 | { |
| 675 | typedef typename _Ptr::difference_type type; |
| 676 | }; |
| 677 | |
| 678 | template <class _Tp, class _Up> |
| 679 | struct __has_rebind |
| 680 | { |
| 681 | private: |
| 682 | struct __two {char _; char __;}; |
| 683 | template <class _Xp> static __two __test(...); |
| 684 | template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0); |
| 685 | public: |
| 686 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 687 | }; |
| 688 | |
| 689 | template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> |
| 690 | struct __pointer_traits_rebind |
| 691 | { |
| 692 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 693 | typedef typename _Tp::template rebind<_Up> type; |
| 694 | #else |
| 695 | typedef typename _Tp::template rebind<_Up>::other type; |
| 696 | #endif |
| 697 | }; |
| 698 | |
| 699 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 700 | |
| 701 | template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> |
| 702 | struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> |
| 703 | { |
| 704 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 705 | typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type; |
| 706 | #else |
| 707 | typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; |
| 708 | #endif |
| 709 | }; |
| 710 | |
| 711 | template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> |
| 712 | struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> |
| 713 | { |
| 714 | typedef _Sp<_Up, _Args...> type; |
| 715 | }; |
| 716 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 717 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 718 | |
| 719 | template <template <class> class _Sp, class _Tp, class _Up> |
| 720 | struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true> |
| 721 | { |
| 722 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 723 | typedef typename _Sp<_Tp>::template rebind<_Up> type; |
| 724 | #else |
| 725 | typedef typename _Sp<_Tp>::template rebind<_Up>::other type; |
| 726 | #endif |
| 727 | }; |
| 728 | |
| 729 | template <template <class> class _Sp, class _Tp, class _Up> |
| 730 | struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false> |
| 731 | { |
| 732 | typedef _Sp<_Up> type; |
| 733 | }; |
| 734 | |
| 735 | template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> |
| 736 | struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true> |
| 737 | { |
| 738 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 739 | typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type; |
| 740 | #else |
| 741 | typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type; |
| 742 | #endif |
| 743 | }; |
| 744 | |
| 745 | template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> |
| 746 | struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false> |
| 747 | { |
| 748 | typedef _Sp<_Up, _A0> type; |
| 749 | }; |
| 750 | |
| 751 | template <template <class, class, class> class _Sp, class _Tp, class _A0, |
| 752 | class _A1, class _Up> |
| 753 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true> |
| 754 | { |
| 755 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 756 | typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type; |
| 757 | #else |
| 758 | typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type; |
| 759 | #endif |
| 760 | }; |
| 761 | |
| 762 | template <template <class, class, class> class _Sp, class _Tp, class _A0, |
| 763 | class _A1, class _Up> |
| 764 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false> |
| 765 | { |
| 766 | typedef _Sp<_Up, _A0, _A1> type; |
| 767 | }; |
| 768 | |
| 769 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 770 | class _A1, class _A2, class _Up> |
| 771 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true> |
| 772 | { |
| 773 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 774 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type; |
| 775 | #else |
| 776 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; |
| 777 | #endif |
| 778 | }; |
| 779 | |
| 780 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 781 | class _A1, class _A2, class _Up> |
| 782 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false> |
| 783 | { |
| 784 | typedef _Sp<_Up, _A0, _A1, _A2> type; |
| 785 | }; |
| 786 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 787 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 788 | |
| 789 | template <class _Ptr> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 790 | struct _LIBCPP_VISIBLE pointer_traits |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | { |
| 792 | typedef _Ptr pointer; |
| 793 | typedef typename __pointer_traits_element_type<pointer>::type element_type; |
| 794 | typedef typename __pointer_traits_difference_type<pointer>::type difference_type; |
| 795 | |
| 796 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 797 | template <class _Up> using rebind = __pointer_traits_rebind<pointer, _Up>::type; |
| 798 | #else |
| 799 | template <class _Up> struct rebind |
| 800 | {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;}; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 801 | #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 802 | |
| 803 | private: |
| 804 | struct __nat {}; |
| 805 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 806 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 807 | static pointer pointer_to(typename conditional<is_void<element_type>::value, |
| 808 | __nat, element_type>::type& __r) |
| 809 | {return pointer::pointer_to(__r);} |
| 810 | }; |
| 811 | |
| 812 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 813 | struct _LIBCPP_VISIBLE pointer_traits<_Tp*> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 814 | { |
| 815 | typedef _Tp* pointer; |
| 816 | typedef _Tp element_type; |
| 817 | typedef ptrdiff_t difference_type; |
| 818 | |
| 819 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 820 | template <class _Up> using rebind = _Up*; |
| 821 | #else |
| 822 | template <class _Up> struct rebind {typedef _Up* other;}; |
| 823 | #endif |
| 824 | |
| 825 | private: |
| 826 | struct __nat {}; |
| 827 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 828 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 829 | static pointer pointer_to(typename conditional<is_void<element_type>::value, |
| 830 | __nat, element_type>::type& __r) |
| 831 | {return _STD::addressof(__r);} |
| 832 | }; |
| 833 | |
| 834 | // allocator_traits |
| 835 | |
| 836 | namespace __has_pointer_type_imp |
| 837 | { |
| 838 | template <class _Up> static __two test(...); |
| 839 | template <class _Up> static char test(typename _Up::pointer* = 0); |
| 840 | } |
| 841 | |
| 842 | template <class _Tp> |
| 843 | struct __has_pointer_type |
| 844 | : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1> |
| 845 | { |
| 846 | }; |
| 847 | |
| 848 | namespace __pointer_type_imp |
| 849 | { |
| 850 | |
| 851 | template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value> |
| 852 | struct __pointer_type |
| 853 | { |
| 854 | typedef typename _Dp::pointer type; |
| 855 | }; |
| 856 | |
| 857 | template <class _Tp, class _Dp> |
| 858 | struct __pointer_type<_Tp, _Dp, false> |
| 859 | { |
| 860 | typedef _Tp* type; |
| 861 | }; |
| 862 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 863 | } // __pointer_type_imp |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 864 | |
| 865 | template <class _Tp, class _Dp> |
| 866 | struct __pointer_type |
| 867 | { |
| 868 | typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; |
| 869 | }; |
| 870 | |
| 871 | template <class _Tp> |
| 872 | struct __has_const_pointer |
| 873 | { |
| 874 | private: |
| 875 | struct __two {char _; char __;}; |
| 876 | template <class _Up> static __two __test(...); |
| 877 | template <class _Up> static char __test(typename _Up::const_pointer* = 0); |
| 878 | public: |
| 879 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 880 | }; |
| 881 | |
| 882 | template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> |
| 883 | struct __const_pointer |
| 884 | { |
| 885 | typedef typename _Alloc::const_pointer type; |
| 886 | }; |
| 887 | |
| 888 | template <class _Tp, class _Ptr, class _Alloc> |
| 889 | struct __const_pointer<_Tp, _Ptr, _Alloc, false> |
| 890 | { |
| 891 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 892 | typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type; |
| 893 | #else |
| 894 | typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type; |
| 895 | #endif |
| 896 | }; |
| 897 | |
| 898 | template <class _Tp> |
| 899 | struct __has_void_pointer |
| 900 | { |
| 901 | private: |
| 902 | struct __two {char _; char __;}; |
| 903 | template <class _Up> static __two __test(...); |
| 904 | template <class _Up> static char __test(typename _Up::void_pointer* = 0); |
| 905 | public: |
| 906 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 907 | }; |
| 908 | |
| 909 | template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> |
| 910 | struct __void_pointer |
| 911 | { |
| 912 | typedef typename _Alloc::void_pointer type; |
| 913 | }; |
| 914 | |
| 915 | template <class _Ptr, class _Alloc> |
| 916 | struct __void_pointer<_Ptr, _Alloc, false> |
| 917 | { |
| 918 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 919 | typedef typename pointer_traits<_Ptr>::template rebind<void> type; |
| 920 | #else |
| 921 | typedef typename pointer_traits<_Ptr>::template rebind<void>::other type; |
| 922 | #endif |
| 923 | }; |
| 924 | |
| 925 | template <class _Tp> |
| 926 | struct __has_const_void_pointer |
| 927 | { |
| 928 | private: |
| 929 | struct __two {char _; char __;}; |
| 930 | template <class _Up> static __two __test(...); |
| 931 | template <class _Up> static char __test(typename _Up::const_void_pointer* = 0); |
| 932 | public: |
| 933 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 934 | }; |
| 935 | |
| 936 | template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> |
| 937 | struct __const_void_pointer |
| 938 | { |
| 939 | typedef typename _Alloc::const_void_pointer type; |
| 940 | }; |
| 941 | |
| 942 | template <class _Ptr, class _Alloc> |
| 943 | struct __const_void_pointer<_Ptr, _Alloc, false> |
| 944 | { |
| 945 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 946 | typedef typename pointer_traits<_Ptr>::template rebind<const void> type; |
| 947 | #else |
| 948 | typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type; |
| 949 | #endif |
| 950 | }; |
| 951 | |
| 952 | template <class _T> |
| 953 | inline _LIBCPP_INLINE_VISIBILITY |
| 954 | _T* |
| 955 | __to_raw_pointer(_T* __p) |
| 956 | { |
| 957 | return __p; |
| 958 | } |
| 959 | |
| 960 | template <class _Pointer> |
| 961 | inline _LIBCPP_INLINE_VISIBILITY |
| 962 | typename pointer_traits<_Pointer>::element_type* |
| 963 | __to_raw_pointer(_Pointer __p) |
| 964 | { |
| 965 | return _STD::__to_raw_pointer(__p.operator->()); |
| 966 | } |
| 967 | |
| 968 | template <class _Tp> |
| 969 | struct __has_size_type |
| 970 | { |
| 971 | private: |
| 972 | struct __two {char _; char __;}; |
| 973 | template <class _Up> static __two __test(...); |
| 974 | template <class _Up> static char __test(typename _Up::size_type* = 0); |
| 975 | public: |
| 976 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 977 | }; |
| 978 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 979 | template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 980 | struct __size_type |
| 981 | { |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 982 | typedef typename make_unsigned<_DiffType>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 983 | }; |
| 984 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 985 | template <class _Alloc, class _DiffType> |
| 986 | struct __size_type<_Alloc, _DiffType, true> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 987 | { |
| 988 | typedef typename _Alloc::size_type type; |
| 989 | }; |
| 990 | |
| 991 | template <class _Tp> |
| 992 | struct __has_propagate_on_container_copy_assignment |
| 993 | { |
| 994 | private: |
| 995 | struct __two {char _; char __;}; |
| 996 | template <class _Up> static __two __test(...); |
| 997 | template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0); |
| 998 | public: |
| 999 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1000 | }; |
| 1001 | |
| 1002 | template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> |
| 1003 | struct __propagate_on_container_copy_assignment |
| 1004 | { |
| 1005 | typedef false_type type; |
| 1006 | }; |
| 1007 | |
| 1008 | template <class _Alloc> |
| 1009 | struct __propagate_on_container_copy_assignment<_Alloc, true> |
| 1010 | { |
| 1011 | typedef typename _Alloc::propagate_on_container_copy_assignment type; |
| 1012 | }; |
| 1013 | |
| 1014 | template <class _Tp> |
| 1015 | struct __has_propagate_on_container_move_assignment |
| 1016 | { |
| 1017 | private: |
| 1018 | struct __two {char _; char __;}; |
| 1019 | template <class _Up> static __two __test(...); |
| 1020 | template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0); |
| 1021 | public: |
| 1022 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1023 | }; |
| 1024 | |
| 1025 | template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value> |
| 1026 | struct __propagate_on_container_move_assignment |
| 1027 | { |
| 1028 | typedef false_type type; |
| 1029 | }; |
| 1030 | |
| 1031 | template <class _Alloc> |
| 1032 | struct __propagate_on_container_move_assignment<_Alloc, true> |
| 1033 | { |
| 1034 | typedef typename _Alloc::propagate_on_container_move_assignment type; |
| 1035 | }; |
| 1036 | |
| 1037 | template <class _Tp> |
| 1038 | struct __has_propagate_on_container_swap |
| 1039 | { |
| 1040 | private: |
| 1041 | struct __two {char _; char __;}; |
| 1042 | template <class _Up> static __two __test(...); |
| 1043 | template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0); |
| 1044 | public: |
| 1045 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1046 | }; |
| 1047 | |
| 1048 | template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value> |
| 1049 | struct __propagate_on_container_swap |
| 1050 | { |
| 1051 | typedef false_type type; |
| 1052 | }; |
| 1053 | |
| 1054 | template <class _Alloc> |
| 1055 | struct __propagate_on_container_swap<_Alloc, true> |
| 1056 | { |
| 1057 | typedef typename _Alloc::propagate_on_container_swap type; |
| 1058 | }; |
| 1059 | |
| 1060 | template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> |
| 1061 | struct __has_rebind_other |
| 1062 | { |
| 1063 | private: |
| 1064 | struct __two {char _; char __;}; |
| 1065 | template <class _Xp> static __two __test(...); |
| 1066 | template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0); |
| 1067 | public: |
| 1068 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1069 | }; |
| 1070 | |
| 1071 | template <class _Tp, class _Up> |
| 1072 | struct __has_rebind_other<_Tp, _Up, false> |
| 1073 | { |
| 1074 | static const bool value = false; |
| 1075 | }; |
| 1076 | |
| 1077 | template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> |
| 1078 | struct __allocator_traits_rebind |
| 1079 | { |
| 1080 | typedef typename _Tp::template rebind<_Up>::other type; |
| 1081 | }; |
| 1082 | |
| 1083 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1084 | |
| 1085 | template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> |
| 1086 | struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> |
| 1087 | { |
| 1088 | typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type; |
| 1089 | }; |
| 1090 | |
| 1091 | template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> |
| 1092 | struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> |
| 1093 | { |
| 1094 | typedef _Alloc<_Up, _Args...> type; |
| 1095 | }; |
| 1096 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1097 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1098 | |
| 1099 | template <template <class> class _Alloc, class _Tp, class _Up> |
| 1100 | struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true> |
| 1101 | { |
| 1102 | typedef typename _Alloc<_Tp>::template rebind<_Up>::other type; |
| 1103 | }; |
| 1104 | |
| 1105 | template <template <class> class _Alloc, class _Tp, class _Up> |
| 1106 | struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false> |
| 1107 | { |
| 1108 | typedef _Alloc<_Up> type; |
| 1109 | }; |
| 1110 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1111 | template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> |
| 1112 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true> |
| 1113 | { |
| 1114 | typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type; |
| 1115 | }; |
| 1116 | |
| 1117 | template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> |
| 1118 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false> |
| 1119 | { |
| 1120 | typedef _Alloc<_Up, _A0> type; |
| 1121 | }; |
| 1122 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1123 | template <template <class, class, class> class _Alloc, class _Tp, class _A0, |
| 1124 | class _A1, class _Up> |
| 1125 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true> |
| 1126 | { |
| 1127 | typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type; |
| 1128 | }; |
| 1129 | |
| 1130 | template <template <class, class, class> class _Alloc, class _Tp, class _A0, |
| 1131 | class _A1, class _Up> |
| 1132 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false> |
| 1133 | { |
| 1134 | typedef _Alloc<_Up, _A0, _A1> type; |
| 1135 | }; |
| 1136 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1137 | template <template <class, class, class, class> class _Alloc, class _Tp, class _A0, |
| 1138 | class _A1, class _A2, class _Up> |
| 1139 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true> |
| 1140 | { |
| 1141 | typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; |
| 1142 | }; |
| 1143 | |
| 1144 | template <template <class, class, class, class> class _Alloc, class _Tp, class _A0, |
| 1145 | class _A1, class _A2, class _Up> |
| 1146 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false> |
| 1147 | { |
| 1148 | typedef _Alloc<_Up, _A0, _A1, _A2> type; |
| 1149 | }; |
| 1150 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1151 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1152 | |
| 1153 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
| 1154 | |
| 1155 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1156 | auto |
| 1157 | __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) |
| 1158 | -> decltype(__a.allocate(__sz, __p), true_type()); |
| 1159 | |
| 1160 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1161 | auto |
| 1162 | __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) |
| 1163 | -> false_type; |
| 1164 | |
| 1165 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1166 | struct __has_allocate_hint |
| 1167 | : integral_constant<bool, |
| 1168 | is_same< |
| 1169 | decltype(__has_allocate_hint_test(declval<_Alloc>(), |
| 1170 | declval<_SizeType>(), |
| 1171 | declval<_ConstVoidPtr>())), |
| 1172 | true_type>::value> |
| 1173 | { |
| 1174 | }; |
| 1175 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1176 | #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1177 | |
| 1178 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1179 | struct __has_allocate_hint |
| 1180 | : true_type |
| 1181 | { |
| 1182 | }; |
| 1183 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1184 | #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1185 | |
| 1186 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
| 1187 | |
| 1188 | template <class _Alloc, class _Tp, class ..._Args> |
| 1189 | decltype(_STD::declval<_Alloc>().construct(_STD::declval<_Tp*>(), |
| 1190 | _STD::declval<_Args>()...), |
| 1191 | true_type()) |
| 1192 | __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args); |
| 1193 | |
| 1194 | template <class _Alloc, class _Pointer, class ..._Args> |
| 1195 | false_type |
| 1196 | __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args); |
| 1197 | |
| 1198 | template <class _Alloc, class _Pointer, class ..._Args> |
| 1199 | struct __has_construct |
| 1200 | : integral_constant<bool, |
| 1201 | is_same< |
| 1202 | decltype(__has_construct_test(declval<_Alloc>(), |
| 1203 | declval<_Pointer>(), |
| 1204 | declval<_Args>()...)), |
| 1205 | true_type>::value> |
| 1206 | { |
| 1207 | }; |
| 1208 | |
| 1209 | template <class _Alloc, class _Pointer> |
| 1210 | auto |
| 1211 | __has_destroy_test(_Alloc&& __a, _Pointer&& __p) |
| 1212 | -> decltype(__a.destroy(__p), true_type()); |
| 1213 | |
| 1214 | template <class _Alloc, class _Pointer> |
| 1215 | auto |
| 1216 | __has_destroy_test(const _Alloc& __a, _Pointer&& __p) |
| 1217 | -> false_type; |
| 1218 | |
| 1219 | template <class _Alloc, class _Pointer> |
| 1220 | struct __has_destroy |
| 1221 | : integral_constant<bool, |
| 1222 | is_same< |
| 1223 | decltype(__has_destroy_test(declval<_Alloc>(), |
| 1224 | declval<_Pointer>())), |
| 1225 | true_type>::value> |
| 1226 | { |
| 1227 | }; |
| 1228 | |
| 1229 | template <class _Alloc> |
| 1230 | auto |
| 1231 | __has_max_size_test(_Alloc&& __a) |
| 1232 | -> decltype(__a.max_size(), true_type()); |
| 1233 | |
| 1234 | template <class _Alloc> |
| 1235 | auto |
| 1236 | __has_max_size_test(const volatile _Alloc& __a) |
| 1237 | -> false_type; |
| 1238 | |
| 1239 | template <class _Alloc> |
| 1240 | struct __has_max_size |
| 1241 | : integral_constant<bool, |
| 1242 | is_same< |
| 1243 | decltype(__has_max_size_test(declval<_Alloc&>())), |
| 1244 | true_type>::value> |
| 1245 | { |
| 1246 | }; |
| 1247 | |
| 1248 | template <class _Alloc> |
| 1249 | auto |
| 1250 | __has_select_on_container_copy_construction_test(_Alloc&& __a) |
| 1251 | -> decltype(__a.select_on_container_copy_construction(), true_type()); |
| 1252 | |
| 1253 | template <class _Alloc> |
| 1254 | auto |
| 1255 | __has_select_on_container_copy_construction_test(const volatile _Alloc& __a) |
| 1256 | -> false_type; |
| 1257 | |
| 1258 | template <class _Alloc> |
| 1259 | struct __has_select_on_container_copy_construction |
| 1260 | : integral_constant<bool, |
| 1261 | is_same< |
| 1262 | decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())), |
| 1263 | true_type>::value> |
| 1264 | { |
| 1265 | }; |
| 1266 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1267 | #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1268 | |
| 1269 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1270 | |
| 1271 | template <class _Alloc, class _Pointer, class ..._Args> |
| 1272 | struct __has_construct |
| 1273 | : false_type |
| 1274 | { |
| 1275 | }; |
| 1276 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1277 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1278 | |
| 1279 | template <class _Alloc, class _Pointer> |
| 1280 | struct __has_destroy |
| 1281 | : false_type |
| 1282 | { |
| 1283 | }; |
| 1284 | |
| 1285 | template <class _Alloc> |
| 1286 | struct __has_max_size |
| 1287 | : true_type |
| 1288 | { |
| 1289 | }; |
| 1290 | |
| 1291 | template <class _Alloc> |
| 1292 | struct __has_select_on_container_copy_construction |
| 1293 | : false_type |
| 1294 | { |
| 1295 | }; |
| 1296 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1297 | #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1298 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1299 | template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> |
| 1300 | struct __alloc_traits_difference_type |
| 1301 | { |
| 1302 | typedef typename pointer_traits<_Ptr>::difference_type type; |
| 1303 | }; |
| 1304 | |
| 1305 | template <class _Alloc, class _Ptr> |
| 1306 | struct __alloc_traits_difference_type<_Alloc, _Ptr, true> |
| 1307 | { |
| 1308 | typedef typename _Alloc::difference_type type; |
| 1309 | }; |
| 1310 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1311 | template <class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1312 | struct _LIBCPP_VISIBLE allocator_traits |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1313 | { |
| 1314 | typedef _Alloc allocator_type; |
| 1315 | typedef typename allocator_type::value_type value_type; |
| 1316 | |
| 1317 | typedef typename __pointer_type<value_type, allocator_type>::type pointer; |
| 1318 | typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer; |
| 1319 | typedef typename __void_pointer<pointer, allocator_type>::type void_pointer; |
| 1320 | typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer; |
| 1321 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1322 | typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type; |
| 1323 | typedef typename __size_type<allocator_type, difference_type>::type size_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1324 | |
| 1325 | typedef typename __propagate_on_container_copy_assignment<allocator_type>::type |
| 1326 | propagate_on_container_copy_assignment; |
| 1327 | typedef typename __propagate_on_container_move_assignment<allocator_type>::type |
| 1328 | propagate_on_container_move_assignment; |
| 1329 | typedef typename __propagate_on_container_swap<allocator_type>::type |
| 1330 | propagate_on_container_swap; |
| 1331 | |
| 1332 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1333 | template <class _Tp> using rebind_alloc = |
| 1334 | __allocator_traits_rebind<allocator_type, _Tp>::type; |
| 1335 | template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1336 | #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1337 | template <class _Tp> struct rebind_alloc |
| 1338 | {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; |
| 1339 | template <class _Tp> struct rebind_traits |
| 1340 | {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;}; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1341 | #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1342 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1343 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1344 | static pointer allocate(allocator_type& __a, size_type __n) |
| 1345 | {return __a.allocate(__n);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1346 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1347 | static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) |
| 1348 | {return allocate(__a, __n, __hint, |
| 1349 | __has_allocate_hint<allocator_type, size_type, const_void_pointer>());} |
| 1350 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1351 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | static void deallocate(allocator_type& __a, pointer __p, size_type __n) |
| 1353 | {__a.deallocate(__p, __n);} |
| 1354 | |
| 1355 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1356 | template <class _Tp, class... _Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1357 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1358 | static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) |
| 1359 | {__construct(__has_construct<allocator_type, pointer, _Args...>(), |
| 1360 | __a, __p, _STD::forward<_Args>(__args)...);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1361 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1362 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1363 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1364 | static void construct(allocator_type& __a, _Tp* __p) |
| 1365 | { |
| 1366 | ::new ((void*)__p) _Tp(); |
| 1367 | } |
| 1368 | template <class _Tp, class _A0> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1369 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1370 | static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0) |
| 1371 | { |
| 1372 | ::new ((void*)__p) _Tp(__a0); |
| 1373 | } |
| 1374 | template <class _Tp, class _A0, class _A1> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1375 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1376 | static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0, |
| 1377 | const _A1& __a1) |
| 1378 | { |
| 1379 | ::new ((void*)__p) _Tp(__a0, __a1); |
| 1380 | } |
| 1381 | template <class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1382 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1383 | static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0, |
| 1384 | const _A1& __a1, const _A2& __a2) |
| 1385 | { |
| 1386 | ::new ((void*)__p) _Tp(__a0, __a1, __a2); |
| 1387 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1388 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1389 | |
| 1390 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1391 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1392 | static void destroy(allocator_type& __a, _Tp* __p) |
| 1393 | {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);} |
| 1394 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1395 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1396 | static size_type max_size(const allocator_type& __a) |
| 1397 | {return __max_size(__has_max_size<const allocator_type>(), __a);} |
| 1398 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1399 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1400 | static allocator_type |
| 1401 | select_on_container_copy_construction(const allocator_type& __a) |
| 1402 | {return select_on_container_copy_construction( |
| 1403 | __has_select_on_container_copy_construction<const allocator_type>(), |
| 1404 | __a);} |
| 1405 | |
| 1406 | private: |
| 1407 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1408 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1409 | static pointer allocate(allocator_type& __a, size_type __n, |
| 1410 | const_void_pointer __hint, true_type) |
| 1411 | {return __a.allocate(__n, __hint);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1412 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1413 | static pointer allocate(allocator_type& __a, size_type __n, |
| 1414 | const_void_pointer __hint, false_type) |
| 1415 | {return __a.allocate(__n);} |
| 1416 | |
| 1417 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1418 | template <class _Tp, class... _Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1419 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1420 | static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args) |
| 1421 | {__a.construct(__p, _STD::forward<_Args>(__args)...);} |
| 1422 | template <class _Tp, class... _Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1423 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1424 | static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args) |
| 1425 | { |
| 1426 | ::new ((void*)__p) _Tp(_STD::forward<_Args>(__args)...); |
| 1427 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1428 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1429 | |
| 1430 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1431 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1432 | static void __destroy(true_type, allocator_type& __a, _Tp* __p) |
| 1433 | {__a.destroy(__p);} |
| 1434 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1435 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | static void __destroy(false_type, allocator_type&, _Tp* __p) |
| 1437 | { |
| 1438 | __p->~_Tp(); |
| 1439 | } |
| 1440 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1441 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1442 | static size_type __max_size(true_type, const allocator_type& __a) |
| 1443 | {return __a.max_size();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1444 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1445 | static size_type __max_size(false_type, const allocator_type&) |
| 1446 | {return numeric_limits<size_type>::max();} |
| 1447 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1449 | static allocator_type |
| 1450 | select_on_container_copy_construction(true_type, const allocator_type& __a) |
| 1451 | {return __a.select_on_container_copy_construction();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1452 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1453 | static allocator_type |
| 1454 | select_on_container_copy_construction(false_type, const allocator_type& __a) |
| 1455 | {return __a;} |
| 1456 | }; |
| 1457 | |
| 1458 | // uses_allocator |
| 1459 | |
| 1460 | template <class _Tp> |
| 1461 | struct __has_allocator_type |
| 1462 | { |
| 1463 | private: |
| 1464 | struct __two {char _; char __;}; |
| 1465 | template <class _Up> static __two __test(...); |
| 1466 | template <class _Up> static char __test(typename _Up::allocator_type* = 0); |
| 1467 | public: |
| 1468 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1469 | }; |
| 1470 | |
| 1471 | template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value> |
| 1472 | struct __uses_allocator |
| 1473 | : public integral_constant<bool, |
| 1474 | is_convertible<_Alloc, typename _Tp::allocator_type>::value> |
| 1475 | { |
| 1476 | }; |
| 1477 | |
| 1478 | template <class _Tp, class _Alloc> |
| 1479 | struct __uses_allocator<_Tp, _Alloc, false> |
| 1480 | : public false_type |
| 1481 | { |
| 1482 | }; |
| 1483 | |
| 1484 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1485 | struct _LIBCPP_VISIBLE uses_allocator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | : public __uses_allocator<_Tp, _Alloc> |
| 1487 | { |
| 1488 | }; |
| 1489 | |
Howard Hinnant | ac38bae | 2011-01-11 20:02:45 +0000 | [diff] [blame] | 1490 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1491 | |
| 1492 | // uses-allocator construction |
| 1493 | |
| 1494 | template <class _Tp, class _Alloc, class ..._Args> |
| 1495 | struct __uses_alloc_ctor_imp |
| 1496 | { |
| 1497 | static const bool __ua = uses_allocator<_Tp, _Alloc>::value; |
| 1498 | static const bool __ic = |
| 1499 | is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; |
| 1500 | static const int value = __ua ? 2 - __ic : 0; |
| 1501 | }; |
| 1502 | |
| 1503 | template <class _Tp, class _Alloc, class ..._Args> |
| 1504 | struct __uses_alloc_ctor |
| 1505 | : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> |
| 1506 | {}; |
| 1507 | |
Howard Hinnant | ac38bae | 2011-01-11 20:02:45 +0000 | [diff] [blame] | 1508 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1509 | |
| 1510 | // allocator |
| 1511 | |
| 1512 | template <class _Tp> |
Howard Hinnant | 36cdf02 | 2010-09-10 16:42:26 +0000 | [diff] [blame] | 1513 | class _LIBCPP_VISIBLE allocator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1514 | { |
| 1515 | public: |
| 1516 | typedef size_t size_type; |
| 1517 | typedef ptrdiff_t difference_type; |
| 1518 | typedef _Tp* pointer; |
| 1519 | typedef const _Tp* const_pointer; |
| 1520 | typedef _Tp& reference; |
| 1521 | typedef const _Tp& const_reference; |
| 1522 | typedef _Tp value_type; |
| 1523 | |
| 1524 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 1525 | |
| 1526 | _LIBCPP_INLINE_VISIBILITY allocator() throw() {} |
| 1527 | template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) throw() {} |
Howard Hinnant | 2529d02 | 2011-02-02 17:36:20 +0000 | [diff] [blame] | 1528 | _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const {return _STD::addressof(__x);} |
| 1529 | _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const {return _STD::addressof(__x);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1530 | _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) |
| 1531 | {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));} |
| 1532 | _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) {::operator delete((void*)__p);} |
| 1533 | _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1534 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | template <class _Up, class... _Args> |
| 1536 | _LIBCPP_INLINE_VISIBILITY |
| 1537 | void |
| 1538 | construct(_Up* __p, _Args&&... __args) |
| 1539 | { |
| 1540 | ::new((void*)__p) _Up(_STD::forward<_Args>(__args)...); |
| 1541 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1542 | #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1543 | _LIBCPP_INLINE_VISIBILITY |
| 1544 | void |
| 1545 | construct(pointer __p) |
| 1546 | { |
| 1547 | ::new((void*)__p) _Tp(); |
| 1548 | } |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1549 | # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1550 | template <class _A0> |
| 1551 | _LIBCPP_INLINE_VISIBILITY |
| 1552 | typename enable_if |
| 1553 | < |
| 1554 | !is_convertible<_A0, __rv<_A0> >::value, |
| 1555 | void |
| 1556 | >::type |
| 1557 | construct(pointer __p, _A0& __a0) |
| 1558 | { |
| 1559 | ::new((void*)__p) _Tp(__a0); |
| 1560 | } |
| 1561 | template <class _A0> |
| 1562 | _LIBCPP_INLINE_VISIBILITY |
| 1563 | typename enable_if |
| 1564 | < |
| 1565 | !is_convertible<_A0, __rv<_A0> >::value, |
| 1566 | void |
| 1567 | >::type |
| 1568 | construct(pointer __p, const _A0& __a0) |
| 1569 | { |
| 1570 | ::new((void*)__p) _Tp(__a0); |
| 1571 | } |
| 1572 | template <class _A0> |
| 1573 | _LIBCPP_INLINE_VISIBILITY |
| 1574 | typename enable_if |
| 1575 | < |
| 1576 | is_convertible<_A0, __rv<_A0> >::value, |
| 1577 | void |
| 1578 | >::type |
| 1579 | construct(pointer __p, _A0 __a0) |
| 1580 | { |
| 1581 | ::new((void*)__p) _Tp(_STD::move(__a0)); |
| 1582 | } |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1583 | # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1584 | template <class _A0, class _A1> |
| 1585 | _LIBCPP_INLINE_VISIBILITY |
| 1586 | void |
| 1587 | construct(pointer __p, _A0& __a0, _A1& __a1) |
| 1588 | { |
| 1589 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1590 | } |
| 1591 | template <class _A0, class _A1> |
| 1592 | _LIBCPP_INLINE_VISIBILITY |
| 1593 | void |
| 1594 | construct(pointer __p, const _A0& __a0, _A1& __a1) |
| 1595 | { |
| 1596 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1597 | } |
| 1598 | template <class _A0, class _A1> |
| 1599 | _LIBCPP_INLINE_VISIBILITY |
| 1600 | void |
| 1601 | construct(pointer __p, _A0& __a0, const _A1& __a1) |
| 1602 | { |
| 1603 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1604 | } |
| 1605 | template <class _A0, class _A1> |
| 1606 | _LIBCPP_INLINE_VISIBILITY |
| 1607 | void |
| 1608 | construct(pointer __p, const _A0& __a0, const _A1& __a1) |
| 1609 | { |
| 1610 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1611 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1612 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1613 | _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} |
| 1614 | }; |
| 1615 | |
| 1616 | template <class _Tp, class _Up> |
| 1617 | inline _LIBCPP_INLINE_VISIBILITY |
| 1618 | bool operator==(const allocator<_Tp>&, const allocator<_Up>&) throw() {return true;} |
| 1619 | |
| 1620 | template <class _Tp, class _Up> |
| 1621 | inline _LIBCPP_INLINE_VISIBILITY |
| 1622 | bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) throw() {return false;} |
| 1623 | |
| 1624 | template <class _OutputIterator, class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1625 | class _LIBCPP_VISIBLE raw_storage_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1626 | : public iterator<output_iterator_tag, |
| 1627 | _Tp, // purposefully not C++03 |
| 1628 | ptrdiff_t, // purposefully not C++03 |
| 1629 | _Tp*, // purposefully not C++03 |
| 1630 | raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 |
| 1631 | { |
| 1632 | private: |
| 1633 | _OutputIterator __x_; |
| 1634 | public: |
| 1635 | _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} |
| 1636 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} |
| 1637 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) |
| 1638 | {::new(&*__x_) _Tp(__element); return *this;} |
| 1639 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} |
| 1640 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) |
| 1641 | {raw_storage_iterator __t(*this); ++__x_; return __t;} |
| 1642 | }; |
| 1643 | |
| 1644 | template <class _Tp> |
| 1645 | pair<_Tp*, ptrdiff_t> |
| 1646 | get_temporary_buffer(ptrdiff_t __n) |
| 1647 | { |
| 1648 | pair<_Tp*, ptrdiff_t> __r(0, 0); |
| 1649 | const ptrdiff_t __m = (~ptrdiff_t(0) ^ |
| 1650 | ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) |
| 1651 | / sizeof(_Tp); |
| 1652 | if (__n > __m) |
| 1653 | __n = __m; |
| 1654 | while (__n > 0) |
| 1655 | { |
| 1656 | __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); |
| 1657 | if (__r.first) |
| 1658 | { |
| 1659 | __r.second = __n; |
| 1660 | break; |
| 1661 | } |
| 1662 | __n /= 2; |
| 1663 | } |
| 1664 | return __r; |
| 1665 | } |
| 1666 | |
| 1667 | template <class _Tp> |
| 1668 | inline _LIBCPP_INLINE_VISIBILITY |
| 1669 | void return_temporary_buffer(_Tp* __p) {::operator delete(__p);} |
| 1670 | |
| 1671 | template <class _Tp> |
| 1672 | struct auto_ptr_ref |
| 1673 | { |
| 1674 | _Tp* __ptr_; |
| 1675 | }; |
| 1676 | |
| 1677 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1678 | class _LIBCPP_VISIBLE auto_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1679 | { |
| 1680 | private: |
| 1681 | _Tp* __ptr_; |
| 1682 | public: |
| 1683 | typedef _Tp element_type; |
| 1684 | |
| 1685 | _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {} |
| 1686 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {} |
| 1687 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw() |
| 1688 | : __ptr_(__p.release()) {} |
| 1689 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw() |
| 1690 | {reset(__p.release()); return *this;} |
| 1691 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw() |
| 1692 | {reset(__p.release()); return *this;} |
| 1693 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw() |
| 1694 | {reset(__p.__ptr_); return *this;} |
| 1695 | _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;} |
| 1696 | |
| 1697 | _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw() |
| 1698 | {return *__ptr_;} |
| 1699 | _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;} |
| 1700 | _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;} |
| 1701 | _LIBCPP_INLINE_VISIBILITY _Tp* release() throw() |
| 1702 | { |
| 1703 | _Tp* __t = __ptr_; |
| 1704 | __ptr_ = 0; |
| 1705 | return __t; |
| 1706 | } |
| 1707 | _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw() |
| 1708 | { |
| 1709 | if (__ptr_ != __p) |
| 1710 | delete __ptr_; |
| 1711 | __ptr_ = __p; |
| 1712 | } |
| 1713 | |
| 1714 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {} |
| 1715 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw() |
| 1716 | {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} |
| 1717 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw() |
| 1718 | {return auto_ptr<_Up>(release());} |
| 1719 | }; |
| 1720 | |
| 1721 | template <> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1722 | class _LIBCPP_VISIBLE auto_ptr<void> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1723 | { |
| 1724 | public: |
| 1725 | typedef void element_type; |
| 1726 | }; |
| 1727 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1728 | template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type, |
| 1729 | typename remove_cv<_T2>::type>::value, |
| 1730 | bool = is_empty<_T1>::value, |
| 1731 | bool = is_empty<_T2>::value> |
| 1732 | struct __libcpp_compressed_pair_switch; |
| 1733 | |
| 1734 | template <class _T1, class _T2, bool IsSame> |
| 1735 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};}; |
| 1736 | |
| 1737 | template <class _T1, class _T2, bool IsSame> |
| 1738 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};}; |
| 1739 | |
| 1740 | template <class _T1, class _T2, bool IsSame> |
| 1741 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};}; |
| 1742 | |
| 1743 | template <class _T1, class _T2> |
| 1744 | struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};}; |
| 1745 | |
| 1746 | template <class _T1, class _T2> |
| 1747 | struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};}; |
| 1748 | |
| 1749 | template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value> |
| 1750 | class __libcpp_compressed_pair_imp; |
| 1751 | |
| 1752 | template <class _T1, class _T2> |
| 1753 | class __libcpp_compressed_pair_imp<_T1, _T2, 0> |
| 1754 | { |
| 1755 | private: |
| 1756 | _T1 __first_; |
| 1757 | _T2 __second_; |
| 1758 | public: |
| 1759 | typedef _T1 _T1_param; |
| 1760 | typedef _T2 _T2_param; |
| 1761 | |
| 1762 | typedef typename remove_reference<_T1>::type& _T1_reference; |
| 1763 | typedef typename remove_reference<_T2>::type& _T2_reference; |
| 1764 | |
| 1765 | typedef const typename remove_reference<_T1>::type& _T1_const_reference; |
| 1766 | typedef const typename remove_reference<_T2>::type& _T2_const_reference; |
| 1767 | |
| 1768 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1769 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0) |
| 1770 | : __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1771 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0) |
| 1772 | : __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1773 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1774 | : __first_(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1775 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1776 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1777 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
| 1778 | : __first_(_STD::forward<_T1>(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1779 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1780 | |
| 1781 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return __first_;} |
| 1782 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return __first_;} |
| 1783 | |
| 1784 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return __second_;} |
| 1785 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return __second_;} |
| 1786 | |
| 1787 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
| 1788 | { |
| 1789 | using _STD::swap; |
| 1790 | swap(__first_, __x.__first_); |
| 1791 | swap(__second_, __x.__second_); |
| 1792 | } |
| 1793 | }; |
| 1794 | |
| 1795 | template <class _T1, class _T2> |
| 1796 | class __libcpp_compressed_pair_imp<_T1, _T2, 1> |
| 1797 | : private _T1 |
| 1798 | { |
| 1799 | private: |
| 1800 | _T2 __second_; |
| 1801 | public: |
| 1802 | typedef _T1 _T1_param; |
| 1803 | typedef _T2 _T2_param; |
| 1804 | |
| 1805 | typedef _T1& _T1_reference; |
| 1806 | typedef typename remove_reference<_T2>::type& _T2_reference; |
| 1807 | |
| 1808 | typedef const _T1& _T1_const_reference; |
| 1809 | typedef const typename remove_reference<_T2>::type& _T2_const_reference; |
| 1810 | |
| 1811 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1812 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0) |
| 1813 | : _T1(_STD::forward<_T1_param>(__t1)) {} |
| 1814 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0) |
| 1815 | : __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1816 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1817 | : _T1(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1818 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1819 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1820 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
| 1821 | : _T1(_STD::move(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1822 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1823 | |
| 1824 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return *this;} |
| 1825 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return *this;} |
| 1826 | |
| 1827 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return __second_;} |
| 1828 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return __second_;} |
| 1829 | |
| 1830 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
| 1831 | { |
| 1832 | using _STD::swap; |
| 1833 | swap(__second_, __x.__second_); |
| 1834 | } |
| 1835 | }; |
| 1836 | |
| 1837 | template <class _T1, class _T2> |
| 1838 | class __libcpp_compressed_pair_imp<_T1, _T2, 2> |
| 1839 | : private _T2 |
| 1840 | { |
| 1841 | private: |
| 1842 | _T1 __first_; |
| 1843 | public: |
| 1844 | typedef _T1 _T1_param; |
| 1845 | typedef _T2 _T2_param; |
| 1846 | |
| 1847 | typedef typename remove_reference<_T1>::type& _T1_reference; |
| 1848 | typedef _T2& _T2_reference; |
| 1849 | |
| 1850 | typedef const typename remove_reference<_T1>::type& _T1_const_reference; |
| 1851 | typedef const _T2& _T2_const_reference; |
| 1852 | |
| 1853 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1854 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) |
| 1855 | : __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1856 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) |
| 1857 | : _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1858 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1859 | : _T2(_STD::forward<_T2_param>(__t2)), __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1860 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1861 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 | __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
| 1863 | : _T2(_STD::forward<_T2>(__p.second())), __first_(_STD::move(__p.first())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1864 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | |
| 1866 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return __first_;} |
| 1867 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return __first_;} |
| 1868 | |
| 1869 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return *this;} |
| 1870 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return *this;} |
| 1871 | |
| 1872 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
| 1873 | { |
| 1874 | using _STD::swap; |
| 1875 | swap(__first_, __x.__first_); |
| 1876 | } |
| 1877 | }; |
| 1878 | |
| 1879 | template <class _T1, class _T2> |
| 1880 | class __libcpp_compressed_pair_imp<_T1, _T2, 3> |
| 1881 | : private _T1, |
| 1882 | private _T2 |
| 1883 | { |
| 1884 | public: |
| 1885 | typedef _T1 _T1_param; |
| 1886 | typedef _T2 _T2_param; |
| 1887 | |
| 1888 | typedef _T1& _T1_reference; |
| 1889 | typedef _T2& _T2_reference; |
| 1890 | |
| 1891 | typedef const _T1& _T1_const_reference; |
| 1892 | typedef const _T2& _T2_const_reference; |
| 1893 | |
| 1894 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1895 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) |
| 1896 | : _T1(_STD::forward<_T1_param>(__t1)) {} |
| 1897 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) |
| 1898 | : _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1899 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1900 | : _T1(_STD::forward<_T1_param>(__t1)), _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1901 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1902 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1903 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
| 1904 | : _T1(_STD::move(__p.first())), _T2(_STD::move(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1905 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1906 | |
| 1907 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return *this;} |
| 1908 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return *this;} |
| 1909 | |
| 1910 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return *this;} |
| 1911 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return *this;} |
| 1912 | |
| 1913 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
| 1914 | { |
| 1915 | } |
| 1916 | }; |
| 1917 | |
| 1918 | template <class _T1, class _T2> |
| 1919 | class __compressed_pair |
| 1920 | : private __libcpp_compressed_pair_imp<_T1, _T2> |
| 1921 | { |
| 1922 | typedef __libcpp_compressed_pair_imp<_T1, _T2> base; |
| 1923 | public: |
| 1924 | typedef typename base::_T1_param _T1_param; |
| 1925 | typedef typename base::_T2_param _T2_param; |
| 1926 | |
| 1927 | typedef typename base::_T1_reference _T1_reference; |
| 1928 | typedef typename base::_T2_reference _T2_reference; |
| 1929 | |
| 1930 | typedef typename base::_T1_const_reference _T1_const_reference; |
| 1931 | typedef typename base::_T2_const_reference _T2_const_reference; |
| 1932 | |
| 1933 | _LIBCPP_INLINE_VISIBILITY __compressed_pair() {} |
| 1934 | _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1, int = 0) |
| 1935 | : base(_STD::forward<_T1_param>(__t1)) {} |
| 1936 | _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2, int* = 0) |
| 1937 | : base(_STD::forward<_T2_param>(__t2)) {} |
| 1938 | _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2) |
| 1939 | : base(_STD::forward<_T1_param>(__t1), _STD::forward<_T2_param>(__t2)) {} |
| 1940 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1941 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1942 | __compressed_pair(__compressed_pair&& __p) |
| 1943 | : base(_STD::move(__p)) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1944 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1945 | |
| 1946 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() {return base::first();} |
| 1947 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return base::first();} |
| 1948 | |
| 1949 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() {return base::second();} |
| 1950 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return base::second();} |
| 1951 | |
| 1952 | _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) {base::swap(__x);} |
| 1953 | }; |
| 1954 | |
| 1955 | template <class _T1, class _T2> |
| 1956 | inline _LIBCPP_INLINE_VISIBILITY |
| 1957 | void |
| 1958 | swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) |
| 1959 | {__x.swap(__y);} |
| 1960 | |
| 1961 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1962 | struct _LIBCPP_VISIBLE default_delete |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1963 | { |
| 1964 | _LIBCPP_INLINE_VISIBILITY default_delete() {} |
| 1965 | template <class _Up> |
| 1966 | _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&, |
| 1967 | typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) {} |
| 1968 | _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const |
| 1969 | { |
| 1970 | static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); |
| 1971 | delete __ptr; |
| 1972 | } |
| 1973 | }; |
| 1974 | |
| 1975 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1976 | struct _LIBCPP_VISIBLE default_delete<_Tp[]> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1977 | { |
| 1978 | _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const |
| 1979 | { |
| 1980 | static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); |
| 1981 | delete [] __ptr; |
| 1982 | } |
| 1983 | private: |
| 1984 | template <class _Up> void operator() (_Up*) const; |
| 1985 | }; |
| 1986 | |
| 1987 | template <class _Tp, class _Dp = default_delete<_Tp> > |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1988 | class _LIBCPP_VISIBLE unique_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1989 | { |
| 1990 | public: |
| 1991 | typedef _Tp element_type; |
| 1992 | typedef _Dp deleter_type; |
| 1993 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 1994 | private: |
| 1995 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 1996 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1997 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1998 | unique_ptr(const unique_ptr&); |
| 1999 | unique_ptr& operator=(const unique_ptr&); |
| 2000 | template <class _Up, class _Ep> |
| 2001 | unique_ptr(const unique_ptr<_Up, _Ep>&); |
| 2002 | template <class _Up, class _Ep> |
| 2003 | unique_ptr& operator=(const unique_ptr<_Up, _Ep>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2004 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2005 | unique_ptr(unique_ptr&); |
| 2006 | template <class _Up, class _Ep> |
| 2007 | unique_ptr(unique_ptr<_Up, _Ep>&); |
| 2008 | unique_ptr& operator=(unique_ptr&); |
| 2009 | template <class _Up, class _Ep> |
| 2010 | unique_ptr& operator=(unique_ptr<_Up, _Ep>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2011 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2012 | |
| 2013 | struct __nat {int __for_bool_;}; |
| 2014 | |
| 2015 | typedef typename remove_reference<deleter_type>::type& _Dp_reference; |
| 2016 | typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; |
| 2017 | public: |
| 2018 | _LIBCPP_INLINE_VISIBILITY unique_ptr() |
| 2019 | : __ptr_(pointer()) |
| 2020 | { |
| 2021 | static_assert(!is_pointer<deleter_type>::value, |
| 2022 | "unique_ptr constructed with null function pointer deleter"); |
| 2023 | } |
| 2024 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) |
| 2025 | : __ptr_(pointer()) |
| 2026 | { |
| 2027 | static_assert(!is_pointer<deleter_type>::value, |
| 2028 | "unique_ptr constructed with null function pointer deleter"); |
| 2029 | } |
| 2030 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) |
| 2031 | : __ptr_(_STD::move(__p)) |
| 2032 | { |
| 2033 | static_assert(!is_pointer<deleter_type>::value, |
| 2034 | "unique_ptr constructed with null function pointer deleter"); |
| 2035 | } |
| 2036 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2037 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2038 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional< |
| 2039 | is_reference<deleter_type>::value, |
| 2040 | deleter_type, |
| 2041 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
| 2042 | : __ptr_(__p, __d) {} |
| 2043 | |
| 2044 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d) |
| 2045 | : __ptr_(__p, _STD::move(__d)) |
| 2046 | { |
| 2047 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2048 | } |
| 2049 | _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) |
| 2050 | : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {} |
| 2051 | template <class _Up, class _Ep> |
| 2052 | _LIBCPP_INLINE_VISIBILITY |
| 2053 | unique_ptr(unique_ptr<_Up, _Ep>&& __u, |
| 2054 | typename enable_if |
| 2055 | < |
| 2056 | !is_array<_Up>::value && |
| 2057 | is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && |
| 2058 | is_convertible<_Ep, deleter_type>::value && |
| 2059 | ( |
| 2060 | !is_reference<deleter_type>::value || |
| 2061 | is_same<deleter_type, _Ep>::value |
| 2062 | ), |
| 2063 | __nat |
| 2064 | >::type = __nat()) |
| 2065 | : __ptr_(__u.release(), _STD::forward<_Ep>(__u.get_deleter())) {} |
| 2066 | |
| 2067 | template <class _Up> |
| 2068 | _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p, |
| 2069 | typename enable_if< |
| 2070 | is_convertible<_Up*, _Tp*>::value && |
| 2071 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2072 | __nat |
| 2073 | >::type = __nat()) |
| 2074 | : __ptr_(__p.release()) |
| 2075 | { |
| 2076 | } |
| 2077 | |
| 2078 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) |
| 2079 | { |
| 2080 | reset(__u.release()); |
| 2081 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2082 | return *this; |
| 2083 | } |
| 2084 | |
| 2085 | template <class _Up, class _Ep> |
| 2086 | _LIBCPP_INLINE_VISIBILITY |
| 2087 | typename enable_if |
| 2088 | < |
| 2089 | !is_array<_Up>::value, |
| 2090 | unique_ptr& |
| 2091 | >::type |
| 2092 | operator=(unique_ptr<_Up, _Ep>&& __u) |
| 2093 | { |
| 2094 | reset(__u.release()); |
| 2095 | __ptr_.second() = _STD::forward<_Ep>(__u.get_deleter()); |
| 2096 | return *this; |
| 2097 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2098 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2099 | |
| 2100 | _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() |
| 2101 | { |
| 2102 | return __rv<unique_ptr>(*this); |
| 2103 | } |
| 2104 | |
| 2105 | _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) |
| 2106 | : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {} |
| 2107 | |
| 2108 | template <class _Up, class _Ep> |
| 2109 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u) |
| 2110 | { |
| 2111 | reset(__u.release()); |
| 2112 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2113 | return *this; |
| 2114 | } |
| 2115 | |
| 2116 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) |
| 2117 | : __ptr_(_STD::move(__p), _STD::move(__d)) {} |
| 2118 | |
| 2119 | template <class _Up> |
| 2120 | _LIBCPP_INLINE_VISIBILITY |
| 2121 | typename enable_if< |
| 2122 | is_convertible<_Up*, _Tp*>::value && |
| 2123 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2124 | unique_ptr& |
| 2125 | >::type |
| 2126 | operator=(auto_ptr<_Up> __p) |
| 2127 | {reset(__p.release()); return *this;} |
| 2128 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2129 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2130 | _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} |
| 2131 | |
| 2132 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) |
| 2133 | { |
| 2134 | reset(); |
| 2135 | return *this; |
| 2136 | } |
| 2137 | |
| 2138 | _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const |
| 2139 | {return *__ptr_.first();} |
| 2140 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_.first();} |
| 2141 | _LIBCPP_INLINE_VISIBILITY pointer get() const {return __ptr_.first();} |
| 2142 | _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() {return __ptr_.second();} |
| 2143 | _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const {return __ptr_.second();} |
| 2144 | _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const {return __ptr_.first() ? &__nat::__for_bool_ : 0;} |
| 2145 | |
| 2146 | _LIBCPP_INLINE_VISIBILITY pointer release() |
| 2147 | { |
| 2148 | pointer __t = __ptr_.first(); |
| 2149 | __ptr_.first() = pointer(); |
| 2150 | return __t; |
| 2151 | } |
| 2152 | |
| 2153 | _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) |
| 2154 | { |
| 2155 | pointer __tmp = __ptr_.first(); |
| 2156 | __ptr_.first() = __p; |
| 2157 | if (__tmp) |
| 2158 | __ptr_.second()(__tmp); |
| 2159 | } |
| 2160 | |
| 2161 | _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);} |
| 2162 | }; |
| 2163 | |
| 2164 | template <class _Tp, class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2165 | class _LIBCPP_VISIBLE unique_ptr<_Tp[], _Dp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2166 | { |
| 2167 | public: |
| 2168 | typedef _Tp element_type; |
| 2169 | typedef _Dp deleter_type; |
| 2170 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2171 | private: |
| 2172 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 2173 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2174 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2175 | unique_ptr(const unique_ptr&); |
| 2176 | unique_ptr& operator=(const unique_ptr&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2177 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2178 | unique_ptr(unique_ptr&); |
| 2179 | template <class _Up> |
| 2180 | unique_ptr(unique_ptr<_Up>&); |
| 2181 | unique_ptr& operator=(unique_ptr&); |
| 2182 | template <class _Up> |
| 2183 | unique_ptr& operator=(unique_ptr<_Up>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2184 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2185 | |
| 2186 | struct __nat {int __for_bool_;}; |
| 2187 | |
| 2188 | typedef typename remove_reference<deleter_type>::type& _Dp_reference; |
| 2189 | typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; |
| 2190 | public: |
| 2191 | _LIBCPP_INLINE_VISIBILITY unique_ptr() |
| 2192 | : __ptr_(pointer()) |
| 2193 | { |
| 2194 | static_assert(!is_pointer<deleter_type>::value, |
| 2195 | "unique_ptr constructed with null function pointer deleter"); |
| 2196 | } |
| 2197 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) |
| 2198 | : __ptr_(pointer()) |
| 2199 | { |
| 2200 | static_assert(!is_pointer<deleter_type>::value, |
| 2201 | "unique_ptr constructed with null function pointer deleter"); |
| 2202 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2203 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2204 | template <class _P, |
| 2205 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2206 | > |
| 2207 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_P __p) |
| 2208 | : __ptr_(__p) |
| 2209 | { |
| 2210 | static_assert(!is_pointer<deleter_type>::value, |
| 2211 | "unique_ptr constructed with null function pointer deleter"); |
| 2212 | } |
| 2213 | |
| 2214 | template <class _P, |
| 2215 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2216 | > |
| 2217 | _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename conditional< |
| 2218 | is_reference<deleter_type>::value, |
| 2219 | deleter_type, |
| 2220 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
| 2221 | : __ptr_(__p, __d) {} |
| 2222 | |
| 2223 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional< |
| 2224 | is_reference<deleter_type>::value, |
| 2225 | deleter_type, |
| 2226 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
| 2227 | : __ptr_(pointer(), __d) {} |
| 2228 | |
| 2229 | template <class _P, |
| 2230 | class = typename enable_if<is_same<_P, pointer>::value || |
| 2231 | is_same<_P, nullptr_t>::value>::type |
| 2232 | > |
| 2233 | _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename remove_reference<deleter_type>::type&& __d) |
| 2234 | : __ptr_(__p, _STD::move(__d)) |
| 2235 | { |
| 2236 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2237 | } |
| 2238 | |
| 2239 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d) |
| 2240 | : __ptr_(pointer(), _STD::move(__d)) |
| 2241 | { |
| 2242 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2243 | } |
| 2244 | |
| 2245 | _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) |
| 2246 | : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {} |
| 2247 | |
| 2248 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) |
| 2249 | { |
| 2250 | reset(__u.release()); |
| 2251 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2252 | return *this; |
| 2253 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2254 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2255 | |
| 2256 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) |
| 2257 | : __ptr_(__p) |
| 2258 | { |
| 2259 | static_assert(!is_pointer<deleter_type>::value, |
| 2260 | "unique_ptr constructed with null function pointer deleter"); |
| 2261 | } |
| 2262 | |
| 2263 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) |
| 2264 | : __ptr_(__p, _STD::forward<deleter_type>(__d)) {} |
| 2265 | |
| 2266 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d) |
| 2267 | : __ptr_(pointer(), _STD::forward<deleter_type>(__d)) {} |
| 2268 | |
| 2269 | _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() |
| 2270 | { |
| 2271 | return __rv<unique_ptr>(*this); |
| 2272 | } |
| 2273 | |
| 2274 | _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) |
| 2275 | : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {} |
| 2276 | |
| 2277 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u) |
| 2278 | { |
| 2279 | reset(__u->release()); |
| 2280 | __ptr_.second() = _STD::forward<deleter_type>(__u->get_deleter()); |
| 2281 | return *this; |
| 2282 | } |
| 2283 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2284 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2285 | _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} |
| 2286 | |
| 2287 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) |
| 2288 | { |
| 2289 | reset(); |
| 2290 | return *this; |
| 2291 | } |
| 2292 | |
| 2293 | _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const |
| 2294 | {return __ptr_.first()[__i];} |
| 2295 | _LIBCPP_INLINE_VISIBILITY pointer get() const {return __ptr_.first();} |
| 2296 | _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() {return __ptr_.second();} |
| 2297 | _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const {return __ptr_.second();} |
| 2298 | _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const {return __ptr_.first() ? &__nat::__for_bool_ : 0;} |
| 2299 | |
| 2300 | _LIBCPP_INLINE_VISIBILITY pointer release() |
| 2301 | { |
| 2302 | pointer __t = __ptr_.first(); |
| 2303 | __ptr_.first() = pointer(); |
| 2304 | return __t; |
| 2305 | } |
| 2306 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2307 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2308 | template <class _P, |
| 2309 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2310 | > |
| 2311 | _LIBCPP_INLINE_VISIBILITY void reset(_P __p) |
| 2312 | { |
| 2313 | pointer __tmp = __ptr_.first(); |
| 2314 | __ptr_.first() = __p; |
| 2315 | if (__tmp) |
| 2316 | __ptr_.second()(__tmp); |
| 2317 | } |
| 2318 | _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) |
| 2319 | { |
| 2320 | pointer __tmp = __ptr_.first(); |
| 2321 | __ptr_.first() = nullptr; |
| 2322 | if (__tmp) |
| 2323 | __ptr_.second()(__tmp); |
| 2324 | } |
| 2325 | _LIBCPP_INLINE_VISIBILITY void reset() |
| 2326 | { |
| 2327 | pointer __tmp = __ptr_.first(); |
| 2328 | __ptr_.first() = nullptr; |
| 2329 | if (__tmp) |
| 2330 | __ptr_.second()(__tmp); |
| 2331 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2332 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2333 | _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) |
| 2334 | { |
| 2335 | pointer __tmp = __ptr_.first(); |
| 2336 | __ptr_.first() = __p; |
| 2337 | if (__tmp) |
| 2338 | __ptr_.second()(__tmp); |
| 2339 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2340 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2341 | |
| 2342 | _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);} |
| 2343 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2344 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2345 | #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2346 | template <class _Up> |
| 2347 | explicit unique_ptr(_Up); |
| 2348 | template <class _Up> |
| 2349 | unique_ptr(_Up __u, |
| 2350 | typename conditional< |
| 2351 | is_reference<deleter_type>::value, |
| 2352 | deleter_type, |
| 2353 | typename add_lvalue_reference<const deleter_type>::type>::type, |
| 2354 | typename enable_if |
| 2355 | < |
| 2356 | is_convertible<_Up, pointer>::value, |
| 2357 | __nat |
| 2358 | >::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2359 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2360 | }; |
| 2361 | |
| 2362 | template <class _Tp, class _Dp> |
| 2363 | inline _LIBCPP_INLINE_VISIBILITY |
| 2364 | void |
| 2365 | swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) {__x.swap(__y);} |
| 2366 | |
| 2367 | template <class _T1, class _D1, class _T2, class _D2> |
| 2368 | inline _LIBCPP_INLINE_VISIBILITY |
| 2369 | bool |
| 2370 | operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} |
| 2371 | |
| 2372 | template <class _T1, class _D1, class _T2, class _D2> |
| 2373 | inline _LIBCPP_INLINE_VISIBILITY |
| 2374 | bool |
| 2375 | operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} |
| 2376 | |
| 2377 | template <class _T1, class _D1, class _T2, class _D2> |
| 2378 | inline _LIBCPP_INLINE_VISIBILITY |
| 2379 | bool |
| 2380 | operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() < __y.get();} |
| 2381 | |
| 2382 | template <class _T1, class _D1, class _T2, class _D2> |
| 2383 | inline _LIBCPP_INLINE_VISIBILITY |
| 2384 | bool |
| 2385 | operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} |
| 2386 | |
| 2387 | template <class _T1, class _D1, class _T2, class _D2> |
| 2388 | inline _LIBCPP_INLINE_VISIBILITY |
| 2389 | bool |
| 2390 | operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} |
| 2391 | |
| 2392 | template <class _T1, class _D1, class _T2, class _D2> |
| 2393 | inline _LIBCPP_INLINE_VISIBILITY |
| 2394 | bool |
| 2395 | operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} |
| 2396 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2397 | template <class> struct hash; |
| 2398 | |
| 2399 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2400 | struct _LIBCPP_VISIBLE hash<_Tp*> |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2401 | : public unary_function<_Tp*, size_t> |
| 2402 | { |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2403 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2404 | size_t operator()(_Tp* __v) const |
| 2405 | { |
| 2406 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 2407 | return *__p; |
| 2408 | } |
| 2409 | }; |
| 2410 | |
| 2411 | template <class _Tp, class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2412 | struct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> > |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2413 | { |
| 2414 | typedef unique_ptr<_Tp, _Dp> argument_type; |
| 2415 | typedef size_t result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2416 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2417 | result_type operator()(const argument_type& __ptr) const |
| 2418 | { |
| 2419 | typedef typename argument_type::pointer pointer; |
| 2420 | return hash<pointer>()(__ptr.get()); |
| 2421 | } |
| 2422 | }; |
| 2423 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2424 | struct __destruct_n |
| 2425 | { |
| 2426 | private: |
| 2427 | size_t size; |
| 2428 | |
| 2429 | template <class _Tp> |
| 2430 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) |
| 2431 | {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();} |
| 2432 | |
| 2433 | template <class _Tp> |
| 2434 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) |
| 2435 | {} |
| 2436 | |
| 2437 | _LIBCPP_INLINE_VISIBILITY void __incr(false_type) |
| 2438 | {++size;} |
| 2439 | _LIBCPP_INLINE_VISIBILITY void __incr(true_type) |
| 2440 | {} |
| 2441 | |
| 2442 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) |
| 2443 | {size = __s;} |
| 2444 | _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) |
| 2445 | {} |
| 2446 | public: |
| 2447 | _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) : size(__s) {} |
| 2448 | |
| 2449 | template <class _Tp> |
| 2450 | _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2451 | {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2452 | |
| 2453 | template <class _Tp> |
| 2454 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2455 | {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2456 | |
| 2457 | template <class _Tp> |
| 2458 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2459 | {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2460 | }; |
| 2461 | |
| 2462 | template <class _Alloc> |
| 2463 | class __allocator_destructor |
| 2464 | { |
| 2465 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 2466 | public: |
| 2467 | typedef typename __alloc_traits::pointer pointer; |
| 2468 | typedef typename __alloc_traits::size_type size_type; |
| 2469 | private: |
| 2470 | _Alloc& __alloc_; |
| 2471 | size_type __s_; |
| 2472 | public: |
| 2473 | _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) |
| 2474 | : __alloc_(__a), __s_(__s) {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2475 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2476 | void operator()(pointer __p) {__alloc_traits::deallocate(__alloc_, __p, __s_);} |
| 2477 | }; |
| 2478 | |
| 2479 | template <class _InputIterator, class _ForwardIterator> |
| 2480 | _ForwardIterator |
| 2481 | uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) |
| 2482 | { |
| 2483 | __destruct_n __d(0); |
| 2484 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2485 | unique_ptr<value_type, __destruct_n&> __h(&*__r, __d); |
| 2486 | for (; __f != __l; ++__f, ++__r, __d.__incr((value_type*)0)) |
| 2487 | ::new(&*__r) value_type(*__f); |
| 2488 | __h.release(); |
| 2489 | return __r; |
| 2490 | } |
| 2491 | |
| 2492 | template <class _InputIterator, class _Size, class _ForwardIterator> |
| 2493 | _ForwardIterator |
| 2494 | uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) |
| 2495 | { |
| 2496 | __destruct_n __d(0); |
| 2497 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2498 | unique_ptr<value_type, __destruct_n&> __h(&*__r, __d); |
| 2499 | for (; __n > 0; ++__f, ++__r, __d.__incr((value_type*)0), --__n) |
| 2500 | ::new(&*__r) value_type(*__f); |
| 2501 | __h.release(); |
| 2502 | return __r; |
| 2503 | } |
| 2504 | |
| 2505 | template <class _ForwardIterator, class _Tp> |
| 2506 | void |
| 2507 | uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) |
| 2508 | { |
| 2509 | __destruct_n __d(0); |
| 2510 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2511 | unique_ptr<value_type, __destruct_n&> __h(&*__f, __d); |
| 2512 | for (; __f != __l; ++__f, __d.__incr((value_type*)0)) |
| 2513 | ::new(&*__f) value_type(__x); |
| 2514 | __h.release(); |
| 2515 | } |
| 2516 | |
| 2517 | template <class _ForwardIterator, class _Size, class _Tp> |
Howard Hinnant | 2f6a627 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 2518 | _ForwardIterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2519 | uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) |
| 2520 | { |
| 2521 | __destruct_n __d(0); |
| 2522 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2523 | unique_ptr<value_type, __destruct_n&> __h(&*__f, __d); |
| 2524 | for (; __n > 0; ++__f, --__n, __d.__incr((value_type*)0)) |
| 2525 | ::new(&*__f) value_type(__x); |
| 2526 | __h.release(); |
Howard Hinnant | 2f6a627 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 2527 | return __f; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2530 | class _LIBCPP_EXCEPTION_ABI bad_weak_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2531 | : public std::exception |
| 2532 | { |
| 2533 | public: |
| 2534 | virtual ~bad_weak_ptr() throw(); |
| 2535 | virtual const char* what() const throw(); |
| 2536 | }; |
| 2537 | |
| 2538 | template<class _Tp> class weak_ptr; |
| 2539 | |
| 2540 | class __shared_count |
| 2541 | { |
| 2542 | __shared_count(const __shared_count&); |
| 2543 | __shared_count& operator=(const __shared_count&); |
| 2544 | |
| 2545 | protected: |
| 2546 | long __shared_owners_; |
| 2547 | virtual ~__shared_count(); |
| 2548 | private: |
| 2549 | virtual void __on_zero_shared() = 0; |
| 2550 | |
| 2551 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2552 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2553 | explicit __shared_count(long __refs = 0) |
| 2554 | : __shared_owners_(__refs) {} |
| 2555 | |
| 2556 | void __add_shared(); |
Howard Hinnant | 28dbbe0 | 2010-11-16 21:33:17 +0000 | [diff] [blame] | 2557 | bool __release_shared(); |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2558 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2559 | long use_count() const {return __shared_owners_ + 1;} |
| 2560 | }; |
| 2561 | |
| 2562 | class __shared_weak_count |
| 2563 | : private __shared_count |
| 2564 | { |
| 2565 | long __shared_weak_owners_; |
| 2566 | |
| 2567 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2569 | explicit __shared_weak_count(long __refs = 0) |
| 2570 | : __shared_count(__refs), |
| 2571 | __shared_weak_owners_(__refs) {} |
| 2572 | protected: |
| 2573 | virtual ~__shared_weak_count(); |
| 2574 | |
| 2575 | public: |
| 2576 | void __add_shared(); |
| 2577 | void __add_weak(); |
| 2578 | void __release_shared(); |
| 2579 | void __release_weak(); |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2581 | long use_count() const {return __shared_count::use_count();} |
| 2582 | __shared_weak_count* lock(); |
| 2583 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2584 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2585 | virtual const void* __get_deleter(const type_info&) const; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2586 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2587 | private: |
| 2588 | virtual void __on_zero_shared_weak() = 0; |
| 2589 | }; |
| 2590 | |
| 2591 | template <class _Tp, class _Dp, class _Alloc> |
| 2592 | class __shared_ptr_pointer |
| 2593 | : public __shared_weak_count |
| 2594 | { |
| 2595 | __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; |
| 2596 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2597 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2598 | __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) |
| 2599 | : __data_(__compressed_pair<_Tp, _Dp>(__p, _STD::move(__d)), _STD::move(__a)) {} |
| 2600 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2601 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2602 | virtual const void* __get_deleter(const type_info&) const; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2603 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2604 | |
| 2605 | private: |
| 2606 | virtual void __on_zero_shared(); |
| 2607 | virtual void __on_zero_shared_weak(); |
| 2608 | }; |
| 2609 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2610 | #ifndef _LIBCPP_NO_RTTI |
| 2611 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2612 | template <class _Tp, class _Dp, class _Alloc> |
| 2613 | const void* |
| 2614 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const |
| 2615 | { |
| 2616 | return __t == typeid(_Dp) ? &__data_.first().second() : 0; |
| 2617 | } |
| 2618 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2619 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2620 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2621 | template <class _Tp, class _Dp, class _Alloc> |
| 2622 | void |
| 2623 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() |
| 2624 | { |
| 2625 | __data_.first().second()(__data_.first().first()); |
| 2626 | __data_.first().second().~_Dp(); |
| 2627 | } |
| 2628 | |
| 2629 | template <class _Tp, class _Dp, class _Alloc> |
| 2630 | void |
| 2631 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() |
| 2632 | { |
| 2633 | typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second()); |
| 2634 | __data_.second().~_Alloc(); |
| 2635 | __a.deallocate(this, 1); |
| 2636 | } |
| 2637 | |
| 2638 | template <class _Tp, class _Alloc> |
| 2639 | class __shared_ptr_emplace |
| 2640 | : public __shared_weak_count |
| 2641 | { |
| 2642 | __compressed_pair<_Alloc, _Tp> __data_; |
| 2643 | public: |
| 2644 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 2645 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2646 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2647 | __shared_ptr_emplace(_Alloc __a) |
| 2648 | : __data_(_STD::move(__a)) {} |
| 2649 | |
| 2650 | template <class ..._Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2651 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2652 | __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) |
| 2653 | : __data_(_STD::move(__a), _Tp(_STD::forward<_Args>(__args)...)) {} |
| 2654 | |
| 2655 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 2656 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2657 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2658 | __shared_ptr_emplace(_Alloc __a) |
| 2659 | : __data_(__a) {} |
| 2660 | |
| 2661 | template <class _A0> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2662 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2663 | __shared_ptr_emplace(_Alloc __a, _A0& __a0) |
| 2664 | : __data_(__a, _Tp(__a0)) {} |
| 2665 | |
| 2666 | template <class _A0, class _A1> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2667 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2668 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) |
| 2669 | : __data_(__a, _Tp(__a0, __a1)) {} |
| 2670 | |
| 2671 | template <class _A0, class _A1, class _A2> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2672 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2673 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 2674 | : __data_(__a, _Tp(__a0, __a1, __a2)) {} |
| 2675 | |
| 2676 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2677 | |
| 2678 | private: |
| 2679 | virtual void __on_zero_shared(); |
| 2680 | virtual void __on_zero_shared_weak(); |
| 2681 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2682 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2683 | _Tp* get() {return &__data_.second();} |
| 2684 | }; |
| 2685 | |
| 2686 | template <class _Tp, class _Alloc> |
| 2687 | void |
| 2688 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() |
| 2689 | { |
| 2690 | __data_.second().~_Tp(); |
| 2691 | } |
| 2692 | |
| 2693 | template <class _Tp, class _Alloc> |
| 2694 | void |
| 2695 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() |
| 2696 | { |
| 2697 | typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first()); |
| 2698 | __data_.first().~_Alloc(); |
| 2699 | __a.deallocate(this, 1); |
| 2700 | } |
| 2701 | |
| 2702 | template<class _Tp> class enable_shared_from_this; |
| 2703 | |
| 2704 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2705 | class _LIBCPP_VISIBLE shared_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2706 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2707 | public: |
| 2708 | typedef _Tp element_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2709 | private: |
| 2710 | element_type* __ptr_; |
| 2711 | __shared_weak_count* __cntrl_; |
| 2712 | |
| 2713 | struct __nat {int __for_bool_;}; |
| 2714 | public: |
| 2715 | shared_ptr(); |
| 2716 | shared_ptr(nullptr_t); |
| 2717 | template<class _Yp> explicit shared_ptr(_Yp* __p); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2718 | template<class _Yp, class _Dp> shared_ptr(_Yp* __p, _Dp __d); |
| 2719 | template<class _Yp, class _Dp, class _Alloc> shared_ptr(_Yp* __p, _Dp __d, _Alloc __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2720 | template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); |
| 2721 | template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2722 | template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2723 | shared_ptr(const shared_ptr& __r); |
| 2724 | template<class _Yp> |
| 2725 | shared_ptr(const shared_ptr<_Yp>& __r, |
| 2726 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2727 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2728 | shared_ptr(shared_ptr&& __r); |
| 2729 | template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r, |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2730 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2731 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2732 | template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2733 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2734 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2735 | template<class _Yp> shared_ptr(auto_ptr<_Yp>&& __r); |
| 2736 | #else |
| 2737 | template<class _Yp> shared_ptr(auto_ptr<_Yp> __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2738 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2739 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2740 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2741 | template <class _Yp, class _Dp> shared_ptr(const unique_ptr<_Yp, _Dp>& __r);// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2742 | public: |
| 2743 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 2744 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
| 2745 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 2746 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2747 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2748 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>, |
| 2749 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
| 2750 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>, |
| 2751 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2752 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2753 | |
| 2754 | ~shared_ptr(); |
| 2755 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2756 | shared_ptr& operator=(const shared_ptr& __r); |
| 2757 | template<class _Yp> shared_ptr& operator=(const shared_ptr<_Yp>& __r); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2758 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2759 | shared_ptr& operator=(shared_ptr&& __r); |
| 2760 | template<class _Yp> shared_ptr& operator=(shared_ptr<_Yp>&& __r); |
| 2761 | template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp>&& __r); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2762 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2763 | template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp> __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2764 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2765 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2766 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2767 | template <class _Yp, class _Dp> shared_ptr& operator=(const unique_ptr<_Yp, _Dp>& __r);// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2768 | public: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2769 | template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp>&& __r); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2770 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2771 | template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp> __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2772 | #endif |
| 2773 | |
| 2774 | void swap(shared_ptr& __r); |
| 2775 | void reset(); |
| 2776 | template<class _Yp> void reset(_Yp* __p); |
| 2777 | template<class _Yp, class _Dp> void reset(_Yp* __p, _Dp __d); |
| 2778 | template<class _Yp, class _Dp, class _Alloc> void reset(_Yp* __p, _Dp __d, _Alloc __a); |
| 2779 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2780 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2781 | element_type* get() const {return __ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2782 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2783 | typename add_lvalue_reference<element_type>::type operator*() const {return *__ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2784 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2785 | element_type* operator->() const {return __ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2786 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2787 | long use_count() const {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2788 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2789 | bool unique() const {return use_count() == 1;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2790 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2791 | bool empty() const {return __cntrl_ == 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2793 | /*explicit*/ operator bool() const {return get() != 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2794 | template <class _U> |
| 2795 | _LIBCPP_INLINE_VISIBILITY |
| 2796 | bool owner_before(shared_ptr<_U> const& __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2797 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2798 | template <class _U> |
| 2799 | _LIBCPP_INLINE_VISIBILITY |
| 2800 | bool owner_before(weak_ptr<_U> const& __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2801 | {return __cntrl_ < __p.__cntrl_;} |
| 2802 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2803 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2804 | template <class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2805 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2806 | _Dp* __get_deleter() const |
| 2807 | {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2808 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2809 | |
| 2810 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 2811 | |
| 2812 | template<class ..._Args> |
| 2813 | static |
| 2814 | shared_ptr<_Tp> |
| 2815 | make_shared(_Args&& ...__args); |
| 2816 | |
| 2817 | template<class _Alloc, class ..._Args> |
| 2818 | static |
| 2819 | shared_ptr<_Tp> |
| 2820 | allocate_shared(const _Alloc& __a, _Args&& ...__args); |
| 2821 | |
| 2822 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 2823 | |
| 2824 | static shared_ptr<_Tp> make_shared(); |
| 2825 | |
| 2826 | template<class _A0> |
| 2827 | static shared_ptr<_Tp> make_shared(_A0&); |
| 2828 | |
| 2829 | template<class _A0, class _A1> |
| 2830 | static shared_ptr<_Tp> make_shared(_A0&, _A1&); |
| 2831 | |
| 2832 | template<class _A0, class _A1, class _A2> |
| 2833 | static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); |
| 2834 | |
| 2835 | template<class _Alloc> |
| 2836 | static shared_ptr<_Tp> |
| 2837 | allocate_shared(const _Alloc& __a); |
| 2838 | |
| 2839 | template<class _Alloc, class _A0> |
| 2840 | static shared_ptr<_Tp> |
| 2841 | allocate_shared(const _Alloc& __a, _A0& __a0); |
| 2842 | |
| 2843 | template<class _Alloc, class _A0, class _A1> |
| 2844 | static shared_ptr<_Tp> |
| 2845 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); |
| 2846 | |
| 2847 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 2848 | static shared_ptr<_Tp> |
| 2849 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); |
| 2850 | |
| 2851 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2852 | |
| 2853 | private: |
| 2854 | |
| 2855 | template <class _Yp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2857 | void |
| 2858 | __enable_weak_this(const enable_shared_from_this<_Yp>* __e) |
| 2859 | { |
| 2860 | if (__e) |
| 2861 | __e->__weak_this_ = *this; |
| 2862 | } |
| 2863 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2864 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2865 | void __enable_weak_this(const void*) {} |
| 2866 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2867 | template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr; |
| 2868 | template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2869 | }; |
| 2870 | |
| 2871 | template<class _Tp> |
| 2872 | inline _LIBCPP_INLINE_VISIBILITY |
| 2873 | shared_ptr<_Tp>::shared_ptr() |
| 2874 | : __ptr_(0), |
| 2875 | __cntrl_(0) |
| 2876 | { |
| 2877 | } |
| 2878 | |
| 2879 | template<class _Tp> |
| 2880 | inline _LIBCPP_INLINE_VISIBILITY |
| 2881 | shared_ptr<_Tp>::shared_ptr(nullptr_t) |
| 2882 | : __ptr_(0), |
| 2883 | __cntrl_(0) |
| 2884 | { |
| 2885 | } |
| 2886 | |
| 2887 | template<class _Tp> |
| 2888 | template<class _Yp> |
| 2889 | shared_ptr<_Tp>::shared_ptr(_Yp* __p) |
| 2890 | : __ptr_(__p) |
| 2891 | { |
| 2892 | unique_ptr<_Yp> __hold(__p); |
| 2893 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 2894 | __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>()); |
| 2895 | __hold.release(); |
| 2896 | __enable_weak_this(__p); |
| 2897 | } |
| 2898 | |
| 2899 | template<class _Tp> |
| 2900 | template<class _Yp, class _Dp> |
| 2901 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d) |
| 2902 | : __ptr_(__p) |
| 2903 | { |
| 2904 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2905 | try |
| 2906 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2907 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2908 | typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; |
| 2909 | __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>()); |
| 2910 | __enable_weak_this(__p); |
| 2911 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2912 | } |
| 2913 | catch (...) |
| 2914 | { |
| 2915 | __d(__p); |
| 2916 | throw; |
| 2917 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2918 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | template<class _Tp> |
| 2922 | template<class _Dp> |
| 2923 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) |
| 2924 | : __ptr_(0) |
| 2925 | { |
| 2926 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2927 | try |
| 2928 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2929 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2930 | typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk; |
| 2931 | __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>()); |
| 2932 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2933 | } |
| 2934 | catch (...) |
| 2935 | { |
| 2936 | __d(__p); |
| 2937 | throw; |
| 2938 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2939 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | template<class _Tp> |
| 2943 | template<class _Yp, class _Dp, class _Alloc> |
| 2944 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) |
| 2945 | : __ptr_(__p) |
| 2946 | { |
| 2947 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2948 | try |
| 2949 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2950 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2951 | typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; |
| 2952 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 2953 | typedef __allocator_destructor<_A2> _D2; |
| 2954 | _A2 __a2(__a); |
| 2955 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 2956 | ::new(__hold2.get()) _CntrlBlk(__p, __d, __a); |
| 2957 | __cntrl_ = __hold2.release(); |
| 2958 | __enable_weak_this(__p); |
| 2959 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2960 | } |
| 2961 | catch (...) |
| 2962 | { |
| 2963 | __d(__p); |
| 2964 | throw; |
| 2965 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2966 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | template<class _Tp> |
| 2970 | template<class _Dp, class _Alloc> |
| 2971 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) |
| 2972 | : __ptr_(0) |
| 2973 | { |
| 2974 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2975 | try |
| 2976 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2977 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2978 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; |
| 2979 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 2980 | typedef __allocator_destructor<_A2> _D2; |
| 2981 | _A2 __a2(__a); |
| 2982 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 2983 | ::new(__hold2.get()) _CntrlBlk(__p, __d, __a); |
| 2984 | __cntrl_ = __hold2.release(); |
| 2985 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2986 | } |
| 2987 | catch (...) |
| 2988 | { |
| 2989 | __d(__p); |
| 2990 | throw; |
| 2991 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2992 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | template<class _Tp> |
| 2996 | template<class _Yp> |
| 2997 | inline _LIBCPP_INLINE_VISIBILITY |
| 2998 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) |
| 2999 | : __ptr_(__p), |
| 3000 | __cntrl_(__r.__cntrl_) |
| 3001 | { |
| 3002 | if (__cntrl_) |
| 3003 | __cntrl_->__add_shared(); |
| 3004 | } |
| 3005 | |
| 3006 | template<class _Tp> |
| 3007 | inline _LIBCPP_INLINE_VISIBILITY |
| 3008 | shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) |
| 3009 | : __ptr_(__r.__ptr_), |
| 3010 | __cntrl_(__r.__cntrl_) |
| 3011 | { |
| 3012 | if (__cntrl_) |
| 3013 | __cntrl_->__add_shared(); |
| 3014 | } |
| 3015 | |
| 3016 | template<class _Tp> |
| 3017 | template<class _Yp> |
| 3018 | inline _LIBCPP_INLINE_VISIBILITY |
| 3019 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, |
| 3020 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
| 3021 | : __ptr_(__r.__ptr_), |
| 3022 | __cntrl_(__r.__cntrl_) |
| 3023 | { |
| 3024 | if (__cntrl_) |
| 3025 | __cntrl_->__add_shared(); |
| 3026 | } |
| 3027 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3028 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3029 | |
| 3030 | template<class _Tp> |
| 3031 | inline _LIBCPP_INLINE_VISIBILITY |
| 3032 | shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) |
| 3033 | : __ptr_(__r.__ptr_), |
| 3034 | __cntrl_(__r.__cntrl_) |
| 3035 | { |
| 3036 | __r.__ptr_ = 0; |
| 3037 | __r.__cntrl_ = 0; |
| 3038 | } |
| 3039 | |
| 3040 | template<class _Tp> |
| 3041 | template<class _Yp> |
| 3042 | inline _LIBCPP_INLINE_VISIBILITY |
| 3043 | shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, |
| 3044 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
| 3045 | : __ptr_(__r.__ptr_), |
| 3046 | __cntrl_(__r.__cntrl_) |
| 3047 | { |
| 3048 | __r.__ptr_ = 0; |
| 3049 | __r.__cntrl_ = 0; |
| 3050 | } |
| 3051 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3052 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3053 | |
| 3054 | template<class _Tp> |
| 3055 | template<class _Yp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3056 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3057 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r) |
| 3058 | #else |
Howard Hinnant | 92172b8 | 2010-08-21 21:14:53 +0000 | [diff] [blame] | 3059 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3060 | #endif |
| 3061 | : __ptr_(__r.get()) |
| 3062 | { |
| 3063 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 3064 | __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); |
| 3065 | __enable_weak_this(__r.get()); |
| 3066 | __r.release(); |
| 3067 | } |
| 3068 | |
| 3069 | template<class _Tp> |
| 3070 | template <class _Yp, class _Dp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3071 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3072 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 3073 | #else |
| 3074 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 3075 | #endif |
| 3076 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type) |
| 3077 | : __ptr_(__r.get()) |
| 3078 | { |
| 3079 | typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; |
| 3080 | __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); |
| 3081 | __enable_weak_this(__r.get()); |
| 3082 | __r.release(); |
| 3083 | } |
| 3084 | |
| 3085 | template<class _Tp> |
| 3086 | template <class _Yp, class _Dp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3087 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3088 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 3089 | #else |
| 3090 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 3091 | #endif |
| 3092 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type) |
| 3093 | : __ptr_(__r.get()) |
| 3094 | { |
| 3095 | typedef __shared_ptr_pointer<_Yp*, |
| 3096 | reference_wrapper<typename remove_reference<_Dp>::type>, |
| 3097 | allocator<_Yp> > _CntrlBlk; |
| 3098 | __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); |
| 3099 | __enable_weak_this(__r.get()); |
| 3100 | __r.release(); |
| 3101 | } |
| 3102 | |
| 3103 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3104 | |
| 3105 | template<class _Tp> |
| 3106 | template<class ..._Args> |
| 3107 | shared_ptr<_Tp> |
| 3108 | shared_ptr<_Tp>::make_shared(_Args&& ...__args) |
| 3109 | { |
| 3110 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3111 | typedef allocator<_CntrlBlk> _A2; |
| 3112 | typedef __allocator_destructor<_A2> _D2; |
| 3113 | _A2 __a2; |
| 3114 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3115 | ::new(__hold2.get()) _CntrlBlk(__a2, _STD::forward<_Args>(__args)...); |
| 3116 | shared_ptr<_Tp> __r; |
| 3117 | __r.__ptr_ = __hold2.get()->get(); |
| 3118 | __r.__cntrl_ = __hold2.release(); |
| 3119 | __r.__enable_weak_this(__r.__ptr_); |
| 3120 | return __r; |
| 3121 | } |
| 3122 | |
| 3123 | template<class _Tp> |
| 3124 | template<class _Alloc, class ..._Args> |
| 3125 | shared_ptr<_Tp> |
| 3126 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 3127 | { |
| 3128 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3129 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 3130 | typedef __allocator_destructor<_A2> _D2; |
| 3131 | _A2 __a2(__a); |
| 3132 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3133 | ::new(__hold2.get()) _CntrlBlk(__a, _STD::forward<_Args>(__args)...); |
| 3134 | shared_ptr<_Tp> __r; |
| 3135 | __r.__ptr_ = __hold2.get()->get(); |
| 3136 | __r.__cntrl_ = __hold2.release(); |
| 3137 | __r.__enable_weak_this(__r.__ptr_); |
| 3138 | return __r; |
| 3139 | } |
| 3140 | |
| 3141 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3142 | |
| 3143 | template<class _Tp> |
| 3144 | shared_ptr<_Tp> |
| 3145 | shared_ptr<_Tp>::make_shared() |
| 3146 | { |
| 3147 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3148 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3149 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3150 | _Alloc2 __alloc2; |
| 3151 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3152 | ::new(__hold2.get()) _CntrlBlk(__alloc2); |
| 3153 | shared_ptr<_Tp> __r; |
| 3154 | __r.__ptr_ = __hold2.get()->get(); |
| 3155 | __r.__cntrl_ = __hold2.release(); |
| 3156 | __r.__enable_weak_this(__r.__ptr_); |
| 3157 | return __r; |
| 3158 | } |
| 3159 | |
| 3160 | template<class _Tp> |
| 3161 | template<class _A0> |
| 3162 | shared_ptr<_Tp> |
| 3163 | shared_ptr<_Tp>::make_shared(_A0& __a0) |
| 3164 | { |
| 3165 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3166 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3167 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3168 | _Alloc2 __alloc2; |
| 3169 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3170 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); |
| 3171 | shared_ptr<_Tp> __r; |
| 3172 | __r.__ptr_ = __hold2.get()->get(); |
| 3173 | __r.__cntrl_ = __hold2.release(); |
| 3174 | __r.__enable_weak_this(__r.__ptr_); |
| 3175 | return __r; |
| 3176 | } |
| 3177 | |
| 3178 | template<class _Tp> |
| 3179 | template<class _A0, class _A1> |
| 3180 | shared_ptr<_Tp> |
| 3181 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) |
| 3182 | { |
| 3183 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3184 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3185 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3186 | _Alloc2 __alloc2; |
| 3187 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3188 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); |
| 3189 | shared_ptr<_Tp> __r; |
| 3190 | __r.__ptr_ = __hold2.get()->get(); |
| 3191 | __r.__cntrl_ = __hold2.release(); |
| 3192 | __r.__enable_weak_this(__r.__ptr_); |
| 3193 | return __r; |
| 3194 | } |
| 3195 | |
| 3196 | template<class _Tp> |
| 3197 | template<class _A0, class _A1, class _A2> |
| 3198 | shared_ptr<_Tp> |
| 3199 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 3200 | { |
| 3201 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3202 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3203 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3204 | _Alloc2 __alloc2; |
| 3205 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3206 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); |
| 3207 | shared_ptr<_Tp> __r; |
| 3208 | __r.__ptr_ = __hold2.get()->get(); |
| 3209 | __r.__cntrl_ = __hold2.release(); |
| 3210 | __r.__enable_weak_this(__r.__ptr_); |
| 3211 | return __r; |
| 3212 | } |
| 3213 | |
| 3214 | template<class _Tp> |
| 3215 | template<class _Alloc> |
| 3216 | shared_ptr<_Tp> |
| 3217 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) |
| 3218 | { |
| 3219 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3220 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3221 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3222 | _Alloc2 __alloc2(__a); |
| 3223 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3224 | ::new(__hold2.get()) _CntrlBlk(__a); |
| 3225 | shared_ptr<_Tp> __r; |
| 3226 | __r.__ptr_ = __hold2.get()->get(); |
| 3227 | __r.__cntrl_ = __hold2.release(); |
| 3228 | __r.__enable_weak_this(__r.__ptr_); |
| 3229 | return __r; |
| 3230 | } |
| 3231 | |
| 3232 | template<class _Tp> |
| 3233 | template<class _Alloc, class _A0> |
| 3234 | shared_ptr<_Tp> |
| 3235 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) |
| 3236 | { |
| 3237 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3238 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3239 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3240 | _Alloc2 __alloc2(__a); |
| 3241 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3242 | ::new(__hold2.get()) _CntrlBlk(__a, __a0); |
| 3243 | shared_ptr<_Tp> __r; |
| 3244 | __r.__ptr_ = __hold2.get()->get(); |
| 3245 | __r.__cntrl_ = __hold2.release(); |
| 3246 | __r.__enable_weak_this(__r.__ptr_); |
| 3247 | return __r; |
| 3248 | } |
| 3249 | |
| 3250 | template<class _Tp> |
| 3251 | template<class _Alloc, class _A0, class _A1> |
| 3252 | shared_ptr<_Tp> |
| 3253 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 3254 | { |
| 3255 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3256 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3257 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3258 | _Alloc2 __alloc2(__a); |
| 3259 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3260 | ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1); |
| 3261 | shared_ptr<_Tp> __r; |
| 3262 | __r.__ptr_ = __hold2.get()->get(); |
| 3263 | __r.__cntrl_ = __hold2.release(); |
| 3264 | __r.__enable_weak_this(__r.__ptr_); |
| 3265 | return __r; |
| 3266 | } |
| 3267 | |
| 3268 | template<class _Tp> |
| 3269 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 3270 | shared_ptr<_Tp> |
| 3271 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3272 | { |
| 3273 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3274 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3275 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3276 | _Alloc2 __alloc2(__a); |
| 3277 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3278 | ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2); |
| 3279 | shared_ptr<_Tp> __r; |
| 3280 | __r.__ptr_ = __hold2.get()->get(); |
| 3281 | __r.__cntrl_ = __hold2.release(); |
| 3282 | __r.__enable_weak_this(__r.__ptr_); |
| 3283 | return __r; |
| 3284 | } |
| 3285 | |
| 3286 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3287 | |
| 3288 | template<class _Tp> |
| 3289 | shared_ptr<_Tp>::~shared_ptr() |
| 3290 | { |
| 3291 | if (__cntrl_) |
| 3292 | __cntrl_->__release_shared(); |
| 3293 | } |
| 3294 | |
| 3295 | template<class _Tp> |
| 3296 | inline _LIBCPP_INLINE_VISIBILITY |
| 3297 | shared_ptr<_Tp>& |
| 3298 | shared_ptr<_Tp>::operator=(const shared_ptr& __r) |
| 3299 | { |
| 3300 | shared_ptr(__r).swap(*this); |
| 3301 | return *this; |
| 3302 | } |
| 3303 | |
| 3304 | template<class _Tp> |
| 3305 | template<class _Yp> |
| 3306 | inline _LIBCPP_INLINE_VISIBILITY |
| 3307 | shared_ptr<_Tp>& |
| 3308 | shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) |
| 3309 | { |
| 3310 | shared_ptr(__r).swap(*this); |
| 3311 | return *this; |
| 3312 | } |
| 3313 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3314 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3315 | |
| 3316 | template<class _Tp> |
| 3317 | inline _LIBCPP_INLINE_VISIBILITY |
| 3318 | shared_ptr<_Tp>& |
| 3319 | shared_ptr<_Tp>::operator=(shared_ptr&& __r) |
| 3320 | { |
| 3321 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3322 | return *this; |
| 3323 | } |
| 3324 | |
| 3325 | template<class _Tp> |
| 3326 | template<class _Yp> |
| 3327 | inline _LIBCPP_INLINE_VISIBILITY |
| 3328 | shared_ptr<_Tp>& |
| 3329 | shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) |
| 3330 | { |
| 3331 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3332 | return *this; |
| 3333 | } |
| 3334 | |
| 3335 | template<class _Tp> |
| 3336 | template<class _Yp> |
| 3337 | inline _LIBCPP_INLINE_VISIBILITY |
| 3338 | shared_ptr<_Tp>& |
| 3339 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) |
| 3340 | { |
| 3341 | shared_ptr(__r).swap(*this); |
| 3342 | return *this; |
| 3343 | } |
| 3344 | |
| 3345 | template<class _Tp> |
| 3346 | template <class _Yp, class _Dp> |
| 3347 | inline _LIBCPP_INLINE_VISIBILITY |
| 3348 | shared_ptr<_Tp>& |
| 3349 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) |
| 3350 | { |
| 3351 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3352 | return *this; |
| 3353 | } |
| 3354 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3355 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3356 | |
| 3357 | template<class _Tp> |
| 3358 | template<class _Yp> |
| 3359 | inline _LIBCPP_INLINE_VISIBILITY |
| 3360 | shared_ptr<_Tp>& |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3361 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3362 | { |
| 3363 | shared_ptr(__r).swap(*this); |
| 3364 | return *this; |
| 3365 | } |
| 3366 | |
| 3367 | template<class _Tp> |
| 3368 | template <class _Yp, class _Dp> |
| 3369 | inline _LIBCPP_INLINE_VISIBILITY |
| 3370 | shared_ptr<_Tp>& |
| 3371 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) |
| 3372 | { |
| 3373 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3374 | return *this; |
| 3375 | } |
| 3376 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3377 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3378 | |
| 3379 | template<class _Tp> |
| 3380 | inline _LIBCPP_INLINE_VISIBILITY |
| 3381 | void |
| 3382 | shared_ptr<_Tp>::swap(shared_ptr& __r) |
| 3383 | { |
| 3384 | _STD::swap(__ptr_, __r.__ptr_); |
| 3385 | _STD::swap(__cntrl_, __r.__cntrl_); |
| 3386 | } |
| 3387 | |
| 3388 | template<class _Tp> |
| 3389 | inline _LIBCPP_INLINE_VISIBILITY |
| 3390 | void |
| 3391 | shared_ptr<_Tp>::reset() |
| 3392 | { |
| 3393 | shared_ptr().swap(*this); |
| 3394 | } |
| 3395 | |
| 3396 | template<class _Tp> |
| 3397 | template<class _Yp> |
| 3398 | inline _LIBCPP_INLINE_VISIBILITY |
| 3399 | void |
| 3400 | shared_ptr<_Tp>::reset(_Yp* __p) |
| 3401 | { |
| 3402 | shared_ptr(__p).swap(*this); |
| 3403 | } |
| 3404 | |
| 3405 | template<class _Tp> |
| 3406 | template<class _Yp, class _Dp> |
| 3407 | inline _LIBCPP_INLINE_VISIBILITY |
| 3408 | void |
| 3409 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) |
| 3410 | { |
| 3411 | shared_ptr(__p, __d).swap(*this); |
| 3412 | } |
| 3413 | |
| 3414 | template<class _Tp> |
| 3415 | template<class _Yp, class _Dp, class _Alloc> |
| 3416 | inline _LIBCPP_INLINE_VISIBILITY |
| 3417 | void |
| 3418 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) |
| 3419 | { |
| 3420 | shared_ptr(__p, __d, __a).swap(*this); |
| 3421 | } |
| 3422 | |
| 3423 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3424 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3425 | template<class _Tp, class ..._Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3426 | inline _LIBCPP_INLINE_VISIBILITY |
| 3427 | shared_ptr<_Tp> |
| 3428 | make_shared(_Args&& ...__args) |
| 3429 | { |
| 3430 | return shared_ptr<_Tp>::make_shared(_STD::forward<_Args>(__args)...); |
| 3431 | } |
| 3432 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3433 | template<class _Tp, class _Alloc, class ..._Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3434 | inline _LIBCPP_INLINE_VISIBILITY |
| 3435 | shared_ptr<_Tp> |
| 3436 | allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 3437 | { |
| 3438 | return shared_ptr<_Tp>::allocate_shared(__a, _STD::forward<_Args>(__args)...); |
| 3439 | } |
| 3440 | |
| 3441 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3442 | |
| 3443 | template<class _Tp> |
| 3444 | inline _LIBCPP_INLINE_VISIBILITY |
| 3445 | shared_ptr<_Tp> |
| 3446 | make_shared() |
| 3447 | { |
| 3448 | return shared_ptr<_Tp>::make_shared(); |
| 3449 | } |
| 3450 | |
| 3451 | template<class _Tp, class _A0> |
| 3452 | inline _LIBCPP_INLINE_VISIBILITY |
| 3453 | shared_ptr<_Tp> |
| 3454 | make_shared(_A0& __a0) |
| 3455 | { |
| 3456 | return shared_ptr<_Tp>::make_shared(__a0); |
| 3457 | } |
| 3458 | |
| 3459 | template<class _Tp, class _A0, class _A1> |
| 3460 | inline _LIBCPP_INLINE_VISIBILITY |
| 3461 | shared_ptr<_Tp> |
| 3462 | make_shared(_A0& __a0, _A1& __a1) |
| 3463 | { |
| 3464 | return shared_ptr<_Tp>::make_shared(__a0, __a1); |
| 3465 | } |
| 3466 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3467 | template<class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3468 | inline _LIBCPP_INLINE_VISIBILITY |
| 3469 | shared_ptr<_Tp> |
| 3470 | make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 3471 | { |
| 3472 | return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); |
| 3473 | } |
| 3474 | |
| 3475 | template<class _Tp, class _Alloc> |
| 3476 | inline _LIBCPP_INLINE_VISIBILITY |
| 3477 | shared_ptr<_Tp> |
| 3478 | allocate_shared(const _Alloc& __a) |
| 3479 | { |
| 3480 | return shared_ptr<_Tp>::allocate_shared(__a); |
| 3481 | } |
| 3482 | |
| 3483 | template<class _Tp, class _Alloc, class _A0> |
| 3484 | inline _LIBCPP_INLINE_VISIBILITY |
| 3485 | shared_ptr<_Tp> |
| 3486 | allocate_shared(const _Alloc& __a, _A0& __a0) |
| 3487 | { |
| 3488 | return shared_ptr<_Tp>::allocate_shared(__a, __a0); |
| 3489 | } |
| 3490 | |
| 3491 | template<class _Tp, class _Alloc, class _A0, class _A1> |
| 3492 | inline _LIBCPP_INLINE_VISIBILITY |
| 3493 | shared_ptr<_Tp> |
| 3494 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 3495 | { |
| 3496 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); |
| 3497 | } |
| 3498 | |
| 3499 | template<class _Tp, class _Alloc, class _A0, class _A1, class _A2> |
| 3500 | inline _LIBCPP_INLINE_VISIBILITY |
| 3501 | shared_ptr<_Tp> |
| 3502 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3503 | { |
| 3504 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); |
| 3505 | } |
| 3506 | |
| 3507 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3508 | |
| 3509 | template<class _Tp, class _Up> |
| 3510 | inline _LIBCPP_INLINE_VISIBILITY |
| 3511 | bool |
| 3512 | operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) |
| 3513 | { |
| 3514 | return __x.get() == __y.get(); |
| 3515 | } |
| 3516 | |
| 3517 | template<class _Tp, class _Up> |
| 3518 | inline _LIBCPP_INLINE_VISIBILITY |
| 3519 | bool |
| 3520 | operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) |
| 3521 | { |
| 3522 | return !(__x == __y); |
| 3523 | } |
| 3524 | |
| 3525 | template<class _Tp, class _Up> |
| 3526 | inline _LIBCPP_INLINE_VISIBILITY |
| 3527 | bool |
| 3528 | operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) |
| 3529 | { |
| 3530 | return __x.get() < __y.get(); |
| 3531 | } |
| 3532 | |
| 3533 | template<class _Tp> |
| 3534 | inline _LIBCPP_INLINE_VISIBILITY |
| 3535 | void |
| 3536 | swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) |
| 3537 | { |
| 3538 | __x.swap(__y); |
| 3539 | } |
| 3540 | |
| 3541 | template<class _Tp, class _Up> |
| 3542 | inline _LIBCPP_INLINE_VISIBILITY |
| 3543 | shared_ptr<_Tp> |
| 3544 | static_pointer_cast(const shared_ptr<_Up>& __r) |
| 3545 | { |
| 3546 | return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); |
| 3547 | } |
| 3548 | |
| 3549 | template<class _Tp, class _Up> |
| 3550 | inline _LIBCPP_INLINE_VISIBILITY |
| 3551 | shared_ptr<_Tp> |
| 3552 | dynamic_pointer_cast(const shared_ptr<_Up>& __r) |
| 3553 | { |
| 3554 | _Tp* __p = dynamic_cast<_Tp*>(__r.get()); |
| 3555 | return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); |
| 3556 | } |
| 3557 | |
| 3558 | template<class _Tp, class _Up> |
| 3559 | shared_ptr<_Tp> |
| 3560 | const_pointer_cast(const shared_ptr<_Up>& __r) |
| 3561 | { |
| 3562 | return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get())); |
| 3563 | } |
| 3564 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3565 | #ifndef _LIBCPP_NO_RTTI |
| 3566 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3567 | template<class _Dp, class _Tp> |
| 3568 | inline _LIBCPP_INLINE_VISIBILITY |
| 3569 | _Dp* |
| 3570 | get_deleter(const shared_ptr<_Tp>& __p) |
| 3571 | { |
| 3572 | return __p.template __get_deleter<_Dp>(); |
| 3573 | } |
| 3574 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3575 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3576 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3577 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3578 | class _LIBCPP_VISIBLE weak_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3579 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3580 | public: |
| 3581 | typedef _Tp element_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3582 | private: |
| 3583 | element_type* __ptr_; |
| 3584 | __shared_weak_count* __cntrl_; |
| 3585 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3586 | public: |
| 3587 | weak_ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3588 | template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r, |
| 3589 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3590 | weak_ptr(weak_ptr const& __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3591 | template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3592 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()); |
| 3593 | |
| 3594 | ~weak_ptr(); |
| 3595 | |
| 3596 | weak_ptr& operator=(weak_ptr const& __r); |
| 3597 | template<class _Yp> weak_ptr& operator=(weak_ptr<_Yp> const& __r); |
| 3598 | template<class _Yp> weak_ptr& operator=(shared_ptr<_Yp> const& __r); |
| 3599 | |
| 3600 | void swap(weak_ptr& __r); |
| 3601 | void reset(); |
| 3602 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3603 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3604 | long use_count() const {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3605 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3606 | bool expired() const {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3607 | shared_ptr<_Tp> lock() const; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3608 | template<class _Up> |
| 3609 | _LIBCPP_INLINE_VISIBILITY |
| 3610 | bool owner_before(const shared_ptr<_Up>& __r) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3611 | {return __cntrl_ < __r.__cntrl_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3612 | template<class _Up> |
| 3613 | _LIBCPP_INLINE_VISIBILITY |
| 3614 | bool owner_before(const weak_ptr<_Up>& __r) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3615 | {return __cntrl_ < __r.__cntrl_;} |
| 3616 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3617 | template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr; |
| 3618 | template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3619 | }; |
| 3620 | |
| 3621 | template<class _Tp> |
| 3622 | inline _LIBCPP_INLINE_VISIBILITY |
| 3623 | weak_ptr<_Tp>::weak_ptr() |
| 3624 | : __ptr_(0), |
| 3625 | __cntrl_(0) |
| 3626 | { |
| 3627 | } |
| 3628 | |
| 3629 | template<class _Tp> |
| 3630 | inline _LIBCPP_INLINE_VISIBILITY |
| 3631 | weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) |
| 3632 | : __ptr_(__r.__ptr_), |
| 3633 | __cntrl_(__r.__cntrl_) |
| 3634 | { |
| 3635 | if (__cntrl_) |
| 3636 | __cntrl_->__add_weak(); |
| 3637 | } |
| 3638 | |
| 3639 | template<class _Tp> |
| 3640 | template<class _Yp> |
| 3641 | inline _LIBCPP_INLINE_VISIBILITY |
| 3642 | weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, |
| 3643 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
| 3644 | : __ptr_(__r.__ptr_), |
| 3645 | __cntrl_(__r.__cntrl_) |
| 3646 | { |
| 3647 | if (__cntrl_) |
| 3648 | __cntrl_->__add_weak(); |
| 3649 | } |
| 3650 | |
| 3651 | template<class _Tp> |
| 3652 | template<class _Yp> |
| 3653 | inline _LIBCPP_INLINE_VISIBILITY |
| 3654 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, |
| 3655 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
| 3656 | : __ptr_(__r.__ptr_), |
| 3657 | __cntrl_(__r.__cntrl_) |
| 3658 | { |
| 3659 | if (__cntrl_) |
| 3660 | __cntrl_->__add_weak(); |
| 3661 | } |
| 3662 | |
| 3663 | template<class _Tp> |
| 3664 | weak_ptr<_Tp>::~weak_ptr() |
| 3665 | { |
| 3666 | if (__cntrl_) |
| 3667 | __cntrl_->__release_weak(); |
| 3668 | } |
| 3669 | |
| 3670 | template<class _Tp> |
| 3671 | inline _LIBCPP_INLINE_VISIBILITY |
| 3672 | weak_ptr<_Tp>& |
| 3673 | weak_ptr<_Tp>::operator=(weak_ptr const& __r) |
| 3674 | { |
| 3675 | weak_ptr(__r).swap(*this); |
| 3676 | return *this; |
| 3677 | } |
| 3678 | |
| 3679 | template<class _Tp> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3680 | template<class _Yp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3681 | inline _LIBCPP_INLINE_VISIBILITY |
| 3682 | weak_ptr<_Tp>& |
| 3683 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) |
| 3684 | { |
| 3685 | weak_ptr(__r).swap(*this); |
| 3686 | return *this; |
| 3687 | } |
| 3688 | |
| 3689 | template<class _Tp> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3690 | template<class _Yp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3691 | inline _LIBCPP_INLINE_VISIBILITY |
| 3692 | weak_ptr<_Tp>& |
| 3693 | weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) |
| 3694 | { |
| 3695 | weak_ptr(__r).swap(*this); |
| 3696 | return *this; |
| 3697 | } |
| 3698 | |
| 3699 | template<class _Tp> |
| 3700 | inline _LIBCPP_INLINE_VISIBILITY |
| 3701 | void |
| 3702 | weak_ptr<_Tp>::swap(weak_ptr& __r) |
| 3703 | { |
| 3704 | _STD::swap(__ptr_, __r.__ptr_); |
| 3705 | _STD::swap(__cntrl_, __r.__cntrl_); |
| 3706 | } |
| 3707 | |
| 3708 | template<class _Tp> |
| 3709 | inline _LIBCPP_INLINE_VISIBILITY |
| 3710 | void |
| 3711 | swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) |
| 3712 | { |
| 3713 | __x.swap(__y); |
| 3714 | } |
| 3715 | |
| 3716 | template<class _Tp> |
| 3717 | inline _LIBCPP_INLINE_VISIBILITY |
| 3718 | void |
| 3719 | weak_ptr<_Tp>::reset() |
| 3720 | { |
| 3721 | weak_ptr().swap(*this); |
| 3722 | } |
| 3723 | |
| 3724 | template<class _Tp> |
| 3725 | template<class _Yp> |
| 3726 | shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, |
| 3727 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
| 3728 | : __ptr_(__r.__ptr_), |
| 3729 | __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) |
| 3730 | { |
| 3731 | if (__cntrl_ == 0) |
| 3732 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3733 | throw bad_weak_ptr(); |
| 3734 | #else |
| 3735 | assert(!"bad_weak_ptr"); |
| 3736 | #endif |
| 3737 | } |
| 3738 | |
| 3739 | template<class _Tp> |
| 3740 | shared_ptr<_Tp> |
| 3741 | weak_ptr<_Tp>::lock() const |
| 3742 | { |
| 3743 | shared_ptr<_Tp> __r; |
| 3744 | __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; |
| 3745 | if (__r.__cntrl_) |
| 3746 | __r.__ptr_ = __ptr_; |
| 3747 | return __r; |
| 3748 | } |
| 3749 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3750 | template <class _Tp> struct owner_less; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3751 | |
| 3752 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3753 | struct _LIBCPP_VISIBLE owner_less<shared_ptr<_Tp> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3754 | : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3755 | { |
| 3756 | typedef bool result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3757 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3758 | bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3759 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3760 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3761 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3762 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3763 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3764 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3765 | {return __x.owner_before(__y);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3766 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3767 | |
| 3768 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3769 | struct _LIBCPP_VISIBLE owner_less<weak_ptr<_Tp> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3770 | : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> |
| 3771 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3772 | typedef bool result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3773 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3774 | bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3775 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3776 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3777 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3778 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3779 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3780 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3781 | {return __x.owner_before(__y);} |
| 3782 | }; |
| 3783 | |
| 3784 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3785 | class _LIBCPP_VISIBLE enable_shared_from_this |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3786 | { |
| 3787 | mutable weak_ptr<_Tp> __weak_this_; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3788 | protected: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3789 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3790 | enable_shared_from_this() {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3791 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3792 | enable_shared_from_this(enable_shared_from_this const&) {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3793 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3794 | enable_shared_from_this& operator=(enable_shared_from_this const&) {return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3795 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3796 | ~enable_shared_from_this() {} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3797 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3799 | shared_ptr<_Tp> shared_from_this() {return shared_ptr<_Tp>(__weak_this_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3800 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3801 | shared_ptr<_Tp const> shared_from_this() const {return shared_ptr<const _Tp>(__weak_this_);} |
| 3802 | |
| 3803 | template <class _Up> friend class shared_ptr; |
| 3804 | }; |
| 3805 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3806 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3807 | struct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> > |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3808 | { |
| 3809 | typedef shared_ptr<_Tp> argument_type; |
| 3810 | typedef size_t result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3811 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3812 | result_type operator()(const argument_type& __ptr) const |
| 3813 | { |
| 3814 | return hash<_Tp*>()(__ptr.get()); |
| 3815 | } |
| 3816 | }; |
| 3817 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3818 | //enum class |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3819 | struct _LIBCPP_VISIBLE pointer_safety |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3820 | { |
| 3821 | enum _ |
| 3822 | { |
| 3823 | relaxed, |
| 3824 | preferred, |
| 3825 | strict |
| 3826 | }; |
| 3827 | |
| 3828 | _ __v_; |
| 3829 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3830 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3831 | pointer_safety(_ __v) : __v_(__v) {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3832 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3833 | operator int() const {return __v_;} |
| 3834 | }; |
| 3835 | |
| 3836 | void declare_reachable(void* __p); |
| 3837 | void declare_no_pointers(char* __p, size_t __n); |
| 3838 | void undeclare_no_pointers(char* __p, size_t __n); |
| 3839 | pointer_safety get_pointer_safety(); |
| 3840 | void* __undeclare_reachable(void*); |
| 3841 | |
| 3842 | template <class _Tp> |
| 3843 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3844 | _Tp* |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3845 | undeclare_reachable(_Tp* __p) |
| 3846 | { |
| 3847 | return static_cast<_Tp*>(__undeclare_reachable(__p)); |
| 3848 | } |
| 3849 | |
| 3850 | void* align(size_t, size_t, void*&, size_t&); |
| 3851 | |
| 3852 | _LIBCPP_END_NAMESPACE_STD |
| 3853 | |
| 3854 | #endif // _LIBCPP_MEMORY |