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