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