1// -*- C++ -*- 2//===-------------------------- memory ------------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP_MEMORY 11#define _LIBCPP_MEMORY 12 13/* 14 memory synopsis 15 16namespace std 17{ 18 19struct allocator_arg_t { }; 20inline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); 21 22template <class T, class Alloc> struct uses_allocator; 23 24template <class Ptr> 25struct pointer_traits 26{ 27 typedef Ptr pointer; 28 typedef <details> element_type; 29 typedef <details> difference_type; 30 31 template <class U> using rebind = <details>; 32 33 static pointer pointer_to(<details>); 34}; 35 36template <class T> 37struct pointer_traits<T*> 38{ 39 typedef T* pointer; 40 typedef T element_type; 41 typedef ptrdiff_t difference_type; 42 43 template <class U> using rebind = U*; 44 45 static pointer pointer_to(<details>) noexcept; // constexpr in C++20 46}; 47 48template <class T> constexpr T* to_address(T* p) noexcept; // C++20 49template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20 50 51template <class Alloc> 52struct allocator_traits 53{ 54 typedef Alloc allocator_type; 55 typedef typename allocator_type::value_type 56 value_type; 57 58 typedef Alloc::pointer | value_type* pointer; 59 typedef Alloc::const_pointer 60 | pointer_traits<pointer>::rebind<const value_type> 61 const_pointer; 62 typedef Alloc::void_pointer 63 | pointer_traits<pointer>::rebind<void> 64 void_pointer; 65 typedef Alloc::const_void_pointer 66 | pointer_traits<pointer>::rebind<const void> 67 const_void_pointer; 68 typedef Alloc::difference_type 69 | pointer_traits<pointer>::difference_type 70 difference_type; 71 typedef Alloc::size_type 72 | make_unsigned<difference_type>::type 73 size_type; 74 typedef Alloc::propagate_on_container_copy_assignment 75 | false_type propagate_on_container_copy_assignment; 76 typedef Alloc::propagate_on_container_move_assignment 77 | false_type propagate_on_container_move_assignment; 78 typedef Alloc::propagate_on_container_swap 79 | false_type propagate_on_container_swap; 80 typedef Alloc::is_always_equal 81 | is_empty is_always_equal; 82 83 template <class T> using rebind_alloc = Alloc::rebind<T>::other | Alloc<T, Args...>; 84 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; 85 86 static pointer allocate(allocator_type& a, size_type n); // constexpr and [[nodiscard]] in C++20 87 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // constexpr and [[nodiscard]] in C++20 88 89 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; // constexpr in C++20 90 91 template <class T, class... Args> 92 static void construct(allocator_type& a, T* p, Args&&... args); // constexpr in C++20 93 94 template <class T> 95 static void destroy(allocator_type& a, T* p); // constexpr in C++20 96 97 static size_type max_size(const allocator_type& a); // noexcept in C++14, constexpr in C++20 98 static allocator_type select_on_container_copy_construction(const allocator_type& a); // constexpr in C++20 99}; 100 101template <> 102class allocator<void> // deprecated in C++17, removed in C++20 103{ 104public: 105 typedef void* pointer; 106 typedef const void* const_pointer; 107 typedef void value_type; 108 109 template <class _Up> struct rebind {typedef allocator<_Up> other;}; 110}; 111 112template <class T> 113class allocator 114{ 115public: 116 typedef size_t size_type; 117 typedef ptrdiff_t difference_type; 118 typedef T* pointer; // deprecated in C++17, removed in C++20 119 typedef const T* const_pointer; // deprecated in C++17, removed in C++20 120 typedef typename add_lvalue_reference<T>::type 121 reference; // deprecated in C++17, removed in C++20 122 typedef typename add_lvalue_reference<const T>::type 123 const_reference; // deprecated in C++17, removed in C++20 124 125 typedef T value_type; 126 127 template <class U> struct rebind {typedef allocator<U> other;}; // deprecated in C++17, removed in C++20 128 129 typedef true_type propagate_on_container_move_assignment; 130 typedef true_type is_always_equal; 131 132 constexpr allocator() noexcept; // constexpr in C++20 133 constexpr allocator(const allocator&) noexcept; // constexpr in C++20 134 template <class U> 135 constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20 136 ~allocator(); // constexpr in C++20 137 pointer address(reference x) const noexcept; // deprecated in C++17, removed in C++20 138 const_pointer address(const_reference x) const noexcept; // deprecated in C++17, removed in C++20 139 T* allocate(size_t n, const void* hint); // deprecated in C++17, removed in C++20 140 T* allocate(size_t n); // constexpr in C++20 141 void deallocate(T* p, size_t n) noexcept; // constexpr in C++20 142 size_type max_size() const noexcept; // deprecated in C++17, removed in C++20 143 template<class U, class... Args> 144 void construct(U* p, Args&&... args); // deprecated in C++17, removed in C++20 145 template <class U> 146 void destroy(U* p); // deprecated in C++17, removed in C++20 147}; 148 149template <class T, class U> 150bool operator==(const allocator<T>&, const allocator<U>&) noexcept; // constexpr in C++20 151 152template <class T, class U> 153bool operator!=(const allocator<T>&, const allocator<U>&) noexcept; // constexpr in C++20 154 155template <class OutputIterator, class T> 156class raw_storage_iterator 157 : public iterator<output_iterator_tag, 158 T, // purposefully not C++03 159 ptrdiff_t, // purposefully not C++03 160 T*, // purposefully not C++03 161 raw_storage_iterator&> // purposefully not C++03 162{ 163public: 164 explicit raw_storage_iterator(OutputIterator x); 165 raw_storage_iterator& operator*(); 166 raw_storage_iterator& operator=(const T& element); 167 raw_storage_iterator& operator++(); 168 raw_storage_iterator operator++(int); 169}; 170 171template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; 172template <class T> void return_temporary_buffer(T* p) noexcept; 173 174template <class T> T* addressof(T& r) noexcept; 175template <class T> T* addressof(const T&& r) noexcept = delete; 176 177template <class InputIterator, class ForwardIterator> 178ForwardIterator 179uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); 180 181template <class InputIterator, class Size, class ForwardIterator> 182ForwardIterator 183uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); 184 185template <class ForwardIterator, class T> 186void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); 187 188template <class ForwardIterator, class Size, class T> 189ForwardIterator 190uninitialized_fill_n(ForwardIterator first, Size n, const T& x); 191 192template <class T, class ...Args> 193constexpr T* construct_at(T* location, Args&& ...args); // since C++20 194 195template <class T> 196void destroy_at(T* location); // constexpr in C++20 197 198template <class ForwardIterator> 199void destroy(ForwardIterator first, ForwardIterator last); // constexpr in C++20 200 201template <class ForwardIterator, class Size> 202ForwardIterator destroy_n(ForwardIterator first, Size n); // constexpr in C++20 203 204template <class InputIterator, class ForwardIterator> 205 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result); 206 207template <class InputIterator, class Size, class ForwardIterator> 208 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result); 209 210template <class ForwardIterator> 211 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last); 212 213template <class ForwardIterator, class Size> 214 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n); 215 216template <class ForwardIterator> 217 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last); 218 219template <class ForwardIterator, class Size> 220 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n); 221 222template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17 223 224template<class X> 225class auto_ptr // deprecated in C++11, removed in C++17 226{ 227public: 228 typedef X element_type; 229 230 explicit auto_ptr(X* p =0) throw(); 231 auto_ptr(auto_ptr&) throw(); 232 template<class Y> auto_ptr(auto_ptr<Y>&) throw(); 233 auto_ptr& operator=(auto_ptr&) throw(); 234 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw(); 235 auto_ptr& operator=(auto_ptr_ref<X> r) throw(); 236 ~auto_ptr() throw(); 237 238 typename add_lvalue_reference<X>::type operator*() const throw(); 239 X* operator->() const throw(); 240 X* get() const throw(); 241 X* release() throw(); 242 void reset(X* p =0) throw(); 243 244 auto_ptr(auto_ptr_ref<X>) throw(); 245 template<class Y> operator auto_ptr_ref<Y>() throw(); 246 template<class Y> operator auto_ptr<Y>() throw(); 247}; 248 249template <class T> 250struct default_delete 251{ 252 constexpr default_delete() noexcept = default; 253 template <class U> default_delete(const default_delete<U>&) noexcept; 254 255 void operator()(T*) const noexcept; 256}; 257 258template <class T> 259struct default_delete<T[]> 260{ 261 constexpr default_delete() noexcept = default; 262 void operator()(T*) const noexcept; 263 template <class U> void operator()(U*) const = delete; 264}; 265 266template <class T, class D = default_delete<T>> 267class unique_ptr 268{ 269public: 270 typedef see below pointer; 271 typedef T element_type; 272 typedef D deleter_type; 273 274 // constructors 275 constexpr unique_ptr() noexcept; 276 explicit unique_ptr(pointer p) noexcept; 277 unique_ptr(pointer p, see below d1) noexcept; 278 unique_ptr(pointer p, see below d2) noexcept; 279 unique_ptr(unique_ptr&& u) noexcept; 280 unique_ptr(nullptr_t) noexcept : unique_ptr() { } 281 template <class U, class E> 282 unique_ptr(unique_ptr<U, E>&& u) noexcept; 283 template <class U> 284 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17 285 286 // destructor 287 ~unique_ptr(); 288 289 // assignment 290 unique_ptr& operator=(unique_ptr&& u) noexcept; 291 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; 292 unique_ptr& operator=(nullptr_t) noexcept; 293 294 // observers 295 typename add_lvalue_reference<T>::type operator*() const; 296 pointer operator->() const noexcept; 297 pointer get() const noexcept; 298 deleter_type& get_deleter() noexcept; 299 const deleter_type& get_deleter() const noexcept; 300 explicit operator bool() const noexcept; 301 302 // modifiers 303 pointer release() noexcept; 304 void reset(pointer p = pointer()) noexcept; 305 void swap(unique_ptr& u) noexcept; 306}; 307 308template <class T, class D> 309class unique_ptr<T[], D> 310{ 311public: 312 typedef implementation-defined pointer; 313 typedef T element_type; 314 typedef D deleter_type; 315 316 // constructors 317 constexpr unique_ptr() noexcept; 318 explicit unique_ptr(pointer p) noexcept; 319 unique_ptr(pointer p, see below d) noexcept; 320 unique_ptr(pointer p, see below d) noexcept; 321 unique_ptr(unique_ptr&& u) noexcept; 322 unique_ptr(nullptr_t) noexcept : unique_ptr() { } 323 324 // destructor 325 ~unique_ptr(); 326 327 // assignment 328 unique_ptr& operator=(unique_ptr&& u) noexcept; 329 unique_ptr& operator=(nullptr_t) noexcept; 330 331 // observers 332 T& operator[](size_t i) const; 333 pointer get() const noexcept; 334 deleter_type& get_deleter() noexcept; 335 const deleter_type& get_deleter() const noexcept; 336 explicit operator bool() const noexcept; 337 338 // modifiers 339 pointer release() noexcept; 340 void reset(pointer p = pointer()) noexcept; 341 void reset(nullptr_t) noexcept; 342 template <class U> void reset(U) = delete; 343 void swap(unique_ptr& u) noexcept; 344}; 345 346template <class T, class D> 347 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; 348 349template <class T1, class D1, class T2, class D2> 350 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 351template <class T1, class D1, class T2, class D2> 352 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 353template <class T1, class D1, class T2, class D2> 354 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 355template <class T1, class D1, class T2, class D2> 356 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 357template <class T1, class D1, class T2, class D2> 358 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 359template <class T1, class D1, class T2, class D2> 360 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 361 362template <class T, class D> 363 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; 364template <class T, class D> 365 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; 366template <class T, class D> 367 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; 368template <class T, class D> 369 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; 370 371template <class T, class D> 372 bool operator<(const unique_ptr<T, D>& x, nullptr_t); 373template <class T, class D> 374 bool operator<(nullptr_t, const unique_ptr<T, D>& y); 375template <class T, class D> 376 bool operator<=(const unique_ptr<T, D>& x, nullptr_t); 377template <class T, class D> 378 bool operator<=(nullptr_t, const unique_ptr<T, D>& y); 379template <class T, class D> 380 bool operator>(const unique_ptr<T, D>& x, nullptr_t); 381template <class T, class D> 382 bool operator>(nullptr_t, const unique_ptr<T, D>& y); 383template <class T, class D> 384 bool operator>=(const unique_ptr<T, D>& x, nullptr_t); 385template <class T, class D> 386 bool operator>=(nullptr_t, const unique_ptr<T, D>& y); 387 388class bad_weak_ptr 389 : public std::exception 390{ 391 bad_weak_ptr() noexcept; 392}; 393 394template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14 395template<class T> unique_ptr<T> make_unique(size_t n); // C++14 396template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] 397 398template<class E, class T, class Y, class D> 399 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p); 400 401template<class T> 402class shared_ptr 403{ 404public: 405 typedef T element_type; 406 typedef weak_ptr<T> weak_type; // C++17 407 408 // constructors: 409 constexpr shared_ptr() noexcept; 410 template<class Y> explicit shared_ptr(Y* p); 411 template<class Y, class D> shared_ptr(Y* p, D d); 412 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); 413 template <class D> shared_ptr(nullptr_t p, D d); 414 template <class D, class A> shared_ptr(nullptr_t p, D d, A a); 415 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept; 416 shared_ptr(const shared_ptr& r) noexcept; 417 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept; 418 shared_ptr(shared_ptr&& r) noexcept; 419 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept; 420 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); 421 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17 422 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); 423 shared_ptr(nullptr_t) : shared_ptr() { } 424 425 // destructor: 426 ~shared_ptr(); 427 428 // assignment: 429 shared_ptr& operator=(const shared_ptr& r) noexcept; 430 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept; 431 shared_ptr& operator=(shared_ptr&& r) noexcept; 432 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); 433 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17 434 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); 435 436 // modifiers: 437 void swap(shared_ptr& r) noexcept; 438 void reset() noexcept; 439 template<class Y> void reset(Y* p); 440 template<class Y, class D> void reset(Y* p, D d); 441 template<class Y, class D, class A> void reset(Y* p, D d, A a); 442 443 // observers: 444 T* get() const noexcept; 445 T& operator*() const noexcept; 446 T* operator->() const noexcept; 447 long use_count() const noexcept; 448 bool unique() const noexcept; 449 explicit operator bool() const noexcept; 450 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; 451 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; 452}; 453 454template<class T> 455shared_ptr(weak_ptr<T>) -> shared_ptr<T>; 456template<class T, class D> 457shared_ptr(unique_ptr<T, D>) -> shared_ptr<T>; 458 459// shared_ptr comparisons: 460template<class T, class U> 461 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 462template<class T, class U> 463 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 464template<class T, class U> 465 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 466template<class T, class U> 467 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 468template<class T, class U> 469 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 470template<class T, class U> 471 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 472 473template <class T> 474 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; 475template <class T> 476 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; 477template <class T> 478 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; 479template <class T> 480 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; 481template <class T> 482 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; 483template <class T> 484bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; 485template <class T> 486 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; 487template <class T> 488 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; 489template <class T> 490 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; 491template <class T> 492 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; 493template <class T> 494 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; 495template <class T> 496 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; 497 498// shared_ptr specialized algorithms: 499template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept; 500 501// shared_ptr casts: 502template<class T, class U> 503 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept; 504template<class T, class U> 505 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept; 506template<class T, class U> 507 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept; 508 509// shared_ptr I/O: 510template<class E, class T, class Y> 511 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p); 512 513// shared_ptr get_deleter: 514template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept; 515 516template<class T, class... Args> 517 shared_ptr<T> make_shared(Args&&... args); 518template<class T, class A, class... Args> 519 shared_ptr<T> allocate_shared(const A& a, Args&&... args); 520 521template<class T> 522class weak_ptr 523{ 524public: 525 typedef T element_type; 526 527 // constructors 528 constexpr weak_ptr() noexcept; 529 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; 530 weak_ptr(weak_ptr const& r) noexcept; 531 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; 532 weak_ptr(weak_ptr&& r) noexcept; // C++14 533 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14 534 535 // destructor 536 ~weak_ptr(); 537 538 // assignment 539 weak_ptr& operator=(weak_ptr const& r) noexcept; 540 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; 541 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; 542 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 543 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14 544 545 // modifiers 546 void swap(weak_ptr& r) noexcept; 547 void reset() noexcept; 548 549 // observers 550 long use_count() const noexcept; 551 bool expired() const noexcept; 552 shared_ptr<T> lock() const noexcept; 553 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; 554 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; 555}; 556 557template<class T> 558weak_ptr(shared_ptr<T>) -> weak_ptr<T>; 559 560// weak_ptr specialized algorithms: 561template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept; 562 563// class owner_less: 564template<class T> struct owner_less; 565 566template<class T> 567struct owner_less<shared_ptr<T> > 568 : binary_function<shared_ptr<T>, shared_ptr<T>, bool> 569{ 570 typedef bool result_type; 571 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept; 572 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; 573 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; 574}; 575 576template<class T> 577struct owner_less<weak_ptr<T> > 578 : binary_function<weak_ptr<T>, weak_ptr<T>, bool> 579{ 580 typedef bool result_type; 581 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept; 582 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; 583 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; 584}; 585 586template <> // Added in C++14 587struct owner_less<void> 588{ 589 template <class _Tp, class _Up> 590 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; 591 template <class _Tp, class _Up> 592 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; 593 template <class _Tp, class _Up> 594 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; 595 template <class _Tp, class _Up> 596 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; 597 598 typedef void is_transparent; 599}; 600 601template<class T> 602class enable_shared_from_this 603{ 604protected: 605 constexpr enable_shared_from_this() noexcept; 606 enable_shared_from_this(enable_shared_from_this const&) noexcept; 607 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; 608 ~enable_shared_from_this(); 609public: 610 shared_ptr<T> shared_from_this(); 611 shared_ptr<T const> shared_from_this() const; 612}; 613 614template<class T> 615 bool atomic_is_lock_free(const shared_ptr<T>* p); 616template<class T> 617 shared_ptr<T> atomic_load(const shared_ptr<T>* p); 618template<class T> 619 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo); 620template<class T> 621 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r); 622template<class T> 623 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); 624template<class T> 625 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r); 626template<class T> 627 shared_ptr<T> 628 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); 629template<class T> 630 bool 631 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); 632template<class T> 633 bool 634 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); 635template<class T> 636 bool 637 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, 638 shared_ptr<T> w, memory_order success, 639 memory_order failure); 640template<class T> 641 bool 642 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, 643 shared_ptr<T> w, memory_order success, 644 memory_order failure); 645// Hash support 646template <class T> struct hash; 647template <class T, class D> struct hash<unique_ptr<T, D> >; 648template <class T> struct hash<shared_ptr<T> >; 649 650template <class T, class Alloc> 651 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; 652 653// Pointer safety 654enum class pointer_safety { relaxed, preferred, strict }; 655void declare_reachable(void *p); 656template <class T> T *undeclare_reachable(T *p); 657void declare_no_pointers(char *p, size_t n); 658void undeclare_no_pointers(char *p, size_t n); 659pointer_safety get_pointer_safety() noexcept; 660 661void* align(size_t alignment, size_t size, void*& ptr, size_t& space); 662 663} // std 664 665*/ 666 667#include <__config> 668#include <type_traits> 669#include <typeinfo> 670#include <cstddef> 671#include <cstdint> 672#include <new> 673#include <utility> 674#include <limits> 675#include <iterator> 676#include <__functional_base> 677#include <iosfwd> 678#include <tuple> 679#include <stdexcept> 680#include <cstring> 681#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) 682# include <atomic> 683#endif 684#include <version> 685 686#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 687#pragma GCC system_header 688#endif 689 690_LIBCPP_PUSH_MACROS 691#include <__undef_macros> 692 693 694_LIBCPP_BEGIN_NAMESPACE_STD 695 696template <class _ValueType> 697inline _LIBCPP_INLINE_VISIBILITY 698_ValueType __libcpp_relaxed_load(_ValueType const* __value) { 699#if !defined(_LIBCPP_HAS_NO_THREADS) && \ 700 defined(__ATOMIC_RELAXED) && \ 701 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) 702 return __atomic_load_n(__value, __ATOMIC_RELAXED); 703#else 704 return *__value; 705#endif 706} 707 708template <class _ValueType> 709inline _LIBCPP_INLINE_VISIBILITY 710_ValueType __libcpp_acquire_load(_ValueType const* __value) { 711#if !defined(_LIBCPP_HAS_NO_THREADS) && \ 712 defined(__ATOMIC_ACQUIRE) && \ 713 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) 714 return __atomic_load_n(__value, __ATOMIC_ACQUIRE); 715#else 716 return *__value; 717#endif 718} 719 720// addressof moved to <type_traits> 721 722template <class _Tp> class allocator; 723 724#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) 725template <> 726class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator<void> 727{ 728public: 729 typedef void* pointer; 730 typedef const void* const_pointer; 731 typedef void value_type; 732 733 template <class _Up> struct rebind {typedef allocator<_Up> other;}; 734}; 735 736template <> 737class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator<const void> 738{ 739public: 740 typedef const void* pointer; 741 typedef const void* const_pointer; 742 typedef const void value_type; 743 744 template <class _Up> struct rebind {typedef allocator<_Up> other;}; 745}; 746#endif 747 748// pointer_traits 749 750template <class _Tp, class = void> 751struct __has_element_type : false_type {}; 752 753template <class _Tp> 754struct __has_element_type<_Tp, 755 typename __void_t<typename _Tp::element_type>::type> : true_type {}; 756 757template <class _Ptr, bool = __has_element_type<_Ptr>::value> 758struct __pointer_traits_element_type; 759 760template <class _Ptr> 761struct __pointer_traits_element_type<_Ptr, true> 762{ 763 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type; 764}; 765 766template <template <class, class...> class _Sp, class _Tp, class ..._Args> 767struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> 768{ 769 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type; 770}; 771 772template <template <class, class...> class _Sp, class _Tp, class ..._Args> 773struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> 774{ 775 typedef _LIBCPP_NODEBUG_TYPE _Tp type; 776}; 777 778template <class _Tp, class = void> 779struct __has_difference_type : false_type {}; 780 781template <class _Tp> 782struct __has_difference_type<_Tp, 783 typename __void_t<typename _Tp::difference_type>::type> : true_type {}; 784 785template <class _Ptr, bool = __has_difference_type<_Ptr>::value> 786struct __pointer_traits_difference_type 787{ 788 typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type; 789}; 790 791template <class _Ptr> 792struct __pointer_traits_difference_type<_Ptr, true> 793{ 794 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type; 795}; 796 797template <class _Tp, class _Up> 798struct __has_rebind 799{ 800private: 801 struct __two {char __lx; char __lxx;}; 802 template <class _Xp> static __two __test(...); 803 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 804 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0); 805 _LIBCPP_SUPPRESS_DEPRECATED_POP 806public: 807 static const bool value = sizeof(__test<_Tp>(0)) == 1; 808}; 809 810template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> 811struct __pointer_traits_rebind 812{ 813#ifndef _LIBCPP_CXX03_LANG 814 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type; 815#else 816 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type; 817#endif 818}; 819 820template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> 821struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> 822{ 823#ifndef _LIBCPP_CXX03_LANG 824 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type; 825#else 826 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; 827#endif 828}; 829 830template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> 831struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> 832{ 833 typedef _Sp<_Up, _Args...> type; 834}; 835 836template <class _Ptr> 837struct _LIBCPP_TEMPLATE_VIS pointer_traits 838{ 839 typedef _Ptr pointer; 840 typedef typename __pointer_traits_element_type<pointer>::type element_type; 841 typedef typename __pointer_traits_difference_type<pointer>::type difference_type; 842 843#ifndef _LIBCPP_CXX03_LANG 844 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; 845#else 846 template <class _Up> struct rebind 847 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;}; 848#endif // _LIBCPP_CXX03_LANG 849 850private: 851 struct __nat {}; 852public: 853 _LIBCPP_INLINE_VISIBILITY 854 static pointer pointer_to(typename conditional<is_void<element_type>::value, 855 __nat, element_type>::type& __r) 856 {return pointer::pointer_to(__r);} 857}; 858 859template <class _Tp> 860struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> 861{ 862 typedef _Tp* pointer; 863 typedef _Tp element_type; 864 typedef ptrdiff_t difference_type; 865 866#ifndef _LIBCPP_CXX03_LANG 867 template <class _Up> using rebind = _Up*; 868#else 869 template <class _Up> struct rebind {typedef _Up* other;}; 870#endif 871 872private: 873 struct __nat {}; 874public: 875 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 876 static pointer pointer_to(typename conditional<is_void<element_type>::value, 877 __nat, element_type>::type& __r) _NOEXCEPT 878 {return _VSTD::addressof(__r);} 879}; 880 881template <class _From, class _To> 882struct __rebind_pointer { 883#ifndef _LIBCPP_CXX03_LANG 884 typedef typename pointer_traits<_From>::template rebind<_To> type; 885#else 886 typedef typename pointer_traits<_From>::template rebind<_To>::other type; 887#endif 888}; 889 890// construct_at 891 892#if _LIBCPP_STD_VER > 17 893 894template<class _Tp> 895_LIBCPP_CONSTEXPR_AFTER_CXX17 void* __voidify(_Tp& __ptr) noexcept { 896 return const_cast<void*>(static_cast<const volatile void*>(_VSTD::addressof(__ptr))); 897} 898 899template<class _Tp, class ..._Args, class = decltype( 900 ::new (_VSTD::declval<void*>()) _Tp(_VSTD::declval<_Args>()...) 901)> 902_LIBCPP_INLINE_VISIBILITY 903constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) { 904 _LIBCPP_ASSERT(__location, "null pointer given to construct_at"); 905 return ::new (_VSTD::__voidify(*__location)) _Tp(_VSTD::forward<_Args>(__args)...); 906} 907 908#endif 909 910// destroy_at 911 912#if _LIBCPP_STD_VER > 14 913 914template <class _Tp> 915inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 916void destroy_at(_Tp* __loc) { 917 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); 918 __loc->~_Tp(); 919} 920 921#endif 922 923// allocator_traits 924 925template <class _Tp, class = void> 926struct __has_pointer_type : false_type {}; 927 928template <class _Tp> 929struct __has_pointer_type<_Tp, 930 typename __void_t<typename _Tp::pointer>::type> : true_type {}; 931 932namespace __pointer_type_imp 933{ 934 935template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value> 936struct __pointer_type 937{ 938 typedef _LIBCPP_NODEBUG_TYPE typename _Dp::pointer type; 939}; 940 941template <class _Tp, class _Dp> 942struct __pointer_type<_Tp, _Dp, false> 943{ 944 typedef _LIBCPP_NODEBUG_TYPE _Tp* type; 945}; 946 947} // __pointer_type_imp 948 949template <class _Tp, class _Dp> 950struct __pointer_type 951{ 952 typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; 953}; 954 955template <class _Tp, class = void> 956struct __has_const_pointer : false_type {}; 957 958template <class _Tp> 959struct __has_const_pointer<_Tp, 960 typename __void_t<typename _Tp::const_pointer>::type> : true_type {}; 961 962template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> 963struct __const_pointer 964{ 965 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_pointer type; 966}; 967 968template <class _Tp, class _Ptr, class _Alloc> 969struct __const_pointer<_Tp, _Ptr, _Alloc, false> 970{ 971#ifndef _LIBCPP_CXX03_LANG 972 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type; 973#else 974 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type; 975#endif 976}; 977 978template <class _Tp, class = void> 979struct __has_void_pointer : false_type {}; 980 981template <class _Tp> 982struct __has_void_pointer<_Tp, 983 typename __void_t<typename _Tp::void_pointer>::type> : true_type {}; 984 985template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> 986struct __void_pointer 987{ 988 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::void_pointer type; 989}; 990 991template <class _Ptr, class _Alloc> 992struct __void_pointer<_Ptr, _Alloc, false> 993{ 994#ifndef _LIBCPP_CXX03_LANG 995 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type; 996#else 997 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void>::other type; 998#endif 999}; 1000 1001template <class _Tp, class = void> 1002struct __has_const_void_pointer : false_type {}; 1003 1004template <class _Tp> 1005struct __has_const_void_pointer<_Tp, 1006 typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {}; 1007 1008template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> 1009struct __const_void_pointer 1010{ 1011 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_void_pointer type; 1012}; 1013 1014template <class _Ptr, class _Alloc> 1015struct __const_void_pointer<_Ptr, _Alloc, false> 1016{ 1017#ifndef _LIBCPP_CXX03_LANG 1018 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type; 1019#else 1020 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void>::other type; 1021#endif 1022}; 1023 1024 1025template <bool _UsePointerTraits> struct __to_address_helper; 1026 1027template <> struct __to_address_helper<true> { 1028 template <class _Pointer> 1029 using __return_type = decltype(pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>())); 1030 1031 template <class _Pointer> 1032 _LIBCPP_CONSTEXPR 1033 static __return_type<_Pointer> 1034 __do_it(const _Pointer &__p) _NOEXCEPT { return pointer_traits<_Pointer>::to_address(__p); } 1035}; 1036 1037template <class _Pointer, bool _Dummy = true> 1038using __choose_to_address = __to_address_helper<_IsValidExpansion<__to_address_helper<_Dummy>::template __return_type, _Pointer>::value>; 1039 1040 1041template <class _Tp> 1042inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1043_Tp* 1044__to_address(_Tp* __p) _NOEXCEPT 1045{ 1046 static_assert(!is_function<_Tp>::value, "_Tp is a function type"); 1047 return __p; 1048} 1049 1050template <class _Pointer> 1051inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1052typename __choose_to_address<_Pointer>::template __return_type<_Pointer> 1053__to_address(const _Pointer& __p) _NOEXCEPT { 1054 return __choose_to_address<_Pointer>::__do_it(__p); 1055} 1056 1057template <> struct __to_address_helper<false> { 1058 template <class _Pointer> 1059 using __return_type = typename pointer_traits<_Pointer>::element_type*; 1060 1061 template <class _Pointer> 1062 _LIBCPP_CONSTEXPR 1063 static __return_type<_Pointer> 1064 __do_it(const _Pointer &__p) _NOEXCEPT { return std::__to_address(__p.operator->()); } 1065}; 1066 1067 1068#if _LIBCPP_STD_VER > 17 1069template <class _Tp> 1070inline _LIBCPP_INLINE_VISIBILITY constexpr 1071_Tp* 1072to_address(_Tp* __p) _NOEXCEPT 1073{ 1074 static_assert(!is_function_v<_Tp>, "_Tp is a function type"); 1075 return __p; 1076} 1077 1078template <class _Pointer> 1079inline _LIBCPP_INLINE_VISIBILITY 1080auto 1081to_address(const _Pointer& __p) _NOEXCEPT 1082{ 1083 return _VSTD::__to_address(__p); 1084} 1085#endif 1086 1087template <class _Tp, class = void> 1088struct __has_size_type : false_type {}; 1089 1090template <class _Tp> 1091struct __has_size_type<_Tp, 1092 typename __void_t<typename _Tp::size_type>::type> : true_type {}; 1093 1094template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> 1095struct __size_type 1096{ 1097 typedef _LIBCPP_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type; 1098}; 1099 1100template <class _Alloc, class _DiffType> 1101struct __size_type<_Alloc, _DiffType, true> 1102{ 1103 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::size_type type; 1104}; 1105 1106template <class _Tp, class = void> 1107struct __has_propagate_on_container_copy_assignment : false_type {}; 1108 1109template <class _Tp> 1110struct __has_propagate_on_container_copy_assignment<_Tp, 1111 typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type> 1112 : true_type {}; 1113 1114template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> 1115struct __propagate_on_container_copy_assignment 1116{ 1117 typedef _LIBCPP_NODEBUG_TYPE false_type type; 1118}; 1119 1120template <class _Alloc> 1121struct __propagate_on_container_copy_assignment<_Alloc, true> 1122{ 1123 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type; 1124}; 1125 1126template <class _Tp, class = void> 1127struct __has_propagate_on_container_move_assignment : false_type {}; 1128 1129template <class _Tp> 1130struct __has_propagate_on_container_move_assignment<_Tp, 1131 typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type> 1132 : true_type {}; 1133 1134template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value> 1135struct __propagate_on_container_move_assignment 1136{ 1137 typedef false_type type; 1138}; 1139 1140template <class _Alloc> 1141struct __propagate_on_container_move_assignment<_Alloc, true> 1142{ 1143 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type; 1144}; 1145 1146template <class _Tp, class = void> 1147struct __has_propagate_on_container_swap : false_type {}; 1148 1149template <class _Tp> 1150struct __has_propagate_on_container_swap<_Tp, 1151 typename __void_t<typename _Tp::propagate_on_container_swap>::type> 1152 : true_type {}; 1153 1154template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value> 1155struct __propagate_on_container_swap 1156{ 1157 typedef false_type type; 1158}; 1159 1160template <class _Alloc> 1161struct __propagate_on_container_swap<_Alloc, true> 1162{ 1163 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type; 1164}; 1165 1166template <class _Tp, class = void> 1167struct __has_is_always_equal : false_type {}; 1168 1169template <class _Tp> 1170struct __has_is_always_equal<_Tp, 1171 typename __void_t<typename _Tp::is_always_equal>::type> 1172 : true_type {}; 1173 1174template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value> 1175struct __is_always_equal 1176{ 1177 typedef _LIBCPP_NODEBUG_TYPE typename _VSTD::is_empty<_Alloc>::type type; 1178}; 1179 1180template <class _Alloc> 1181struct __is_always_equal<_Alloc, true> 1182{ 1183 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::is_always_equal type; 1184}; 1185 1186template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> 1187struct __has_rebind_other 1188{ 1189private: 1190 struct __two {char __lx; char __lxx;}; 1191 template <class _Xp> static __two __test(...); 1192 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 1193 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0); 1194 _LIBCPP_SUPPRESS_DEPRECATED_POP 1195public: 1196 static const bool value = sizeof(__test<_Tp>(0)) == 1; 1197}; 1198 1199template <class _Tp, class _Up> 1200struct __has_rebind_other<_Tp, _Up, false> 1201{ 1202 static const bool value = false; 1203}; 1204 1205template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> 1206struct __allocator_traits_rebind 1207{ 1208 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 1209 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type; 1210 _LIBCPP_SUPPRESS_DEPRECATED_POP 1211}; 1212 1213template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> 1214struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> 1215{ 1216 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 1217 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type; 1218 _LIBCPP_SUPPRESS_DEPRECATED_POP 1219}; 1220 1221template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> 1222struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> 1223{ 1224 typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type; 1225}; 1226 1227#ifndef _LIBCPP_CXX03_LANG 1228 1229_LIBCPP_SUPPRESS_DEPRECATED_PUSH 1230template <class _Alloc, class _SizeType, class _ConstVoidPtr> 1231auto 1232__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) 1233 -> decltype((void)__a.allocate(__sz, __p), true_type()); 1234_LIBCPP_SUPPRESS_DEPRECATED_POP 1235 1236template <class _Alloc, class _SizeType, class _ConstVoidPtr> 1237auto 1238__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) 1239 -> false_type; 1240 1241template <class _Alloc, class _SizeType, class _ConstVoidPtr> 1242struct __has_allocate_hint 1243 : decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(), 1244 declval<_SizeType>(), 1245 declval<_ConstVoidPtr>())) 1246{ 1247}; 1248 1249#else // _LIBCPP_CXX03_LANG 1250 1251template <class _Alloc, class _SizeType, class _ConstVoidPtr> 1252struct __has_allocate_hint 1253 : true_type 1254{ 1255}; 1256 1257#endif // _LIBCPP_CXX03_LANG 1258 1259_LIBCPP_SUPPRESS_DEPRECATED_PUSH 1260template <class _Alloc, class ..._Args, 1261 class = decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Args>()...))> 1262static true_type __test_has_construct(int); 1263_LIBCPP_SUPPRESS_DEPRECATED_POP 1264 1265template <class _Alloc, class...> 1266static false_type __test_has_construct(...); 1267 1268template <class _Alloc, class ..._Args> 1269struct __has_construct : decltype(__test_has_construct<_Alloc, _Args...>(0)) {}; 1270 1271#if !defined(_LIBCPP_CXX03_LANG) 1272 1273_LIBCPP_SUPPRESS_DEPRECATED_PUSH 1274template <class _Alloc, class _Pointer> 1275auto 1276__has_destroy_test(_Alloc&& __a, _Pointer&& __p) 1277 -> decltype(__a.destroy(__p), true_type()); 1278_LIBCPP_SUPPRESS_DEPRECATED_POP 1279 1280template <class _Alloc, class _Pointer> 1281auto 1282__has_destroy_test(const _Alloc& __a, _Pointer&& __p) 1283 -> false_type; 1284 1285template <class _Alloc, class _Pointer> 1286struct __has_destroy 1287 : decltype(_VSTD::__has_destroy_test(declval<_Alloc>(), 1288 declval<_Pointer>())) 1289{ 1290}; 1291 1292_LIBCPP_SUPPRESS_DEPRECATED_PUSH 1293template <class _Alloc> 1294auto 1295__has_max_size_test(_Alloc&& __a) 1296 -> decltype(__a.max_size(), true_type()); 1297_LIBCPP_SUPPRESS_DEPRECATED_POP 1298 1299template <class _Alloc> 1300auto 1301__has_max_size_test(const volatile _Alloc& __a) 1302 -> false_type; 1303 1304template <class _Alloc> 1305struct __has_max_size 1306 : decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())) 1307{ 1308}; 1309 1310template <class _Alloc> 1311auto 1312__has_select_on_container_copy_construction_test(_Alloc&& __a) 1313 -> decltype(__a.select_on_container_copy_construction(), true_type()); 1314 1315template <class _Alloc> 1316auto 1317__has_select_on_container_copy_construction_test(const volatile _Alloc& __a) 1318 -> false_type; 1319 1320template <class _Alloc> 1321struct __has_select_on_container_copy_construction 1322 : decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())) 1323{ 1324}; 1325 1326#else // _LIBCPP_CXX03_LANG 1327 1328template <class _Alloc, class _Pointer, class = void> 1329struct __has_destroy : false_type {}; 1330 1331template <class _Alloc, class _Pointer> 1332struct __has_destroy<_Alloc, _Pointer, typename __void_t< 1333 decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>())) 1334>::type> : std::true_type {}; 1335 1336template <class _Alloc> 1337struct __has_max_size 1338 : true_type 1339{ 1340}; 1341 1342template <class _Alloc> 1343struct __has_select_on_container_copy_construction 1344 : false_type 1345{ 1346}; 1347 1348#endif // _LIBCPP_CXX03_LANG 1349 1350template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> 1351struct __alloc_traits_difference_type 1352{ 1353 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type; 1354}; 1355 1356template <class _Alloc, class _Ptr> 1357struct __alloc_traits_difference_type<_Alloc, _Ptr, true> 1358{ 1359 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::difference_type type; 1360}; 1361 1362template <class _Tp> 1363struct __is_default_allocator : false_type {}; 1364 1365template <class _Tp> 1366struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {}; 1367 1368 1369 1370template <class _Alloc, 1371 bool = __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value && !__is_default_allocator<_Alloc>::value 1372 > 1373struct __is_cpp17_move_insertable; 1374template <class _Alloc> 1375struct __is_cpp17_move_insertable<_Alloc, true> : std::true_type {}; 1376template <class _Alloc> 1377struct __is_cpp17_move_insertable<_Alloc, false> : std::is_move_constructible<typename _Alloc::value_type> {}; 1378 1379template <class _Alloc, 1380 bool = __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value && !__is_default_allocator<_Alloc>::value 1381 > 1382struct __is_cpp17_copy_insertable; 1383template <class _Alloc> 1384struct __is_cpp17_copy_insertable<_Alloc, true> : __is_cpp17_move_insertable<_Alloc> {}; 1385template <class _Alloc> 1386struct __is_cpp17_copy_insertable<_Alloc, false> : integral_constant<bool, 1387 std::is_copy_constructible<typename _Alloc::value_type>::value && 1388 __is_cpp17_move_insertable<_Alloc>::value> 1389 {}; 1390 1391 1392 1393template <class _Alloc> 1394struct _LIBCPP_TEMPLATE_VIS allocator_traits 1395{ 1396 typedef _Alloc allocator_type; 1397 typedef typename allocator_type::value_type value_type; 1398 1399 typedef typename __pointer_type<value_type, allocator_type>::type pointer; 1400 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer; 1401 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer; 1402 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer; 1403 1404 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type; 1405 typedef typename __size_type<allocator_type, difference_type>::type size_type; 1406 1407 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type 1408 propagate_on_container_copy_assignment; 1409 typedef typename __propagate_on_container_move_assignment<allocator_type>::type 1410 propagate_on_container_move_assignment; 1411 typedef typename __propagate_on_container_swap<allocator_type>::type 1412 propagate_on_container_swap; 1413 typedef typename __is_always_equal<allocator_type>::type 1414 is_always_equal; 1415 1416#ifndef _LIBCPP_CXX03_LANG 1417 template <class _Tp> using rebind_alloc = 1418 typename __allocator_traits_rebind<allocator_type, _Tp>::type; 1419 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp> >; 1420#else // _LIBCPP_CXX03_LANG 1421 template <class _Tp> struct rebind_alloc 1422 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; 1423 template <class _Tp> struct rebind_traits 1424 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;}; 1425#endif // _LIBCPP_CXX03_LANG 1426 1427 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1428 static pointer allocate(allocator_type& __a, size_type __n) 1429 {return __a.allocate(__n);} 1430 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1431 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) 1432 {return __allocate(__a, __n, __hint, 1433 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());} 1434 1435 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1436 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT 1437 {__a.deallocate(__p, __n);} 1438 1439 template <class _Tp, class... _Args> 1440 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1441 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) 1442 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(), 1443 __a, __p, _VSTD::forward<_Args>(__args)...);} 1444 1445 template <class _Tp> 1446 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1447 static void destroy(allocator_type& __a, _Tp* __p) 1448 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);} 1449 1450 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1451 static size_type max_size(const allocator_type& __a) _NOEXCEPT 1452 {return __max_size(__has_max_size<const allocator_type>(), __a);} 1453 1454 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1455 static allocator_type 1456 select_on_container_copy_construction(const allocator_type& __a) 1457 {return __select_on_container_copy_construction( 1458 __has_select_on_container_copy_construction<const allocator_type>(), 1459 __a);} 1460 1461 template <class _Ptr> 1462 _LIBCPP_INLINE_VISIBILITY 1463 static 1464 void 1465 __construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) 1466 { 1467 static_assert(__is_cpp17_move_insertable<allocator_type>::value, 1468 "The specified type does not meet the requirements of Cpp17MoveInsertible"); 1469 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) 1470 construct(__a, _VSTD::__to_address(__begin2), 1471#ifdef _LIBCPP_NO_EXCEPTIONS 1472 _VSTD::move(*__begin1) 1473#else 1474 _VSTD::move_if_noexcept(*__begin1) 1475#endif 1476 ); 1477 } 1478 1479 template <class _Tp> 1480 _LIBCPP_INLINE_VISIBILITY 1481 static 1482 typename enable_if 1483 < 1484 (__is_default_allocator<allocator_type>::value 1485 || !__has_construct<allocator_type, _Tp*, _Tp>::value) && 1486 is_trivially_move_constructible<_Tp>::value, 1487 void 1488 >::type 1489 __construct_forward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) 1490 { 1491 ptrdiff_t _Np = __end1 - __begin1; 1492 if (_Np > 0) 1493 { 1494 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); 1495 __begin2 += _Np; 1496 } 1497 } 1498 1499 template <class _Iter, class _Ptr> 1500 _LIBCPP_INLINE_VISIBILITY 1501 static 1502 void 1503 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) 1504 { 1505 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) 1506 construct(__a, _VSTD::__to_address(__begin2), *__begin1); 1507 } 1508 1509 template <class _SourceTp, class _DestTp, 1510 class _RawSourceTp = typename remove_const<_SourceTp>::type, 1511 class _RawDestTp = typename remove_const<_DestTp>::type> 1512 _LIBCPP_INLINE_VISIBILITY 1513 static 1514 typename enable_if 1515 < 1516 is_trivially_copy_constructible<_DestTp>::value && 1517 is_same<_RawSourceTp, _RawDestTp>::value && 1518 (__is_default_allocator<allocator_type>::value || 1519 !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value), 1520 void 1521 >::type 1522 __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2) 1523 { 1524 ptrdiff_t _Np = __end1 - __begin1; 1525 if (_Np > 0) 1526 { 1527 _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp)); 1528 __begin2 += _Np; 1529 } 1530 } 1531 1532 template <class _Ptr> 1533 _LIBCPP_INLINE_VISIBILITY 1534 static 1535 void 1536 __construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) 1537 { 1538 static_assert(__is_cpp17_move_insertable<allocator_type>::value, 1539 "The specified type does not meet the requirements of Cpp17MoveInsertable"); 1540 while (__end1 != __begin1) 1541 { 1542 construct(__a, _VSTD::__to_address(__end2 - 1), 1543#ifdef _LIBCPP_NO_EXCEPTIONS 1544 _VSTD::move(*--__end1) 1545#else 1546 _VSTD::move_if_noexcept(*--__end1) 1547#endif 1548 ); 1549 --__end2; 1550 } 1551 } 1552 1553 template <class _Tp> 1554 _LIBCPP_INLINE_VISIBILITY 1555 static 1556 typename enable_if 1557 < 1558 (__is_default_allocator<allocator_type>::value 1559 || !__has_construct<allocator_type, _Tp*, _Tp>::value) && 1560 is_trivially_move_constructible<_Tp>::value, 1561 void 1562 >::type 1563 __construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) 1564 { 1565 ptrdiff_t _Np = __end1 - __begin1; 1566 __end2 -= _Np; 1567 if (_Np > 0) 1568 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); 1569 } 1570 1571private: 1572 1573 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1574 static pointer __allocate(allocator_type& __a, size_type __n, 1575 const_void_pointer __hint, true_type) 1576 { 1577 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 1578 return __a.allocate(__n, __hint); 1579 _LIBCPP_SUPPRESS_DEPRECATED_POP 1580 } 1581 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1582 static pointer __allocate(allocator_type& __a, size_type __n, 1583 const_void_pointer, false_type) 1584 {return __a.allocate(__n);} 1585 1586 template <class _Tp, class... _Args> 1587 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1588 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args) 1589 { 1590 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 1591 __a.construct(__p, _VSTD::forward<_Args>(__args)...); 1592 _LIBCPP_SUPPRESS_DEPRECATED_POP 1593 } 1594 1595 template <class _Tp, class... _Args> 1596 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1597 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args) 1598 { 1599#if _LIBCPP_STD_VER > 17 1600 _VSTD::construct_at(__p, _VSTD::forward<_Args>(__args)...); 1601#else 1602 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...); 1603#endif 1604 } 1605 1606 template <class _Tp> 1607 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1608 static void __destroy(true_type, allocator_type& __a, _Tp* __p) 1609 { 1610 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 1611 __a.destroy(__p); 1612 _LIBCPP_SUPPRESS_DEPRECATED_POP 1613 } 1614 template <class _Tp> 1615 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1616 static void __destroy(false_type, allocator_type&, _Tp* __p) 1617 { 1618#if _LIBCPP_STD_VER > 17 1619 _VSTD::destroy_at(__p); 1620#else 1621 __p->~_Tp(); 1622#endif 1623 } 1624 1625 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1626 static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT 1627 { 1628 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 1629 return __a.max_size(); 1630 _LIBCPP_SUPPRESS_DEPRECATED_POP 1631 } 1632 1633 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1634 static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT 1635 {return numeric_limits<size_type>::max() / sizeof(value_type);} 1636 1637 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1638 static allocator_type 1639 __select_on_container_copy_construction(true_type, const allocator_type& __a) 1640 {return __a.select_on_container_copy_construction();} 1641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1642 static allocator_type 1643 __select_on_container_copy_construction(false_type, const allocator_type& __a) 1644 {return __a;} 1645}; 1646 1647template <class _Traits, class _Tp> 1648struct __rebind_alloc_helper 1649{ 1650#ifndef _LIBCPP_CXX03_LANG 1651 typedef _LIBCPP_NODEBUG_TYPE typename _Traits::template rebind_alloc<_Tp> type; 1652#else 1653 typedef typename _Traits::template rebind_alloc<_Tp>::other type; 1654#endif 1655}; 1656 1657// allocator 1658 1659template <class _Tp> 1660class _LIBCPP_TEMPLATE_VIS allocator 1661{ 1662public: 1663 typedef size_t size_type; 1664 typedef ptrdiff_t difference_type; 1665 typedef _Tp value_type; 1666 typedef true_type propagate_on_container_move_assignment; 1667 typedef true_type is_always_equal; 1668 1669 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1670 allocator() _NOEXCEPT { } 1671 1672 template <class _Up> 1673 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1674 allocator(const allocator<_Up>&) _NOEXCEPT { } 1675 1676 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1677 _Tp* allocate(size_t __n) { 1678 if (__n > allocator_traits<allocator>::max_size(*this)) 1679 __throw_length_error("allocator<T>::allocate(size_t n)" 1680 " 'n' exceeds maximum supported size"); 1681 if (__libcpp_is_constant_evaluated()) { 1682 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); 1683 } else { 1684 return static_cast<_Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); 1685 } 1686 } 1687 1688 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1689 void deallocate(_Tp* __p, size_t __n) _NOEXCEPT { 1690 if (__libcpp_is_constant_evaluated()) { 1691 ::operator delete(__p); 1692 } else { 1693 _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); 1694 } 1695 } 1696 1697 // C++20 Removed members 1698#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) 1699 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp* pointer; 1700 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; 1701 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp& reference; 1702 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; 1703 1704 template <class _Up> 1705 struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { 1706 typedef allocator<_Up> other; 1707 }; 1708 1709 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY 1710 pointer address(reference __x) const _NOEXCEPT { 1711 return _VSTD::addressof(__x); 1712 } 1713 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY 1714 const_pointer address(const_reference __x) const _NOEXCEPT { 1715 return _VSTD::addressof(__x); 1716 } 1717 1718 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 1719 _Tp* allocate(size_t __n, const void*) { 1720 return allocate(__n); 1721 } 1722 1723 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { 1724 return size_type(~0) / sizeof(_Tp); 1725 } 1726 1727 template <class _Up, class... _Args> 1728 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY 1729 void construct(_Up* __p, _Args&&... __args) { 1730 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); 1731 } 1732 1733 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY 1734 void destroy(pointer __p) { 1735 __p->~_Tp(); 1736 } 1737#endif 1738}; 1739 1740template <class _Tp> 1741class _LIBCPP_TEMPLATE_VIS allocator<const _Tp> 1742{ 1743public: 1744 typedef size_t size_type; 1745 typedef ptrdiff_t difference_type; 1746 typedef const _Tp value_type; 1747 typedef true_type propagate_on_container_move_assignment; 1748 typedef true_type is_always_equal; 1749 1750 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1751 allocator() _NOEXCEPT { } 1752 1753 template <class _Up> 1754 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1755 allocator(const allocator<_Up>&) _NOEXCEPT { } 1756 1757 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1758 const _Tp* allocate(size_t __n) { 1759 if (__n > allocator_traits<allocator>::max_size(*this)) 1760 __throw_length_error("allocator<const T>::allocate(size_t n)" 1761 " 'n' exceeds maximum supported size"); 1762 if (__libcpp_is_constant_evaluated()) { 1763 return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp))); 1764 } else { 1765 return static_cast<const _Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); 1766 } 1767 } 1768 1769 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1770 void deallocate(const _Tp* __p, size_t __n) { 1771 if (__libcpp_is_constant_evaluated()) { 1772 ::operator delete(const_cast<_Tp*>(__p)); 1773 } else { 1774 _VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); 1775 } 1776 } 1777 1778 // C++20 Removed members 1779#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) 1780 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer; 1781 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; 1782 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference; 1783 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; 1784 1785 template <class _Up> 1786 struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { 1787 typedef allocator<_Up> other; 1788 }; 1789 1790 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY 1791 const_pointer address(const_reference __x) const _NOEXCEPT { 1792 return _VSTD::addressof(__x); 1793 } 1794 1795 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 1796 const _Tp* allocate(size_t __n, const void*) { 1797 return allocate(__n); 1798 } 1799 1800 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { 1801 return size_type(~0) / sizeof(_Tp); 1802 } 1803 1804 template <class _Up, class... _Args> 1805 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY 1806 void construct(_Up* __p, _Args&&... __args) { 1807 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); 1808 } 1809 1810 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY 1811 void destroy(pointer __p) { 1812 __p->~_Tp(); 1813 } 1814#endif 1815}; 1816 1817template <class _Tp, class _Up> 1818inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1819bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} 1820 1821template <class _Tp, class _Up> 1822inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1823bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} 1824 1825template <class _OutputIterator, class _Tp> 1826class _LIBCPP_TEMPLATE_VIS raw_storage_iterator 1827 : public iterator<output_iterator_tag, 1828 _Tp, // purposefully not C++03 1829 ptrdiff_t, // purposefully not C++03 1830 _Tp*, // purposefully not C++03 1831 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 1832{ 1833private: 1834 _OutputIterator __x_; 1835public: 1836 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} 1837 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} 1838 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) 1839 {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;} 1840#if _LIBCPP_STD_VER >= 14 1841 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) 1842 {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} 1843#endif 1844 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} 1845 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) 1846 {raw_storage_iterator __t(*this); ++__x_; return __t;} 1847#if _LIBCPP_STD_VER >= 14 1848 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } 1849#endif 1850}; 1851 1852template <class _Tp> 1853_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI 1854pair<_Tp*, ptrdiff_t> 1855get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT 1856{ 1857 pair<_Tp*, ptrdiff_t> __r(0, 0); 1858 const ptrdiff_t __m = (~ptrdiff_t(0) ^ 1859 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) 1860 / sizeof(_Tp); 1861 if (__n > __m) 1862 __n = __m; 1863 while (__n > 0) 1864 { 1865#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) 1866 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) 1867 { 1868 std::align_val_t __al = 1869 std::align_val_t(std::alignment_of<_Tp>::value); 1870 __r.first = static_cast<_Tp*>(::operator new( 1871 __n * sizeof(_Tp), __al, nothrow)); 1872 } else { 1873 __r.first = static_cast<_Tp*>(::operator new( 1874 __n * sizeof(_Tp), nothrow)); 1875 } 1876#else 1877 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) 1878 { 1879 // Since aligned operator new is unavailable, return an empty 1880 // buffer rather than one with invalid alignment. 1881 return __r; 1882 } 1883 1884 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); 1885#endif 1886 1887 if (__r.first) 1888 { 1889 __r.second = __n; 1890 break; 1891 } 1892 __n /= 2; 1893 } 1894 return __r; 1895} 1896 1897template <class _Tp> 1898inline _LIBCPP_INLINE_VISIBILITY 1899void return_temporary_buffer(_Tp* __p) _NOEXCEPT 1900{ 1901 _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); 1902} 1903 1904#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 1905template <class _Tp> 1906struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref 1907{ 1908 _Tp* __ptr_; 1909}; 1910 1911template<class _Tp> 1912class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr 1913{ 1914private: 1915 _Tp* __ptr_; 1916public: 1917 typedef _Tp element_type; 1918 1919 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {} 1920 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {} 1921 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT 1922 : __ptr_(__p.release()) {} 1923 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT 1924 {reset(__p.release()); return *this;} 1925 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT 1926 {reset(__p.release()); return *this;} 1927 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT 1928 {reset(__p.__ptr_); return *this;} 1929 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() _NOEXCEPT {delete __ptr_;} 1930 1931 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const _NOEXCEPT 1932 {return *__ptr_;} 1933 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const _NOEXCEPT {return __ptr_;} 1934 _LIBCPP_INLINE_VISIBILITY _Tp* get() const _NOEXCEPT {return __ptr_;} 1935 _LIBCPP_INLINE_VISIBILITY _Tp* release() _NOEXCEPT 1936 { 1937 _Tp* __t = __ptr_; 1938 __ptr_ = 0; 1939 return __t; 1940 } 1941 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) _NOEXCEPT 1942 { 1943 if (__ptr_ != __p) 1944 delete __ptr_; 1945 __ptr_ = __p; 1946 } 1947 1948 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {} 1949 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() _NOEXCEPT 1950 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} 1951 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() _NOEXCEPT 1952 {return auto_ptr<_Up>(release());} 1953}; 1954 1955template <> 1956class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> 1957{ 1958public: 1959 typedef void element_type; 1960}; 1961#endif 1962 1963// Tag used to default initialize one or both of the pair's elements. 1964struct __default_init_tag {}; 1965struct __value_init_tag {}; 1966 1967template <class _Tp, int _Idx, 1968 bool _CanBeEmptyBase = 1969 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value> 1970struct __compressed_pair_elem { 1971 typedef _Tp _ParamT; 1972 typedef _Tp& reference; 1973 typedef const _Tp& const_reference; 1974 1975 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1976 __compressed_pair_elem(__default_init_tag) {} 1977 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1978 __compressed_pair_elem(__value_init_tag) : __value_() {} 1979 1980 template <class _Up, class = typename enable_if< 1981 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value 1982 >::type> 1983 _LIBCPP_INLINE_VISIBILITY 1984 _LIBCPP_CONSTEXPR explicit 1985 __compressed_pair_elem(_Up&& __u) 1986 : __value_(_VSTD::forward<_Up>(__u)) 1987 { 1988 } 1989 1990 1991#ifndef _LIBCPP_CXX03_LANG 1992 template <class... _Args, size_t... _Indexes> 1993 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1994 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, 1995 __tuple_indices<_Indexes...>) 1996 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} 1997#endif 1998 1999 2000 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } 2001 _LIBCPP_INLINE_VISIBILITY 2002 const_reference __get() const _NOEXCEPT { return __value_; } 2003 2004private: 2005 _Tp __value_; 2006}; 2007 2008template <class _Tp, int _Idx> 2009struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { 2010 typedef _Tp _ParamT; 2011 typedef _Tp& reference; 2012 typedef const _Tp& const_reference; 2013 typedef _Tp __value_type; 2014 2015 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __compressed_pair_elem() = default; 2016 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 2017 __compressed_pair_elem(__default_init_tag) {} 2018 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 2019 __compressed_pair_elem(__value_init_tag) : __value_type() {} 2020 2021 template <class _Up, class = typename enable_if< 2022 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value 2023 >::type> 2024 _LIBCPP_INLINE_VISIBILITY 2025 _LIBCPP_CONSTEXPR explicit 2026 __compressed_pair_elem(_Up&& __u) 2027 : __value_type(_VSTD::forward<_Up>(__u)) 2028 {} 2029 2030#ifndef _LIBCPP_CXX03_LANG 2031 template <class... _Args, size_t... _Indexes> 2032 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2033 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, 2034 __tuple_indices<_Indexes...>) 2035 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} 2036#endif 2037 2038 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } 2039 _LIBCPP_INLINE_VISIBILITY 2040 const_reference __get() const _NOEXCEPT { return *this; } 2041}; 2042 2043template <class _T1, class _T2> 2044class __compressed_pair : private __compressed_pair_elem<_T1, 0>, 2045 private __compressed_pair_elem<_T2, 1> { 2046 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1; 2047 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2; 2048 2049 // NOTE: This static assert should never fire because __compressed_pair 2050 // is *almost never* used in a scenario where it's possible for T1 == T2. 2051 // (The exception is std::function where it is possible that the function 2052 // object and the allocator have the same type). 2053 static_assert((!is_same<_T1, _T2>::value), 2054 "__compressed_pair cannot be instantated when T1 and T2 are the same type; " 2055 "The current implementation is NOT ABI-compatible with the previous " 2056 "implementation for this configuration"); 2057 2058public: 2059 template <bool _Dummy = true, 2060 class = typename enable_if< 2061 __dependent_type<is_default_constructible<_T1>, _Dummy>::value && 2062 __dependent_type<is_default_constructible<_T2>, _Dummy>::value 2063 >::type 2064 > 2065 _LIBCPP_INLINE_VISIBILITY 2066 _LIBCPP_CONSTEXPR __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} 2067 2068 template <class _U1, class _U2> 2069 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 2070 __compressed_pair(_U1&& __t1, _U2&& __t2) 2071 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} 2072 2073#ifndef _LIBCPP_CXX03_LANG 2074 template <class... _Args1, class... _Args2> 2075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2076 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, 2077 tuple<_Args2...> __second_args) 2078 : _Base1(__pc, _VSTD::move(__first_args), 2079 typename __make_tuple_indices<sizeof...(_Args1)>::type()), 2080 _Base2(__pc, _VSTD::move(__second_args), 2081 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} 2082#endif 2083 2084 _LIBCPP_INLINE_VISIBILITY 2085 typename _Base1::reference first() _NOEXCEPT { 2086 return static_cast<_Base1&>(*this).__get(); 2087 } 2088 2089 _LIBCPP_INLINE_VISIBILITY 2090 typename _Base1::const_reference first() const _NOEXCEPT { 2091 return static_cast<_Base1 const&>(*this).__get(); 2092 } 2093 2094 _LIBCPP_INLINE_VISIBILITY 2095 typename _Base2::reference second() _NOEXCEPT { 2096 return static_cast<_Base2&>(*this).__get(); 2097 } 2098 2099 _LIBCPP_INLINE_VISIBILITY 2100 typename _Base2::const_reference second() const _NOEXCEPT { 2101 return static_cast<_Base2 const&>(*this).__get(); 2102 } 2103 2104 _LIBCPP_INLINE_VISIBILITY 2105 void swap(__compressed_pair& __x) 2106 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2107 __is_nothrow_swappable<_T2>::value) 2108 { 2109 using std::swap; 2110 swap(first(), __x.first()); 2111 swap(second(), __x.second()); 2112 } 2113}; 2114 2115template <class _T1, class _T2> 2116inline _LIBCPP_INLINE_VISIBILITY 2117void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) 2118 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2119 __is_nothrow_swappable<_T2>::value) { 2120 __x.swap(__y); 2121} 2122 2123// default_delete 2124 2125template <class _Tp> 2126struct _LIBCPP_TEMPLATE_VIS default_delete { 2127 static_assert(!is_function<_Tp>::value, 2128 "default_delete cannot be instantiated for function types"); 2129#ifndef _LIBCPP_CXX03_LANG 2130 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; 2131#else 2132 _LIBCPP_INLINE_VISIBILITY default_delete() {} 2133#endif 2134 template <class _Up> 2135 _LIBCPP_INLINE_VISIBILITY 2136 default_delete(const default_delete<_Up>&, 2137 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 2138 0) _NOEXCEPT {} 2139 2140 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT { 2141 static_assert(sizeof(_Tp) > 0, 2142 "default_delete can not delete incomplete type"); 2143 static_assert(!is_void<_Tp>::value, 2144 "default_delete can not delete incomplete type"); 2145 delete __ptr; 2146 } 2147}; 2148 2149template <class _Tp> 2150struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { 2151private: 2152 template <class _Up> 2153 struct _EnableIfConvertible 2154 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; 2155 2156public: 2157#ifndef _LIBCPP_CXX03_LANG 2158 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; 2159#else 2160 _LIBCPP_INLINE_VISIBILITY default_delete() {} 2161#endif 2162 2163 template <class _Up> 2164 _LIBCPP_INLINE_VISIBILITY 2165 default_delete(const default_delete<_Up[]>&, 2166 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} 2167 2168 template <class _Up> 2169 _LIBCPP_INLINE_VISIBILITY 2170 typename _EnableIfConvertible<_Up>::type 2171 operator()(_Up* __ptr) const _NOEXCEPT { 2172 static_assert(sizeof(_Tp) > 0, 2173 "default_delete can not delete incomplete type"); 2174 static_assert(!is_void<_Tp>::value, 2175 "default_delete can not delete void type"); 2176 delete[] __ptr; 2177 } 2178}; 2179 2180template <class _Deleter> 2181struct __unique_ptr_deleter_sfinae { 2182 static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); 2183 typedef const _Deleter& __lval_ref_type; 2184 typedef _Deleter&& __good_rval_ref_type; 2185 typedef true_type __enable_rval_overload; 2186}; 2187 2188template <class _Deleter> 2189struct __unique_ptr_deleter_sfinae<_Deleter const&> { 2190 typedef const _Deleter& __lval_ref_type; 2191 typedef const _Deleter&& __bad_rval_ref_type; 2192 typedef false_type __enable_rval_overload; 2193}; 2194 2195template <class _Deleter> 2196struct __unique_ptr_deleter_sfinae<_Deleter&> { 2197 typedef _Deleter& __lval_ref_type; 2198 typedef _Deleter&& __bad_rval_ref_type; 2199 typedef false_type __enable_rval_overload; 2200}; 2201 2202#if defined(_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI) 2203# define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI __attribute__((trivial_abi)) 2204#else 2205# define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI 2206#endif 2207 2208template <class _Tp, class _Dp = default_delete<_Tp> > 2209class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr { 2210public: 2211 typedef _Tp element_type; 2212 typedef _Dp deleter_type; 2213 typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type<_Tp, deleter_type>::type pointer; 2214 2215 static_assert(!is_rvalue_reference<deleter_type>::value, 2216 "the specified deleter type cannot be an rvalue reference"); 2217 2218private: 2219 __compressed_pair<pointer, deleter_type> __ptr_; 2220 2221 struct __nat { int __for_bool_; }; 2222 2223 typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; 2224 2225 template <bool _Dummy> 2226 using _LValRefType _LIBCPP_NODEBUG_TYPE = 2227 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; 2228 2229 template <bool _Dummy> 2230 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE = 2231 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; 2232 2233 template <bool _Dummy> 2234 using _BadRValRefType _LIBCPP_NODEBUG_TYPE = 2235 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; 2236 2237 template <bool _Dummy, class _Deleter = typename __dependent_type< 2238 __identity<deleter_type>, _Dummy>::type> 2239 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE = 2240 typename enable_if<is_default_constructible<_Deleter>::value && 2241 !is_pointer<_Deleter>::value>::type; 2242 2243 template <class _ArgType> 2244 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE = 2245 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; 2246 2247 template <class _UPtr, class _Up> 2248 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< 2249 is_convertible<typename _UPtr::pointer, pointer>::value && 2250 !is_array<_Up>::value 2251 >::type; 2252 2253 template <class _UDel> 2254 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< 2255 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || 2256 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) 2257 >::type; 2258 2259 template <class _UDel> 2260 using _EnableIfDeleterAssignable = typename enable_if< 2261 is_assignable<_Dp&, _UDel&&>::value 2262 >::type; 2263 2264public: 2265 template <bool _Dummy = true, 2266 class = _EnableIfDeleterDefaultConstructible<_Dummy> > 2267 _LIBCPP_INLINE_VISIBILITY 2268 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} 2269 2270 template <bool _Dummy = true, 2271 class = _EnableIfDeleterDefaultConstructible<_Dummy> > 2272 _LIBCPP_INLINE_VISIBILITY 2273 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} 2274 2275 template <bool _Dummy = true, 2276 class = _EnableIfDeleterDefaultConstructible<_Dummy> > 2277 _LIBCPP_INLINE_VISIBILITY 2278 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {} 2279 2280 template <bool _Dummy = true, 2281 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > 2282 _LIBCPP_INLINE_VISIBILITY 2283 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT 2284 : __ptr_(__p, __d) {} 2285 2286 template <bool _Dummy = true, 2287 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > 2288 _LIBCPP_INLINE_VISIBILITY 2289 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT 2290 : __ptr_(__p, _VSTD::move(__d)) { 2291 static_assert(!is_reference<deleter_type>::value, 2292 "rvalue deleter bound to reference"); 2293 } 2294 2295 template <bool _Dummy = true, 2296 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > > 2297 _LIBCPP_INLINE_VISIBILITY 2298 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; 2299 2300 _LIBCPP_INLINE_VISIBILITY 2301 unique_ptr(unique_ptr&& __u) _NOEXCEPT 2302 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { 2303 } 2304 2305 template <class _Up, class _Ep, 2306 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, 2307 class = _EnableIfDeleterConvertible<_Ep> 2308 > 2309 _LIBCPP_INLINE_VISIBILITY 2310 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT 2311 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} 2312 2313#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 2314 template <class _Up> 2315 _LIBCPP_INLINE_VISIBILITY 2316 unique_ptr(auto_ptr<_Up>&& __p, 2317 typename enable_if<is_convertible<_Up*, _Tp*>::value && 2318 is_same<_Dp, default_delete<_Tp> >::value, 2319 __nat>::type = __nat()) _NOEXCEPT 2320 : __ptr_(__p.release(), __default_init_tag()) {} 2321#endif 2322 2323 _LIBCPP_INLINE_VISIBILITY 2324 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { 2325 reset(__u.release()); 2326 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); 2327 return *this; 2328 } 2329 2330 template <class _Up, class _Ep, 2331 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, 2332 class = _EnableIfDeleterAssignable<_Ep> 2333 > 2334 _LIBCPP_INLINE_VISIBILITY 2335 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { 2336 reset(__u.release()); 2337 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); 2338 return *this; 2339 } 2340 2341#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 2342 template <class _Up> 2343 _LIBCPP_INLINE_VISIBILITY 2344 typename enable_if<is_convertible<_Up*, _Tp*>::value && 2345 is_same<_Dp, default_delete<_Tp> >::value, 2346 unique_ptr&>::type 2347 operator=(auto_ptr<_Up> __p) { 2348 reset(__p.release()); 2349 return *this; 2350 } 2351#endif 2352 2353#ifdef _LIBCPP_CXX03_LANG 2354 unique_ptr(unique_ptr const&) = delete; 2355 unique_ptr& operator=(unique_ptr const&) = delete; 2356#endif 2357 2358 2359 _LIBCPP_INLINE_VISIBILITY 2360 ~unique_ptr() { reset(); } 2361 2362 _LIBCPP_INLINE_VISIBILITY 2363 unique_ptr& operator=(nullptr_t) _NOEXCEPT { 2364 reset(); 2365 return *this; 2366 } 2367 2368 _LIBCPP_INLINE_VISIBILITY 2369 typename add_lvalue_reference<_Tp>::type 2370 operator*() const { 2371 return *__ptr_.first(); 2372 } 2373 _LIBCPP_INLINE_VISIBILITY 2374 pointer operator->() const _NOEXCEPT { 2375 return __ptr_.first(); 2376 } 2377 _LIBCPP_INLINE_VISIBILITY 2378 pointer get() const _NOEXCEPT { 2379 return __ptr_.first(); 2380 } 2381 _LIBCPP_INLINE_VISIBILITY 2382 deleter_type& get_deleter() _NOEXCEPT { 2383 return __ptr_.second(); 2384 } 2385 _LIBCPP_INLINE_VISIBILITY 2386 const deleter_type& get_deleter() const _NOEXCEPT { 2387 return __ptr_.second(); 2388 } 2389 _LIBCPP_INLINE_VISIBILITY 2390 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { 2391 return __ptr_.first() != nullptr; 2392 } 2393 2394 _LIBCPP_INLINE_VISIBILITY 2395 pointer release() _NOEXCEPT { 2396 pointer __t = __ptr_.first(); 2397 __ptr_.first() = pointer(); 2398 return __t; 2399 } 2400 2401 _LIBCPP_INLINE_VISIBILITY 2402 void reset(pointer __p = pointer()) _NOEXCEPT { 2403 pointer __tmp = __ptr_.first(); 2404 __ptr_.first() = __p; 2405 if (__tmp) 2406 __ptr_.second()(__tmp); 2407 } 2408 2409 _LIBCPP_INLINE_VISIBILITY 2410 void swap(unique_ptr& __u) _NOEXCEPT { 2411 __ptr_.swap(__u.__ptr_); 2412 } 2413}; 2414 2415 2416template <class _Tp, class _Dp> 2417class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> { 2418public: 2419 typedef _Tp element_type; 2420 typedef _Dp deleter_type; 2421 typedef typename __pointer_type<_Tp, deleter_type>::type pointer; 2422 2423private: 2424 __compressed_pair<pointer, deleter_type> __ptr_; 2425 2426 template <class _From> 2427 struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; 2428 2429 template <class _FromElem> 2430 struct _CheckArrayPointerConversion<_FromElem*> 2431 : integral_constant<bool, 2432 is_same<_FromElem*, pointer>::value || 2433 (is_same<pointer, element_type*>::value && 2434 is_convertible<_FromElem(*)[], element_type(*)[]>::value) 2435 > 2436 {}; 2437 2438 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; 2439 2440 template <bool _Dummy> 2441 using _LValRefType _LIBCPP_NODEBUG_TYPE = 2442 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; 2443 2444 template <bool _Dummy> 2445 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE = 2446 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; 2447 2448 template <bool _Dummy> 2449 using _BadRValRefType _LIBCPP_NODEBUG_TYPE = 2450 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; 2451 2452 template <bool _Dummy, class _Deleter = typename __dependent_type< 2453 __identity<deleter_type>, _Dummy>::type> 2454 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE = 2455 typename enable_if<is_default_constructible<_Deleter>::value && 2456 !is_pointer<_Deleter>::value>::type; 2457 2458 template <class _ArgType> 2459 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE = 2460 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; 2461 2462 template <class _Pp> 2463 using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< 2464 _CheckArrayPointerConversion<_Pp>::value 2465 >::type; 2466 2467 template <class _UPtr, class _Up, 2468 class _ElemT = typename _UPtr::element_type> 2469 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< 2470 is_array<_Up>::value && 2471 is_same<pointer, element_type*>::value && 2472 is_same<typename _UPtr::pointer, _ElemT*>::value && 2473 is_convertible<_ElemT(*)[], element_type(*)[]>::value 2474 >::type; 2475 2476 template <class _UDel> 2477 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< 2478 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || 2479 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) 2480 >::type; 2481 2482 template <class _UDel> 2483 using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if< 2484 is_assignable<_Dp&, _UDel&&>::value 2485 >::type; 2486 2487public: 2488 template <bool _Dummy = true, 2489 class = _EnableIfDeleterDefaultConstructible<_Dummy> > 2490 _LIBCPP_INLINE_VISIBILITY 2491 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} 2492 2493 template <bool _Dummy = true, 2494 class = _EnableIfDeleterDefaultConstructible<_Dummy> > 2495 _LIBCPP_INLINE_VISIBILITY 2496 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} 2497 2498 template <class _Pp, bool _Dummy = true, 2499 class = _EnableIfDeleterDefaultConstructible<_Dummy>, 2500 class = _EnableIfPointerConvertible<_Pp> > 2501 _LIBCPP_INLINE_VISIBILITY 2502 explicit unique_ptr(_Pp __p) _NOEXCEPT 2503 : __ptr_(__p, __default_init_tag()) {} 2504 2505 template <class _Pp, bool _Dummy = true, 2506 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >, 2507 class = _EnableIfPointerConvertible<_Pp> > 2508 _LIBCPP_INLINE_VISIBILITY 2509 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT 2510 : __ptr_(__p, __d) {} 2511 2512 template <bool _Dummy = true, 2513 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > 2514 _LIBCPP_INLINE_VISIBILITY 2515 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT 2516 : __ptr_(nullptr, __d) {} 2517 2518 template <class _Pp, bool _Dummy = true, 2519 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >, 2520 class = _EnableIfPointerConvertible<_Pp> > 2521 _LIBCPP_INLINE_VISIBILITY 2522 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT 2523 : __ptr_(__p, _VSTD::move(__d)) { 2524 static_assert(!is_reference<deleter_type>::value, 2525 "rvalue deleter bound to reference"); 2526 } 2527 2528 template <bool _Dummy = true, 2529 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > 2530 _LIBCPP_INLINE_VISIBILITY 2531 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT 2532 : __ptr_(nullptr, _VSTD::move(__d)) { 2533 static_assert(!is_reference<deleter_type>::value, 2534 "rvalue deleter bound to reference"); 2535 } 2536 2537 template <class _Pp, bool _Dummy = true, 2538 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >, 2539 class = _EnableIfPointerConvertible<_Pp> > 2540 _LIBCPP_INLINE_VISIBILITY 2541 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; 2542 2543 _LIBCPP_INLINE_VISIBILITY 2544 unique_ptr(unique_ptr&& __u) _NOEXCEPT 2545 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { 2546 } 2547 2548 _LIBCPP_INLINE_VISIBILITY 2549 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { 2550 reset(__u.release()); 2551 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); 2552 return *this; 2553 } 2554 2555 template <class _Up, class _Ep, 2556 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, 2557 class = _EnableIfDeleterConvertible<_Ep> 2558 > 2559 _LIBCPP_INLINE_VISIBILITY 2560 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT 2561 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { 2562 } 2563 2564 template <class _Up, class _Ep, 2565 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, 2566 class = _EnableIfDeleterAssignable<_Ep> 2567 > 2568 _LIBCPP_INLINE_VISIBILITY 2569 unique_ptr& 2570 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { 2571 reset(__u.release()); 2572 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); 2573 return *this; 2574 } 2575 2576#ifdef _LIBCPP_CXX03_LANG 2577 unique_ptr(unique_ptr const&) = delete; 2578 unique_ptr& operator=(unique_ptr const&) = delete; 2579#endif 2580 2581public: 2582 _LIBCPP_INLINE_VISIBILITY 2583 ~unique_ptr() { reset(); } 2584 2585 _LIBCPP_INLINE_VISIBILITY 2586 unique_ptr& operator=(nullptr_t) _NOEXCEPT { 2587 reset(); 2588 return *this; 2589 } 2590 2591 _LIBCPP_INLINE_VISIBILITY 2592 typename add_lvalue_reference<_Tp>::type 2593 operator[](size_t __i) const { 2594 return __ptr_.first()[__i]; 2595 } 2596 _LIBCPP_INLINE_VISIBILITY 2597 pointer get() const _NOEXCEPT { 2598 return __ptr_.first(); 2599 } 2600 2601 _LIBCPP_INLINE_VISIBILITY 2602 deleter_type& get_deleter() _NOEXCEPT { 2603 return __ptr_.second(); 2604 } 2605 2606 _LIBCPP_INLINE_VISIBILITY 2607 const deleter_type& get_deleter() const _NOEXCEPT { 2608 return __ptr_.second(); 2609 } 2610 _LIBCPP_INLINE_VISIBILITY 2611 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { 2612 return __ptr_.first() != nullptr; 2613 } 2614 2615 _LIBCPP_INLINE_VISIBILITY 2616 pointer release() _NOEXCEPT { 2617 pointer __t = __ptr_.first(); 2618 __ptr_.first() = pointer(); 2619 return __t; 2620 } 2621 2622 template <class _Pp> 2623 _LIBCPP_INLINE_VISIBILITY 2624 typename enable_if< 2625 _CheckArrayPointerConversion<_Pp>::value 2626 >::type 2627 reset(_Pp __p) _NOEXCEPT { 2628 pointer __tmp = __ptr_.first(); 2629 __ptr_.first() = __p; 2630 if (__tmp) 2631 __ptr_.second()(__tmp); 2632 } 2633 2634 _LIBCPP_INLINE_VISIBILITY 2635 void reset(nullptr_t = nullptr) _NOEXCEPT { 2636 pointer __tmp = __ptr_.first(); 2637 __ptr_.first() = nullptr; 2638 if (__tmp) 2639 __ptr_.second()(__tmp); 2640 } 2641 2642 _LIBCPP_INLINE_VISIBILITY 2643 void swap(unique_ptr& __u) _NOEXCEPT { 2644 __ptr_.swap(__u.__ptr_); 2645 } 2646 2647}; 2648 2649template <class _Tp, class _Dp> 2650inline _LIBCPP_INLINE_VISIBILITY 2651typename enable_if< 2652 __is_swappable<_Dp>::value, 2653 void 2654>::type 2655swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);} 2656 2657template <class _T1, class _D1, class _T2, class _D2> 2658inline _LIBCPP_INLINE_VISIBILITY 2659bool 2660operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} 2661 2662template <class _T1, class _D1, class _T2, class _D2> 2663inline _LIBCPP_INLINE_VISIBILITY 2664bool 2665operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} 2666 2667template <class _T1, class _D1, class _T2, class _D2> 2668inline _LIBCPP_INLINE_VISIBILITY 2669bool 2670operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) 2671{ 2672 typedef typename unique_ptr<_T1, _D1>::pointer _P1; 2673 typedef typename unique_ptr<_T2, _D2>::pointer _P2; 2674 typedef typename common_type<_P1, _P2>::type _Vp; 2675 return less<_Vp>()(__x.get(), __y.get()); 2676} 2677 2678template <class _T1, class _D1, class _T2, class _D2> 2679inline _LIBCPP_INLINE_VISIBILITY 2680bool 2681operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} 2682 2683template <class _T1, class _D1, class _T2, class _D2> 2684inline _LIBCPP_INLINE_VISIBILITY 2685bool 2686operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} 2687 2688template <class _T1, class _D1, class _T2, class _D2> 2689inline _LIBCPP_INLINE_VISIBILITY 2690bool 2691operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} 2692 2693template <class _T1, class _D1> 2694inline _LIBCPP_INLINE_VISIBILITY 2695bool 2696operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT 2697{ 2698 return !__x; 2699} 2700 2701template <class _T1, class _D1> 2702inline _LIBCPP_INLINE_VISIBILITY 2703bool 2704operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT 2705{ 2706 return !__x; 2707} 2708 2709template <class _T1, class _D1> 2710inline _LIBCPP_INLINE_VISIBILITY 2711bool 2712operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT 2713{ 2714 return static_cast<bool>(__x); 2715} 2716 2717template <class _T1, class _D1> 2718inline _LIBCPP_INLINE_VISIBILITY 2719bool 2720operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT 2721{ 2722 return static_cast<bool>(__x); 2723} 2724 2725template <class _T1, class _D1> 2726inline _LIBCPP_INLINE_VISIBILITY 2727bool 2728operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) 2729{ 2730 typedef typename unique_ptr<_T1, _D1>::pointer _P1; 2731 return less<_P1>()(__x.get(), nullptr); 2732} 2733 2734template <class _T1, class _D1> 2735inline _LIBCPP_INLINE_VISIBILITY 2736bool 2737operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) 2738{ 2739 typedef typename unique_ptr<_T1, _D1>::pointer _P1; 2740 return less<_P1>()(nullptr, __x.get()); 2741} 2742 2743template <class _T1, class _D1> 2744inline _LIBCPP_INLINE_VISIBILITY 2745bool 2746operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) 2747{ 2748 return nullptr < __x; 2749} 2750 2751template <class _T1, class _D1> 2752inline _LIBCPP_INLINE_VISIBILITY 2753bool 2754operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) 2755{ 2756 return __x < nullptr; 2757} 2758 2759template <class _T1, class _D1> 2760inline _LIBCPP_INLINE_VISIBILITY 2761bool 2762operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) 2763{ 2764 return !(nullptr < __x); 2765} 2766 2767template <class _T1, class _D1> 2768inline _LIBCPP_INLINE_VISIBILITY 2769bool 2770operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) 2771{ 2772 return !(__x < nullptr); 2773} 2774 2775template <class _T1, class _D1> 2776inline _LIBCPP_INLINE_VISIBILITY 2777bool 2778operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) 2779{ 2780 return !(__x < nullptr); 2781} 2782 2783template <class _T1, class _D1> 2784inline _LIBCPP_INLINE_VISIBILITY 2785bool 2786operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) 2787{ 2788 return !(nullptr < __x); 2789} 2790 2791#if _LIBCPP_STD_VER > 11 2792 2793template<class _Tp> 2794struct __unique_if 2795{ 2796 typedef unique_ptr<_Tp> __unique_single; 2797}; 2798 2799template<class _Tp> 2800struct __unique_if<_Tp[]> 2801{ 2802 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; 2803}; 2804 2805template<class _Tp, size_t _Np> 2806struct __unique_if<_Tp[_Np]> 2807{ 2808 typedef void __unique_array_known_bound; 2809}; 2810 2811template<class _Tp, class... _Args> 2812inline _LIBCPP_INLINE_VISIBILITY 2813typename __unique_if<_Tp>::__unique_single 2814make_unique(_Args&&... __args) 2815{ 2816 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); 2817} 2818 2819template<class _Tp> 2820inline _LIBCPP_INLINE_VISIBILITY 2821typename __unique_if<_Tp>::__unique_array_unknown_bound 2822make_unique(size_t __n) 2823{ 2824 typedef typename remove_extent<_Tp>::type _Up; 2825 return unique_ptr<_Tp>(new _Up[__n]()); 2826} 2827 2828template<class _Tp, class... _Args> 2829 typename __unique_if<_Tp>::__unique_array_known_bound 2830 make_unique(_Args&&...) = delete; 2831 2832#endif // _LIBCPP_STD_VER > 11 2833 2834template <class _Tp, class _Dp> 2835#ifdef _LIBCPP_CXX03_LANG 2836struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> > 2837#else 2838struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< 2839 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> > 2840#endif 2841{ 2842 typedef unique_ptr<_Tp, _Dp> argument_type; 2843 typedef size_t result_type; 2844 _LIBCPP_INLINE_VISIBILITY 2845 result_type operator()(const argument_type& __ptr) const 2846 { 2847 typedef typename argument_type::pointer pointer; 2848 return hash<pointer>()(__ptr.get()); 2849 } 2850}; 2851 2852struct __destruct_n 2853{ 2854private: 2855 size_t __size_; 2856 2857 template <class _Tp> 2858 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT 2859 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} 2860 2861 template <class _Tp> 2862 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT 2863 {} 2864 2865 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT 2866 {++__size_;} 2867 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT 2868 {} 2869 2870 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT 2871 {__size_ = __s;} 2872 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT 2873 {} 2874public: 2875 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT 2876 : __size_(__s) {} 2877 2878 template <class _Tp> 2879 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT 2880 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 2881 2882 template <class _Tp> 2883 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT 2884 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 2885 2886 template <class _Tp> 2887 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT 2888 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 2889}; 2890 2891template <class _Alloc> 2892class __allocator_destructor 2893{ 2894 typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits; 2895public: 2896 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer; 2897 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type; 2898private: 2899 _Alloc& __alloc_; 2900 size_type __s_; 2901public: 2902 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) 2903 _NOEXCEPT 2904 : __alloc_(__a), __s_(__s) {} 2905 _LIBCPP_INLINE_VISIBILITY 2906 void operator()(pointer __p) _NOEXCEPT 2907 {__alloc_traits::deallocate(__alloc_, __p, __s_);} 2908}; 2909 2910template <class _InputIterator, class _ForwardIterator> 2911_ForwardIterator 2912uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) 2913{ 2914 typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 2915#ifndef _LIBCPP_NO_EXCEPTIONS 2916 _ForwardIterator __s = __r; 2917 try 2918 { 2919#endif 2920 for (; __f != __l; ++__f, (void) ++__r) 2921 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); 2922#ifndef _LIBCPP_NO_EXCEPTIONS 2923 } 2924 catch (...) 2925 { 2926 for (; __s != __r; ++__s) 2927 __s->~value_type(); 2928 throw; 2929 } 2930#endif 2931 return __r; 2932} 2933 2934template <class _InputIterator, class _Size, class _ForwardIterator> 2935_ForwardIterator 2936uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) 2937{ 2938 typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 2939#ifndef _LIBCPP_NO_EXCEPTIONS 2940 _ForwardIterator __s = __r; 2941 try 2942 { 2943#endif 2944 for (; __n > 0; ++__f, (void) ++__r, (void) --__n) 2945 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); 2946#ifndef _LIBCPP_NO_EXCEPTIONS 2947 } 2948 catch (...) 2949 { 2950 for (; __s != __r; ++__s) 2951 __s->~value_type(); 2952 throw; 2953 } 2954#endif 2955 return __r; 2956} 2957 2958template <class _ForwardIterator, class _Tp> 2959void 2960uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) 2961{ 2962 typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 2963#ifndef _LIBCPP_NO_EXCEPTIONS 2964 _ForwardIterator __s = __f; 2965 try 2966 { 2967#endif 2968 for (; __f != __l; ++__f) 2969 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); 2970#ifndef _LIBCPP_NO_EXCEPTIONS 2971 } 2972 catch (...) 2973 { 2974 for (; __s != __f; ++__s) 2975 __s->~value_type(); 2976 throw; 2977 } 2978#endif 2979} 2980 2981template <class _ForwardIterator, class _Size, class _Tp> 2982_ForwardIterator 2983uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) 2984{ 2985 typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 2986#ifndef _LIBCPP_NO_EXCEPTIONS 2987 _ForwardIterator __s = __f; 2988 try 2989 { 2990#endif 2991 for (; __n > 0; ++__f, (void) --__n) 2992 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); 2993#ifndef _LIBCPP_NO_EXCEPTIONS 2994 } 2995 catch (...) 2996 { 2997 for (; __s != __f; ++__s) 2998 __s->~value_type(); 2999 throw; 3000 } 3001#endif 3002 return __f; 3003} 3004 3005#if _LIBCPP_STD_VER > 14 3006 3007template <class _ForwardIterator> 3008inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 3009void destroy(_ForwardIterator __first, _ForwardIterator __last) { 3010 for (; __first != __last; ++__first) 3011 _VSTD::destroy_at(_VSTD::addressof(*__first)); 3012} 3013 3014template <class _ForwardIterator, class _Size> 3015inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 3016_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { 3017 for (; __n > 0; (void)++__first, --__n) 3018 _VSTD::destroy_at(_VSTD::addressof(*__first)); 3019 return __first; 3020} 3021 3022template <class _ForwardIterator> 3023inline _LIBCPP_INLINE_VISIBILITY 3024void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { 3025 using _Vt = typename iterator_traits<_ForwardIterator>::value_type; 3026 auto __idx = __first; 3027#ifndef _LIBCPP_NO_EXCEPTIONS 3028 try { 3029#endif 3030 for (; __idx != __last; ++__idx) 3031 ::new((void*)_VSTD::addressof(*__idx)) _Vt; 3032#ifndef _LIBCPP_NO_EXCEPTIONS 3033 } catch (...) { 3034 _VSTD::destroy(__first, __idx); 3035 throw; 3036 } 3037#endif 3038} 3039 3040template <class _ForwardIterator, class _Size> 3041inline _LIBCPP_INLINE_VISIBILITY 3042_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { 3043 using _Vt = typename iterator_traits<_ForwardIterator>::value_type; 3044 auto __idx = __first; 3045#ifndef _LIBCPP_NO_EXCEPTIONS 3046 try { 3047#endif 3048 for (; __n > 0; (void)++__idx, --__n) 3049 ::new((void*)_VSTD::addressof(*__idx)) _Vt; 3050 return __idx; 3051#ifndef _LIBCPP_NO_EXCEPTIONS 3052 } catch (...) { 3053 _VSTD::destroy(__first, __idx); 3054 throw; 3055 } 3056#endif 3057} 3058 3059 3060template <class _ForwardIterator> 3061inline _LIBCPP_INLINE_VISIBILITY 3062void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { 3063 using _Vt = typename iterator_traits<_ForwardIterator>::value_type; 3064 auto __idx = __first; 3065#ifndef _LIBCPP_NO_EXCEPTIONS 3066 try { 3067#endif 3068 for (; __idx != __last; ++__idx) 3069 ::new((void*)_VSTD::addressof(*__idx)) _Vt(); 3070#ifndef _LIBCPP_NO_EXCEPTIONS 3071 } catch (...) { 3072 _VSTD::destroy(__first, __idx); 3073 throw; 3074 } 3075#endif 3076} 3077 3078template <class _ForwardIterator, class _Size> 3079inline _LIBCPP_INLINE_VISIBILITY 3080_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { 3081 using _Vt = typename iterator_traits<_ForwardIterator>::value_type; 3082 auto __idx = __first; 3083#ifndef _LIBCPP_NO_EXCEPTIONS 3084 try { 3085#endif 3086 for (; __n > 0; (void)++__idx, --__n) 3087 ::new((void*)_VSTD::addressof(*__idx)) _Vt(); 3088 return __idx; 3089#ifndef _LIBCPP_NO_EXCEPTIONS 3090 } catch (...) { 3091 _VSTD::destroy(__first, __idx); 3092 throw; 3093 } 3094#endif 3095} 3096 3097 3098template <class _InputIt, class _ForwardIt> 3099inline _LIBCPP_INLINE_VISIBILITY 3100_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) { 3101 using _Vt = typename iterator_traits<_ForwardIt>::value_type; 3102 auto __idx = __first_res; 3103#ifndef _LIBCPP_NO_EXCEPTIONS 3104 try { 3105#endif 3106 for (; __first != __last; (void)++__idx, ++__first) 3107 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); 3108 return __idx; 3109#ifndef _LIBCPP_NO_EXCEPTIONS 3110 } catch (...) { 3111 _VSTD::destroy(__first_res, __idx); 3112 throw; 3113 } 3114#endif 3115} 3116 3117template <class _InputIt, class _Size, class _ForwardIt> 3118inline _LIBCPP_INLINE_VISIBILITY 3119pair<_InputIt, _ForwardIt> 3120uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { 3121 using _Vt = typename iterator_traits<_ForwardIt>::value_type; 3122 auto __idx = __first_res; 3123#ifndef _LIBCPP_NO_EXCEPTIONS 3124 try { 3125#endif 3126 for (; __n > 0; ++__idx, (void)++__first, --__n) 3127 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); 3128 return {__first, __idx}; 3129#ifndef _LIBCPP_NO_EXCEPTIONS 3130 } catch (...) { 3131 _VSTD::destroy(__first_res, __idx); 3132 throw; 3133 } 3134#endif 3135} 3136 3137 3138#endif // _LIBCPP_STD_VER > 14 3139 3140// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) 3141// should be sufficient for thread safety. 3142// See https://bugs.llvm.org/show_bug.cgi?id=22803 3143#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \ 3144 && defined(__ATOMIC_RELAXED) \ 3145 && defined(__ATOMIC_ACQ_REL) 3146# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT 3147#elif defined(_LIBCPP_COMPILER_GCC) 3148# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT 3149#endif 3150 3151template <class _Tp> 3152inline _LIBCPP_INLINE_VISIBILITY _Tp 3153__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT 3154{ 3155#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) 3156 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED); 3157#else 3158 return __t += 1; 3159#endif 3160} 3161 3162template <class _Tp> 3163inline _LIBCPP_INLINE_VISIBILITY _Tp 3164__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT 3165{ 3166#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) 3167 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); 3168#else 3169 return __t -= 1; 3170#endif 3171} 3172 3173class _LIBCPP_EXCEPTION_ABI bad_weak_ptr 3174 : public std::exception 3175{ 3176public: 3177 bad_weak_ptr() _NOEXCEPT = default; 3178 bad_weak_ptr(const bad_weak_ptr&) _NOEXCEPT = default; 3179 virtual ~bad_weak_ptr() _NOEXCEPT; 3180 virtual const char* what() const _NOEXCEPT; 3181}; 3182 3183_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 3184void __throw_bad_weak_ptr() 3185{ 3186#ifndef _LIBCPP_NO_EXCEPTIONS 3187 throw bad_weak_ptr(); 3188#else 3189 _VSTD::abort(); 3190#endif 3191} 3192 3193template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; 3194 3195class _LIBCPP_TYPE_VIS __shared_count 3196{ 3197 __shared_count(const __shared_count&); 3198 __shared_count& operator=(const __shared_count&); 3199 3200protected: 3201 long __shared_owners_; 3202 virtual ~__shared_count(); 3203private: 3204 virtual void __on_zero_shared() _NOEXCEPT = 0; 3205 3206public: 3207 _LIBCPP_INLINE_VISIBILITY 3208 explicit __shared_count(long __refs = 0) _NOEXCEPT 3209 : __shared_owners_(__refs) {} 3210 3211#if defined(_LIBCPP_BUILDING_LIBRARY) && \ 3212 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) 3213 void __add_shared() _NOEXCEPT; 3214 bool __release_shared() _NOEXCEPT; 3215#else 3216 _LIBCPP_INLINE_VISIBILITY 3217 void __add_shared() _NOEXCEPT { 3218 __libcpp_atomic_refcount_increment(__shared_owners_); 3219 } 3220 _LIBCPP_INLINE_VISIBILITY 3221 bool __release_shared() _NOEXCEPT { 3222 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { 3223 __on_zero_shared(); 3224 return true; 3225 } 3226 return false; 3227 } 3228#endif 3229 _LIBCPP_INLINE_VISIBILITY 3230 long use_count() const _NOEXCEPT { 3231 return __libcpp_relaxed_load(&__shared_owners_) + 1; 3232 } 3233}; 3234 3235class _LIBCPP_TYPE_VIS __shared_weak_count 3236 : private __shared_count 3237{ 3238 long __shared_weak_owners_; 3239 3240public: 3241 _LIBCPP_INLINE_VISIBILITY 3242 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT 3243 : __shared_count(__refs), 3244 __shared_weak_owners_(__refs) {} 3245protected: 3246 virtual ~__shared_weak_count(); 3247 3248public: 3249#if defined(_LIBCPP_BUILDING_LIBRARY) && \ 3250 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) 3251 void __add_shared() _NOEXCEPT; 3252 void __add_weak() _NOEXCEPT; 3253 void __release_shared() _NOEXCEPT; 3254#else 3255 _LIBCPP_INLINE_VISIBILITY 3256 void __add_shared() _NOEXCEPT { 3257 __shared_count::__add_shared(); 3258 } 3259 _LIBCPP_INLINE_VISIBILITY 3260 void __add_weak() _NOEXCEPT { 3261 __libcpp_atomic_refcount_increment(__shared_weak_owners_); 3262 } 3263 _LIBCPP_INLINE_VISIBILITY 3264 void __release_shared() _NOEXCEPT { 3265 if (__shared_count::__release_shared()) 3266 __release_weak(); 3267 } 3268#endif 3269 void __release_weak() _NOEXCEPT; 3270 _LIBCPP_INLINE_VISIBILITY 3271 long use_count() const _NOEXCEPT {return __shared_count::use_count();} 3272 __shared_weak_count* lock() _NOEXCEPT; 3273 3274 // Define the function out only if we build static libc++ without RTTI. 3275 // Otherwise we may break clients who need to compile their projects with 3276 // -fno-rtti and yet link against a libc++.dylib compiled 3277 // without -fno-rtti. 3278#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) 3279 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; 3280#endif 3281private: 3282 virtual void __on_zero_shared_weak() _NOEXCEPT = 0; 3283}; 3284 3285template <class _Tp, class _Dp, class _Alloc> 3286class __shared_ptr_pointer 3287 : public __shared_weak_count 3288{ 3289 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; 3290public: 3291 _LIBCPP_INLINE_VISIBILITY 3292 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) 3293 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} 3294 3295#ifndef _LIBCPP_NO_RTTI 3296 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; 3297#endif 3298 3299private: 3300 virtual void __on_zero_shared() _NOEXCEPT; 3301 virtual void __on_zero_shared_weak() _NOEXCEPT; 3302}; 3303 3304#ifndef _LIBCPP_NO_RTTI 3305 3306template <class _Tp, class _Dp, class _Alloc> 3307const void* 3308__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT 3309{ 3310 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr; 3311} 3312 3313#endif // _LIBCPP_NO_RTTI 3314 3315template <class _Tp, class _Dp, class _Alloc> 3316void 3317__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT 3318{ 3319 __data_.first().second()(__data_.first().first()); 3320 __data_.first().second().~_Dp(); 3321} 3322 3323template <class _Tp, class _Dp, class _Alloc> 3324void 3325__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT 3326{ 3327 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; 3328 typedef allocator_traits<_Al> _ATraits; 3329 typedef pointer_traits<typename _ATraits::pointer> _PTraits; 3330 3331 _Al __a(__data_.second()); 3332 __data_.second().~_Alloc(); 3333 __a.deallocate(_PTraits::pointer_to(*this), 1); 3334} 3335 3336template <class _Tp, class _Alloc> 3337class __shared_ptr_emplace 3338 : public __shared_weak_count 3339{ 3340 __compressed_pair<_Alloc, _Tp> __data_; 3341public: 3342 3343 _LIBCPP_INLINE_VISIBILITY 3344 __shared_ptr_emplace(_Alloc __a) 3345 : __data_(_VSTD::move(__a), __value_init_tag()) {} 3346 3347#ifndef _LIBCPP_CXX03_LANG 3348 template <class ..._Args> 3349 _LIBCPP_INLINE_VISIBILITY 3350 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) 3351 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), 3352 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} 3353#else 3354 template <class ..._Args> 3355 _LIBCPP_INLINE_VISIBILITY 3356 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) 3357 : __data_(__a, _Tp(_VSTD::forward<_Args>(__args)...)) {} 3358#endif 3359 3360private: 3361 virtual void __on_zero_shared() _NOEXCEPT; 3362 virtual void __on_zero_shared_weak() _NOEXCEPT; 3363public: 3364 _LIBCPP_INLINE_VISIBILITY 3365 _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());} 3366}; 3367 3368template <class _Tp, class _Alloc> 3369void 3370__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT 3371{ 3372 __data_.second().~_Tp(); 3373} 3374 3375template <class _Tp, class _Alloc> 3376void 3377__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT 3378{ 3379 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; 3380 typedef allocator_traits<_Al> _ATraits; 3381 typedef pointer_traits<typename _ATraits::pointer> _PTraits; 3382 _Al __a(__data_.first()); 3383 __data_.first().~_Alloc(); 3384 __a.deallocate(_PTraits::pointer_to(*this), 1); 3385} 3386 3387struct __shared_ptr_dummy_rebind_allocator_type; 3388template <> 3389class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> 3390{ 3391public: 3392 template <class _Other> 3393 struct rebind 3394 { 3395 typedef allocator<_Other> other; 3396 }; 3397}; 3398 3399template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; 3400 3401template<class _Tp, class _Up> 3402struct __compatible_with 3403#if _LIBCPP_STD_VER > 14 3404 : is_convertible<remove_extent_t<_Tp>*, remove_extent_t<_Up>*> {}; 3405#else 3406 : is_convertible<_Tp*, _Up*> {}; 3407#endif // _LIBCPP_STD_VER > 14 3408 3409#if defined(_LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI) 3410# define _LIBCPP_SHARED_PTR_TRIVIAL_ABI __attribute__((trivial_abi)) 3411#else 3412# define _LIBCPP_SHARED_PTR_TRIVIAL_ABI 3413#endif 3414 3415template<class _Tp> 3416class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr 3417{ 3418public: 3419#if _LIBCPP_STD_VER > 14 3420 typedef weak_ptr<_Tp> weak_type; 3421 typedef remove_extent_t<_Tp> element_type; 3422#else 3423 typedef _Tp element_type; 3424#endif 3425 3426private: 3427 element_type* __ptr_; 3428 __shared_weak_count* __cntrl_; 3429 3430 struct __nat {int __for_bool_;}; 3431public: 3432 _LIBCPP_INLINE_VISIBILITY 3433 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; 3434 _LIBCPP_INLINE_VISIBILITY 3435 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; 3436 template<class _Yp> 3437 explicit shared_ptr(_Yp* __p, 3438 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); 3439 template<class _Yp, class _Dp> 3440 shared_ptr(_Yp* __p, _Dp __d, 3441 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); 3442 template<class _Yp, class _Dp, class _Alloc> 3443 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, 3444 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); 3445 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); 3446 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); 3447 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; 3448 _LIBCPP_INLINE_VISIBILITY 3449 shared_ptr(const shared_ptr& __r) _NOEXCEPT; 3450 template<class _Yp> 3451 _LIBCPP_INLINE_VISIBILITY 3452 shared_ptr(const shared_ptr<_Yp>& __r, 3453 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) 3454 _NOEXCEPT; 3455 _LIBCPP_INLINE_VISIBILITY 3456 shared_ptr(shared_ptr&& __r) _NOEXCEPT; 3457 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, 3458 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) 3459 _NOEXCEPT; 3460 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, 3461 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); 3462#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 3463 template<class _Yp> 3464 shared_ptr(auto_ptr<_Yp>&& __r, 3465 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3466#endif 3467 template <class _Yp, class _Dp> 3468 shared_ptr(unique_ptr<_Yp, _Dp>&&, 3469 typename enable_if 3470 < 3471 !is_lvalue_reference<_Dp>::value && 3472 !is_array<_Yp>::value && 3473 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3474 __nat 3475 >::type = __nat()); 3476 template <class _Yp, class _Dp> 3477 shared_ptr(unique_ptr<_Yp, _Dp>&&, 3478 typename enable_if 3479 < 3480 is_lvalue_reference<_Dp>::value && 3481 !is_array<_Yp>::value && 3482 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3483 __nat 3484 >::type = __nat()); 3485 3486 ~shared_ptr(); 3487 3488 _LIBCPP_INLINE_VISIBILITY 3489 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; 3490 template<class _Yp> 3491 typename enable_if 3492 < 3493 __compatible_with<_Yp, element_type>::value, 3494 shared_ptr& 3495 >::type 3496 _LIBCPP_INLINE_VISIBILITY 3497 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; 3498 _LIBCPP_INLINE_VISIBILITY 3499 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; 3500 template<class _Yp> 3501 typename enable_if 3502 < 3503 __compatible_with<_Yp, element_type>::value, 3504 shared_ptr& 3505 >::type 3506 _LIBCPP_INLINE_VISIBILITY 3507 operator=(shared_ptr<_Yp>&& __r); 3508#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 3509 template<class _Yp> 3510 _LIBCPP_INLINE_VISIBILITY 3511 typename enable_if 3512 < 3513 !is_array<_Yp>::value && 3514 is_convertible<_Yp*, element_type*>::value, 3515 shared_ptr 3516 >::type& 3517 operator=(auto_ptr<_Yp>&& __r); 3518#endif 3519 template <class _Yp, class _Dp> 3520 typename enable_if 3521 < 3522 !is_array<_Yp>::value && 3523 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3524 shared_ptr& 3525 >::type 3526 _LIBCPP_INLINE_VISIBILITY 3527 operator=(unique_ptr<_Yp, _Dp>&& __r); 3528 3529 _LIBCPP_INLINE_VISIBILITY 3530 void swap(shared_ptr& __r) _NOEXCEPT; 3531 _LIBCPP_INLINE_VISIBILITY 3532 void reset() _NOEXCEPT; 3533 template<class _Yp> 3534 typename enable_if 3535 < 3536 __compatible_with<_Yp, element_type>::value, 3537 void 3538 >::type 3539 _LIBCPP_INLINE_VISIBILITY 3540 reset(_Yp* __p); 3541 template<class _Yp, class _Dp> 3542 typename enable_if 3543 < 3544 __compatible_with<_Yp, element_type>::value, 3545 void 3546 >::type 3547 _LIBCPP_INLINE_VISIBILITY 3548 reset(_Yp* __p, _Dp __d); 3549 template<class _Yp, class _Dp, class _Alloc> 3550 typename enable_if 3551 < 3552 __compatible_with<_Yp, element_type>::value, 3553 void 3554 >::type 3555 _LIBCPP_INLINE_VISIBILITY 3556 reset(_Yp* __p, _Dp __d, _Alloc __a); 3557 3558 _LIBCPP_INLINE_VISIBILITY 3559 element_type* get() const _NOEXCEPT {return __ptr_;} 3560 _LIBCPP_INLINE_VISIBILITY 3561 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT 3562 {return *__ptr_;} 3563 _LIBCPP_INLINE_VISIBILITY 3564 element_type* operator->() const _NOEXCEPT 3565 { 3566 static_assert(!_VSTD::is_array<_Tp>::value, 3567 "std::shared_ptr<T>::operator-> is only valid when T is not an array type."); 3568 return __ptr_; 3569 } 3570 _LIBCPP_INLINE_VISIBILITY 3571 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} 3572 _LIBCPP_INLINE_VISIBILITY 3573 bool unique() const _NOEXCEPT {return use_count() == 1;} 3574 _LIBCPP_INLINE_VISIBILITY 3575 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} 3576 template <class _Up> 3577 _LIBCPP_INLINE_VISIBILITY 3578 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT 3579 {return __cntrl_ < __p.__cntrl_;} 3580 template <class _Up> 3581 _LIBCPP_INLINE_VISIBILITY 3582 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT 3583 {return __cntrl_ < __p.__cntrl_;} 3584 _LIBCPP_INLINE_VISIBILITY 3585 bool 3586 __owner_equivalent(const shared_ptr& __p) const 3587 {return __cntrl_ == __p.__cntrl_;} 3588 3589#if _LIBCPP_STD_VER > 14 3590 typename add_lvalue_reference<element_type>::type 3591 _LIBCPP_INLINE_VISIBILITY 3592 operator[](ptrdiff_t __i) const 3593 { 3594 static_assert(_VSTD::is_array<_Tp>::value, 3595 "std::shared_ptr<T>::operator[] is only valid when T is an array type."); 3596 return __ptr_[__i]; 3597 } 3598#endif 3599 3600#ifndef _LIBCPP_NO_RTTI 3601 template <class _Dp> 3602 _LIBCPP_INLINE_VISIBILITY 3603 _Dp* __get_deleter() const _NOEXCEPT 3604 {return static_cast<_Dp*>(__cntrl_ 3605 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) 3606 : nullptr);} 3607#endif // _LIBCPP_NO_RTTI 3608 3609 template<class _Yp, class _CntrlBlk> 3610 static shared_ptr<_Tp> 3611 __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT 3612 { 3613 shared_ptr<_Tp> __r; 3614 __r.__ptr_ = __p; 3615 __r.__cntrl_ = __cntrl; 3616 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); 3617 return __r; 3618 } 3619 3620private: 3621 template <class _Yp, bool = is_function<_Yp>::value> 3622 struct __shared_ptr_default_allocator 3623 { 3624 typedef allocator<_Yp> type; 3625 }; 3626 3627 template <class _Yp> 3628 struct __shared_ptr_default_allocator<_Yp, true> 3629 { 3630 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; 3631 }; 3632 3633 template <class _Yp, class _OrigPtr> 3634 _LIBCPP_INLINE_VISIBILITY 3635 typename enable_if<is_convertible<_OrigPtr*, 3636 const enable_shared_from_this<_Yp>* 3637 >::value, 3638 void>::type 3639 __enable_weak_this(const enable_shared_from_this<_Yp>* __e, 3640 _OrigPtr* __ptr) _NOEXCEPT 3641 { 3642 typedef typename remove_cv<_Yp>::type _RawYp; 3643 if (__e && __e->__weak_this_.expired()) 3644 { 3645 __e->__weak_this_ = shared_ptr<_RawYp>(*this, 3646 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); 3647 } 3648 } 3649 3650 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} 3651 3652 template <class, class _Yp> 3653 struct __shared_ptr_default_delete 3654 : default_delete<_Yp> {}; 3655 3656 template <class _Yp, class _Un, size_t _Sz> 3657 struct __shared_ptr_default_delete<_Yp[_Sz], _Un> 3658 : default_delete<_Yp[]> {}; 3659 3660 template <class _Yp, class _Un> 3661 struct __shared_ptr_default_delete<_Yp[], _Un> 3662 : default_delete<_Yp[]> {}; 3663 3664 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; 3665 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; 3666}; 3667 3668#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 3669template<class _Tp> 3670shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; 3671template<class _Tp, class _Dp> 3672shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; 3673#endif 3674 3675template<class _Tp> 3676inline 3677_LIBCPP_CONSTEXPR 3678shared_ptr<_Tp>::shared_ptr() _NOEXCEPT 3679 : __ptr_(0), 3680 __cntrl_(0) 3681{ 3682} 3683 3684template<class _Tp> 3685inline 3686_LIBCPP_CONSTEXPR 3687shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT 3688 : __ptr_(0), 3689 __cntrl_(0) 3690{ 3691} 3692 3693template<class _Tp> 3694template<class _Yp> 3695shared_ptr<_Tp>::shared_ptr(_Yp* __p, 3696 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 3697 : __ptr_(__p) 3698{ 3699 unique_ptr<_Yp> __hold(__p); 3700 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; 3701 typedef __shared_ptr_pointer<_Yp*, __shared_ptr_default_delete<_Tp, _Yp>, _AllocT > _CntrlBlk; 3702 __cntrl_ = new _CntrlBlk(__p, __shared_ptr_default_delete<_Tp, _Yp>(), _AllocT()); 3703 __hold.release(); 3704 __enable_weak_this(__p, __p); 3705} 3706 3707template<class _Tp> 3708template<class _Yp, class _Dp> 3709shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, 3710 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 3711 : __ptr_(__p) 3712{ 3713#ifndef _LIBCPP_NO_EXCEPTIONS 3714 try 3715 { 3716#endif // _LIBCPP_NO_EXCEPTIONS 3717 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; 3718 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; 3719 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); 3720 __enable_weak_this(__p, __p); 3721#ifndef _LIBCPP_NO_EXCEPTIONS 3722 } 3723 catch (...) 3724 { 3725 __d(__p); 3726 throw; 3727 } 3728#endif // _LIBCPP_NO_EXCEPTIONS 3729} 3730 3731template<class _Tp> 3732template<class _Dp> 3733shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) 3734 : __ptr_(0) 3735{ 3736#ifndef _LIBCPP_NO_EXCEPTIONS 3737 try 3738 { 3739#endif // _LIBCPP_NO_EXCEPTIONS 3740 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; 3741 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk; 3742 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); 3743#ifndef _LIBCPP_NO_EXCEPTIONS 3744 } 3745 catch (...) 3746 { 3747 __d(__p); 3748 throw; 3749 } 3750#endif // _LIBCPP_NO_EXCEPTIONS 3751} 3752 3753template<class _Tp> 3754template<class _Yp, class _Dp, class _Alloc> 3755shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, 3756 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 3757 : __ptr_(__p) 3758{ 3759#ifndef _LIBCPP_NO_EXCEPTIONS 3760 try 3761 { 3762#endif // _LIBCPP_NO_EXCEPTIONS 3763 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; 3764 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 3765 typedef __allocator_destructor<_A2> _D2; 3766 _A2 __a2(__a); 3767 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 3768 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 3769 _CntrlBlk(__p, __d, __a); 3770 __cntrl_ = _VSTD::addressof(*__hold2.release()); 3771 __enable_weak_this(__p, __p); 3772#ifndef _LIBCPP_NO_EXCEPTIONS 3773 } 3774 catch (...) 3775 { 3776 __d(__p); 3777 throw; 3778 } 3779#endif // _LIBCPP_NO_EXCEPTIONS 3780} 3781 3782template<class _Tp> 3783template<class _Dp, class _Alloc> 3784shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) 3785 : __ptr_(0) 3786{ 3787#ifndef _LIBCPP_NO_EXCEPTIONS 3788 try 3789 { 3790#endif // _LIBCPP_NO_EXCEPTIONS 3791 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; 3792 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 3793 typedef __allocator_destructor<_A2> _D2; 3794 _A2 __a2(__a); 3795 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 3796 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 3797 _CntrlBlk(__p, __d, __a); 3798 __cntrl_ = _VSTD::addressof(*__hold2.release()); 3799#ifndef _LIBCPP_NO_EXCEPTIONS 3800 } 3801 catch (...) 3802 { 3803 __d(__p); 3804 throw; 3805 } 3806#endif // _LIBCPP_NO_EXCEPTIONS 3807} 3808 3809template<class _Tp> 3810template<class _Yp> 3811inline 3812shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT 3813 : __ptr_(__p), 3814 __cntrl_(__r.__cntrl_) 3815{ 3816 if (__cntrl_) 3817 __cntrl_->__add_shared(); 3818} 3819 3820template<class _Tp> 3821inline 3822shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT 3823 : __ptr_(__r.__ptr_), 3824 __cntrl_(__r.__cntrl_) 3825{ 3826 if (__cntrl_) 3827 __cntrl_->__add_shared(); 3828} 3829 3830template<class _Tp> 3831template<class _Yp> 3832inline 3833shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, 3834 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 3835 _NOEXCEPT 3836 : __ptr_(__r.__ptr_), 3837 __cntrl_(__r.__cntrl_) 3838{ 3839 if (__cntrl_) 3840 __cntrl_->__add_shared(); 3841} 3842 3843template<class _Tp> 3844inline 3845shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT 3846 : __ptr_(__r.__ptr_), 3847 __cntrl_(__r.__cntrl_) 3848{ 3849 __r.__ptr_ = 0; 3850 __r.__cntrl_ = 0; 3851} 3852 3853template<class _Tp> 3854template<class _Yp> 3855inline 3856shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, 3857 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 3858 _NOEXCEPT 3859 : __ptr_(__r.__ptr_), 3860 __cntrl_(__r.__cntrl_) 3861{ 3862 __r.__ptr_ = 0; 3863 __r.__cntrl_ = 0; 3864} 3865 3866#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 3867template<class _Tp> 3868template<class _Yp> 3869shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, 3870 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 3871 : __ptr_(__r.get()) 3872{ 3873 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; 3874 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); 3875 __enable_weak_this(__r.get(), __r.get()); 3876 __r.release(); 3877} 3878#endif 3879 3880template<class _Tp> 3881template <class _Yp, class _Dp> 3882shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, 3883 typename enable_if 3884 < 3885 !is_lvalue_reference<_Dp>::value && 3886 !is_array<_Yp>::value && 3887 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3888 __nat 3889 >::type) 3890 : __ptr_(__r.get()) 3891{ 3892#if _LIBCPP_STD_VER > 11 3893 if (__ptr_ == nullptr) 3894 __cntrl_ = nullptr; 3895 else 3896#endif 3897 { 3898 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; 3899 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; 3900 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); 3901 __enable_weak_this(__r.get(), __r.get()); 3902 } 3903 __r.release(); 3904} 3905 3906template<class _Tp> 3907template <class _Yp, class _Dp> 3908shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, 3909 typename enable_if 3910 < 3911 is_lvalue_reference<_Dp>::value && 3912 !is_array<_Yp>::value && 3913 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3914 __nat 3915 >::type) 3916 : __ptr_(__r.get()) 3917{ 3918#if _LIBCPP_STD_VER > 11 3919 if (__ptr_ == nullptr) 3920 __cntrl_ = nullptr; 3921 else 3922#endif 3923 { 3924 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; 3925 typedef __shared_ptr_pointer<_Yp*, 3926 reference_wrapper<typename remove_reference<_Dp>::type>, 3927 _AllocT > _CntrlBlk; 3928 __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT()); 3929 __enable_weak_this(__r.get(), __r.get()); 3930 } 3931 __r.release(); 3932} 3933 3934template<class _Tp> 3935shared_ptr<_Tp>::~shared_ptr() 3936{ 3937 if (__cntrl_) 3938 __cntrl_->__release_shared(); 3939} 3940 3941template<class _Tp> 3942inline 3943shared_ptr<_Tp>& 3944shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT 3945{ 3946 shared_ptr(__r).swap(*this); 3947 return *this; 3948} 3949 3950template<class _Tp> 3951template<class _Yp> 3952inline 3953typename enable_if 3954< 3955 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 3956 shared_ptr<_Tp>& 3957>::type 3958shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT 3959{ 3960 shared_ptr(__r).swap(*this); 3961 return *this; 3962} 3963 3964template<class _Tp> 3965inline 3966shared_ptr<_Tp>& 3967shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT 3968{ 3969 shared_ptr(_VSTD::move(__r)).swap(*this); 3970 return *this; 3971} 3972 3973template<class _Tp> 3974template<class _Yp> 3975inline 3976typename enable_if 3977< 3978 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 3979 shared_ptr<_Tp>& 3980>::type 3981shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) 3982{ 3983 shared_ptr(_VSTD::move(__r)).swap(*this); 3984 return *this; 3985} 3986 3987#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 3988template<class _Tp> 3989template<class _Yp> 3990inline 3991typename enable_if 3992< 3993 !is_array<_Yp>::value && 3994 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, 3995 shared_ptr<_Tp> 3996>::type& 3997shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) 3998{ 3999 shared_ptr(_VSTD::move(__r)).swap(*this); 4000 return *this; 4001} 4002#endif 4003 4004template<class _Tp> 4005template <class _Yp, class _Dp> 4006inline 4007typename enable_if 4008< 4009 !is_array<_Yp>::value && 4010 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, 4011 typename shared_ptr<_Tp>::element_type*>::value, 4012 shared_ptr<_Tp>& 4013>::type 4014shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) 4015{ 4016 shared_ptr(_VSTD::move(__r)).swap(*this); 4017 return *this; 4018} 4019 4020template<class _Tp> 4021inline 4022void 4023shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT 4024{ 4025 _VSTD::swap(__ptr_, __r.__ptr_); 4026 _VSTD::swap(__cntrl_, __r.__cntrl_); 4027} 4028 4029template<class _Tp> 4030inline 4031void 4032shared_ptr<_Tp>::reset() _NOEXCEPT 4033{ 4034 shared_ptr().swap(*this); 4035} 4036 4037template<class _Tp> 4038template<class _Yp> 4039inline 4040typename enable_if 4041< 4042 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 4043 void 4044>::type 4045shared_ptr<_Tp>::reset(_Yp* __p) 4046{ 4047 shared_ptr(__p).swap(*this); 4048} 4049 4050template<class _Tp> 4051template<class _Yp, class _Dp> 4052inline 4053typename enable_if 4054< 4055 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 4056 void 4057>::type 4058shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) 4059{ 4060 shared_ptr(__p, __d).swap(*this); 4061} 4062 4063template<class _Tp> 4064template<class _Yp, class _Dp, class _Alloc> 4065inline 4066typename enable_if 4067< 4068 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 4069 void 4070>::type 4071shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) 4072{ 4073 shared_ptr(__p, __d, __a).swap(*this); 4074} 4075 4076template<class _Tp, class ..._Args> 4077inline _LIBCPP_INLINE_VISIBILITY 4078typename enable_if 4079< 4080 !is_array<_Tp>::value, 4081 shared_ptr<_Tp> 4082>::type 4083make_shared(_Args&& ...__args) 4084{ 4085 static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared"); 4086 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4087 typedef allocator<_CntrlBlk> _A2; 4088 typedef __allocator_destructor<_A2> _D2; 4089 4090 _A2 __a2; 4091 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4092 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); 4093 4094 _Tp *__ptr = __hold2.get()->get(); 4095 return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release()); 4096} 4097 4098template<class _Tp, class _Alloc, class ..._Args> 4099inline _LIBCPP_INLINE_VISIBILITY 4100typename enable_if 4101< 4102 !is_array<_Tp>::value, 4103 shared_ptr<_Tp> 4104>::type 4105allocate_shared(const _Alloc& __a, _Args&& ...__args) 4106{ 4107 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared"); 4108 4109 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4110 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4111 typedef __allocator_destructor<_A2> _D2; 4112 4113 _A2 __a2(__a); 4114 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4115 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4116 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); 4117 4118 typename shared_ptr<_Tp>::element_type *__p = __hold2.get()->get(); 4119 return shared_ptr<_Tp>::__create_with_control_block(__p, _VSTD::addressof(*__hold2.release())); 4120} 4121 4122template<class _Tp, class _Up> 4123inline _LIBCPP_INLINE_VISIBILITY 4124bool 4125operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4126{ 4127 return __x.get() == __y.get(); 4128} 4129 4130template<class _Tp, class _Up> 4131inline _LIBCPP_INLINE_VISIBILITY 4132bool 4133operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4134{ 4135 return !(__x == __y); 4136} 4137 4138template<class _Tp, class _Up> 4139inline _LIBCPP_INLINE_VISIBILITY 4140bool 4141operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4142{ 4143#if _LIBCPP_STD_VER <= 11 4144 typedef typename common_type<_Tp*, _Up*>::type _Vp; 4145 return less<_Vp>()(__x.get(), __y.get()); 4146#else 4147 return less<>()(__x.get(), __y.get()); 4148#endif 4149 4150} 4151 4152template<class _Tp, class _Up> 4153inline _LIBCPP_INLINE_VISIBILITY 4154bool 4155operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4156{ 4157 return __y < __x; 4158} 4159 4160template<class _Tp, class _Up> 4161inline _LIBCPP_INLINE_VISIBILITY 4162bool 4163operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4164{ 4165 return !(__y < __x); 4166} 4167 4168template<class _Tp, class _Up> 4169inline _LIBCPP_INLINE_VISIBILITY 4170bool 4171operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4172{ 4173 return !(__x < __y); 4174} 4175 4176template<class _Tp> 4177inline _LIBCPP_INLINE_VISIBILITY 4178bool 4179operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4180{ 4181 return !__x; 4182} 4183 4184template<class _Tp> 4185inline _LIBCPP_INLINE_VISIBILITY 4186bool 4187operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4188{ 4189 return !__x; 4190} 4191 4192template<class _Tp> 4193inline _LIBCPP_INLINE_VISIBILITY 4194bool 4195operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4196{ 4197 return static_cast<bool>(__x); 4198} 4199 4200template<class _Tp> 4201inline _LIBCPP_INLINE_VISIBILITY 4202bool 4203operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4204{ 4205 return static_cast<bool>(__x); 4206} 4207 4208template<class _Tp> 4209inline _LIBCPP_INLINE_VISIBILITY 4210bool 4211operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4212{ 4213 return less<_Tp*>()(__x.get(), nullptr); 4214} 4215 4216template<class _Tp> 4217inline _LIBCPP_INLINE_VISIBILITY 4218bool 4219operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4220{ 4221 return less<_Tp*>()(nullptr, __x.get()); 4222} 4223 4224template<class _Tp> 4225inline _LIBCPP_INLINE_VISIBILITY 4226bool 4227operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4228{ 4229 return nullptr < __x; 4230} 4231 4232template<class _Tp> 4233inline _LIBCPP_INLINE_VISIBILITY 4234bool 4235operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4236{ 4237 return __x < nullptr; 4238} 4239 4240template<class _Tp> 4241inline _LIBCPP_INLINE_VISIBILITY 4242bool 4243operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4244{ 4245 return !(nullptr < __x); 4246} 4247 4248template<class _Tp> 4249inline _LIBCPP_INLINE_VISIBILITY 4250bool 4251operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4252{ 4253 return !(__x < nullptr); 4254} 4255 4256template<class _Tp> 4257inline _LIBCPP_INLINE_VISIBILITY 4258bool 4259operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4260{ 4261 return !(__x < nullptr); 4262} 4263 4264template<class _Tp> 4265inline _LIBCPP_INLINE_VISIBILITY 4266bool 4267operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4268{ 4269 return !(nullptr < __x); 4270} 4271 4272template<class _Tp> 4273inline _LIBCPP_INLINE_VISIBILITY 4274void 4275swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT 4276{ 4277 __x.swap(__y); 4278} 4279 4280template<class _Tp, class _Up> 4281inline _LIBCPP_INLINE_VISIBILITY 4282shared_ptr<_Tp> 4283static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 4284{ 4285 return shared_ptr<_Tp>(__r, 4286 static_cast< 4287 typename shared_ptr<_Tp>::element_type*>(__r.get())); 4288} 4289 4290template<class _Tp, class _Up> 4291inline _LIBCPP_INLINE_VISIBILITY 4292shared_ptr<_Tp> 4293dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 4294{ 4295 typedef typename shared_ptr<_Tp>::element_type _ET; 4296 _ET* __p = dynamic_cast<_ET*>(__r.get()); 4297 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); 4298} 4299 4300template<class _Tp, class _Up> 4301shared_ptr<_Tp> 4302const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 4303{ 4304 typedef typename shared_ptr<_Tp>::element_type _RTp; 4305 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); 4306} 4307 4308template<class _Tp, class _Up> 4309shared_ptr<_Tp> 4310reinterpret_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 4311{ 4312 return shared_ptr<_Tp>(__r, 4313 reinterpret_cast< 4314 typename shared_ptr<_Tp>::element_type*>(__r.get())); 4315} 4316 4317#ifndef _LIBCPP_NO_RTTI 4318 4319template<class _Dp, class _Tp> 4320inline _LIBCPP_INLINE_VISIBILITY 4321_Dp* 4322get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT 4323{ 4324 return __p.template __get_deleter<_Dp>(); 4325} 4326 4327#endif // _LIBCPP_NO_RTTI 4328 4329template<class _Tp> 4330class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr 4331{ 4332public: 4333 typedef _Tp element_type; 4334private: 4335 element_type* __ptr_; 4336 __shared_weak_count* __cntrl_; 4337 4338public: 4339 _LIBCPP_INLINE_VISIBILITY 4340 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; 4341 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r, 4342 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 4343 _NOEXCEPT; 4344 _LIBCPP_INLINE_VISIBILITY 4345 weak_ptr(weak_ptr const& __r) _NOEXCEPT; 4346 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r, 4347 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 4348 _NOEXCEPT; 4349 4350 _LIBCPP_INLINE_VISIBILITY 4351 weak_ptr(weak_ptr&& __r) _NOEXCEPT; 4352 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r, 4353 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 4354 _NOEXCEPT; 4355 ~weak_ptr(); 4356 4357 _LIBCPP_INLINE_VISIBILITY 4358 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; 4359 template<class _Yp> 4360 typename enable_if 4361 < 4362 is_convertible<_Yp*, element_type*>::value, 4363 weak_ptr& 4364 >::type 4365 _LIBCPP_INLINE_VISIBILITY 4366 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; 4367 4368 _LIBCPP_INLINE_VISIBILITY 4369 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; 4370 template<class _Yp> 4371 typename enable_if 4372 < 4373 is_convertible<_Yp*, element_type*>::value, 4374 weak_ptr& 4375 >::type 4376 _LIBCPP_INLINE_VISIBILITY 4377 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; 4378 4379 template<class _Yp> 4380 typename enable_if 4381 < 4382 is_convertible<_Yp*, element_type*>::value, 4383 weak_ptr& 4384 >::type 4385 _LIBCPP_INLINE_VISIBILITY 4386 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; 4387 4388 _LIBCPP_INLINE_VISIBILITY 4389 void swap(weak_ptr& __r) _NOEXCEPT; 4390 _LIBCPP_INLINE_VISIBILITY 4391 void reset() _NOEXCEPT; 4392 4393 _LIBCPP_INLINE_VISIBILITY 4394 long use_count() const _NOEXCEPT 4395 {return __cntrl_ ? __cntrl_->use_count() : 0;} 4396 _LIBCPP_INLINE_VISIBILITY 4397 bool expired() const _NOEXCEPT 4398 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} 4399 shared_ptr<_Tp> lock() const _NOEXCEPT; 4400 template<class _Up> 4401 _LIBCPP_INLINE_VISIBILITY 4402 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT 4403 {return __cntrl_ < __r.__cntrl_;} 4404 template<class _Up> 4405 _LIBCPP_INLINE_VISIBILITY 4406 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT 4407 {return __cntrl_ < __r.__cntrl_;} 4408 4409 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; 4410 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; 4411}; 4412 4413#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 4414template<class _Tp> 4415weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; 4416#endif 4417 4418template<class _Tp> 4419inline 4420_LIBCPP_CONSTEXPR 4421weak_ptr<_Tp>::weak_ptr() _NOEXCEPT 4422 : __ptr_(0), 4423 __cntrl_(0) 4424{ 4425} 4426 4427template<class _Tp> 4428inline 4429weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT 4430 : __ptr_(__r.__ptr_), 4431 __cntrl_(__r.__cntrl_) 4432{ 4433 if (__cntrl_) 4434 __cntrl_->__add_weak(); 4435} 4436 4437template<class _Tp> 4438template<class _Yp> 4439inline 4440weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, 4441 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 4442 _NOEXCEPT 4443 : __ptr_(__r.__ptr_), 4444 __cntrl_(__r.__cntrl_) 4445{ 4446 if (__cntrl_) 4447 __cntrl_->__add_weak(); 4448} 4449 4450template<class _Tp> 4451template<class _Yp> 4452inline 4453weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, 4454 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 4455 _NOEXCEPT 4456 : __ptr_(__r.__ptr_), 4457 __cntrl_(__r.__cntrl_) 4458{ 4459 if (__cntrl_) 4460 __cntrl_->__add_weak(); 4461} 4462 4463template<class _Tp> 4464inline 4465weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT 4466 : __ptr_(__r.__ptr_), 4467 __cntrl_(__r.__cntrl_) 4468{ 4469 __r.__ptr_ = 0; 4470 __r.__cntrl_ = 0; 4471} 4472 4473template<class _Tp> 4474template<class _Yp> 4475inline 4476weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, 4477 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 4478 _NOEXCEPT 4479 : __ptr_(__r.__ptr_), 4480 __cntrl_(__r.__cntrl_) 4481{ 4482 __r.__ptr_ = 0; 4483 __r.__cntrl_ = 0; 4484} 4485 4486template<class _Tp> 4487weak_ptr<_Tp>::~weak_ptr() 4488{ 4489 if (__cntrl_) 4490 __cntrl_->__release_weak(); 4491} 4492 4493template<class _Tp> 4494inline 4495weak_ptr<_Tp>& 4496weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT 4497{ 4498 weak_ptr(__r).swap(*this); 4499 return *this; 4500} 4501 4502template<class _Tp> 4503template<class _Yp> 4504inline 4505typename enable_if 4506< 4507 is_convertible<_Yp*, _Tp*>::value, 4508 weak_ptr<_Tp>& 4509>::type 4510weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT 4511{ 4512 weak_ptr(__r).swap(*this); 4513 return *this; 4514} 4515 4516template<class _Tp> 4517inline 4518weak_ptr<_Tp>& 4519weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT 4520{ 4521 weak_ptr(_VSTD::move(__r)).swap(*this); 4522 return *this; 4523} 4524 4525template<class _Tp> 4526template<class _Yp> 4527inline 4528typename enable_if 4529< 4530 is_convertible<_Yp*, _Tp*>::value, 4531 weak_ptr<_Tp>& 4532>::type 4533weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT 4534{ 4535 weak_ptr(_VSTD::move(__r)).swap(*this); 4536 return *this; 4537} 4538 4539template<class _Tp> 4540template<class _Yp> 4541inline 4542typename enable_if 4543< 4544 is_convertible<_Yp*, _Tp*>::value, 4545 weak_ptr<_Tp>& 4546>::type 4547weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT 4548{ 4549 weak_ptr(__r).swap(*this); 4550 return *this; 4551} 4552 4553template<class _Tp> 4554inline 4555void 4556weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT 4557{ 4558 _VSTD::swap(__ptr_, __r.__ptr_); 4559 _VSTD::swap(__cntrl_, __r.__cntrl_); 4560} 4561 4562template<class _Tp> 4563inline _LIBCPP_INLINE_VISIBILITY 4564void 4565swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT 4566{ 4567 __x.swap(__y); 4568} 4569 4570template<class _Tp> 4571inline 4572void 4573weak_ptr<_Tp>::reset() _NOEXCEPT 4574{ 4575 weak_ptr().swap(*this); 4576} 4577 4578template<class _Tp> 4579template<class _Yp> 4580shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, 4581 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4582 : __ptr_(__r.__ptr_), 4583 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) 4584{ 4585 if (__cntrl_ == 0) 4586 __throw_bad_weak_ptr(); 4587} 4588 4589template<class _Tp> 4590shared_ptr<_Tp> 4591weak_ptr<_Tp>::lock() const _NOEXCEPT 4592{ 4593 shared_ptr<_Tp> __r; 4594 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; 4595 if (__r.__cntrl_) 4596 __r.__ptr_ = __ptr_; 4597 return __r; 4598} 4599 4600#if _LIBCPP_STD_VER > 14 4601template <class _Tp = void> struct owner_less; 4602#else 4603template <class _Tp> struct owner_less; 4604#endif 4605 4606template <class _Tp> 4607struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > 4608 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> 4609{ 4610 typedef bool result_type; 4611 _LIBCPP_INLINE_VISIBILITY 4612 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT 4613 {return __x.owner_before(__y);} 4614 _LIBCPP_INLINE_VISIBILITY 4615 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT 4616 {return __x.owner_before(__y);} 4617 _LIBCPP_INLINE_VISIBILITY 4618 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT 4619 {return __x.owner_before(__y);} 4620}; 4621 4622template <class _Tp> 4623struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > 4624 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> 4625{ 4626 typedef bool result_type; 4627 _LIBCPP_INLINE_VISIBILITY 4628 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT 4629 {return __x.owner_before(__y);} 4630 _LIBCPP_INLINE_VISIBILITY 4631 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT 4632 {return __x.owner_before(__y);} 4633 _LIBCPP_INLINE_VISIBILITY 4634 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT 4635 {return __x.owner_before(__y);} 4636}; 4637 4638#if _LIBCPP_STD_VER > 14 4639template <> 4640struct _LIBCPP_TEMPLATE_VIS owner_less<void> 4641{ 4642 template <class _Tp, class _Up> 4643 _LIBCPP_INLINE_VISIBILITY 4644 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT 4645 {return __x.owner_before(__y);} 4646 template <class _Tp, class _Up> 4647 _LIBCPP_INLINE_VISIBILITY 4648 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT 4649 {return __x.owner_before(__y);} 4650 template <class _Tp, class _Up> 4651 _LIBCPP_INLINE_VISIBILITY 4652 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT 4653 {return __x.owner_before(__y);} 4654 template <class _Tp, class _Up> 4655 _LIBCPP_INLINE_VISIBILITY 4656 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT 4657 {return __x.owner_before(__y);} 4658 typedef void is_transparent; 4659}; 4660#endif 4661 4662template<class _Tp> 4663class _LIBCPP_TEMPLATE_VIS enable_shared_from_this 4664{ 4665 mutable weak_ptr<_Tp> __weak_this_; 4666protected: 4667 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 4668 enable_shared_from_this() _NOEXCEPT {} 4669 _LIBCPP_INLINE_VISIBILITY 4670 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} 4671 _LIBCPP_INLINE_VISIBILITY 4672 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT 4673 {return *this;} 4674 _LIBCPP_INLINE_VISIBILITY 4675 ~enable_shared_from_this() {} 4676public: 4677 _LIBCPP_INLINE_VISIBILITY 4678 shared_ptr<_Tp> shared_from_this() 4679 {return shared_ptr<_Tp>(__weak_this_);} 4680 _LIBCPP_INLINE_VISIBILITY 4681 shared_ptr<_Tp const> shared_from_this() const 4682 {return shared_ptr<const _Tp>(__weak_this_);} 4683 4684#if _LIBCPP_STD_VER > 14 4685 _LIBCPP_INLINE_VISIBILITY 4686 weak_ptr<_Tp> weak_from_this() _NOEXCEPT 4687 { return __weak_this_; } 4688 4689 _LIBCPP_INLINE_VISIBILITY 4690 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT 4691 { return __weak_this_; } 4692#endif // _LIBCPP_STD_VER > 14 4693 4694 template <class _Up> friend class shared_ptr; 4695}; 4696 4697template <class _Tp> 4698struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > 4699{ 4700 typedef shared_ptr<_Tp> argument_type; 4701 typedef size_t result_type; 4702 4703 _LIBCPP_INLINE_VISIBILITY 4704 result_type operator()(const argument_type& __ptr) const _NOEXCEPT 4705 { 4706 return hash<typename shared_ptr<_Tp>::element_type*>()(__ptr.get()); 4707 } 4708}; 4709 4710template<class _CharT, class _Traits, class _Yp> 4711inline _LIBCPP_INLINE_VISIBILITY 4712basic_ostream<_CharT, _Traits>& 4713operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); 4714 4715 4716#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) 4717 4718class _LIBCPP_TYPE_VIS __sp_mut 4719{ 4720 void* __lx; 4721public: 4722 void lock() _NOEXCEPT; 4723 void unlock() _NOEXCEPT; 4724 4725private: 4726 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; 4727 __sp_mut(const __sp_mut&); 4728 __sp_mut& operator=(const __sp_mut&); 4729 4730 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); 4731}; 4732 4733_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4734__sp_mut& __get_sp_mut(const void*); 4735 4736template <class _Tp> 4737inline _LIBCPP_INLINE_VISIBILITY 4738bool 4739atomic_is_lock_free(const shared_ptr<_Tp>*) 4740{ 4741 return false; 4742} 4743 4744template <class _Tp> 4745_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4746shared_ptr<_Tp> 4747atomic_load(const shared_ptr<_Tp>* __p) 4748{ 4749 __sp_mut& __m = __get_sp_mut(__p); 4750 __m.lock(); 4751 shared_ptr<_Tp> __q = *__p; 4752 __m.unlock(); 4753 return __q; 4754} 4755 4756template <class _Tp> 4757inline _LIBCPP_INLINE_VISIBILITY 4758_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4759shared_ptr<_Tp> 4760atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) 4761{ 4762 return atomic_load(__p); 4763} 4764 4765template <class _Tp> 4766_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4767void 4768atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) 4769{ 4770 __sp_mut& __m = __get_sp_mut(__p); 4771 __m.lock(); 4772 __p->swap(__r); 4773 __m.unlock(); 4774} 4775 4776template <class _Tp> 4777inline _LIBCPP_INLINE_VISIBILITY 4778_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4779void 4780atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) 4781{ 4782 atomic_store(__p, __r); 4783} 4784 4785template <class _Tp> 4786_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4787shared_ptr<_Tp> 4788atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) 4789{ 4790 __sp_mut& __m = __get_sp_mut(__p); 4791 __m.lock(); 4792 __p->swap(__r); 4793 __m.unlock(); 4794 return __r; 4795} 4796 4797template <class _Tp> 4798inline _LIBCPP_INLINE_VISIBILITY 4799_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4800shared_ptr<_Tp> 4801atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) 4802{ 4803 return atomic_exchange(__p, __r); 4804} 4805 4806template <class _Tp> 4807_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4808bool 4809atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) 4810{ 4811 shared_ptr<_Tp> __temp; 4812 __sp_mut& __m = __get_sp_mut(__p); 4813 __m.lock(); 4814 if (__p->__owner_equivalent(*__v)) 4815 { 4816 _VSTD::swap(__temp, *__p); 4817 *__p = __w; 4818 __m.unlock(); 4819 return true; 4820 } 4821 _VSTD::swap(__temp, *__v); 4822 *__v = *__p; 4823 __m.unlock(); 4824 return false; 4825} 4826 4827template <class _Tp> 4828inline _LIBCPP_INLINE_VISIBILITY 4829_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4830bool 4831atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) 4832{ 4833 return atomic_compare_exchange_strong(__p, __v, __w); 4834} 4835 4836template <class _Tp> 4837inline _LIBCPP_INLINE_VISIBILITY 4838_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4839bool 4840atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, 4841 shared_ptr<_Tp> __w, memory_order, memory_order) 4842{ 4843 return atomic_compare_exchange_strong(__p, __v, __w); 4844} 4845 4846template <class _Tp> 4847inline _LIBCPP_INLINE_VISIBILITY 4848_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 4849bool 4850atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, 4851 shared_ptr<_Tp> __w, memory_order, memory_order) 4852{ 4853 return atomic_compare_exchange_weak(__p, __v, __w); 4854} 4855 4856#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) 4857 4858//enum class 4859#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) 4860# ifndef _LIBCPP_CXX03_LANG 4861enum class pointer_safety : unsigned char { 4862 relaxed, 4863 preferred, 4864 strict 4865}; 4866# endif 4867#else 4868struct _LIBCPP_TYPE_VIS pointer_safety 4869{ 4870 enum __lx 4871 { 4872 relaxed, 4873 preferred, 4874 strict 4875 }; 4876 4877 __lx __v_; 4878 4879 _LIBCPP_INLINE_VISIBILITY 4880 pointer_safety() : __v_() {} 4881 4882 _LIBCPP_INLINE_VISIBILITY 4883 pointer_safety(__lx __v) : __v_(__v) {} 4884 _LIBCPP_INLINE_VISIBILITY 4885 operator int() const {return __v_;} 4886}; 4887#endif 4888 4889#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \ 4890 defined(_LIBCPP_BUILDING_LIBRARY) 4891_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; 4892#else 4893// This function is only offered in C++03 under ABI v1. 4894# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG) 4895inline _LIBCPP_INLINE_VISIBILITY 4896pointer_safety get_pointer_safety() _NOEXCEPT { 4897 return pointer_safety::relaxed; 4898} 4899# endif 4900#endif 4901 4902 4903_LIBCPP_FUNC_VIS void declare_reachable(void* __p); 4904_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); 4905_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); 4906_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); 4907 4908template <class _Tp> 4909inline _LIBCPP_INLINE_VISIBILITY 4910_Tp* 4911undeclare_reachable(_Tp* __p) 4912{ 4913 return static_cast<_Tp*>(__undeclare_reachable(__p)); 4914} 4915 4916_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); 4917 4918// --- Helper for container swap -- 4919template <typename _Alloc> 4920inline _LIBCPP_INLINE_VISIBILITY 4921void __swap_allocator(_Alloc & __a1, _Alloc & __a2) 4922#if _LIBCPP_STD_VER >= 14 4923 _NOEXCEPT 4924#else 4925 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 4926#endif 4927{ 4928 __swap_allocator(__a1, __a2, 4929 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); 4930} 4931 4932template <typename _Alloc> 4933_LIBCPP_INLINE_VISIBILITY 4934void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) 4935#if _LIBCPP_STD_VER >= 14 4936 _NOEXCEPT 4937#else 4938 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 4939#endif 4940{ 4941 using _VSTD::swap; 4942 swap(__a1, __a2); 4943} 4944 4945template <typename _Alloc> 4946inline _LIBCPP_INLINE_VISIBILITY 4947void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} 4948 4949template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > 4950struct __noexcept_move_assign_container : public integral_constant<bool, 4951 _Traits::propagate_on_container_move_assignment::value 4952#if _LIBCPP_STD_VER > 14 4953 || _Traits::is_always_equal::value 4954#else 4955 && is_nothrow_move_assignable<_Alloc>::value 4956#endif 4957 > {}; 4958 4959 4960template <class _Tp, class _Alloc> 4961struct __temp_value { 4962 typedef allocator_traits<_Alloc> _Traits; 4963 4964 typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v; 4965 _Alloc &__a; 4966 4967 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } 4968 _Tp & get() { return *__addr(); } 4969 4970 template<class... _Args> 4971 _LIBCPP_NO_CFI 4972 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { 4973 _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)), 4974 _VSTD::forward<_Args>(__args)...); 4975 } 4976 4977 ~__temp_value() { _Traits::destroy(__a, __addr()); } 4978 }; 4979 4980template<typename _Alloc, typename = void, typename = void> 4981struct __is_allocator : false_type {}; 4982 4983template<typename _Alloc> 4984struct __is_allocator<_Alloc, 4985 typename __void_t<typename _Alloc::value_type>::type, 4986 typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type 4987 > 4988 : true_type {}; 4989 4990// __builtin_new_allocator -- A non-templated helper for allocating and 4991// deallocating memory using __builtin_operator_new and 4992// __builtin_operator_delete. It should be used in preference to 4993// `std::allocator<T>` to avoid additional instantiations. 4994struct __builtin_new_allocator { 4995 struct __builtin_new_deleter { 4996 typedef void* pointer_type; 4997 4998 _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align) 4999 : __size_(__size), __align_(__align) {} 5000 5001 void operator()(void* p) const _NOEXCEPT { 5002 std::__libcpp_deallocate(p, __size_, __align_); 5003 } 5004 5005 private: 5006 size_t __size_; 5007 size_t __align_; 5008 }; 5009 5010 typedef unique_ptr<void, __builtin_new_deleter> __holder_t; 5011 5012 static __holder_t __allocate_bytes(size_t __s, size_t __align) { 5013 return __holder_t(std::__libcpp_allocate(__s, __align), 5014 __builtin_new_deleter(__s, __align)); 5015 } 5016 5017 static void __deallocate_bytes(void* __p, size_t __s, 5018 size_t __align) _NOEXCEPT { 5019 std::__libcpp_deallocate(__p, __s, __align); 5020 } 5021 5022 template <class _Tp> 5023 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE 5024 static __holder_t __allocate_type(size_t __n) { 5025 return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); 5026 } 5027 5028 template <class _Tp> 5029 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE 5030 static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { 5031 __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); 5032 } 5033}; 5034 5035 5036_LIBCPP_END_NAMESPACE_STD 5037 5038_LIBCPP_POP_MACROS 5039 5040#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 5041# include <__pstl_memory> 5042#endif 5043 5044#endif // _LIBCPP_MEMORY 5045