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