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