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, class _Up> 3706struct __compatible_with 3707#if _LIBCPP_STD_VER > 14 3708 : is_convertible<remove_extent_t<_Tp>*, remove_extent_t<_Up>*> {}; 3709#else 3710 : is_convertible<_Tp*, _Up*> {}; 3711#endif // _LIBCPP_STD_VER > 14 3712 3713template<class _Tp> 3714class _LIBCPP_TEMPLATE_VIS shared_ptr 3715{ 3716public: 3717#if _LIBCPP_STD_VER > 14 3718 typedef weak_ptr<_Tp> weak_type; 3719 typedef remove_extent_t<_Tp> element_type; 3720#else 3721 typedef _Tp element_type; 3722#endif 3723 3724private: 3725 element_type* __ptr_; 3726 __shared_weak_count* __cntrl_; 3727 3728 struct __nat {int __for_bool_;}; 3729public: 3730 _LIBCPP_INLINE_VISIBILITY 3731 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; 3732 _LIBCPP_INLINE_VISIBILITY 3733 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; 3734 template<class _Yp> 3735 explicit shared_ptr(_Yp* __p, 3736 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); 3737 template<class _Yp, class _Dp> 3738 shared_ptr(_Yp* __p, _Dp __d, 3739 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); 3740 template<class _Yp, class _Dp, class _Alloc> 3741 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, 3742 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); 3743 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); 3744 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); 3745 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; 3746 _LIBCPP_INLINE_VISIBILITY 3747 shared_ptr(const shared_ptr& __r) _NOEXCEPT; 3748 template<class _Yp> 3749 _LIBCPP_INLINE_VISIBILITY 3750 shared_ptr(const shared_ptr<_Yp>& __r, 3751 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) 3752 _NOEXCEPT; 3753#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3754 _LIBCPP_INLINE_VISIBILITY 3755 shared_ptr(shared_ptr&& __r) _NOEXCEPT; 3756 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, 3757 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) 3758 _NOEXCEPT; 3759#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3760 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, 3761 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); 3762#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 3763#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3764 template<class _Yp> 3765 shared_ptr(auto_ptr<_Yp>&& __r, 3766 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3767#else 3768 template<class _Yp> 3769 shared_ptr(auto_ptr<_Yp> __r, 3770 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3771#endif 3772#endif 3773#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3774 template <class _Yp, class _Dp> 3775 shared_ptr(unique_ptr<_Yp, _Dp>&&, 3776 typename enable_if 3777 < 3778 !is_lvalue_reference<_Dp>::value && 3779 !is_array<_Yp>::value && 3780 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3781 __nat 3782 >::type = __nat()); 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#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3793 template <class _Yp, class _Dp> 3794 shared_ptr(unique_ptr<_Yp, _Dp>, 3795 typename enable_if 3796 < 3797 !is_lvalue_reference<_Dp>::value && 3798 !is_array<_Yp>::value && 3799 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3800 __nat 3801 >::type = __nat()); 3802 template <class _Yp, class _Dp> 3803 shared_ptr(unique_ptr<_Yp, _Dp>, 3804 typename enable_if 3805 < 3806 is_lvalue_reference<_Dp>::value && 3807 !is_array<_Yp>::value && 3808 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3809 __nat 3810 >::type = __nat()); 3811#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3812 3813 ~shared_ptr(); 3814 3815 _LIBCPP_INLINE_VISIBILITY 3816 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; 3817 template<class _Yp> 3818 typename enable_if 3819 < 3820 __compatible_with<_Yp, element_type>::value, 3821 shared_ptr& 3822 >::type 3823 _LIBCPP_INLINE_VISIBILITY 3824 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; 3825#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3826 _LIBCPP_INLINE_VISIBILITY 3827 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; 3828 template<class _Yp> 3829 typename enable_if 3830 < 3831 __compatible_with<_Yp, element_type>::value, 3832 shared_ptr& 3833 >::type 3834 _LIBCPP_INLINE_VISIBILITY 3835 operator=(shared_ptr<_Yp>&& __r); 3836#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 3837 template<class _Yp> 3838 _LIBCPP_INLINE_VISIBILITY 3839 typename enable_if 3840 < 3841 !is_array<_Yp>::value && 3842 is_convertible<_Yp*, element_type*>::value, 3843 shared_ptr 3844 >::type& 3845 operator=(auto_ptr<_Yp>&& __r); 3846#endif 3847#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3848#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 3849 template<class _Yp> 3850 _LIBCPP_INLINE_VISIBILITY 3851 typename enable_if 3852 < 3853 !is_array<_Yp>::value && 3854 is_convertible<_Yp*, element_type*>::value, 3855 shared_ptr& 3856 >::type 3857 operator=(auto_ptr<_Yp> __r); 3858#endif 3859#endif 3860 template <class _Yp, class _Dp> 3861 typename enable_if 3862 < 3863 !is_array<_Yp>::value && 3864 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3865 shared_ptr& 3866 >::type 3867#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3868 _LIBCPP_INLINE_VISIBILITY 3869 operator=(unique_ptr<_Yp, _Dp>&& __r); 3870#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3871 _LIBCPP_INLINE_VISIBILITY 3872 operator=(unique_ptr<_Yp, _Dp> __r); 3873#endif 3874 3875 _LIBCPP_INLINE_VISIBILITY 3876 void swap(shared_ptr& __r) _NOEXCEPT; 3877 _LIBCPP_INLINE_VISIBILITY 3878 void reset() _NOEXCEPT; 3879 template<class _Yp> 3880 typename enable_if 3881 < 3882 __compatible_with<_Yp, element_type>::value, 3883 void 3884 >::type 3885 _LIBCPP_INLINE_VISIBILITY 3886 reset(_Yp* __p); 3887 template<class _Yp, class _Dp> 3888 typename enable_if 3889 < 3890 __compatible_with<_Yp, element_type>::value, 3891 void 3892 >::type 3893 _LIBCPP_INLINE_VISIBILITY 3894 reset(_Yp* __p, _Dp __d); 3895 template<class _Yp, class _Dp, class _Alloc> 3896 typename enable_if 3897 < 3898 __compatible_with<_Yp, element_type>::value, 3899 void 3900 >::type 3901 _LIBCPP_INLINE_VISIBILITY 3902 reset(_Yp* __p, _Dp __d, _Alloc __a); 3903 3904 _LIBCPP_INLINE_VISIBILITY 3905 element_type* get() const _NOEXCEPT {return __ptr_;} 3906 _LIBCPP_INLINE_VISIBILITY 3907 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT 3908 {return *__ptr_;} 3909 _LIBCPP_INLINE_VISIBILITY 3910 element_type* operator->() const _NOEXCEPT 3911 { 3912 static_assert(!_VSTD::is_array<_Tp>::value, 3913 "std::shared_ptr<T>::operator-> is only valid when T is not an array type."); 3914 return __ptr_; 3915 } 3916 _LIBCPP_INLINE_VISIBILITY 3917 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} 3918 _LIBCPP_INLINE_VISIBILITY 3919 bool unique() const _NOEXCEPT {return use_count() == 1;} 3920 _LIBCPP_INLINE_VISIBILITY 3921 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} 3922 template <class _Up> 3923 _LIBCPP_INLINE_VISIBILITY 3924 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT 3925 {return __cntrl_ < __p.__cntrl_;} 3926 template <class _Up> 3927 _LIBCPP_INLINE_VISIBILITY 3928 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT 3929 {return __cntrl_ < __p.__cntrl_;} 3930 _LIBCPP_INLINE_VISIBILITY 3931 bool 3932 __owner_equivalent(const shared_ptr& __p) const 3933 {return __cntrl_ == __p.__cntrl_;} 3934 3935#if _LIBCPP_STD_VER > 14 3936 typename add_lvalue_reference<element_type>::type 3937 _LIBCPP_INLINE_VISIBILITY 3938 operator[](ptrdiff_t __i) const 3939 { 3940 static_assert(_VSTD::is_array<_Tp>::value, 3941 "std::shared_ptr<T>::operator[] is only valid when T is an array type."); 3942 return __ptr_[__i]; 3943 } 3944#endif 3945 3946#ifndef _LIBCPP_NO_RTTI 3947 template <class _Dp> 3948 _LIBCPP_INLINE_VISIBILITY 3949 _Dp* __get_deleter() const _NOEXCEPT 3950 {return static_cast<_Dp*>(__cntrl_ 3951 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) 3952 : nullptr);} 3953#endif // _LIBCPP_NO_RTTI 3954 3955 template<class _Yp, class _CntrlBlk> 3956 static shared_ptr<_Tp> 3957 __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) 3958 { 3959 shared_ptr<_Tp> __r; 3960 __r.__ptr_ = __p; 3961 __r.__cntrl_ = __cntrl; 3962 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); 3963 return __r; 3964 } 3965 3966private: 3967 template <class _Yp, bool = is_function<_Yp>::value> 3968 struct __shared_ptr_default_allocator 3969 { 3970 typedef allocator<_Yp> type; 3971 }; 3972 3973 template <class _Yp> 3974 struct __shared_ptr_default_allocator<_Yp, true> 3975 { 3976 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; 3977 }; 3978 3979 template <class _Yp, class _OrigPtr> 3980 _LIBCPP_INLINE_VISIBILITY 3981 typename enable_if<is_convertible<_OrigPtr*, 3982 const enable_shared_from_this<_Yp>* 3983 >::value, 3984 void>::type 3985 __enable_weak_this(const enable_shared_from_this<_Yp>* __e, 3986 _OrigPtr* __ptr) _NOEXCEPT 3987 { 3988 typedef typename remove_cv<_Yp>::type _RawYp; 3989 if (__e && __e->__weak_this_.expired()) 3990 { 3991 __e->__weak_this_ = shared_ptr<_RawYp>(*this, 3992 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); 3993 } 3994 } 3995 3996 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} 3997 3998 template <class, class _Yp> 3999 struct __shared_ptr_default_delete 4000 : default_delete<_Yp> {}; 4001 4002 template <class _Yp, class _Un, size_t _Sz> 4003 struct __shared_ptr_default_delete<_Yp[_Sz], _Un> 4004 : default_delete<_Yp[]> {}; 4005 4006 template <class _Yp, class _Un> 4007 struct __shared_ptr_default_delete<_Yp[], _Un> 4008 : default_delete<_Yp[]> {}; 4009 4010 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; 4011 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; 4012}; 4013 4014#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 4015template<class _Tp> 4016shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; 4017template<class _Tp, class _Dp> 4018shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; 4019#endif 4020 4021template<class _Tp> 4022inline 4023_LIBCPP_CONSTEXPR 4024shared_ptr<_Tp>::shared_ptr() _NOEXCEPT 4025 : __ptr_(0), 4026 __cntrl_(0) 4027{ 4028} 4029 4030template<class _Tp> 4031inline 4032_LIBCPP_CONSTEXPR 4033shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT 4034 : __ptr_(0), 4035 __cntrl_(0) 4036{ 4037} 4038 4039template<class _Tp> 4040template<class _Yp> 4041shared_ptr<_Tp>::shared_ptr(_Yp* __p, 4042 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 4043 : __ptr_(__p) 4044{ 4045 unique_ptr<_Yp> __hold(__p); 4046 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; 4047 typedef __shared_ptr_pointer<_Yp*, __shared_ptr_default_delete<_Tp, _Yp>, _AllocT > _CntrlBlk; 4048 __cntrl_ = new _CntrlBlk(__p, __shared_ptr_default_delete<_Tp, _Yp>(), _AllocT()); 4049 __hold.release(); 4050 __enable_weak_this(__p, __p); 4051} 4052 4053template<class _Tp> 4054template<class _Yp, class _Dp> 4055shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, 4056 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 4057 : __ptr_(__p) 4058{ 4059#ifndef _LIBCPP_NO_EXCEPTIONS 4060 try 4061 { 4062#endif // _LIBCPP_NO_EXCEPTIONS 4063 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; 4064 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; 4065 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); 4066 __enable_weak_this(__p, __p); 4067#ifndef _LIBCPP_NO_EXCEPTIONS 4068 } 4069 catch (...) 4070 { 4071 __d(__p); 4072 throw; 4073 } 4074#endif // _LIBCPP_NO_EXCEPTIONS 4075} 4076 4077template<class _Tp> 4078template<class _Dp> 4079shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) 4080 : __ptr_(0) 4081{ 4082#ifndef _LIBCPP_NO_EXCEPTIONS 4083 try 4084 { 4085#endif // _LIBCPP_NO_EXCEPTIONS 4086 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; 4087 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk; 4088 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); 4089#ifndef _LIBCPP_NO_EXCEPTIONS 4090 } 4091 catch (...) 4092 { 4093 __d(__p); 4094 throw; 4095 } 4096#endif // _LIBCPP_NO_EXCEPTIONS 4097} 4098 4099template<class _Tp> 4100template<class _Yp, class _Dp, class _Alloc> 4101shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, 4102 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 4103 : __ptr_(__p) 4104{ 4105#ifndef _LIBCPP_NO_EXCEPTIONS 4106 try 4107 { 4108#endif // _LIBCPP_NO_EXCEPTIONS 4109 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; 4110 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4111 typedef __allocator_destructor<_A2> _D2; 4112 _A2 __a2(__a); 4113 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4114 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4115 _CntrlBlk(__p, __d, __a); 4116 __cntrl_ = _VSTD::addressof(*__hold2.release()); 4117 __enable_weak_this(__p, __p); 4118#ifndef _LIBCPP_NO_EXCEPTIONS 4119 } 4120 catch (...) 4121 { 4122 __d(__p); 4123 throw; 4124 } 4125#endif // _LIBCPP_NO_EXCEPTIONS 4126} 4127 4128template<class _Tp> 4129template<class _Dp, class _Alloc> 4130shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) 4131 : __ptr_(0) 4132{ 4133#ifndef _LIBCPP_NO_EXCEPTIONS 4134 try 4135 { 4136#endif // _LIBCPP_NO_EXCEPTIONS 4137 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; 4138 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4139 typedef __allocator_destructor<_A2> _D2; 4140 _A2 __a2(__a); 4141 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4142 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4143 _CntrlBlk(__p, __d, __a); 4144 __cntrl_ = _VSTD::addressof(*__hold2.release()); 4145#ifndef _LIBCPP_NO_EXCEPTIONS 4146 } 4147 catch (...) 4148 { 4149 __d(__p); 4150 throw; 4151 } 4152#endif // _LIBCPP_NO_EXCEPTIONS 4153} 4154 4155template<class _Tp> 4156template<class _Yp> 4157inline 4158shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT 4159 : __ptr_(__p), 4160 __cntrl_(__r.__cntrl_) 4161{ 4162 if (__cntrl_) 4163 __cntrl_->__add_shared(); 4164} 4165 4166template<class _Tp> 4167inline 4168shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT 4169 : __ptr_(__r.__ptr_), 4170 __cntrl_(__r.__cntrl_) 4171{ 4172 if (__cntrl_) 4173 __cntrl_->__add_shared(); 4174} 4175 4176template<class _Tp> 4177template<class _Yp> 4178inline 4179shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, 4180 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 4181 _NOEXCEPT 4182 : __ptr_(__r.__ptr_), 4183 __cntrl_(__r.__cntrl_) 4184{ 4185 if (__cntrl_) 4186 __cntrl_->__add_shared(); 4187} 4188 4189#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4190 4191template<class _Tp> 4192inline 4193shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT 4194 : __ptr_(__r.__ptr_), 4195 __cntrl_(__r.__cntrl_) 4196{ 4197 __r.__ptr_ = 0; 4198 __r.__cntrl_ = 0; 4199} 4200 4201template<class _Tp> 4202template<class _Yp> 4203inline 4204shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, 4205 typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) 4206 _NOEXCEPT 4207 : __ptr_(__r.__ptr_), 4208 __cntrl_(__r.__cntrl_) 4209{ 4210 __r.__ptr_ = 0; 4211 __r.__cntrl_ = 0; 4212} 4213 4214#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4215 4216#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 4217template<class _Tp> 4218template<class _Yp> 4219#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4220shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, 4221#else 4222shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, 4223#endif 4224 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4225 : __ptr_(__r.get()) 4226{ 4227 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; 4228 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); 4229 __enable_weak_this(__r.get(), __r.get()); 4230 __r.release(); 4231} 4232#endif 4233 4234template<class _Tp> 4235template <class _Yp, class _Dp> 4236#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4237shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, 4238#else 4239shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, 4240#endif 4241 typename enable_if 4242 < 4243 !is_lvalue_reference<_Dp>::value && 4244 !is_array<_Yp>::value && 4245 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 4246 __nat 4247 >::type) 4248 : __ptr_(__r.get()) 4249{ 4250#if _LIBCPP_STD_VER > 11 4251 if (__ptr_ == nullptr) 4252 __cntrl_ = nullptr; 4253 else 4254#endif 4255 { 4256 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; 4257 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; 4258 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); 4259 __enable_weak_this(__r.get(), __r.get()); 4260 } 4261 __r.release(); 4262} 4263 4264template<class _Tp> 4265template <class _Yp, class _Dp> 4266#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4267shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, 4268#else 4269shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, 4270#endif 4271 typename enable_if 4272 < 4273 is_lvalue_reference<_Dp>::value && 4274 !is_array<_Yp>::value && 4275 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 4276 __nat 4277 >::type) 4278 : __ptr_(__r.get()) 4279{ 4280#if _LIBCPP_STD_VER > 11 4281 if (__ptr_ == nullptr) 4282 __cntrl_ = nullptr; 4283 else 4284#endif 4285 { 4286 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; 4287 typedef __shared_ptr_pointer<_Yp*, 4288 reference_wrapper<typename remove_reference<_Dp>::type>, 4289 _AllocT > _CntrlBlk; 4290 __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT()); 4291 __enable_weak_this(__r.get(), __r.get()); 4292 } 4293 __r.release(); 4294} 4295 4296template<class _Tp> 4297shared_ptr<_Tp>::~shared_ptr() 4298{ 4299 if (__cntrl_) 4300 __cntrl_->__release_shared(); 4301} 4302 4303template<class _Tp> 4304inline 4305shared_ptr<_Tp>& 4306shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT 4307{ 4308 shared_ptr(__r).swap(*this); 4309 return *this; 4310} 4311 4312template<class _Tp> 4313template<class _Yp> 4314inline 4315typename enable_if 4316< 4317 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 4318 shared_ptr<_Tp>& 4319>::type 4320shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT 4321{ 4322 shared_ptr(__r).swap(*this); 4323 return *this; 4324} 4325 4326#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4327 4328template<class _Tp> 4329inline 4330shared_ptr<_Tp>& 4331shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT 4332{ 4333 shared_ptr(_VSTD::move(__r)).swap(*this); 4334 return *this; 4335} 4336 4337template<class _Tp> 4338template<class _Yp> 4339inline 4340typename enable_if 4341< 4342 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 4343 shared_ptr<_Tp>& 4344>::type 4345shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) 4346{ 4347 shared_ptr(_VSTD::move(__r)).swap(*this); 4348 return *this; 4349} 4350 4351#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 4352template<class _Tp> 4353template<class _Yp> 4354inline 4355typename enable_if 4356< 4357 !is_array<_Yp>::value && 4358 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, 4359 shared_ptr<_Tp> 4360>::type& 4361shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) 4362{ 4363 shared_ptr(_VSTD::move(__r)).swap(*this); 4364 return *this; 4365} 4366#endif 4367 4368template<class _Tp> 4369template <class _Yp, class _Dp> 4370inline 4371typename enable_if 4372< 4373 !is_array<_Yp>::value && 4374 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, 4375 typename shared_ptr<_Tp>::element_type*>::value, 4376 shared_ptr<_Tp>& 4377>::type 4378shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) 4379{ 4380 shared_ptr(_VSTD::move(__r)).swap(*this); 4381 return *this; 4382} 4383 4384#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4385 4386#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 4387template<class _Tp> 4388template<class _Yp> 4389inline _LIBCPP_INLINE_VISIBILITY 4390typename enable_if 4391< 4392 !is_array<_Yp>::value && 4393 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, 4394 shared_ptr<_Tp>& 4395>::type 4396shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) 4397{ 4398 shared_ptr(__r).swap(*this); 4399 return *this; 4400} 4401#endif 4402 4403template<class _Tp> 4404template <class _Yp, class _Dp> 4405inline _LIBCPP_INLINE_VISIBILITY 4406typename enable_if 4407< 4408 !is_array<_Yp>::value && 4409 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, 4410 typename shared_ptr<_Tp>::element_type*>::value, 4411 shared_ptr<_Tp>& 4412>::type 4413shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) 4414{ 4415 shared_ptr(_VSTD::move(__r)).swap(*this); 4416 return *this; 4417} 4418 4419#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4420 4421template<class _Tp> 4422inline 4423void 4424shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT 4425{ 4426 _VSTD::swap(__ptr_, __r.__ptr_); 4427 _VSTD::swap(__cntrl_, __r.__cntrl_); 4428} 4429 4430template<class _Tp> 4431inline 4432void 4433shared_ptr<_Tp>::reset() _NOEXCEPT 4434{ 4435 shared_ptr().swap(*this); 4436} 4437 4438template<class _Tp> 4439template<class _Yp> 4440inline 4441typename enable_if 4442< 4443 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 4444 void 4445>::type 4446shared_ptr<_Tp>::reset(_Yp* __p) 4447{ 4448 shared_ptr(__p).swap(*this); 4449} 4450 4451template<class _Tp> 4452template<class _Yp, class _Dp> 4453inline 4454typename enable_if 4455< 4456 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 4457 void 4458>::type 4459shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) 4460{ 4461 shared_ptr(__p, __d).swap(*this); 4462} 4463 4464template<class _Tp> 4465template<class _Yp, class _Dp, class _Alloc> 4466inline 4467typename enable_if 4468< 4469 __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, 4470 void 4471>::type 4472shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) 4473{ 4474 shared_ptr(__p, __d, __a).swap(*this); 4475} 4476 4477template<class _Tp, class ..._Args> 4478inline _LIBCPP_INLINE_VISIBILITY 4479typename enable_if 4480< 4481 !is_array<_Tp>::value, 4482 shared_ptr<_Tp> 4483>::type 4484make_shared(_Args&& ...__args) 4485{ 4486 static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared"); 4487 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4488 typedef allocator<_CntrlBlk> _A2; 4489 typedef __allocator_destructor<_A2> _D2; 4490 4491 _A2 __a2; 4492 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4493 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); 4494 4495 _Tp *__ptr = __hold2.get()->get(); 4496 return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release()); 4497} 4498 4499template<class _Tp, class _Alloc, class ..._Args> 4500inline _LIBCPP_INLINE_VISIBILITY 4501typename enable_if 4502< 4503 !is_array<_Tp>::value, 4504 shared_ptr<_Tp> 4505>::type 4506allocate_shared(const _Alloc& __a, _Args&& ...__args) 4507{ 4508 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared"); 4509 4510 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4511 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4512 typedef __allocator_destructor<_A2> _D2; 4513 4514 _A2 __a2(__a); 4515 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4516 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4517 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); 4518 4519 typename shared_ptr<_Tp>::element_type *__p = __hold2.get()->get(); 4520 return shared_ptr<_Tp>::__create_with_control_block(__p, _VSTD::addressof(*__hold2.release())); 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 __x.get() == __y.get(); 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, class _Up> 4540inline _LIBCPP_INLINE_VISIBILITY 4541bool 4542operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4543{ 4544#if _LIBCPP_STD_VER <= 11 4545 typedef typename common_type<_Tp*, _Up*>::type _Vp; 4546 return less<_Vp>()(__x.get(), __y.get()); 4547#else 4548 return less<>()(__x.get(), __y.get()); 4549#endif 4550 4551} 4552 4553template<class _Tp, class _Up> 4554inline _LIBCPP_INLINE_VISIBILITY 4555bool 4556operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4557{ 4558 return __y < __x; 4559} 4560 4561template<class _Tp, class _Up> 4562inline _LIBCPP_INLINE_VISIBILITY 4563bool 4564operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4565{ 4566 return !(__y < __x); 4567} 4568 4569template<class _Tp, class _Up> 4570inline _LIBCPP_INLINE_VISIBILITY 4571bool 4572operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4573{ 4574 return !(__x < __y); 4575} 4576 4577template<class _Tp> 4578inline _LIBCPP_INLINE_VISIBILITY 4579bool 4580operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4581{ 4582 return !__x; 4583} 4584 4585template<class _Tp> 4586inline _LIBCPP_INLINE_VISIBILITY 4587bool 4588operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4589{ 4590 return !__x; 4591} 4592 4593template<class _Tp> 4594inline _LIBCPP_INLINE_VISIBILITY 4595bool 4596operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4597{ 4598 return static_cast<bool>(__x); 4599} 4600 4601template<class _Tp> 4602inline _LIBCPP_INLINE_VISIBILITY 4603bool 4604operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4605{ 4606 return static_cast<bool>(__x); 4607} 4608 4609template<class _Tp> 4610inline _LIBCPP_INLINE_VISIBILITY 4611bool 4612operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4613{ 4614 return less<_Tp*>()(__x.get(), nullptr); 4615} 4616 4617template<class _Tp> 4618inline _LIBCPP_INLINE_VISIBILITY 4619bool 4620operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4621{ 4622 return less<_Tp*>()(nullptr, __x.get()); 4623} 4624 4625template<class _Tp> 4626inline _LIBCPP_INLINE_VISIBILITY 4627bool 4628operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4629{ 4630 return nullptr < __x; 4631} 4632 4633template<class _Tp> 4634inline _LIBCPP_INLINE_VISIBILITY 4635bool 4636operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4637{ 4638 return __x < nullptr; 4639} 4640 4641template<class _Tp> 4642inline _LIBCPP_INLINE_VISIBILITY 4643bool 4644operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4645{ 4646 return !(nullptr < __x); 4647} 4648 4649template<class _Tp> 4650inline _LIBCPP_INLINE_VISIBILITY 4651bool 4652operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4653{ 4654 return !(__x < nullptr); 4655} 4656 4657template<class _Tp> 4658inline _LIBCPP_INLINE_VISIBILITY 4659bool 4660operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4661{ 4662 return !(__x < nullptr); 4663} 4664 4665template<class _Tp> 4666inline _LIBCPP_INLINE_VISIBILITY 4667bool 4668operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4669{ 4670 return !(nullptr < __x); 4671} 4672 4673template<class _Tp> 4674inline _LIBCPP_INLINE_VISIBILITY 4675void 4676swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT 4677{ 4678 __x.swap(__y); 4679} 4680 4681template<class _Tp, class _Up> 4682inline _LIBCPP_INLINE_VISIBILITY 4683shared_ptr<_Tp> 4684static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 4685{ 4686 return shared_ptr<_Tp>(__r, 4687 static_cast< 4688 typename shared_ptr<_Tp>::element_type*>(__r.get())); 4689} 4690 4691template<class _Tp, class _Up> 4692inline _LIBCPP_INLINE_VISIBILITY 4693shared_ptr<_Tp> 4694dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 4695{ 4696 typedef typename shared_ptr<_Tp>::element_type _ET; 4697 _ET* __p = dynamic_cast<_ET*>(__r.get()); 4698 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); 4699} 4700 4701template<class _Tp, class _Up> 4702shared_ptr<_Tp> 4703const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 4704{ 4705 typedef typename shared_ptr<_Tp>::element_type _RTp; 4706 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); 4707} 4708 4709template<class _Tp, class _Up> 4710shared_ptr<_Tp> 4711reinterpret_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 4712{ 4713 return shared_ptr<_Tp>(__r, 4714 reinterpret_cast< 4715 typename shared_ptr<_Tp>::element_type*>(__r.get())); 4716} 4717 4718#ifndef _LIBCPP_NO_RTTI 4719 4720template<class _Dp, class _Tp> 4721inline _LIBCPP_INLINE_VISIBILITY 4722_Dp* 4723get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT 4724{ 4725 return __p.template __get_deleter<_Dp>(); 4726} 4727 4728#endif // _LIBCPP_NO_RTTI 4729 4730template<class _Tp> 4731class _LIBCPP_TEMPLATE_VIS weak_ptr 4732{ 4733public: 4734 typedef _Tp element_type; 4735private: 4736 element_type* __ptr_; 4737 __shared_weak_count* __cntrl_; 4738 4739public: 4740 _LIBCPP_INLINE_VISIBILITY 4741 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; 4742 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r, 4743 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 4744 _NOEXCEPT; 4745 _LIBCPP_INLINE_VISIBILITY 4746 weak_ptr(weak_ptr const& __r) _NOEXCEPT; 4747 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r, 4748 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 4749 _NOEXCEPT; 4750 4751#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4752 _LIBCPP_INLINE_VISIBILITY 4753 weak_ptr(weak_ptr&& __r) _NOEXCEPT; 4754 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r, 4755 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 4756 _NOEXCEPT; 4757#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4758 ~weak_ptr(); 4759 4760 _LIBCPP_INLINE_VISIBILITY 4761 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; 4762 template<class _Yp> 4763 typename enable_if 4764 < 4765 is_convertible<_Yp*, element_type*>::value, 4766 weak_ptr& 4767 >::type 4768 _LIBCPP_INLINE_VISIBILITY 4769 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; 4770 4771#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4772 4773 _LIBCPP_INLINE_VISIBILITY 4774 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; 4775 template<class _Yp> 4776 typename enable_if 4777 < 4778 is_convertible<_Yp*, element_type*>::value, 4779 weak_ptr& 4780 >::type 4781 _LIBCPP_INLINE_VISIBILITY 4782 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; 4783 4784#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4785 4786 template<class _Yp> 4787 typename enable_if 4788 < 4789 is_convertible<_Yp*, element_type*>::value, 4790 weak_ptr& 4791 >::type 4792 _LIBCPP_INLINE_VISIBILITY 4793 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; 4794 4795 _LIBCPP_INLINE_VISIBILITY 4796 void swap(weak_ptr& __r) _NOEXCEPT; 4797 _LIBCPP_INLINE_VISIBILITY 4798 void reset() _NOEXCEPT; 4799 4800 _LIBCPP_INLINE_VISIBILITY 4801 long use_count() const _NOEXCEPT 4802 {return __cntrl_ ? __cntrl_->use_count() : 0;} 4803 _LIBCPP_INLINE_VISIBILITY 4804 bool expired() const _NOEXCEPT 4805 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} 4806 shared_ptr<_Tp> lock() const _NOEXCEPT; 4807 template<class _Up> 4808 _LIBCPP_INLINE_VISIBILITY 4809 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT 4810 {return __cntrl_ < __r.__cntrl_;} 4811 template<class _Up> 4812 _LIBCPP_INLINE_VISIBILITY 4813 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT 4814 {return __cntrl_ < __r.__cntrl_;} 4815 4816 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; 4817 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; 4818}; 4819 4820#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 4821template<class _Tp> 4822weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; 4823#endif 4824 4825template<class _Tp> 4826inline 4827_LIBCPP_CONSTEXPR 4828weak_ptr<_Tp>::weak_ptr() _NOEXCEPT 4829 : __ptr_(0), 4830 __cntrl_(0) 4831{ 4832} 4833 4834template<class _Tp> 4835inline 4836weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT 4837 : __ptr_(__r.__ptr_), 4838 __cntrl_(__r.__cntrl_) 4839{ 4840 if (__cntrl_) 4841 __cntrl_->__add_weak(); 4842} 4843 4844template<class _Tp> 4845template<class _Yp> 4846inline 4847weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, 4848 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 4849 _NOEXCEPT 4850 : __ptr_(__r.__ptr_), 4851 __cntrl_(__r.__cntrl_) 4852{ 4853 if (__cntrl_) 4854 __cntrl_->__add_weak(); 4855} 4856 4857template<class _Tp> 4858template<class _Yp> 4859inline 4860weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, 4861 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 4862 _NOEXCEPT 4863 : __ptr_(__r.__ptr_), 4864 __cntrl_(__r.__cntrl_) 4865{ 4866 if (__cntrl_) 4867 __cntrl_->__add_weak(); 4868} 4869 4870#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4871 4872template<class _Tp> 4873inline 4874weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT 4875 : __ptr_(__r.__ptr_), 4876 __cntrl_(__r.__cntrl_) 4877{ 4878 __r.__ptr_ = 0; 4879 __r.__cntrl_ = 0; 4880} 4881 4882template<class _Tp> 4883template<class _Yp> 4884inline 4885weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, 4886 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 4887 _NOEXCEPT 4888 : __ptr_(__r.__ptr_), 4889 __cntrl_(__r.__cntrl_) 4890{ 4891 __r.__ptr_ = 0; 4892 __r.__cntrl_ = 0; 4893} 4894 4895#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4896 4897template<class _Tp> 4898weak_ptr<_Tp>::~weak_ptr() 4899{ 4900 if (__cntrl_) 4901 __cntrl_->__release_weak(); 4902} 4903 4904template<class _Tp> 4905inline 4906weak_ptr<_Tp>& 4907weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT 4908{ 4909 weak_ptr(__r).swap(*this); 4910 return *this; 4911} 4912 4913template<class _Tp> 4914template<class _Yp> 4915inline 4916typename enable_if 4917< 4918 is_convertible<_Yp*, _Tp*>::value, 4919 weak_ptr<_Tp>& 4920>::type 4921weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT 4922{ 4923 weak_ptr(__r).swap(*this); 4924 return *this; 4925} 4926 4927#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4928 4929template<class _Tp> 4930inline 4931weak_ptr<_Tp>& 4932weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT 4933{ 4934 weak_ptr(_VSTD::move(__r)).swap(*this); 4935 return *this; 4936} 4937 4938template<class _Tp> 4939template<class _Yp> 4940inline 4941typename enable_if 4942< 4943 is_convertible<_Yp*, _Tp*>::value, 4944 weak_ptr<_Tp>& 4945>::type 4946weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT 4947{ 4948 weak_ptr(_VSTD::move(__r)).swap(*this); 4949 return *this; 4950} 4951 4952#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4953 4954template<class _Tp> 4955template<class _Yp> 4956inline 4957typename enable_if 4958< 4959 is_convertible<_Yp*, _Tp*>::value, 4960 weak_ptr<_Tp>& 4961>::type 4962weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT 4963{ 4964 weak_ptr(__r).swap(*this); 4965 return *this; 4966} 4967 4968template<class _Tp> 4969inline 4970void 4971weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT 4972{ 4973 _VSTD::swap(__ptr_, __r.__ptr_); 4974 _VSTD::swap(__cntrl_, __r.__cntrl_); 4975} 4976 4977template<class _Tp> 4978inline _LIBCPP_INLINE_VISIBILITY 4979void 4980swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT 4981{ 4982 __x.swap(__y); 4983} 4984 4985template<class _Tp> 4986inline 4987void 4988weak_ptr<_Tp>::reset() _NOEXCEPT 4989{ 4990 weak_ptr().swap(*this); 4991} 4992 4993template<class _Tp> 4994template<class _Yp> 4995shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, 4996 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4997 : __ptr_(__r.__ptr_), 4998 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) 4999{ 5000 if (__cntrl_ == 0) 5001 __throw_bad_weak_ptr(); 5002} 5003 5004template<class _Tp> 5005shared_ptr<_Tp> 5006weak_ptr<_Tp>::lock() const _NOEXCEPT 5007{ 5008 shared_ptr<_Tp> __r; 5009 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; 5010 if (__r.__cntrl_) 5011 __r.__ptr_ = __ptr_; 5012 return __r; 5013} 5014 5015#if _LIBCPP_STD_VER > 14 5016template <class _Tp = void> struct owner_less; 5017#else 5018template <class _Tp> struct owner_less; 5019#endif 5020 5021template <class _Tp> 5022struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > 5023 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> 5024{ 5025 typedef bool result_type; 5026 _LIBCPP_INLINE_VISIBILITY 5027 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT 5028 {return __x.owner_before(__y);} 5029 _LIBCPP_INLINE_VISIBILITY 5030 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT 5031 {return __x.owner_before(__y);} 5032 _LIBCPP_INLINE_VISIBILITY 5033 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT 5034 {return __x.owner_before(__y);} 5035}; 5036 5037template <class _Tp> 5038struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > 5039 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> 5040{ 5041 typedef bool result_type; 5042 _LIBCPP_INLINE_VISIBILITY 5043 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT 5044 {return __x.owner_before(__y);} 5045 _LIBCPP_INLINE_VISIBILITY 5046 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT 5047 {return __x.owner_before(__y);} 5048 _LIBCPP_INLINE_VISIBILITY 5049 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT 5050 {return __x.owner_before(__y);} 5051}; 5052 5053#if _LIBCPP_STD_VER > 14 5054template <> 5055struct _LIBCPP_TEMPLATE_VIS owner_less<void> 5056{ 5057 template <class _Tp, class _Up> 5058 _LIBCPP_INLINE_VISIBILITY 5059 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT 5060 {return __x.owner_before(__y);} 5061 template <class _Tp, class _Up> 5062 _LIBCPP_INLINE_VISIBILITY 5063 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT 5064 {return __x.owner_before(__y);} 5065 template <class _Tp, class _Up> 5066 _LIBCPP_INLINE_VISIBILITY 5067 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT 5068 {return __x.owner_before(__y);} 5069 template <class _Tp, class _Up> 5070 _LIBCPP_INLINE_VISIBILITY 5071 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT 5072 {return __x.owner_before(__y);} 5073 typedef void is_transparent; 5074}; 5075#endif 5076 5077template<class _Tp> 5078class _LIBCPP_TEMPLATE_VIS enable_shared_from_this 5079{ 5080 mutable weak_ptr<_Tp> __weak_this_; 5081protected: 5082 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 5083 enable_shared_from_this() _NOEXCEPT {} 5084 _LIBCPP_INLINE_VISIBILITY 5085 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} 5086 _LIBCPP_INLINE_VISIBILITY 5087 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT 5088 {return *this;} 5089 _LIBCPP_INLINE_VISIBILITY 5090 ~enable_shared_from_this() {} 5091public: 5092 _LIBCPP_INLINE_VISIBILITY 5093 shared_ptr<_Tp> shared_from_this() 5094 {return shared_ptr<_Tp>(__weak_this_);} 5095 _LIBCPP_INLINE_VISIBILITY 5096 shared_ptr<_Tp const> shared_from_this() const 5097 {return shared_ptr<const _Tp>(__weak_this_);} 5098 5099#if _LIBCPP_STD_VER > 14 5100 _LIBCPP_INLINE_VISIBILITY 5101 weak_ptr<_Tp> weak_from_this() _NOEXCEPT 5102 { return __weak_this_; } 5103 5104 _LIBCPP_INLINE_VISIBILITY 5105 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT 5106 { return __weak_this_; } 5107#endif // _LIBCPP_STD_VER > 14 5108 5109 template <class _Up> friend class shared_ptr; 5110}; 5111 5112template <class _Tp> 5113struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > 5114{ 5115 typedef shared_ptr<_Tp> argument_type; 5116 typedef size_t result_type; 5117 5118 _LIBCPP_INLINE_VISIBILITY 5119 result_type operator()(const argument_type& __ptr) const _NOEXCEPT 5120 { 5121 return hash<typename shared_ptr<_Tp>::element_type*>()(__ptr.get()); 5122 } 5123}; 5124 5125template<class _CharT, class _Traits, class _Yp> 5126inline _LIBCPP_INLINE_VISIBILITY 5127basic_ostream<_CharT, _Traits>& 5128operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); 5129 5130 5131#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) 5132 5133class _LIBCPP_TYPE_VIS __sp_mut 5134{ 5135 void* __lx; 5136public: 5137 void lock() _NOEXCEPT; 5138 void unlock() _NOEXCEPT; 5139 5140private: 5141 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; 5142 __sp_mut(const __sp_mut&); 5143 __sp_mut& operator=(const __sp_mut&); 5144 5145 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); 5146}; 5147 5148_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5149__sp_mut& __get_sp_mut(const void*); 5150 5151template <class _Tp> 5152inline _LIBCPP_INLINE_VISIBILITY 5153bool 5154atomic_is_lock_free(const shared_ptr<_Tp>*) 5155{ 5156 return false; 5157} 5158 5159template <class _Tp> 5160_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5161shared_ptr<_Tp> 5162atomic_load(const shared_ptr<_Tp>* __p) 5163{ 5164 __sp_mut& __m = __get_sp_mut(__p); 5165 __m.lock(); 5166 shared_ptr<_Tp> __q = *__p; 5167 __m.unlock(); 5168 return __q; 5169} 5170 5171template <class _Tp> 5172inline _LIBCPP_INLINE_VISIBILITY 5173_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5174shared_ptr<_Tp> 5175atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) 5176{ 5177 return atomic_load(__p); 5178} 5179 5180template <class _Tp> 5181_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5182void 5183atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) 5184{ 5185 __sp_mut& __m = __get_sp_mut(__p); 5186 __m.lock(); 5187 __p->swap(__r); 5188 __m.unlock(); 5189} 5190 5191template <class _Tp> 5192inline _LIBCPP_INLINE_VISIBILITY 5193_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5194void 5195atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) 5196{ 5197 atomic_store(__p, __r); 5198} 5199 5200template <class _Tp> 5201_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5202shared_ptr<_Tp> 5203atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) 5204{ 5205 __sp_mut& __m = __get_sp_mut(__p); 5206 __m.lock(); 5207 __p->swap(__r); 5208 __m.unlock(); 5209 return __r; 5210} 5211 5212template <class _Tp> 5213inline _LIBCPP_INLINE_VISIBILITY 5214_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5215shared_ptr<_Tp> 5216atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) 5217{ 5218 return atomic_exchange(__p, __r); 5219} 5220 5221template <class _Tp> 5222_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5223bool 5224atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) 5225{ 5226 shared_ptr<_Tp> __temp; 5227 __sp_mut& __m = __get_sp_mut(__p); 5228 __m.lock(); 5229 if (__p->__owner_equivalent(*__v)) 5230 { 5231 _VSTD::swap(__temp, *__p); 5232 *__p = __w; 5233 __m.unlock(); 5234 return true; 5235 } 5236 _VSTD::swap(__temp, *__v); 5237 *__v = *__p; 5238 __m.unlock(); 5239 return false; 5240} 5241 5242template <class _Tp> 5243inline _LIBCPP_INLINE_VISIBILITY 5244_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5245bool 5246atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) 5247{ 5248 return atomic_compare_exchange_strong(__p, __v, __w); 5249} 5250 5251template <class _Tp> 5252inline _LIBCPP_INLINE_VISIBILITY 5253_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5254bool 5255atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, 5256 shared_ptr<_Tp> __w, memory_order, memory_order) 5257{ 5258 return atomic_compare_exchange_strong(__p, __v, __w); 5259} 5260 5261template <class _Tp> 5262inline _LIBCPP_INLINE_VISIBILITY 5263_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 5264bool 5265atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, 5266 shared_ptr<_Tp> __w, memory_order, memory_order) 5267{ 5268 return atomic_compare_exchange_weak(__p, __v, __w); 5269} 5270 5271#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) 5272 5273//enum class 5274#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) 5275# ifndef _LIBCPP_CXX03_LANG 5276enum class pointer_safety : unsigned char { 5277 relaxed, 5278 preferred, 5279 strict 5280}; 5281# endif 5282#else 5283struct _LIBCPP_TYPE_VIS pointer_safety 5284{ 5285 enum __lx 5286 { 5287 relaxed, 5288 preferred, 5289 strict 5290 }; 5291 5292 __lx __v_; 5293 5294 _LIBCPP_INLINE_VISIBILITY 5295 pointer_safety() : __v_() {} 5296 5297 _LIBCPP_INLINE_VISIBILITY 5298 pointer_safety(__lx __v) : __v_(__v) {} 5299 _LIBCPP_INLINE_VISIBILITY 5300 operator int() const {return __v_;} 5301}; 5302#endif 5303 5304#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \ 5305 defined(_LIBCPP_BUILDING_LIBRARY) 5306_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; 5307#else 5308// This function is only offered in C++03 under ABI v1. 5309# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG) 5310inline _LIBCPP_INLINE_VISIBILITY 5311pointer_safety get_pointer_safety() _NOEXCEPT { 5312 return pointer_safety::relaxed; 5313} 5314# endif 5315#endif 5316 5317 5318_LIBCPP_FUNC_VIS void declare_reachable(void* __p); 5319_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); 5320_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); 5321_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); 5322 5323template <class _Tp> 5324inline _LIBCPP_INLINE_VISIBILITY 5325_Tp* 5326undeclare_reachable(_Tp* __p) 5327{ 5328 return static_cast<_Tp*>(__undeclare_reachable(__p)); 5329} 5330 5331_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); 5332 5333// --- Helper for container swap -- 5334template <typename _Alloc> 5335inline _LIBCPP_INLINE_VISIBILITY 5336void __swap_allocator(_Alloc & __a1, _Alloc & __a2) 5337#if _LIBCPP_STD_VER >= 14 5338 _NOEXCEPT 5339#else 5340 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 5341#endif 5342{ 5343 __swap_allocator(__a1, __a2, 5344 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); 5345} 5346 5347template <typename _Alloc> 5348_LIBCPP_INLINE_VISIBILITY 5349void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) 5350#if _LIBCPP_STD_VER >= 14 5351 _NOEXCEPT 5352#else 5353 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 5354#endif 5355{ 5356 using _VSTD::swap; 5357 swap(__a1, __a2); 5358} 5359 5360template <typename _Alloc> 5361inline _LIBCPP_INLINE_VISIBILITY 5362void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} 5363 5364template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > 5365struct __noexcept_move_assign_container : public integral_constant<bool, 5366 _Traits::propagate_on_container_move_assignment::value 5367#if _LIBCPP_STD_VER > 14 5368 || _Traits::is_always_equal::value 5369#else 5370 && is_nothrow_move_assignable<_Alloc>::value 5371#endif 5372 > {}; 5373 5374 5375#ifndef _LIBCPP_HAS_NO_VARIADICS 5376template <class _Tp, class _Alloc> 5377struct __temp_value { 5378 typedef allocator_traits<_Alloc> _Traits; 5379 5380 typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v; 5381 _Alloc &__a; 5382 5383 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } 5384 _Tp & get() { return *__addr(); } 5385 5386 template<class... _Args> 5387 _LIBCPP_NO_CFI 5388 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { 5389 _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)), 5390 _VSTD::forward<_Args>(__args)...); 5391 } 5392 5393 ~__temp_value() { _Traits::destroy(__a, __addr()); } 5394 }; 5395#endif 5396 5397template<typename _Alloc, typename = void, typename = void> 5398struct __is_allocator : false_type {}; 5399 5400template<typename _Alloc> 5401struct __is_allocator<_Alloc, 5402 typename __void_t<typename _Alloc::value_type>::type, 5403 typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type 5404 > 5405 : true_type {}; 5406 5407// __builtin_new_allocator -- A non-templated helper for allocating and 5408// deallocating memory using __builtin_operator_new and 5409// __builtin_operator_delete. It should be used in preference to 5410// `std::allocator<T>` to avoid additional instantiations. 5411struct __builtin_new_allocator { 5412 struct __builtin_new_deleter { 5413 typedef void* pointer_type; 5414 5415 _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align) 5416 : __size_(__size), __align_(__align) {} 5417 5418 void operator()(void* p) const _NOEXCEPT { 5419 std::__libcpp_deallocate(p, __size_, __align_); 5420 } 5421 5422 private: 5423 size_t __size_; 5424 size_t __align_; 5425 }; 5426 5427 typedef unique_ptr<void, __builtin_new_deleter> __holder_t; 5428 5429 static __holder_t __allocate_bytes(size_t __s, size_t __align) { 5430 return __holder_t(std::__libcpp_allocate(__s, __align), 5431 __builtin_new_deleter(__s, __align)); 5432 } 5433 5434 static void __deallocate_bytes(void* __p, size_t __s, 5435 size_t __align) _NOEXCEPT { 5436 std::__libcpp_deallocate(__p, __s, __align); 5437 } 5438 5439 template <class _Tp> 5440 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE 5441 static __holder_t __allocate_type(size_t __n) { 5442 return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); 5443 } 5444 5445 template <class _Tp> 5446 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE 5447 static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { 5448 __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); 5449 } 5450}; 5451 5452 5453_LIBCPP_END_NAMESPACE_STD 5454 5455_LIBCPP_POP_MACROS 5456 5457#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 5458# include <__pstl_memory> 5459#endif 5460 5461#endif // _LIBCPP_MEMORY 5462