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