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();} 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 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} 1730 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT 1731 {_VSTD::__deallocate((void*)__p);} 1732 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT 1733 {return size_type(~0) / sizeof(_Tp);} 1734#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1735 template <class _Up, class... _Args> 1736 _LIBCPP_INLINE_VISIBILITY 1737 void 1738 construct(_Up* __p, _Args&&... __args) 1739 { 1740 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); 1741 } 1742#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1743 _LIBCPP_INLINE_VISIBILITY 1744 void 1745 construct(pointer __p) 1746 { 1747 ::new((void*)__p) _Tp(); 1748 } 1749# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 1750 1751 template <class _A0> 1752 _LIBCPP_INLINE_VISIBILITY 1753 void 1754 construct(pointer __p, _A0& __a0) 1755 { 1756 ::new((void*)__p) _Tp(__a0); 1757 } 1758 template <class _A0> 1759 _LIBCPP_INLINE_VISIBILITY 1760 void 1761 construct(pointer __p, const _A0& __a0) 1762 { 1763 ::new((void*)__p) _Tp(__a0); 1764 } 1765# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 1766 template <class _A0, class _A1> 1767 _LIBCPP_INLINE_VISIBILITY 1768 void 1769 construct(pointer __p, _A0& __a0, _A1& __a1) 1770 { 1771 ::new((void*)__p) _Tp(__a0, __a1); 1772 } 1773 template <class _A0, class _A1> 1774 _LIBCPP_INLINE_VISIBILITY 1775 void 1776 construct(pointer __p, const _A0& __a0, _A1& __a1) 1777 { 1778 ::new((void*)__p) _Tp(__a0, __a1); 1779 } 1780 template <class _A0, class _A1> 1781 _LIBCPP_INLINE_VISIBILITY 1782 void 1783 construct(pointer __p, _A0& __a0, const _A1& __a1) 1784 { 1785 ::new((void*)__p) _Tp(__a0, __a1); 1786 } 1787 template <class _A0, class _A1> 1788 _LIBCPP_INLINE_VISIBILITY 1789 void 1790 construct(pointer __p, const _A0& __a0, const _A1& __a1) 1791 { 1792 ::new((void*)__p) _Tp(__a0, __a1); 1793 } 1794#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1795 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} 1796}; 1797 1798template <class _Tp> 1799class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp> 1800{ 1801public: 1802 typedef size_t size_type; 1803 typedef ptrdiff_t difference_type; 1804 typedef const _Tp* pointer; 1805 typedef const _Tp* const_pointer; 1806 typedef const _Tp& reference; 1807 typedef const _Tp& const_reference; 1808 typedef const _Tp value_type; 1809 1810 typedef true_type propagate_on_container_move_assignment; 1811 typedef true_type is_always_equal; 1812 1813 template <class _Up> struct rebind {typedef allocator<_Up> other;}; 1814 1815 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {} 1816 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {} 1817 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT 1818 {return _VSTD::addressof(__x);} 1819 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) 1820 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} 1821 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT 1822 {_VSTD::__deallocate((void*)__p);} 1823 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT 1824 {return size_type(~0) / sizeof(_Tp);} 1825#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1826 template <class _Up, class... _Args> 1827 _LIBCPP_INLINE_VISIBILITY 1828 void 1829 construct(_Up* __p, _Args&&... __args) 1830 { 1831 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); 1832 } 1833#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1834 _LIBCPP_INLINE_VISIBILITY 1835 void 1836 construct(pointer __p) 1837 { 1838 ::new((void*)__p) _Tp(); 1839 } 1840# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 1841 1842 template <class _A0> 1843 _LIBCPP_INLINE_VISIBILITY 1844 void 1845 construct(pointer __p, _A0& __a0) 1846 { 1847 ::new((void*)__p) _Tp(__a0); 1848 } 1849 template <class _A0> 1850 _LIBCPP_INLINE_VISIBILITY 1851 void 1852 construct(pointer __p, const _A0& __a0) 1853 { 1854 ::new((void*)__p) _Tp(__a0); 1855 } 1856# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 1857 template <class _A0, class _A1> 1858 _LIBCPP_INLINE_VISIBILITY 1859 void 1860 construct(pointer __p, _A0& __a0, _A1& __a1) 1861 { 1862 ::new((void*)__p) _Tp(__a0, __a1); 1863 } 1864 template <class _A0, class _A1> 1865 _LIBCPP_INLINE_VISIBILITY 1866 void 1867 construct(pointer __p, const _A0& __a0, _A1& __a1) 1868 { 1869 ::new((void*)__p) _Tp(__a0, __a1); 1870 } 1871 template <class _A0, class _A1> 1872 _LIBCPP_INLINE_VISIBILITY 1873 void 1874 construct(pointer __p, _A0& __a0, const _A1& __a1) 1875 { 1876 ::new((void*)__p) _Tp(__a0, __a1); 1877 } 1878 template <class _A0, class _A1> 1879 _LIBCPP_INLINE_VISIBILITY 1880 void 1881 construct(pointer __p, const _A0& __a0, const _A1& __a1) 1882 { 1883 ::new((void*)__p) _Tp(__a0, __a1); 1884 } 1885#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1886 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} 1887}; 1888 1889template <class _Tp, class _Up> 1890inline _LIBCPP_INLINE_VISIBILITY 1891bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} 1892 1893template <class _Tp, class _Up> 1894inline _LIBCPP_INLINE_VISIBILITY 1895bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} 1896 1897template <class _OutputIterator, class _Tp> 1898class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator 1899 : public iterator<output_iterator_tag, 1900 _Tp, // purposefully not C++03 1901 ptrdiff_t, // purposefully not C++03 1902 _Tp*, // purposefully not C++03 1903 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 1904{ 1905private: 1906 _OutputIterator __x_; 1907public: 1908 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} 1909 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} 1910 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) 1911 {::new(&*__x_) _Tp(__element); return *this;} 1912 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} 1913 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) 1914 {raw_storage_iterator __t(*this); ++__x_; return __t;} 1915#if _LIBCPP_STD_VER >= 14 1916 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } 1917#endif 1918}; 1919 1920template <class _Tp> 1921pair<_Tp*, ptrdiff_t> 1922get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT 1923{ 1924 pair<_Tp*, ptrdiff_t> __r(0, 0); 1925 const ptrdiff_t __m = (~ptrdiff_t(0) ^ 1926 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) 1927 / sizeof(_Tp); 1928 if (__n > __m) 1929 __n = __m; 1930 while (__n > 0) 1931 { 1932 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); 1933 if (__r.first) 1934 { 1935 __r.second = __n; 1936 break; 1937 } 1938 __n /= 2; 1939 } 1940 return __r; 1941} 1942 1943template <class _Tp> 1944inline _LIBCPP_INLINE_VISIBILITY 1945void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);} 1946 1947template <class _Tp> 1948struct auto_ptr_ref 1949{ 1950 _Tp* __ptr_; 1951}; 1952 1953template<class _Tp> 1954class _LIBCPP_TYPE_VIS_ONLY auto_ptr 1955{ 1956private: 1957 _Tp* __ptr_; 1958public: 1959 typedef _Tp element_type; 1960 1961 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {} 1962 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {} 1963 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw() 1964 : __ptr_(__p.release()) {} 1965 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw() 1966 {reset(__p.release()); return *this;} 1967 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw() 1968 {reset(__p.release()); return *this;} 1969 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw() 1970 {reset(__p.__ptr_); return *this;} 1971 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;} 1972 1973 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw() 1974 {return *__ptr_;} 1975 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;} 1976 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;} 1977 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw() 1978 { 1979 _Tp* __t = __ptr_; 1980 __ptr_ = 0; 1981 return __t; 1982 } 1983 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw() 1984 { 1985 if (__ptr_ != __p) 1986 delete __ptr_; 1987 __ptr_ = __p; 1988 } 1989 1990 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {} 1991 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw() 1992 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} 1993 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw() 1994 {return auto_ptr<_Up>(release());} 1995}; 1996 1997template <> 1998class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void> 1999{ 2000public: 2001 typedef void element_type; 2002}; 2003 2004template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type, 2005 typename remove_cv<_T2>::type>::value, 2006 bool = is_empty<_T1>::value 2007 && !__libcpp_is_final<_T1>::value, 2008 bool = is_empty<_T2>::value 2009 && !__libcpp_is_final<_T2>::value 2010 > 2011struct __libcpp_compressed_pair_switch; 2012 2013template <class _T1, class _T2, bool IsSame> 2014struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};}; 2015 2016template <class _T1, class _T2, bool IsSame> 2017struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};}; 2018 2019template <class _T1, class _T2, bool IsSame> 2020struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};}; 2021 2022template <class _T1, class _T2> 2023struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};}; 2024 2025template <class _T1, class _T2> 2026struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};}; 2027 2028template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value> 2029class __libcpp_compressed_pair_imp; 2030 2031template <class _T1, class _T2> 2032class __libcpp_compressed_pair_imp<_T1, _T2, 0> 2033{ 2034private: 2035 _T1 __first_; 2036 _T2 __second_; 2037public: 2038 typedef _T1 _T1_param; 2039 typedef _T2 _T2_param; 2040 2041 typedef typename remove_reference<_T1>::type& _T1_reference; 2042 typedef typename remove_reference<_T2>::type& _T2_reference; 2043 2044 typedef const typename remove_reference<_T1>::type& _T1_const_reference; 2045 typedef const typename remove_reference<_T2>::type& _T2_const_reference; 2046 2047 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {} 2048 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) 2049 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {} 2050 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) 2051 : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {} 2052 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) 2053 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {} 2054 2055#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2056 2057 _LIBCPP_INLINE_VISIBILITY 2058 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) 2059 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2060 is_nothrow_copy_constructible<_T2>::value) 2061 : __first_(__p.first()), 2062 __second_(__p.second()) {} 2063 2064 _LIBCPP_INLINE_VISIBILITY 2065 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) 2066 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2067 is_nothrow_copy_assignable<_T2>::value) 2068 { 2069 __first_ = __p.first(); 2070 __second_ = __p.second(); 2071 return *this; 2072 } 2073 2074 _LIBCPP_INLINE_VISIBILITY 2075 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) 2076 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2077 is_nothrow_move_constructible<_T2>::value) 2078 : __first_(_VSTD::forward<_T1>(__p.first())), 2079 __second_(_VSTD::forward<_T2>(__p.second())) {} 2080 2081 _LIBCPP_INLINE_VISIBILITY 2082 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) 2083 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2084 is_nothrow_move_assignable<_T2>::value) 2085 { 2086 __first_ = _VSTD::forward<_T1>(__p.first()); 2087 __second_ = _VSTD::forward<_T2>(__p.second()); 2088 return *this; 2089 } 2090 2091#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2092 2093#ifndef _LIBCPP_HAS_NO_VARIADICS 2094 2095 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 2096 _LIBCPP_INLINE_VISIBILITY 2097 __libcpp_compressed_pair_imp(piecewise_construct_t __pc, 2098 tuple<_Args1...> __first_args, 2099 tuple<_Args2...> __second_args, 2100 __tuple_indices<_I1...>, 2101 __tuple_indices<_I2...>) 2102 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), 2103 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) 2104 {} 2105 2106#endif // _LIBCPP_HAS_NO_VARIADICS 2107 2108 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} 2109 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} 2110 2111 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} 2112 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} 2113 2114 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) 2115 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2116 __is_nothrow_swappable<_T2>::value) 2117 { 2118 using _VSTD::swap; 2119 swap(__first_, __x.__first_); 2120 swap(__second_, __x.__second_); 2121 } 2122}; 2123 2124template <class _T1, class _T2> 2125class __libcpp_compressed_pair_imp<_T1, _T2, 1> 2126 : private _T1 2127{ 2128private: 2129 _T2 __second_; 2130public: 2131 typedef _T1 _T1_param; 2132 typedef _T2 _T2_param; 2133 2134 typedef _T1& _T1_reference; 2135 typedef typename remove_reference<_T2>::type& _T2_reference; 2136 2137 typedef const _T1& _T1_const_reference; 2138 typedef const typename remove_reference<_T2>::type& _T2_const_reference; 2139 2140 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {} 2141 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) 2142 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {} 2143 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) 2144 : __second_(_VSTD::forward<_T2_param>(__t2)) {} 2145 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) 2146 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {} 2147 2148#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2149 2150 _LIBCPP_INLINE_VISIBILITY 2151 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) 2152 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2153 is_nothrow_copy_constructible<_T2>::value) 2154 : _T1(__p.first()), __second_(__p.second()) {} 2155 2156 _LIBCPP_INLINE_VISIBILITY 2157 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) 2158 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2159 is_nothrow_copy_assignable<_T2>::value) 2160 { 2161 _T1::operator=(__p.first()); 2162 __second_ = __p.second(); 2163 return *this; 2164 } 2165 2166 _LIBCPP_INLINE_VISIBILITY 2167 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) 2168 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2169 is_nothrow_move_constructible<_T2>::value) 2170 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {} 2171 2172 _LIBCPP_INLINE_VISIBILITY 2173 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) 2174 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2175 is_nothrow_move_assignable<_T2>::value) 2176 { 2177 _T1::operator=(_VSTD::move(__p.first())); 2178 __second_ = _VSTD::forward<_T2>(__p.second()); 2179 return *this; 2180 } 2181 2182#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2183 2184#ifndef _LIBCPP_HAS_NO_VARIADICS 2185 2186 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 2187 _LIBCPP_INLINE_VISIBILITY 2188 __libcpp_compressed_pair_imp(piecewise_construct_t __pc, 2189 tuple<_Args1...> __first_args, 2190 tuple<_Args2...> __second_args, 2191 __tuple_indices<_I1...>, 2192 __tuple_indices<_I2...>) 2193 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), 2194 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) 2195 {} 2196 2197#endif // _LIBCPP_HAS_NO_VARIADICS 2198 2199 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} 2200 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} 2201 2202 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} 2203 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} 2204 2205 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) 2206 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2207 __is_nothrow_swappable<_T2>::value) 2208 { 2209 using _VSTD::swap; 2210 swap(__second_, __x.__second_); 2211 } 2212}; 2213 2214template <class _T1, class _T2> 2215class __libcpp_compressed_pair_imp<_T1, _T2, 2> 2216 : private _T2 2217{ 2218private: 2219 _T1 __first_; 2220public: 2221 typedef _T1 _T1_param; 2222 typedef _T2 _T2_param; 2223 2224 typedef typename remove_reference<_T1>::type& _T1_reference; 2225 typedef _T2& _T2_reference; 2226 2227 typedef const typename remove_reference<_T1>::type& _T1_const_reference; 2228 typedef const _T2& _T2_const_reference; 2229 2230 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {} 2231 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) 2232 : __first_(_VSTD::forward<_T1_param>(__t1)) {} 2233 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) 2234 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {} 2235 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) 2236 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2237 is_nothrow_move_constructible<_T2>::value) 2238 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {} 2239 2240#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2241 2242 _LIBCPP_INLINE_VISIBILITY 2243 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) 2244 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2245 is_nothrow_copy_constructible<_T2>::value) 2246 : _T2(__p.second()), __first_(__p.first()) {} 2247 2248 _LIBCPP_INLINE_VISIBILITY 2249 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) 2250 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2251 is_nothrow_copy_assignable<_T2>::value) 2252 { 2253 _T2::operator=(__p.second()); 2254 __first_ = __p.first(); 2255 return *this; 2256 } 2257 2258 _LIBCPP_INLINE_VISIBILITY 2259 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) 2260 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2261 is_nothrow_move_constructible<_T2>::value) 2262 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {} 2263 2264 _LIBCPP_INLINE_VISIBILITY 2265 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) 2266 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2267 is_nothrow_move_assignable<_T2>::value) 2268 { 2269 _T2::operator=(_VSTD::forward<_T2>(__p.second())); 2270 __first_ = _VSTD::move(__p.first()); 2271 return *this; 2272 } 2273 2274#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2275 2276#ifndef _LIBCPP_HAS_NO_VARIADICS 2277 2278 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 2279 _LIBCPP_INLINE_VISIBILITY 2280 __libcpp_compressed_pair_imp(piecewise_construct_t __pc, 2281 tuple<_Args1...> __first_args, 2282 tuple<_Args2...> __second_args, 2283 __tuple_indices<_I1...>, 2284 __tuple_indices<_I2...>) 2285 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...), 2286 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...) 2287 2288 {} 2289 2290#endif // _LIBCPP_HAS_NO_VARIADICS 2291 2292 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} 2293 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} 2294 2295 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} 2296 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} 2297 2298 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) 2299 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2300 __is_nothrow_swappable<_T2>::value) 2301 { 2302 using _VSTD::swap; 2303 swap(__first_, __x.__first_); 2304 } 2305}; 2306 2307template <class _T1, class _T2> 2308class __libcpp_compressed_pair_imp<_T1, _T2, 3> 2309 : private _T1, 2310 private _T2 2311{ 2312public: 2313 typedef _T1 _T1_param; 2314 typedef _T2 _T2_param; 2315 2316 typedef _T1& _T1_reference; 2317 typedef _T2& _T2_reference; 2318 2319 typedef const _T1& _T1_const_reference; 2320 typedef const _T2& _T2_const_reference; 2321 2322 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} 2323 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) 2324 : _T1(_VSTD::forward<_T1_param>(__t1)) {} 2325 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) 2326 : _T2(_VSTD::forward<_T2_param>(__t2)) {} 2327 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) 2328 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {} 2329 2330#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2331 2332 _LIBCPP_INLINE_VISIBILITY 2333 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) 2334 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2335 is_nothrow_copy_constructible<_T2>::value) 2336 : _T1(__p.first()), _T2(__p.second()) {} 2337 2338 _LIBCPP_INLINE_VISIBILITY 2339 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) 2340 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2341 is_nothrow_copy_assignable<_T2>::value) 2342 { 2343 _T1::operator=(__p.first()); 2344 _T2::operator=(__p.second()); 2345 return *this; 2346 } 2347 2348 _LIBCPP_INLINE_VISIBILITY 2349 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) 2350 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2351 is_nothrow_move_constructible<_T2>::value) 2352 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {} 2353 2354 _LIBCPP_INLINE_VISIBILITY 2355 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) 2356 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2357 is_nothrow_move_assignable<_T2>::value) 2358 { 2359 _T1::operator=(_VSTD::move(__p.first())); 2360 _T2::operator=(_VSTD::move(__p.second())); 2361 return *this; 2362 } 2363 2364#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2365 2366#ifndef _LIBCPP_HAS_NO_VARIADICS 2367 2368 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 2369 _LIBCPP_INLINE_VISIBILITY 2370 __libcpp_compressed_pair_imp(piecewise_construct_t __pc, 2371 tuple<_Args1...> __first_args, 2372 tuple<_Args2...> __second_args, 2373 __tuple_indices<_I1...>, 2374 __tuple_indices<_I2...>) 2375 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), 2376 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) 2377 {} 2378 2379#endif // _LIBCPP_HAS_NO_VARIADICS 2380 2381 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} 2382 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} 2383 2384 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} 2385 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} 2386 2387 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&) 2388 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2389 __is_nothrow_swappable<_T2>::value) 2390 { 2391 } 2392}; 2393 2394template <class _T1, class _T2> 2395class __compressed_pair 2396 : private __libcpp_compressed_pair_imp<_T1, _T2> 2397{ 2398 typedef __libcpp_compressed_pair_imp<_T1, _T2> base; 2399public: 2400 typedef typename base::_T1_param _T1_param; 2401 typedef typename base::_T2_param _T2_param; 2402 2403 typedef typename base::_T1_reference _T1_reference; 2404 typedef typename base::_T2_reference _T2_reference; 2405 2406 typedef typename base::_T1_const_reference _T1_const_reference; 2407 typedef typename base::_T2_const_reference _T2_const_reference; 2408 2409 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {} 2410 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1) 2411 : base(_VSTD::forward<_T1_param>(__t1)) {} 2412 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2) 2413 : base(_VSTD::forward<_T2_param>(__t2)) {} 2414 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2) 2415 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {} 2416 2417#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2418 2419 _LIBCPP_INLINE_VISIBILITY 2420 __compressed_pair(const __compressed_pair& __p) 2421 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2422 is_nothrow_copy_constructible<_T2>::value) 2423 : base(__p) {} 2424 2425 _LIBCPP_INLINE_VISIBILITY 2426 __compressed_pair& operator=(const __compressed_pair& __p) 2427 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2428 is_nothrow_copy_assignable<_T2>::value) 2429 { 2430 base::operator=(__p); 2431 return *this; 2432 } 2433 2434 _LIBCPP_INLINE_VISIBILITY 2435 __compressed_pair(__compressed_pair&& __p) 2436 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2437 is_nothrow_move_constructible<_T2>::value) 2438 : base(_VSTD::move(__p)) {} 2439 2440 _LIBCPP_INLINE_VISIBILITY 2441 __compressed_pair& operator=(__compressed_pair&& __p) 2442 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2443 is_nothrow_move_assignable<_T2>::value) 2444 { 2445 base::operator=(_VSTD::move(__p)); 2446 return *this; 2447 } 2448 2449#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2450 2451#ifndef _LIBCPP_HAS_NO_VARIADICS 2452 2453 template <class... _Args1, class... _Args2> 2454 _LIBCPP_INLINE_VISIBILITY 2455 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, 2456 tuple<_Args2...> __second_args) 2457 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args), 2458 typename __make_tuple_indices<sizeof...(_Args1)>::type(), 2459 typename __make_tuple_indices<sizeof...(_Args2) >::type()) 2460 {} 2461 2462#endif // _LIBCPP_HAS_NO_VARIADICS 2463 2464 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();} 2465 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();} 2466 2467 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();} 2468 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();} 2469 2470 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) 2471 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2472 __is_nothrow_swappable<_T2>::value) 2473 {base::swap(__x);} 2474}; 2475 2476template <class _T1, class _T2> 2477inline _LIBCPP_INLINE_VISIBILITY 2478void 2479swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) 2480 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2481 __is_nothrow_swappable<_T2>::value) 2482 {__x.swap(__y);} 2483 2484// __same_or_less_cv_qualified 2485 2486template <class _Ptr1, class _Ptr2, 2487 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type, 2488 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type 2489 >::value 2490 > 2491struct __same_or_less_cv_qualified_imp 2492 : is_convertible<_Ptr1, _Ptr2> {}; 2493 2494template <class _Ptr1, class _Ptr2> 2495struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false> 2496 : false_type {}; 2497 2498template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value || 2499 is_same<_Ptr1, _Ptr2>::value || 2500 __has_element_type<_Ptr1>::value> 2501struct __same_or_less_cv_qualified 2502 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {}; 2503 2504template <class _Ptr1, class _Ptr2> 2505struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false> 2506 : false_type {}; 2507 2508// default_delete 2509 2510template <class _Tp> 2511struct _LIBCPP_TYPE_VIS_ONLY default_delete 2512{ 2513#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2514 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default; 2515#else 2516 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {} 2517#endif 2518 template <class _Up> 2519 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&, 2520 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} 2521 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT 2522 { 2523 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); 2524 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type"); 2525 delete __ptr; 2526 } 2527}; 2528 2529template <class _Tp> 2530struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]> 2531{ 2532public: 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<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} 2541 template <class _Up> 2542 _LIBCPP_INLINE_VISIBILITY 2543 void operator() (_Up* __ptr, 2544 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT 2545 { 2546 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); 2547 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type"); 2548 delete [] __ptr; 2549 } 2550}; 2551 2552template <class _Tp, class _Dp = default_delete<_Tp> > 2553class _LIBCPP_TYPE_VIS_ONLY unique_ptr 2554{ 2555public: 2556 typedef _Tp element_type; 2557 typedef _Dp deleter_type; 2558 typedef typename __pointer_type<_Tp, deleter_type>::type pointer; 2559private: 2560 __compressed_pair<pointer, deleter_type> __ptr_; 2561 2562#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2563 unique_ptr(unique_ptr&); 2564 template <class _Up, class _Ep> 2565 unique_ptr(unique_ptr<_Up, _Ep>&); 2566 unique_ptr& operator=(unique_ptr&); 2567 template <class _Up, class _Ep> 2568 unique_ptr& operator=(unique_ptr<_Up, _Ep>&); 2569#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2570 2571 struct __nat {int __for_bool_;}; 2572 2573 typedef typename remove_reference<deleter_type>::type& _Dp_reference; 2574 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; 2575public: 2576 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT 2577 : __ptr_(pointer()) 2578 { 2579 static_assert(!is_pointer<deleter_type>::value, 2580 "unique_ptr constructed with null function pointer deleter"); 2581 } 2582 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT 2583 : __ptr_(pointer()) 2584 { 2585 static_assert(!is_pointer<deleter_type>::value, 2586 "unique_ptr constructed with null function pointer deleter"); 2587 } 2588 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT 2589 : __ptr_(_VSTD::move(__p)) 2590 { 2591 static_assert(!is_pointer<deleter_type>::value, 2592 "unique_ptr constructed with null function pointer deleter"); 2593 } 2594 2595#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2596 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional< 2597 is_reference<deleter_type>::value, 2598 deleter_type, 2599 typename add_lvalue_reference<const deleter_type>::type>::type __d) 2600 _NOEXCEPT 2601 : __ptr_(__p, __d) {} 2602 2603 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d) 2604 _NOEXCEPT 2605 : __ptr_(__p, _VSTD::move(__d)) 2606 { 2607 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); 2608 } 2609 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT 2610 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} 2611 template <class _Up, class _Ep> 2612 _LIBCPP_INLINE_VISIBILITY 2613 unique_ptr(unique_ptr<_Up, _Ep>&& __u, 2614 typename enable_if 2615 < 2616 !is_array<_Up>::value && 2617 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && 2618 is_convertible<_Ep, deleter_type>::value && 2619 ( 2620 !is_reference<deleter_type>::value || 2621 is_same<deleter_type, _Ep>::value 2622 ), 2623 __nat 2624 >::type = __nat()) _NOEXCEPT 2625 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} 2626 2627 template <class _Up> 2628 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p, 2629 typename enable_if< 2630 is_convertible<_Up*, _Tp*>::value && 2631 is_same<_Dp, default_delete<_Tp> >::value, 2632 __nat 2633 >::type = __nat()) _NOEXCEPT 2634 : __ptr_(__p.release()) 2635 { 2636 } 2637 2638 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT 2639 { 2640 reset(__u.release()); 2641 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); 2642 return *this; 2643 } 2644 2645 template <class _Up, class _Ep> 2646 _LIBCPP_INLINE_VISIBILITY 2647 typename enable_if 2648 < 2649 !is_array<_Up>::value && 2650 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && 2651 is_assignable<deleter_type&, _Ep&&>::value, 2652 unique_ptr& 2653 >::type 2654 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT 2655 { 2656 reset(__u.release()); 2657 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); 2658 return *this; 2659 } 2660#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2661 2662 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() 2663 { 2664 return __rv<unique_ptr>(*this); 2665 } 2666 2667 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) 2668 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {} 2669 2670 template <class _Up, class _Ep> 2671 _LIBCPP_INLINE_VISIBILITY 2672 typename enable_if< 2673 !is_array<_Up>::value && 2674 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && 2675 is_assignable<deleter_type&, _Ep&>::value, 2676 unique_ptr& 2677 >::type 2678 operator=(unique_ptr<_Up, _Ep> __u) 2679 { 2680 reset(__u.release()); 2681 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); 2682 return *this; 2683 } 2684 2685 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) 2686 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {} 2687 2688 template <class _Up> 2689 _LIBCPP_INLINE_VISIBILITY 2690 typename enable_if< 2691 is_convertible<_Up*, _Tp*>::value && 2692 is_same<_Dp, default_delete<_Tp> >::value, 2693 unique_ptr& 2694 >::type 2695 operator=(auto_ptr<_Up> __p) 2696 {reset(__p.release()); return *this;} 2697 2698#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2699 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} 2700 2701 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT 2702 { 2703 reset(); 2704 return *this; 2705 } 2706 2707 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const 2708 {return *__ptr_.first();} 2709 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();} 2710 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} 2711 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT 2712 {return __ptr_.second();} 2713 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT 2714 {return __ptr_.second();} 2715 _LIBCPP_INLINE_VISIBILITY 2716 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT 2717 {return __ptr_.first() != nullptr;} 2718 2719 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT 2720 { 2721 pointer __t = __ptr_.first(); 2722 __ptr_.first() = pointer(); 2723 return __t; 2724 } 2725 2726 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT 2727 { 2728 pointer __tmp = __ptr_.first(); 2729 __ptr_.first() = __p; 2730 if (__tmp) 2731 __ptr_.second()(__tmp); 2732 } 2733 2734 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT 2735 {__ptr_.swap(__u.__ptr_);} 2736}; 2737 2738template <class _Tp, class _Dp> 2739class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp> 2740{ 2741public: 2742 typedef _Tp element_type; 2743 typedef _Dp deleter_type; 2744 typedef typename __pointer_type<_Tp, deleter_type>::type pointer; 2745private: 2746 __compressed_pair<pointer, deleter_type> __ptr_; 2747 2748#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2749 unique_ptr(unique_ptr&); 2750 template <class _Up> 2751 unique_ptr(unique_ptr<_Up>&); 2752 unique_ptr& operator=(unique_ptr&); 2753 template <class _Up> 2754 unique_ptr& operator=(unique_ptr<_Up>&); 2755#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2756 2757 struct __nat {int __for_bool_;}; 2758 2759 typedef typename remove_reference<deleter_type>::type& _Dp_reference; 2760 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; 2761public: 2762 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT 2763 : __ptr_(pointer()) 2764 { 2765 static_assert(!is_pointer<deleter_type>::value, 2766 "unique_ptr constructed with null function pointer deleter"); 2767 } 2768 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT 2769 : __ptr_(pointer()) 2770 { 2771 static_assert(!is_pointer<deleter_type>::value, 2772 "unique_ptr constructed with null function pointer deleter"); 2773 } 2774#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2775 template <class _Pp> 2776 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p, 2777 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT 2778 : __ptr_(__p) 2779 { 2780 static_assert(!is_pointer<deleter_type>::value, 2781 "unique_ptr constructed with null function pointer deleter"); 2782 } 2783 2784 template <class _Pp> 2785 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional< 2786 is_reference<deleter_type>::value, 2787 deleter_type, 2788 typename add_lvalue_reference<const deleter_type>::type>::type __d, 2789 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) 2790 _NOEXCEPT 2791 : __ptr_(__p, __d) {} 2792 2793 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional< 2794 is_reference<deleter_type>::value, 2795 deleter_type, 2796 typename add_lvalue_reference<const deleter_type>::type>::type __d) 2797 _NOEXCEPT 2798 : __ptr_(pointer(), __d) {} 2799 2800 template <class _Pp> 2801 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, 2802 typename remove_reference<deleter_type>::type&& __d, 2803 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) 2804 _NOEXCEPT 2805 : __ptr_(__p, _VSTD::move(__d)) 2806 { 2807 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); 2808 } 2809 2810 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d) 2811 _NOEXCEPT 2812 : __ptr_(pointer(), _VSTD::move(__d)) 2813 { 2814 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); 2815 } 2816 2817 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT 2818 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} 2819 2820 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT 2821 { 2822 reset(__u.release()); 2823 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); 2824 return *this; 2825 } 2826 2827 template <class _Up, class _Ep> 2828 _LIBCPP_INLINE_VISIBILITY 2829 unique_ptr(unique_ptr<_Up, _Ep>&& __u, 2830 typename enable_if 2831 < 2832 is_array<_Up>::value && 2833 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value 2834 && is_convertible<_Ep, deleter_type>::value && 2835 ( 2836 !is_reference<deleter_type>::value || 2837 is_same<deleter_type, _Ep>::value 2838 ), 2839 __nat 2840 >::type = __nat() 2841 ) _NOEXCEPT 2842 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} 2843 2844 2845 template <class _Up, class _Ep> 2846 _LIBCPP_INLINE_VISIBILITY 2847 typename enable_if 2848 < 2849 is_array<_Up>::value && 2850 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && 2851 is_assignable<deleter_type&, _Ep&&>::value, 2852 unique_ptr& 2853 >::type 2854 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT 2855 { 2856 reset(__u.release()); 2857 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); 2858 return *this; 2859 } 2860#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2861 2862 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) 2863 : __ptr_(__p) 2864 { 2865 static_assert(!is_pointer<deleter_type>::value, 2866 "unique_ptr constructed with null function pointer deleter"); 2867 } 2868 2869 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) 2870 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {} 2871 2872 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d) 2873 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {} 2874 2875 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() 2876 { 2877 return __rv<unique_ptr>(*this); 2878 } 2879 2880 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) 2881 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {} 2882 2883 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u) 2884 { 2885 reset(__u->release()); 2886 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter()); 2887 return *this; 2888 } 2889 2890#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2891 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} 2892 2893 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT 2894 { 2895 reset(); 2896 return *this; 2897 } 2898 2899 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const 2900 {return __ptr_.first()[__i];} 2901 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} 2902 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT 2903 {return __ptr_.second();} 2904 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT 2905 {return __ptr_.second();} 2906 _LIBCPP_INLINE_VISIBILITY 2907 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT 2908 {return __ptr_.first() != nullptr;} 2909 2910 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT 2911 { 2912 pointer __t = __ptr_.first(); 2913 __ptr_.first() = pointer(); 2914 return __t; 2915 } 2916 2917#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2918 template <class _Pp> 2919 _LIBCPP_INLINE_VISIBILITY 2920 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type 2921 reset(_Pp __p) _NOEXCEPT 2922 { 2923 pointer __tmp = __ptr_.first(); 2924 __ptr_.first() = __p; 2925 if (__tmp) 2926 __ptr_.second()(__tmp); 2927 } 2928 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT 2929 { 2930 pointer __tmp = __ptr_.first(); 2931 __ptr_.first() = nullptr; 2932 if (__tmp) 2933 __ptr_.second()(__tmp); 2934 } 2935 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT 2936 { 2937 pointer __tmp = __ptr_.first(); 2938 __ptr_.first() = nullptr; 2939 if (__tmp) 2940 __ptr_.second()(__tmp); 2941 } 2942#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2943 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) 2944 { 2945 pointer __tmp = __ptr_.first(); 2946 __ptr_.first() = __p; 2947 if (__tmp) 2948 __ptr_.second()(__tmp); 2949 } 2950#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2951 2952 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);} 2953private: 2954 2955#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2956 template <class _Up> 2957 explicit unique_ptr(_Up); 2958 template <class _Up> 2959 unique_ptr(_Up __u, 2960 typename conditional< 2961 is_reference<deleter_type>::value, 2962 deleter_type, 2963 typename add_lvalue_reference<const deleter_type>::type>::type, 2964 typename enable_if 2965 < 2966 is_convertible<_Up, pointer>::value, 2967 __nat 2968 >::type = __nat()); 2969#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2970}; 2971 2972template <class _Tp, class _Dp> 2973inline _LIBCPP_INLINE_VISIBILITY 2974void 2975swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);} 2976 2977template <class _T1, class _D1, class _T2, class _D2> 2978inline _LIBCPP_INLINE_VISIBILITY 2979bool 2980operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} 2981 2982template <class _T1, class _D1, class _T2, class _D2> 2983inline _LIBCPP_INLINE_VISIBILITY 2984bool 2985operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} 2986 2987template <class _T1, class _D1, class _T2, class _D2> 2988inline _LIBCPP_INLINE_VISIBILITY 2989bool 2990operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) 2991{ 2992 typedef typename unique_ptr<_T1, _D1>::pointer _P1; 2993 typedef typename unique_ptr<_T2, _D2>::pointer _P2; 2994 typedef typename common_type<_P1, _P2>::type _Vp; 2995 return less<_Vp>()(__x.get(), __y.get()); 2996} 2997 2998template <class _T1, class _D1, class _T2, class _D2> 2999inline _LIBCPP_INLINE_VISIBILITY 3000bool 3001operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} 3002 3003template <class _T1, class _D1, class _T2, class _D2> 3004inline _LIBCPP_INLINE_VISIBILITY 3005bool 3006operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} 3007 3008template <class _T1, class _D1, class _T2, class _D2> 3009inline _LIBCPP_INLINE_VISIBILITY 3010bool 3011operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} 3012 3013template <class _T1, class _D1> 3014inline _LIBCPP_INLINE_VISIBILITY 3015bool 3016operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT 3017{ 3018 return !__x; 3019} 3020 3021template <class _T1, class _D1> 3022inline _LIBCPP_INLINE_VISIBILITY 3023bool 3024operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT 3025{ 3026 return !__x; 3027} 3028 3029template <class _T1, class _D1> 3030inline _LIBCPP_INLINE_VISIBILITY 3031bool 3032operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT 3033{ 3034 return static_cast<bool>(__x); 3035} 3036 3037template <class _T1, class _D1> 3038inline _LIBCPP_INLINE_VISIBILITY 3039bool 3040operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT 3041{ 3042 return static_cast<bool>(__x); 3043} 3044 3045template <class _T1, class _D1> 3046inline _LIBCPP_INLINE_VISIBILITY 3047bool 3048operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) 3049{ 3050 typedef typename unique_ptr<_T1, _D1>::pointer _P1; 3051 return less<_P1>()(__x.get(), nullptr); 3052} 3053 3054template <class _T1, class _D1> 3055inline _LIBCPP_INLINE_VISIBILITY 3056bool 3057operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) 3058{ 3059 typedef typename unique_ptr<_T1, _D1>::pointer _P1; 3060 return less<_P1>()(nullptr, __x.get()); 3061} 3062 3063template <class _T1, class _D1> 3064inline _LIBCPP_INLINE_VISIBILITY 3065bool 3066operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) 3067{ 3068 return nullptr < __x; 3069} 3070 3071template <class _T1, class _D1> 3072inline _LIBCPP_INLINE_VISIBILITY 3073bool 3074operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) 3075{ 3076 return __x < nullptr; 3077} 3078 3079template <class _T1, class _D1> 3080inline _LIBCPP_INLINE_VISIBILITY 3081bool 3082operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) 3083{ 3084 return !(nullptr < __x); 3085} 3086 3087template <class _T1, class _D1> 3088inline _LIBCPP_INLINE_VISIBILITY 3089bool 3090operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) 3091{ 3092 return !(__x < nullptr); 3093} 3094 3095template <class _T1, class _D1> 3096inline _LIBCPP_INLINE_VISIBILITY 3097bool 3098operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) 3099{ 3100 return !(__x < nullptr); 3101} 3102 3103template <class _T1, class _D1> 3104inline _LIBCPP_INLINE_VISIBILITY 3105bool 3106operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) 3107{ 3108 return !(nullptr < __x); 3109} 3110 3111#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3112 3113template <class _Tp, class _Dp> 3114inline _LIBCPP_INLINE_VISIBILITY 3115unique_ptr<_Tp, _Dp> 3116move(unique_ptr<_Tp, _Dp>& __t) 3117{ 3118 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t)); 3119} 3120 3121#endif 3122 3123#if _LIBCPP_STD_VER > 11 3124 3125template<class _Tp> 3126struct __unique_if 3127{ 3128 typedef unique_ptr<_Tp> __unique_single; 3129}; 3130 3131template<class _Tp> 3132struct __unique_if<_Tp[]> 3133{ 3134 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; 3135}; 3136 3137template<class _Tp, size_t _Np> 3138struct __unique_if<_Tp[_Np]> 3139{ 3140 typedef void __unique_array_known_bound; 3141}; 3142 3143template<class _Tp, class... _Args> 3144inline _LIBCPP_INLINE_VISIBILITY 3145typename __unique_if<_Tp>::__unique_single 3146make_unique(_Args&&... __args) 3147{ 3148 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); 3149} 3150 3151template<class _Tp> 3152inline _LIBCPP_INLINE_VISIBILITY 3153typename __unique_if<_Tp>::__unique_array_unknown_bound 3154make_unique(size_t __n) 3155{ 3156 typedef typename remove_extent<_Tp>::type _Up; 3157 return unique_ptr<_Tp>(new _Up[__n]()); 3158} 3159 3160template<class _Tp, class... _Args> 3161 typename __unique_if<_Tp>::__unique_array_known_bound 3162 make_unique(_Args&&...) = delete; 3163 3164#endif // _LIBCPP_STD_VER > 11 3165 3166template <class _Tp> struct hash; 3167 3168template <class _Size> 3169inline _LIBCPP_INLINE_VISIBILITY 3170_Size 3171__loadword(const void* __p) 3172{ 3173 _Size __r; 3174 std::memcpy(&__r, __p, sizeof(__r)); 3175 return __r; 3176} 3177 3178// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t 3179// is 64 bits. This is because cityhash64 uses 64bit x 64bit 3180// multiplication, which can be very slow on 32-bit systems. 3181template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__> 3182struct __murmur2_or_cityhash; 3183 3184template <class _Size> 3185struct __murmur2_or_cityhash<_Size, 32> 3186{ 3187 _Size operator()(const void* __key, _Size __len); 3188}; 3189 3190// murmur2 3191template <class _Size> 3192_Size 3193__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) 3194{ 3195 const _Size __m = 0x5bd1e995; 3196 const _Size __r = 24; 3197 _Size __h = __len; 3198 const unsigned char* __data = static_cast<const unsigned char*>(__key); 3199 for (; __len >= 4; __data += 4, __len -= 4) 3200 { 3201 _Size __k = __loadword<_Size>(__data); 3202 __k *= __m; 3203 __k ^= __k >> __r; 3204 __k *= __m; 3205 __h *= __m; 3206 __h ^= __k; 3207 } 3208 switch (__len) 3209 { 3210 case 3: 3211 __h ^= __data[2] << 16; 3212 case 2: 3213 __h ^= __data[1] << 8; 3214 case 1: 3215 __h ^= __data[0]; 3216 __h *= __m; 3217 } 3218 __h ^= __h >> 13; 3219 __h *= __m; 3220 __h ^= __h >> 15; 3221 return __h; 3222} 3223 3224template <class _Size> 3225struct __murmur2_or_cityhash<_Size, 64> 3226{ 3227 _Size operator()(const void* __key, _Size __len); 3228 3229 private: 3230 // Some primes between 2^63 and 2^64. 3231 static const _Size __k0 = 0xc3a5c85c97cb3127ULL; 3232 static const _Size __k1 = 0xb492b66fbe98f273ULL; 3233 static const _Size __k2 = 0x9ae16a3b2f90404fULL; 3234 static const _Size __k3 = 0xc949d7c7509e6557ULL; 3235 3236 static _Size __rotate(_Size __val, int __shift) { 3237 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); 3238 } 3239 3240 static _Size __rotate_by_at_least_1(_Size __val, int __shift) { 3241 return (__val >> __shift) | (__val << (64 - __shift)); 3242 } 3243 3244 static _Size __shift_mix(_Size __val) { 3245 return __val ^ (__val >> 47); 3246 } 3247 3248 static _Size __hash_len_16(_Size __u, _Size __v) { 3249 const _Size __mul = 0x9ddfea08eb382d69ULL; 3250 _Size __a = (__u ^ __v) * __mul; 3251 __a ^= (__a >> 47); 3252 _Size __b = (__v ^ __a) * __mul; 3253 __b ^= (__b >> 47); 3254 __b *= __mul; 3255 return __b; 3256 } 3257 3258 static _Size __hash_len_0_to_16(const char* __s, _Size __len) { 3259 if (__len > 8) { 3260 const _Size __a = __loadword<_Size>(__s); 3261 const _Size __b = __loadword<_Size>(__s + __len - 8); 3262 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; 3263 } 3264 if (__len >= 4) { 3265 const uint32_t __a = __loadword<uint32_t>(__s); 3266 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4); 3267 return __hash_len_16(__len + (__a << 3), __b); 3268 } 3269 if (__len > 0) { 3270 const unsigned char __a = __s[0]; 3271 const unsigned char __b = __s[__len >> 1]; 3272 const unsigned char __c = __s[__len - 1]; 3273 const uint32_t __y = static_cast<uint32_t>(__a) + 3274 (static_cast<uint32_t>(__b) << 8); 3275 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2); 3276 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; 3277 } 3278 return __k2; 3279 } 3280 3281 static _Size __hash_len_17_to_32(const char *__s, _Size __len) { 3282 const _Size __a = __loadword<_Size>(__s) * __k1; 3283 const _Size __b = __loadword<_Size>(__s + 8); 3284 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2; 3285 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0; 3286 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d, 3287 __a + __rotate(__b ^ __k3, 20) - __c + __len); 3288 } 3289 3290 // Return a 16-byte hash for 48 bytes. Quick and dirty. 3291 // Callers do best to use "random-looking" values for a and b. 3292 static pair<_Size, _Size> __weak_hash_len_32_with_seeds( 3293 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) { 3294 __a += __w; 3295 __b = __rotate(__b + __a + __z, 21); 3296 const _Size __c = __a; 3297 __a += __x; 3298 __a += __y; 3299 __b += __rotate(__a, 44); 3300 return pair<_Size, _Size>(__a + __z, __b + __c); 3301 } 3302 3303 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. 3304 static pair<_Size, _Size> __weak_hash_len_32_with_seeds( 3305 const char* __s, _Size __a, _Size __b) { 3306 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s), 3307 __loadword<_Size>(__s + 8), 3308 __loadword<_Size>(__s + 16), 3309 __loadword<_Size>(__s + 24), 3310 __a, 3311 __b); 3312 } 3313 3314 // Return an 8-byte hash for 33 to 64 bytes. 3315 static _Size __hash_len_33_to_64(const char *__s, size_t __len) { 3316 _Size __z = __loadword<_Size>(__s + 24); 3317 _Size __a = __loadword<_Size>(__s) + 3318 (__len + __loadword<_Size>(__s + __len - 16)) * __k0; 3319 _Size __b = __rotate(__a + __z, 52); 3320 _Size __c = __rotate(__a, 37); 3321 __a += __loadword<_Size>(__s + 8); 3322 __c += __rotate(__a, 7); 3323 __a += __loadword<_Size>(__s + 16); 3324 _Size __vf = __a + __z; 3325 _Size __vs = __b + __rotate(__a, 31) + __c; 3326 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32); 3327 __z += __loadword<_Size>(__s + __len - 8); 3328 __b = __rotate(__a + __z, 52); 3329 __c = __rotate(__a, 37); 3330 __a += __loadword<_Size>(__s + __len - 24); 3331 __c += __rotate(__a, 7); 3332 __a += __loadword<_Size>(__s + __len - 16); 3333 _Size __wf = __a + __z; 3334 _Size __ws = __b + __rotate(__a, 31) + __c; 3335 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); 3336 return __shift_mix(__r * __k0 + __vs) * __k2; 3337 } 3338}; 3339 3340// cityhash64 3341template <class _Size> 3342_Size 3343__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) 3344{ 3345 const char* __s = static_cast<const char*>(__key); 3346 if (__len <= 32) { 3347 if (__len <= 16) { 3348 return __hash_len_0_to_16(__s, __len); 3349 } else { 3350 return __hash_len_17_to_32(__s, __len); 3351 } 3352 } else if (__len <= 64) { 3353 return __hash_len_33_to_64(__s, __len); 3354 } 3355 3356 // For strings over 64 bytes we hash the end first, and then as we 3357 // loop we keep 56 bytes of state: v, w, x, y, and z. 3358 _Size __x = __loadword<_Size>(__s + __len - 40); 3359 _Size __y = __loadword<_Size>(__s + __len - 16) + 3360 __loadword<_Size>(__s + __len - 56); 3361 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len, 3362 __loadword<_Size>(__s + __len - 24)); 3363 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); 3364 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); 3365 __x = __x * __k1 + __loadword<_Size>(__s); 3366 3367 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. 3368 __len = (__len - 1) & ~static_cast<_Size>(63); 3369 do { 3370 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1; 3371 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; 3372 __x ^= __w.second; 3373 __y += __v.first + __loadword<_Size>(__s + 40); 3374 __z = __rotate(__z + __w.first, 33) * __k1; 3375 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); 3376 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, 3377 __y + __loadword<_Size>(__s + 16)); 3378 std::swap(__z, __x); 3379 __s += 64; 3380 __len -= 64; 3381 } while (__len != 0); 3382 return __hash_len_16( 3383 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, 3384 __hash_len_16(__v.second, __w.second) + __x); 3385} 3386 3387template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)> 3388struct __scalar_hash; 3389 3390template <class _Tp> 3391struct __scalar_hash<_Tp, 0> 3392 : public unary_function<_Tp, size_t> 3393{ 3394 _LIBCPP_INLINE_VISIBILITY 3395 size_t operator()(_Tp __v) const _NOEXCEPT 3396 { 3397 union 3398 { 3399 _Tp __t; 3400 size_t __a; 3401 } __u; 3402 __u.__a = 0; 3403 __u.__t = __v; 3404 return __u.__a; 3405 } 3406}; 3407 3408template <class _Tp> 3409struct __scalar_hash<_Tp, 1> 3410 : public unary_function<_Tp, size_t> 3411{ 3412 _LIBCPP_INLINE_VISIBILITY 3413 size_t operator()(_Tp __v) const _NOEXCEPT 3414 { 3415 union 3416 { 3417 _Tp __t; 3418 size_t __a; 3419 } __u; 3420 __u.__t = __v; 3421 return __u.__a; 3422 } 3423}; 3424 3425template <class _Tp> 3426struct __scalar_hash<_Tp, 2> 3427 : public unary_function<_Tp, size_t> 3428{ 3429 _LIBCPP_INLINE_VISIBILITY 3430 size_t operator()(_Tp __v) const _NOEXCEPT 3431 { 3432 union 3433 { 3434 _Tp __t; 3435 struct 3436 { 3437 size_t __a; 3438 size_t __b; 3439 } __s; 3440 } __u; 3441 __u.__t = __v; 3442 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 3443 } 3444}; 3445 3446template <class _Tp> 3447struct __scalar_hash<_Tp, 3> 3448 : public unary_function<_Tp, size_t> 3449{ 3450 _LIBCPP_INLINE_VISIBILITY 3451 size_t operator()(_Tp __v) const _NOEXCEPT 3452 { 3453 union 3454 { 3455 _Tp __t; 3456 struct 3457 { 3458 size_t __a; 3459 size_t __b; 3460 size_t __c; 3461 } __s; 3462 } __u; 3463 __u.__t = __v; 3464 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 3465 } 3466}; 3467 3468template <class _Tp> 3469struct __scalar_hash<_Tp, 4> 3470 : public unary_function<_Tp, size_t> 3471{ 3472 _LIBCPP_INLINE_VISIBILITY 3473 size_t operator()(_Tp __v) const _NOEXCEPT 3474 { 3475 union 3476 { 3477 _Tp __t; 3478 struct 3479 { 3480 size_t __a; 3481 size_t __b; 3482 size_t __c; 3483 size_t __d; 3484 } __s; 3485 } __u; 3486 __u.__t = __v; 3487 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 3488 } 3489}; 3490 3491template<class _Tp> 3492struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*> 3493 : public unary_function<_Tp*, size_t> 3494{ 3495 _LIBCPP_INLINE_VISIBILITY 3496 size_t operator()(_Tp* __v) const _NOEXCEPT 3497 { 3498 union 3499 { 3500 _Tp* __t; 3501 size_t __a; 3502 } __u; 3503 __u.__t = __v; 3504 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 3505 } 3506}; 3507 3508template <class _Tp, class _Dp> 3509struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> > 3510{ 3511 typedef unique_ptr<_Tp, _Dp> argument_type; 3512 typedef size_t result_type; 3513 _LIBCPP_INLINE_VISIBILITY 3514 result_type operator()(const argument_type& __ptr) const _NOEXCEPT 3515 { 3516 typedef typename argument_type::pointer pointer; 3517 return hash<pointer>()(__ptr.get()); 3518 } 3519}; 3520 3521struct __destruct_n 3522{ 3523private: 3524 size_t size; 3525 3526 template <class _Tp> 3527 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT 3528 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();} 3529 3530 template <class _Tp> 3531 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT 3532 {} 3533 3534 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT 3535 {++size;} 3536 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT 3537 {} 3538 3539 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT 3540 {size = __s;} 3541 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT 3542 {} 3543public: 3544 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT 3545 : size(__s) {} 3546 3547 template <class _Tp> 3548 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT 3549 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 3550 3551 template <class _Tp> 3552 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT 3553 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 3554 3555 template <class _Tp> 3556 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT 3557 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 3558}; 3559 3560template <class _Alloc> 3561class __allocator_destructor 3562{ 3563 typedef allocator_traits<_Alloc> __alloc_traits; 3564public: 3565 typedef typename __alloc_traits::pointer pointer; 3566 typedef typename __alloc_traits::size_type size_type; 3567private: 3568 _Alloc& __alloc_; 3569 size_type __s_; 3570public: 3571 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) 3572 _NOEXCEPT 3573 : __alloc_(__a), __s_(__s) {} 3574 _LIBCPP_INLINE_VISIBILITY 3575 void operator()(pointer __p) _NOEXCEPT 3576 {__alloc_traits::deallocate(__alloc_, __p, __s_);} 3577}; 3578 3579template <class _InputIterator, class _ForwardIterator> 3580_ForwardIterator 3581uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) 3582{ 3583 typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 3584#ifndef _LIBCPP_NO_EXCEPTIONS 3585 _ForwardIterator __s = __r; 3586 try 3587 { 3588#endif 3589 for (; __f != __l; ++__f, (void) ++__r) 3590 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); 3591#ifndef _LIBCPP_NO_EXCEPTIONS 3592 } 3593 catch (...) 3594 { 3595 for (; __s != __r; ++__s) 3596 __s->~value_type(); 3597 throw; 3598 } 3599#endif 3600 return __r; 3601} 3602 3603template <class _InputIterator, class _Size, class _ForwardIterator> 3604_ForwardIterator 3605uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) 3606{ 3607 typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 3608#ifndef _LIBCPP_NO_EXCEPTIONS 3609 _ForwardIterator __s = __r; 3610 try 3611 { 3612#endif 3613 for (; __n > 0; ++__f, (void) ++__r, (void) --__n) 3614 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); 3615#ifndef _LIBCPP_NO_EXCEPTIONS 3616 } 3617 catch (...) 3618 { 3619 for (; __s != __r; ++__s) 3620 __s->~value_type(); 3621 throw; 3622 } 3623#endif 3624 return __r; 3625} 3626 3627template <class _ForwardIterator, class _Tp> 3628void 3629uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) 3630{ 3631 typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 3632#ifndef _LIBCPP_NO_EXCEPTIONS 3633 _ForwardIterator __s = __f; 3634 try 3635 { 3636#endif 3637 for (; __f != __l; ++__f) 3638 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); 3639#ifndef _LIBCPP_NO_EXCEPTIONS 3640 } 3641 catch (...) 3642 { 3643 for (; __s != __f; ++__s) 3644 __s->~value_type(); 3645 throw; 3646 } 3647#endif 3648} 3649 3650template <class _ForwardIterator, class _Size, class _Tp> 3651_ForwardIterator 3652uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) 3653{ 3654 typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 3655#ifndef _LIBCPP_NO_EXCEPTIONS 3656 _ForwardIterator __s = __f; 3657 try 3658 { 3659#endif 3660 for (; __n > 0; ++__f, (void) --__n) 3661 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); 3662#ifndef _LIBCPP_NO_EXCEPTIONS 3663 } 3664 catch (...) 3665 { 3666 for (; __s != __f; ++__s) 3667 __s->~value_type(); 3668 throw; 3669 } 3670#endif 3671 return __f; 3672} 3673 3674class _LIBCPP_EXCEPTION_ABI bad_weak_ptr 3675 : public std::exception 3676{ 3677public: 3678 virtual ~bad_weak_ptr() _NOEXCEPT; 3679 virtual const char* what() const _NOEXCEPT; 3680}; 3681 3682template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr; 3683 3684class _LIBCPP_TYPE_VIS __shared_count 3685{ 3686 __shared_count(const __shared_count&); 3687 __shared_count& operator=(const __shared_count&); 3688 3689protected: 3690 long __shared_owners_; 3691 virtual ~__shared_count(); 3692private: 3693 virtual void __on_zero_shared() _NOEXCEPT = 0; 3694 3695public: 3696 _LIBCPP_INLINE_VISIBILITY 3697 explicit __shared_count(long __refs = 0) _NOEXCEPT 3698 : __shared_owners_(__refs) {} 3699 3700 void __add_shared() _NOEXCEPT; 3701 bool __release_shared() _NOEXCEPT; 3702 _LIBCPP_INLINE_VISIBILITY 3703 long use_count() const _NOEXCEPT { 3704 return __libcpp_relaxed_load(&__shared_owners_) + 1; 3705 } 3706}; 3707 3708class _LIBCPP_TYPE_VIS __shared_weak_count 3709 : private __shared_count 3710{ 3711 long __shared_weak_owners_; 3712 3713public: 3714 _LIBCPP_INLINE_VISIBILITY 3715 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT 3716 : __shared_count(__refs), 3717 __shared_weak_owners_(__refs) {} 3718protected: 3719 virtual ~__shared_weak_count(); 3720 3721public: 3722 void __add_shared() _NOEXCEPT; 3723 void __add_weak() _NOEXCEPT; 3724 void __release_shared() _NOEXCEPT; 3725 void __release_weak() _NOEXCEPT; 3726 _LIBCPP_INLINE_VISIBILITY 3727 long use_count() const _NOEXCEPT {return __shared_count::use_count();} 3728 __shared_weak_count* lock() _NOEXCEPT; 3729 3730 // Define the function out only if we build static libc++ without RTTI. 3731 // Otherwise we may break clients who need to compile their projects with 3732 // -fno-rtti and yet link against a libc++.dylib compiled 3733 // without -fno-rtti. 3734#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) 3735 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; 3736#endif 3737private: 3738 virtual void __on_zero_shared_weak() _NOEXCEPT = 0; 3739}; 3740 3741template <class _Tp, class _Dp, class _Alloc> 3742class __shared_ptr_pointer 3743 : public __shared_weak_count 3744{ 3745 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; 3746public: 3747 _LIBCPP_INLINE_VISIBILITY 3748 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) 3749 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} 3750 3751#ifndef _LIBCPP_NO_RTTI 3752 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; 3753#endif 3754 3755private: 3756 virtual void __on_zero_shared() _NOEXCEPT; 3757 virtual void __on_zero_shared_weak() _NOEXCEPT; 3758}; 3759 3760#ifndef _LIBCPP_NO_RTTI 3761 3762template <class _Tp, class _Dp, class _Alloc> 3763const void* 3764__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT 3765{ 3766 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0; 3767} 3768 3769#endif // _LIBCPP_NO_RTTI 3770 3771template <class _Tp, class _Dp, class _Alloc> 3772void 3773__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT 3774{ 3775 __data_.first().second()(__data_.first().first()); 3776 __data_.first().second().~_Dp(); 3777} 3778 3779template <class _Tp, class _Dp, class _Alloc> 3780void 3781__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT 3782{ 3783 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; 3784 typedef allocator_traits<_Al> _ATraits; 3785 typedef pointer_traits<typename _ATraits::pointer> _PTraits; 3786 3787 _Al __a(__data_.second()); 3788 __data_.second().~_Alloc(); 3789 __a.deallocate(_PTraits::pointer_to(*this), 1); 3790} 3791 3792template <class _Tp, class _Alloc> 3793class __shared_ptr_emplace 3794 : public __shared_weak_count 3795{ 3796 __compressed_pair<_Alloc, _Tp> __data_; 3797public: 3798#ifndef _LIBCPP_HAS_NO_VARIADICS 3799 3800 _LIBCPP_INLINE_VISIBILITY 3801 __shared_ptr_emplace(_Alloc __a) 3802 : __data_(_VSTD::move(__a)) {} 3803 3804 template <class ..._Args> 3805 _LIBCPP_INLINE_VISIBILITY 3806 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) 3807 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), 3808 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} 3809 3810#else // _LIBCPP_HAS_NO_VARIADICS 3811 3812 _LIBCPP_INLINE_VISIBILITY 3813 __shared_ptr_emplace(_Alloc __a) 3814 : __data_(__a) {} 3815 3816 template <class _A0> 3817 _LIBCPP_INLINE_VISIBILITY 3818 __shared_ptr_emplace(_Alloc __a, _A0& __a0) 3819 : __data_(__a, _Tp(__a0)) {} 3820 3821 template <class _A0, class _A1> 3822 _LIBCPP_INLINE_VISIBILITY 3823 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) 3824 : __data_(__a, _Tp(__a0, __a1)) {} 3825 3826 template <class _A0, class _A1, class _A2> 3827 _LIBCPP_INLINE_VISIBILITY 3828 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) 3829 : __data_(__a, _Tp(__a0, __a1, __a2)) {} 3830 3831#endif // _LIBCPP_HAS_NO_VARIADICS 3832 3833private: 3834 virtual void __on_zero_shared() _NOEXCEPT; 3835 virtual void __on_zero_shared_weak() _NOEXCEPT; 3836public: 3837 _LIBCPP_INLINE_VISIBILITY 3838 _Tp* get() _NOEXCEPT {return &__data_.second();} 3839}; 3840 3841template <class _Tp, class _Alloc> 3842void 3843__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT 3844{ 3845 __data_.second().~_Tp(); 3846} 3847 3848template <class _Tp, class _Alloc> 3849void 3850__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT 3851{ 3852 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; 3853 typedef allocator_traits<_Al> _ATraits; 3854 typedef pointer_traits<typename _ATraits::pointer> _PTraits; 3855 _Al __a(__data_.first()); 3856 __data_.first().~_Alloc(); 3857 __a.deallocate(_PTraits::pointer_to(*this), 1); 3858} 3859 3860template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this; 3861 3862template<class _Tp> 3863class _LIBCPP_TYPE_VIS_ONLY shared_ptr 3864{ 3865public: 3866 typedef _Tp element_type; 3867private: 3868 element_type* __ptr_; 3869 __shared_weak_count* __cntrl_; 3870 3871 struct __nat {int __for_bool_;}; 3872public: 3873 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; 3874 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; 3875 template<class _Yp> 3876 explicit shared_ptr(_Yp* __p, 3877 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3878 template<class _Yp, class _Dp> 3879 shared_ptr(_Yp* __p, _Dp __d, 3880 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3881 template<class _Yp, class _Dp, class _Alloc> 3882 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, 3883 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3884 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); 3885 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); 3886 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; 3887 shared_ptr(const shared_ptr& __r) _NOEXCEPT; 3888 template<class _Yp> 3889 shared_ptr(const shared_ptr<_Yp>& __r, 3890 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) 3891 _NOEXCEPT; 3892#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3893 shared_ptr(shared_ptr&& __r) _NOEXCEPT; 3894 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r, 3895 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) 3896 _NOEXCEPT; 3897#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3898 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, 3899 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat()); 3900#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3901 template<class _Yp> 3902 shared_ptr(auto_ptr<_Yp>&& __r, 3903 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3904#else 3905 template<class _Yp> 3906 shared_ptr(auto_ptr<_Yp> __r, 3907 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3908#endif 3909#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3910 template <class _Yp, class _Dp> 3911 shared_ptr(unique_ptr<_Yp, _Dp>&&, 3912 typename enable_if 3913 < 3914 !is_lvalue_reference<_Dp>::value && 3915 !is_array<_Yp>::value && 3916 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3917 __nat 3918 >::type = __nat()); 3919 template <class _Yp, class _Dp> 3920 shared_ptr(unique_ptr<_Yp, _Dp>&&, 3921 typename enable_if 3922 < 3923 is_lvalue_reference<_Dp>::value && 3924 !is_array<_Yp>::value && 3925 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3926 __nat 3927 >::type = __nat()); 3928#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3929 template <class _Yp, class _Dp> 3930 shared_ptr(unique_ptr<_Yp, _Dp>, 3931 typename enable_if 3932 < 3933 !is_lvalue_reference<_Dp>::value && 3934 !is_array<_Yp>::value && 3935 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3936 __nat 3937 >::type = __nat()); 3938 template <class _Yp, class _Dp> 3939 shared_ptr(unique_ptr<_Yp, _Dp>, 3940 typename enable_if 3941 < 3942 is_lvalue_reference<_Dp>::value && 3943 !is_array<_Yp>::value && 3944 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3945 __nat 3946 >::type = __nat()); 3947#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3948 3949 ~shared_ptr(); 3950 3951 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; 3952 template<class _Yp> 3953 typename enable_if 3954 < 3955 is_convertible<_Yp*, element_type*>::value, 3956 shared_ptr& 3957 >::type 3958 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; 3959#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3960 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; 3961 template<class _Yp> 3962 typename enable_if 3963 < 3964 is_convertible<_Yp*, element_type*>::value, 3965 shared_ptr<_Tp>& 3966 >::type 3967 operator=(shared_ptr<_Yp>&& __r); 3968 template<class _Yp> 3969 typename enable_if 3970 < 3971 !is_array<_Yp>::value && 3972 is_convertible<_Yp*, element_type*>::value, 3973 shared_ptr 3974 >::type& 3975 operator=(auto_ptr<_Yp>&& __r); 3976#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3977 template<class _Yp> 3978 typename enable_if 3979 < 3980 !is_array<_Yp>::value && 3981 is_convertible<_Yp*, element_type*>::value, 3982 shared_ptr& 3983 >::type 3984 operator=(auto_ptr<_Yp> __r); 3985#endif 3986 template <class _Yp, class _Dp> 3987 typename enable_if 3988 < 3989 !is_array<_Yp>::value && 3990 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3991 shared_ptr& 3992 >::type 3993#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3994 operator=(unique_ptr<_Yp, _Dp>&& __r); 3995#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3996 operator=(unique_ptr<_Yp, _Dp> __r); 3997#endif 3998 3999 void swap(shared_ptr& __r) _NOEXCEPT; 4000 void reset() _NOEXCEPT; 4001 template<class _Yp> 4002 typename enable_if 4003 < 4004 is_convertible<_Yp*, element_type*>::value, 4005 void 4006 >::type 4007 reset(_Yp* __p); 4008 template<class _Yp, class _Dp> 4009 typename enable_if 4010 < 4011 is_convertible<_Yp*, element_type*>::value, 4012 void 4013 >::type 4014 reset(_Yp* __p, _Dp __d); 4015 template<class _Yp, class _Dp, class _Alloc> 4016 typename enable_if 4017 < 4018 is_convertible<_Yp*, element_type*>::value, 4019 void 4020 >::type 4021 reset(_Yp* __p, _Dp __d, _Alloc __a); 4022 4023 _LIBCPP_INLINE_VISIBILITY 4024 element_type* get() const _NOEXCEPT {return __ptr_;} 4025 _LIBCPP_INLINE_VISIBILITY 4026 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT 4027 {return *__ptr_;} 4028 _LIBCPP_INLINE_VISIBILITY 4029 element_type* operator->() const _NOEXCEPT {return __ptr_;} 4030 _LIBCPP_INLINE_VISIBILITY 4031 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} 4032 _LIBCPP_INLINE_VISIBILITY 4033 bool unique() const _NOEXCEPT {return use_count() == 1;} 4034 _LIBCPP_INLINE_VISIBILITY 4035 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} 4036 template <class _Up> 4037 _LIBCPP_INLINE_VISIBILITY 4038 bool owner_before(shared_ptr<_Up> const& __p) const 4039 {return __cntrl_ < __p.__cntrl_;} 4040 template <class _Up> 4041 _LIBCPP_INLINE_VISIBILITY 4042 bool owner_before(weak_ptr<_Up> const& __p) const 4043 {return __cntrl_ < __p.__cntrl_;} 4044 _LIBCPP_INLINE_VISIBILITY 4045 bool 4046 __owner_equivalent(const shared_ptr& __p) const 4047 {return __cntrl_ == __p.__cntrl_;} 4048 4049#ifndef _LIBCPP_NO_RTTI 4050 template <class _Dp> 4051 _LIBCPP_INLINE_VISIBILITY 4052 _Dp* __get_deleter() const _NOEXCEPT 4053 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);} 4054#endif // _LIBCPP_NO_RTTI 4055 4056#ifndef _LIBCPP_HAS_NO_VARIADICS 4057 4058 template<class ..._Args> 4059 static 4060 shared_ptr<_Tp> 4061 make_shared(_Args&& ...__args); 4062 4063 template<class _Alloc, class ..._Args> 4064 static 4065 shared_ptr<_Tp> 4066 allocate_shared(const _Alloc& __a, _Args&& ...__args); 4067 4068#else // _LIBCPP_HAS_NO_VARIADICS 4069 4070 static shared_ptr<_Tp> make_shared(); 4071 4072 template<class _A0> 4073 static shared_ptr<_Tp> make_shared(_A0&); 4074 4075 template<class _A0, class _A1> 4076 static shared_ptr<_Tp> make_shared(_A0&, _A1&); 4077 4078 template<class _A0, class _A1, class _A2> 4079 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); 4080 4081 template<class _Alloc> 4082 static shared_ptr<_Tp> 4083 allocate_shared(const _Alloc& __a); 4084 4085 template<class _Alloc, class _A0> 4086 static shared_ptr<_Tp> 4087 allocate_shared(const _Alloc& __a, _A0& __a0); 4088 4089 template<class _Alloc, class _A0, class _A1> 4090 static shared_ptr<_Tp> 4091 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); 4092 4093 template<class _Alloc, class _A0, class _A1, class _A2> 4094 static shared_ptr<_Tp> 4095 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); 4096 4097#endif // _LIBCPP_HAS_NO_VARIADICS 4098 4099private: 4100 4101 template <class _Yp> 4102 _LIBCPP_INLINE_VISIBILITY 4103 void 4104 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT 4105 { 4106 if (__e) 4107 { 4108 __e->__weak_this_.__ptr_ = const_cast<_Yp*>(static_cast<const _Yp*>(__e)); 4109 __e->__weak_this_.__cntrl_ = __cntrl_; 4110 __cntrl_->__add_weak(); 4111 } 4112 } 4113 4114 _LIBCPP_INLINE_VISIBILITY 4115 void __enable_weak_this(const volatile void*) _NOEXCEPT {} 4116 4117 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr; 4118 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr; 4119}; 4120 4121template<class _Tp> 4122inline _LIBCPP_INLINE_VISIBILITY 4123_LIBCPP_CONSTEXPR 4124shared_ptr<_Tp>::shared_ptr() _NOEXCEPT 4125 : __ptr_(0), 4126 __cntrl_(0) 4127{ 4128} 4129 4130template<class _Tp> 4131inline _LIBCPP_INLINE_VISIBILITY 4132_LIBCPP_CONSTEXPR 4133shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT 4134 : __ptr_(0), 4135 __cntrl_(0) 4136{ 4137} 4138 4139template<class _Tp> 4140template<class _Yp> 4141shared_ptr<_Tp>::shared_ptr(_Yp* __p, 4142 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4143 : __ptr_(__p) 4144{ 4145 unique_ptr<_Yp> __hold(__p); 4146 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; 4147 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>()); 4148 __hold.release(); 4149 __enable_weak_this(__p); 4150} 4151 4152template<class _Tp> 4153template<class _Yp, class _Dp> 4154shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, 4155 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4156 : __ptr_(__p) 4157{ 4158#ifndef _LIBCPP_NO_EXCEPTIONS 4159 try 4160 { 4161#endif // _LIBCPP_NO_EXCEPTIONS 4162 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; 4163 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>()); 4164 __enable_weak_this(__p); 4165#ifndef _LIBCPP_NO_EXCEPTIONS 4166 } 4167 catch (...) 4168 { 4169 __d(__p); 4170 throw; 4171 } 4172#endif // _LIBCPP_NO_EXCEPTIONS 4173} 4174 4175template<class _Tp> 4176template<class _Dp> 4177shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) 4178 : __ptr_(0) 4179{ 4180#ifndef _LIBCPP_NO_EXCEPTIONS 4181 try 4182 { 4183#endif // _LIBCPP_NO_EXCEPTIONS 4184 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk; 4185 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>()); 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 _Yp, class _Dp, class _Alloc> 4198shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, 4199 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4200 : __ptr_(__p) 4201{ 4202#ifndef _LIBCPP_NO_EXCEPTIONS 4203 try 4204 { 4205#endif // _LIBCPP_NO_EXCEPTIONS 4206 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; 4207 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4208 typedef __allocator_destructor<_A2> _D2; 4209 _A2 __a2(__a); 4210 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4211 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4212 _CntrlBlk(__p, __d, __a); 4213 __cntrl_ = _VSTD::addressof(*__hold2.release()); 4214 __enable_weak_this(__p); 4215#ifndef _LIBCPP_NO_EXCEPTIONS 4216 } 4217 catch (...) 4218 { 4219 __d(__p); 4220 throw; 4221 } 4222#endif // _LIBCPP_NO_EXCEPTIONS 4223} 4224 4225template<class _Tp> 4226template<class _Dp, class _Alloc> 4227shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) 4228 : __ptr_(0) 4229{ 4230#ifndef _LIBCPP_NO_EXCEPTIONS 4231 try 4232 { 4233#endif // _LIBCPP_NO_EXCEPTIONS 4234 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; 4235 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4236 typedef __allocator_destructor<_A2> _D2; 4237 _A2 __a2(__a); 4238 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4239 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4240 _CntrlBlk(__p, __d, __a); 4241 __cntrl_ = _VSTD::addressof(*__hold2.release()); 4242#ifndef _LIBCPP_NO_EXCEPTIONS 4243 } 4244 catch (...) 4245 { 4246 __d(__p); 4247 throw; 4248 } 4249#endif // _LIBCPP_NO_EXCEPTIONS 4250} 4251 4252template<class _Tp> 4253template<class _Yp> 4254inline _LIBCPP_INLINE_VISIBILITY 4255shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT 4256 : __ptr_(__p), 4257 __cntrl_(__r.__cntrl_) 4258{ 4259 if (__cntrl_) 4260 __cntrl_->__add_shared(); 4261} 4262 4263template<class _Tp> 4264inline _LIBCPP_INLINE_VISIBILITY 4265shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT 4266 : __ptr_(__r.__ptr_), 4267 __cntrl_(__r.__cntrl_) 4268{ 4269 if (__cntrl_) 4270 __cntrl_->__add_shared(); 4271} 4272 4273template<class _Tp> 4274template<class _Yp> 4275inline _LIBCPP_INLINE_VISIBILITY 4276shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, 4277 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) 4278 _NOEXCEPT 4279 : __ptr_(__r.__ptr_), 4280 __cntrl_(__r.__cntrl_) 4281{ 4282 if (__cntrl_) 4283 __cntrl_->__add_shared(); 4284} 4285 4286#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4287 4288template<class _Tp> 4289inline _LIBCPP_INLINE_VISIBILITY 4290shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT 4291 : __ptr_(__r.__ptr_), 4292 __cntrl_(__r.__cntrl_) 4293{ 4294 __r.__ptr_ = 0; 4295 __r.__cntrl_ = 0; 4296} 4297 4298template<class _Tp> 4299template<class _Yp> 4300inline _LIBCPP_INLINE_VISIBILITY 4301shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, 4302 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) 4303 _NOEXCEPT 4304 : __ptr_(__r.__ptr_), 4305 __cntrl_(__r.__cntrl_) 4306{ 4307 __r.__ptr_ = 0; 4308 __r.__cntrl_ = 0; 4309} 4310 4311#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4312 4313template<class _Tp> 4314template<class _Yp> 4315#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4316shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, 4317#else 4318shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, 4319#endif 4320 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4321 : __ptr_(__r.get()) 4322{ 4323 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; 4324 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); 4325 __enable_weak_this(__r.get()); 4326 __r.release(); 4327} 4328 4329template<class _Tp> 4330template <class _Yp, class _Dp> 4331#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4332shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, 4333#else 4334shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, 4335#endif 4336 typename enable_if 4337 < 4338 !is_lvalue_reference<_Dp>::value && 4339 !is_array<_Yp>::value && 4340 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 4341 __nat 4342 >::type) 4343 : __ptr_(__r.get()) 4344{ 4345#if _LIBCPP_STD_VER > 11 4346 if (__ptr_ == nullptr) 4347 __cntrl_ = nullptr; 4348 else 4349#endif 4350 { 4351 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; 4352 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); 4353 __enable_weak_this(__r.get()); 4354 } 4355 __r.release(); 4356} 4357 4358template<class _Tp> 4359template <class _Yp, class _Dp> 4360#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4361shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, 4362#else 4363shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, 4364#endif 4365 typename enable_if 4366 < 4367 is_lvalue_reference<_Dp>::value && 4368 !is_array<_Yp>::value && 4369 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 4370 __nat 4371 >::type) 4372 : __ptr_(__r.get()) 4373{ 4374#if _LIBCPP_STD_VER > 11 4375 if (__ptr_ == nullptr) 4376 __cntrl_ = nullptr; 4377 else 4378#endif 4379 { 4380 typedef __shared_ptr_pointer<_Yp*, 4381 reference_wrapper<typename remove_reference<_Dp>::type>, 4382 allocator<_Yp> > _CntrlBlk; 4383 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); 4384 __enable_weak_this(__r.get()); 4385 } 4386 __r.release(); 4387} 4388 4389#ifndef _LIBCPP_HAS_NO_VARIADICS 4390 4391template<class _Tp> 4392template<class ..._Args> 4393shared_ptr<_Tp> 4394shared_ptr<_Tp>::make_shared(_Args&& ...__args) 4395{ 4396 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4397 typedef allocator<_CntrlBlk> _A2; 4398 typedef __allocator_destructor<_A2> _D2; 4399 _A2 __a2; 4400 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4401 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); 4402 shared_ptr<_Tp> __r; 4403 __r.__ptr_ = __hold2.get()->get(); 4404 __r.__cntrl_ = __hold2.release(); 4405 __r.__enable_weak_this(__r.__ptr_); 4406 return __r; 4407} 4408 4409template<class _Tp> 4410template<class _Alloc, class ..._Args> 4411shared_ptr<_Tp> 4412shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) 4413{ 4414 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4415 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4416 typedef __allocator_destructor<_A2> _D2; 4417 _A2 __a2(__a); 4418 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4419 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4420 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); 4421 shared_ptr<_Tp> __r; 4422 __r.__ptr_ = __hold2.get()->get(); 4423 __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4424 __r.__enable_weak_this(__r.__ptr_); 4425 return __r; 4426} 4427 4428#else // _LIBCPP_HAS_NO_VARIADICS 4429 4430template<class _Tp> 4431shared_ptr<_Tp> 4432shared_ptr<_Tp>::make_shared() 4433{ 4434 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4435 typedef allocator<_CntrlBlk> _Alloc2; 4436 typedef __allocator_destructor<_Alloc2> _D2; 4437 _Alloc2 __alloc2; 4438 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4439 ::new(__hold2.get()) _CntrlBlk(__alloc2); 4440 shared_ptr<_Tp> __r; 4441 __r.__ptr_ = __hold2.get()->get(); 4442 __r.__cntrl_ = __hold2.release(); 4443 __r.__enable_weak_this(__r.__ptr_); 4444 return __r; 4445} 4446 4447template<class _Tp> 4448template<class _A0> 4449shared_ptr<_Tp> 4450shared_ptr<_Tp>::make_shared(_A0& __a0) 4451{ 4452 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4453 typedef allocator<_CntrlBlk> _Alloc2; 4454 typedef __allocator_destructor<_Alloc2> _D2; 4455 _Alloc2 __alloc2; 4456 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4457 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); 4458 shared_ptr<_Tp> __r; 4459 __r.__ptr_ = __hold2.get()->get(); 4460 __r.__cntrl_ = __hold2.release(); 4461 __r.__enable_weak_this(__r.__ptr_); 4462 return __r; 4463} 4464 4465template<class _Tp> 4466template<class _A0, class _A1> 4467shared_ptr<_Tp> 4468shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) 4469{ 4470 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4471 typedef allocator<_CntrlBlk> _Alloc2; 4472 typedef __allocator_destructor<_Alloc2> _D2; 4473 _Alloc2 __alloc2; 4474 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4475 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); 4476 shared_ptr<_Tp> __r; 4477 __r.__ptr_ = __hold2.get()->get(); 4478 __r.__cntrl_ = __hold2.release(); 4479 __r.__enable_weak_this(__r.__ptr_); 4480 return __r; 4481} 4482 4483template<class _Tp> 4484template<class _A0, class _A1, class _A2> 4485shared_ptr<_Tp> 4486shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) 4487{ 4488 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4489 typedef allocator<_CntrlBlk> _Alloc2; 4490 typedef __allocator_destructor<_Alloc2> _D2; 4491 _Alloc2 __alloc2; 4492 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4493 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); 4494 shared_ptr<_Tp> __r; 4495 __r.__ptr_ = __hold2.get()->get(); 4496 __r.__cntrl_ = __hold2.release(); 4497 __r.__enable_weak_this(__r.__ptr_); 4498 return __r; 4499} 4500 4501template<class _Tp> 4502template<class _Alloc> 4503shared_ptr<_Tp> 4504shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) 4505{ 4506 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4507 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; 4508 typedef __allocator_destructor<_Alloc2> _D2; 4509 _Alloc2 __alloc2(__a); 4510 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4511 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4512 _CntrlBlk(__a); 4513 shared_ptr<_Tp> __r; 4514 __r.__ptr_ = __hold2.get()->get(); 4515 __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4516 __r.__enable_weak_this(__r.__ptr_); 4517 return __r; 4518} 4519 4520template<class _Tp> 4521template<class _Alloc, class _A0> 4522shared_ptr<_Tp> 4523shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) 4524{ 4525 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4526 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; 4527 typedef __allocator_destructor<_Alloc2> _D2; 4528 _Alloc2 __alloc2(__a); 4529 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4530 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4531 _CntrlBlk(__a, __a0); 4532 shared_ptr<_Tp> __r; 4533 __r.__ptr_ = __hold2.get()->get(); 4534 __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4535 __r.__enable_weak_this(__r.__ptr_); 4536 return __r; 4537} 4538 4539template<class _Tp> 4540template<class _Alloc, class _A0, class _A1> 4541shared_ptr<_Tp> 4542shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) 4543{ 4544 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4545 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; 4546 typedef __allocator_destructor<_Alloc2> _D2; 4547 _Alloc2 __alloc2(__a); 4548 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4549 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4550 _CntrlBlk(__a, __a0, __a1); 4551 shared_ptr<_Tp> __r; 4552 __r.__ptr_ = __hold2.get()->get(); 4553 __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4554 __r.__enable_weak_this(__r.__ptr_); 4555 return __r; 4556} 4557 4558template<class _Tp> 4559template<class _Alloc, class _A0, class _A1, class _A2> 4560shared_ptr<_Tp> 4561shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) 4562{ 4563 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4564 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; 4565 typedef __allocator_destructor<_Alloc2> _D2; 4566 _Alloc2 __alloc2(__a); 4567 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4568 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4569 _CntrlBlk(__a, __a0, __a1, __a2); 4570 shared_ptr<_Tp> __r; 4571 __r.__ptr_ = __hold2.get()->get(); 4572 __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4573 __r.__enable_weak_this(__r.__ptr_); 4574 return __r; 4575} 4576 4577#endif // _LIBCPP_HAS_NO_VARIADICS 4578 4579template<class _Tp> 4580shared_ptr<_Tp>::~shared_ptr() 4581{ 4582 if (__cntrl_) 4583 __cntrl_->__release_shared(); 4584} 4585 4586template<class _Tp> 4587inline _LIBCPP_INLINE_VISIBILITY 4588shared_ptr<_Tp>& 4589shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT 4590{ 4591 shared_ptr(__r).swap(*this); 4592 return *this; 4593} 4594 4595template<class _Tp> 4596template<class _Yp> 4597inline _LIBCPP_INLINE_VISIBILITY 4598typename enable_if 4599< 4600 is_convertible<_Yp*, _Tp*>::value, 4601 shared_ptr<_Tp>& 4602>::type 4603shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT 4604{ 4605 shared_ptr(__r).swap(*this); 4606 return *this; 4607} 4608 4609#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4610 4611template<class _Tp> 4612inline _LIBCPP_INLINE_VISIBILITY 4613shared_ptr<_Tp>& 4614shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT 4615{ 4616 shared_ptr(_VSTD::move(__r)).swap(*this); 4617 return *this; 4618} 4619 4620template<class _Tp> 4621template<class _Yp> 4622inline _LIBCPP_INLINE_VISIBILITY 4623typename enable_if 4624< 4625 is_convertible<_Yp*, _Tp*>::value, 4626 shared_ptr<_Tp>& 4627>::type 4628shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) 4629{ 4630 shared_ptr(_VSTD::move(__r)).swap(*this); 4631 return *this; 4632} 4633 4634template<class _Tp> 4635template<class _Yp> 4636inline _LIBCPP_INLINE_VISIBILITY 4637typename enable_if 4638< 4639 !is_array<_Yp>::value && 4640 is_convertible<_Yp*, _Tp*>::value, 4641 shared_ptr<_Tp> 4642>::type& 4643shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) 4644{ 4645 shared_ptr(_VSTD::move(__r)).swap(*this); 4646 return *this; 4647} 4648 4649template<class _Tp> 4650template <class _Yp, class _Dp> 4651inline _LIBCPP_INLINE_VISIBILITY 4652typename enable_if 4653< 4654 !is_array<_Yp>::value && 4655 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value, 4656 shared_ptr<_Tp>& 4657>::type 4658shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) 4659{ 4660 shared_ptr(_VSTD::move(__r)).swap(*this); 4661 return *this; 4662} 4663 4664#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4665 4666template<class _Tp> 4667template<class _Yp> 4668inline _LIBCPP_INLINE_VISIBILITY 4669typename enable_if 4670< 4671 !is_array<_Yp>::value && 4672 is_convertible<_Yp*, _Tp*>::value, 4673 shared_ptr<_Tp>& 4674>::type 4675shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) 4676{ 4677 shared_ptr(__r).swap(*this); 4678 return *this; 4679} 4680 4681template<class _Tp> 4682template <class _Yp, class _Dp> 4683inline _LIBCPP_INLINE_VISIBILITY 4684typename enable_if 4685< 4686 !is_array<_Yp>::value && 4687 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value, 4688 shared_ptr<_Tp>& 4689>::type 4690shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) 4691{ 4692 shared_ptr(_VSTD::move(__r)).swap(*this); 4693 return *this; 4694} 4695 4696#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4697 4698template<class _Tp> 4699inline _LIBCPP_INLINE_VISIBILITY 4700void 4701shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT 4702{ 4703 _VSTD::swap(__ptr_, __r.__ptr_); 4704 _VSTD::swap(__cntrl_, __r.__cntrl_); 4705} 4706 4707template<class _Tp> 4708inline _LIBCPP_INLINE_VISIBILITY 4709void 4710shared_ptr<_Tp>::reset() _NOEXCEPT 4711{ 4712 shared_ptr().swap(*this); 4713} 4714 4715template<class _Tp> 4716template<class _Yp> 4717inline _LIBCPP_INLINE_VISIBILITY 4718typename enable_if 4719< 4720 is_convertible<_Yp*, _Tp*>::value, 4721 void 4722>::type 4723shared_ptr<_Tp>::reset(_Yp* __p) 4724{ 4725 shared_ptr(__p).swap(*this); 4726} 4727 4728template<class _Tp> 4729template<class _Yp, class _Dp> 4730inline _LIBCPP_INLINE_VISIBILITY 4731typename enable_if 4732< 4733 is_convertible<_Yp*, _Tp*>::value, 4734 void 4735>::type 4736shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) 4737{ 4738 shared_ptr(__p, __d).swap(*this); 4739} 4740 4741template<class _Tp> 4742template<class _Yp, class _Dp, class _Alloc> 4743inline _LIBCPP_INLINE_VISIBILITY 4744typename enable_if 4745< 4746 is_convertible<_Yp*, _Tp*>::value, 4747 void 4748>::type 4749shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) 4750{ 4751 shared_ptr(__p, __d, __a).swap(*this); 4752} 4753 4754#ifndef _LIBCPP_HAS_NO_VARIADICS 4755 4756template<class _Tp, class ..._Args> 4757inline _LIBCPP_INLINE_VISIBILITY 4758typename enable_if 4759< 4760 !is_array<_Tp>::value, 4761 shared_ptr<_Tp> 4762>::type 4763make_shared(_Args&& ...__args) 4764{ 4765 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...); 4766} 4767 4768template<class _Tp, class _Alloc, class ..._Args> 4769inline _LIBCPP_INLINE_VISIBILITY 4770typename enable_if 4771< 4772 !is_array<_Tp>::value, 4773 shared_ptr<_Tp> 4774>::type 4775allocate_shared(const _Alloc& __a, _Args&& ...__args) 4776{ 4777 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...); 4778} 4779 4780#else // _LIBCPP_HAS_NO_VARIADICS 4781 4782template<class _Tp> 4783inline _LIBCPP_INLINE_VISIBILITY 4784shared_ptr<_Tp> 4785make_shared() 4786{ 4787 return shared_ptr<_Tp>::make_shared(); 4788} 4789 4790template<class _Tp, class _A0> 4791inline _LIBCPP_INLINE_VISIBILITY 4792shared_ptr<_Tp> 4793make_shared(_A0& __a0) 4794{ 4795 return shared_ptr<_Tp>::make_shared(__a0); 4796} 4797 4798template<class _Tp, class _A0, class _A1> 4799inline _LIBCPP_INLINE_VISIBILITY 4800shared_ptr<_Tp> 4801make_shared(_A0& __a0, _A1& __a1) 4802{ 4803 return shared_ptr<_Tp>::make_shared(__a0, __a1); 4804} 4805 4806template<class _Tp, class _A0, class _A1, class _A2> 4807inline _LIBCPP_INLINE_VISIBILITY 4808shared_ptr<_Tp> 4809make_shared(_A0& __a0, _A1& __a1, _A2& __a2) 4810{ 4811 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); 4812} 4813 4814template<class _Tp, class _Alloc> 4815inline _LIBCPP_INLINE_VISIBILITY 4816shared_ptr<_Tp> 4817allocate_shared(const _Alloc& __a) 4818{ 4819 return shared_ptr<_Tp>::allocate_shared(__a); 4820} 4821 4822template<class _Tp, class _Alloc, class _A0> 4823inline _LIBCPP_INLINE_VISIBILITY 4824shared_ptr<_Tp> 4825allocate_shared(const _Alloc& __a, _A0& __a0) 4826{ 4827 return shared_ptr<_Tp>::allocate_shared(__a, __a0); 4828} 4829 4830template<class _Tp, class _Alloc, class _A0, class _A1> 4831inline _LIBCPP_INLINE_VISIBILITY 4832shared_ptr<_Tp> 4833allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) 4834{ 4835 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); 4836} 4837 4838template<class _Tp, class _Alloc, class _A0, class _A1, class _A2> 4839inline _LIBCPP_INLINE_VISIBILITY 4840shared_ptr<_Tp> 4841allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) 4842{ 4843 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); 4844} 4845 4846#endif // _LIBCPP_HAS_NO_VARIADICS 4847 4848template<class _Tp, class _Up> 4849inline _LIBCPP_INLINE_VISIBILITY 4850bool 4851operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4852{ 4853 return __x.get() == __y.get(); 4854} 4855 4856template<class _Tp, class _Up> 4857inline _LIBCPP_INLINE_VISIBILITY 4858bool 4859operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4860{ 4861 return !(__x == __y); 4862} 4863 4864template<class _Tp, class _Up> 4865inline _LIBCPP_INLINE_VISIBILITY 4866bool 4867operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4868{ 4869 typedef typename common_type<_Tp*, _Up*>::type _Vp; 4870 return less<_Vp>()(__x.get(), __y.get()); 4871} 4872 4873template<class _Tp, class _Up> 4874inline _LIBCPP_INLINE_VISIBILITY 4875bool 4876operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4877{ 4878 return __y < __x; 4879} 4880 4881template<class _Tp, class _Up> 4882inline _LIBCPP_INLINE_VISIBILITY 4883bool 4884operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4885{ 4886 return !(__y < __x); 4887} 4888 4889template<class _Tp, class _Up> 4890inline _LIBCPP_INLINE_VISIBILITY 4891bool 4892operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4893{ 4894 return !(__x < __y); 4895} 4896 4897template<class _Tp> 4898inline _LIBCPP_INLINE_VISIBILITY 4899bool 4900operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4901{ 4902 return !__x; 4903} 4904 4905template<class _Tp> 4906inline _LIBCPP_INLINE_VISIBILITY 4907bool 4908operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4909{ 4910 return !__x; 4911} 4912 4913template<class _Tp> 4914inline _LIBCPP_INLINE_VISIBILITY 4915bool 4916operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4917{ 4918 return static_cast<bool>(__x); 4919} 4920 4921template<class _Tp> 4922inline _LIBCPP_INLINE_VISIBILITY 4923bool 4924operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4925{ 4926 return static_cast<bool>(__x); 4927} 4928 4929template<class _Tp> 4930inline _LIBCPP_INLINE_VISIBILITY 4931bool 4932operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4933{ 4934 return less<_Tp*>()(__x.get(), nullptr); 4935} 4936 4937template<class _Tp> 4938inline _LIBCPP_INLINE_VISIBILITY 4939bool 4940operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4941{ 4942 return less<_Tp*>()(nullptr, __x.get()); 4943} 4944 4945template<class _Tp> 4946inline _LIBCPP_INLINE_VISIBILITY 4947bool 4948operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4949{ 4950 return nullptr < __x; 4951} 4952 4953template<class _Tp> 4954inline _LIBCPP_INLINE_VISIBILITY 4955bool 4956operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4957{ 4958 return __x < nullptr; 4959} 4960 4961template<class _Tp> 4962inline _LIBCPP_INLINE_VISIBILITY 4963bool 4964operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4965{ 4966 return !(nullptr < __x); 4967} 4968 4969template<class _Tp> 4970inline _LIBCPP_INLINE_VISIBILITY 4971bool 4972operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4973{ 4974 return !(__x < nullptr); 4975} 4976 4977template<class _Tp> 4978inline _LIBCPP_INLINE_VISIBILITY 4979bool 4980operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4981{ 4982 return !(__x < nullptr); 4983} 4984 4985template<class _Tp> 4986inline _LIBCPP_INLINE_VISIBILITY 4987bool 4988operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4989{ 4990 return !(nullptr < __x); 4991} 4992 4993template<class _Tp> 4994inline _LIBCPP_INLINE_VISIBILITY 4995void 4996swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT 4997{ 4998 __x.swap(__y); 4999} 5000 5001template<class _Tp, class _Up> 5002inline _LIBCPP_INLINE_VISIBILITY 5003typename enable_if 5004< 5005 !is_array<_Tp>::value && !is_array<_Up>::value, 5006 shared_ptr<_Tp> 5007>::type 5008static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 5009{ 5010 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); 5011} 5012 5013template<class _Tp, class _Up> 5014inline _LIBCPP_INLINE_VISIBILITY 5015typename enable_if 5016< 5017 !is_array<_Tp>::value && !is_array<_Up>::value, 5018 shared_ptr<_Tp> 5019>::type 5020dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 5021{ 5022 _Tp* __p = dynamic_cast<_Tp*>(__r.get()); 5023 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); 5024} 5025 5026template<class _Tp, class _Up> 5027typename enable_if 5028< 5029 is_array<_Tp>::value == is_array<_Up>::value, 5030 shared_ptr<_Tp> 5031>::type 5032const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 5033{ 5034 typedef typename remove_extent<_Tp>::type _RTp; 5035 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); 5036} 5037 5038#ifndef _LIBCPP_NO_RTTI 5039 5040template<class _Dp, class _Tp> 5041inline _LIBCPP_INLINE_VISIBILITY 5042_Dp* 5043get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT 5044{ 5045 return __p.template __get_deleter<_Dp>(); 5046} 5047 5048#endif // _LIBCPP_NO_RTTI 5049 5050template<class _Tp> 5051class _LIBCPP_TYPE_VIS_ONLY weak_ptr 5052{ 5053public: 5054 typedef _Tp element_type; 5055private: 5056 element_type* __ptr_; 5057 __shared_weak_count* __cntrl_; 5058 5059public: 5060 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; 5061 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r, 5062 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 5063 _NOEXCEPT; 5064 weak_ptr(weak_ptr const& __r) _NOEXCEPT; 5065 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r, 5066 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 5067 _NOEXCEPT; 5068 5069#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5070 weak_ptr(weak_ptr&& __r) _NOEXCEPT; 5071 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r, 5072 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 5073 _NOEXCEPT; 5074#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5075 ~weak_ptr(); 5076 5077 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; 5078 template<class _Yp> 5079 typename enable_if 5080 < 5081 is_convertible<_Yp*, element_type*>::value, 5082 weak_ptr& 5083 >::type 5084 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; 5085 5086#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5087 5088 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; 5089 template<class _Yp> 5090 typename enable_if 5091 < 5092 is_convertible<_Yp*, element_type*>::value, 5093 weak_ptr& 5094 >::type 5095 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; 5096 5097#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5098 5099 template<class _Yp> 5100 typename enable_if 5101 < 5102 is_convertible<_Yp*, element_type*>::value, 5103 weak_ptr& 5104 >::type 5105 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; 5106 5107 void swap(weak_ptr& __r) _NOEXCEPT; 5108 void reset() _NOEXCEPT; 5109 5110 _LIBCPP_INLINE_VISIBILITY 5111 long use_count() const _NOEXCEPT 5112 {return __cntrl_ ? __cntrl_->use_count() : 0;} 5113 _LIBCPP_INLINE_VISIBILITY 5114 bool expired() const _NOEXCEPT 5115 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} 5116 shared_ptr<_Tp> lock() const _NOEXCEPT; 5117 template<class _Up> 5118 _LIBCPP_INLINE_VISIBILITY 5119 bool owner_before(const shared_ptr<_Up>& __r) const 5120 {return __cntrl_ < __r.__cntrl_;} 5121 template<class _Up> 5122 _LIBCPP_INLINE_VISIBILITY 5123 bool owner_before(const weak_ptr<_Up>& __r) const 5124 {return __cntrl_ < __r.__cntrl_;} 5125 5126 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr; 5127 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr; 5128}; 5129 5130template<class _Tp> 5131inline _LIBCPP_INLINE_VISIBILITY 5132_LIBCPP_CONSTEXPR 5133weak_ptr<_Tp>::weak_ptr() _NOEXCEPT 5134 : __ptr_(0), 5135 __cntrl_(0) 5136{ 5137} 5138 5139template<class _Tp> 5140inline _LIBCPP_INLINE_VISIBILITY 5141weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT 5142 : __ptr_(__r.__ptr_), 5143 __cntrl_(__r.__cntrl_) 5144{ 5145 if (__cntrl_) 5146 __cntrl_->__add_weak(); 5147} 5148 5149template<class _Tp> 5150template<class _Yp> 5151inline _LIBCPP_INLINE_VISIBILITY 5152weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, 5153 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 5154 _NOEXCEPT 5155 : __ptr_(__r.__ptr_), 5156 __cntrl_(__r.__cntrl_) 5157{ 5158 if (__cntrl_) 5159 __cntrl_->__add_weak(); 5160} 5161 5162template<class _Tp> 5163template<class _Yp> 5164inline _LIBCPP_INLINE_VISIBILITY 5165weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, 5166 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 5167 _NOEXCEPT 5168 : __ptr_(__r.__ptr_), 5169 __cntrl_(__r.__cntrl_) 5170{ 5171 if (__cntrl_) 5172 __cntrl_->__add_weak(); 5173} 5174 5175#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5176 5177template<class _Tp> 5178inline _LIBCPP_INLINE_VISIBILITY 5179weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT 5180 : __ptr_(__r.__ptr_), 5181 __cntrl_(__r.__cntrl_) 5182{ 5183 __r.__ptr_ = 0; 5184 __r.__cntrl_ = 0; 5185} 5186 5187template<class _Tp> 5188template<class _Yp> 5189inline _LIBCPP_INLINE_VISIBILITY 5190weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, 5191 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 5192 _NOEXCEPT 5193 : __ptr_(__r.__ptr_), 5194 __cntrl_(__r.__cntrl_) 5195{ 5196 __r.__ptr_ = 0; 5197 __r.__cntrl_ = 0; 5198} 5199 5200#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5201 5202template<class _Tp> 5203weak_ptr<_Tp>::~weak_ptr() 5204{ 5205 if (__cntrl_) 5206 __cntrl_->__release_weak(); 5207} 5208 5209template<class _Tp> 5210inline _LIBCPP_INLINE_VISIBILITY 5211weak_ptr<_Tp>& 5212weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT 5213{ 5214 weak_ptr(__r).swap(*this); 5215 return *this; 5216} 5217 5218template<class _Tp> 5219template<class _Yp> 5220inline _LIBCPP_INLINE_VISIBILITY 5221typename enable_if 5222< 5223 is_convertible<_Yp*, _Tp*>::value, 5224 weak_ptr<_Tp>& 5225>::type 5226weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT 5227{ 5228 weak_ptr(__r).swap(*this); 5229 return *this; 5230} 5231 5232#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5233 5234template<class _Tp> 5235inline _LIBCPP_INLINE_VISIBILITY 5236weak_ptr<_Tp>& 5237weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT 5238{ 5239 weak_ptr(_VSTD::move(__r)).swap(*this); 5240 return *this; 5241} 5242 5243template<class _Tp> 5244template<class _Yp> 5245inline _LIBCPP_INLINE_VISIBILITY 5246typename enable_if 5247< 5248 is_convertible<_Yp*, _Tp*>::value, 5249 weak_ptr<_Tp>& 5250>::type 5251weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT 5252{ 5253 weak_ptr(_VSTD::move(__r)).swap(*this); 5254 return *this; 5255} 5256 5257#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5258 5259template<class _Tp> 5260template<class _Yp> 5261inline _LIBCPP_INLINE_VISIBILITY 5262typename enable_if 5263< 5264 is_convertible<_Yp*, _Tp*>::value, 5265 weak_ptr<_Tp>& 5266>::type 5267weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT 5268{ 5269 weak_ptr(__r).swap(*this); 5270 return *this; 5271} 5272 5273template<class _Tp> 5274inline _LIBCPP_INLINE_VISIBILITY 5275void 5276weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT 5277{ 5278 _VSTD::swap(__ptr_, __r.__ptr_); 5279 _VSTD::swap(__cntrl_, __r.__cntrl_); 5280} 5281 5282template<class _Tp> 5283inline _LIBCPP_INLINE_VISIBILITY 5284void 5285swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT 5286{ 5287 __x.swap(__y); 5288} 5289 5290template<class _Tp> 5291inline _LIBCPP_INLINE_VISIBILITY 5292void 5293weak_ptr<_Tp>::reset() _NOEXCEPT 5294{ 5295 weak_ptr().swap(*this); 5296} 5297 5298template<class _Tp> 5299template<class _Yp> 5300shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, 5301 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) 5302 : __ptr_(__r.__ptr_), 5303 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) 5304{ 5305 if (__cntrl_ == 0) 5306#ifndef _LIBCPP_NO_EXCEPTIONS 5307 throw bad_weak_ptr(); 5308#else 5309 assert(!"bad_weak_ptr"); 5310#endif 5311} 5312 5313template<class _Tp> 5314shared_ptr<_Tp> 5315weak_ptr<_Tp>::lock() const _NOEXCEPT 5316{ 5317 shared_ptr<_Tp> __r; 5318 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; 5319 if (__r.__cntrl_) 5320 __r.__ptr_ = __ptr_; 5321 return __r; 5322} 5323 5324template <class _Tp> struct owner_less; 5325 5326template <class _Tp> 5327struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> > 5328 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> 5329{ 5330 typedef bool result_type; 5331 _LIBCPP_INLINE_VISIBILITY 5332 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const 5333 {return __x.owner_before(__y);} 5334 _LIBCPP_INLINE_VISIBILITY 5335 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const 5336 {return __x.owner_before(__y);} 5337 _LIBCPP_INLINE_VISIBILITY 5338 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const 5339 {return __x.owner_before(__y);} 5340}; 5341 5342template <class _Tp> 5343struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> > 5344 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> 5345{ 5346 typedef bool result_type; 5347 _LIBCPP_INLINE_VISIBILITY 5348 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const 5349 {return __x.owner_before(__y);} 5350 _LIBCPP_INLINE_VISIBILITY 5351 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const 5352 {return __x.owner_before(__y);} 5353 _LIBCPP_INLINE_VISIBILITY 5354 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const 5355 {return __x.owner_before(__y);} 5356}; 5357 5358template<class _Tp> 5359class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this 5360{ 5361 mutable weak_ptr<_Tp> __weak_this_; 5362protected: 5363 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 5364 enable_shared_from_this() _NOEXCEPT {} 5365 _LIBCPP_INLINE_VISIBILITY 5366 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} 5367 _LIBCPP_INLINE_VISIBILITY 5368 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT 5369 {return *this;} 5370 _LIBCPP_INLINE_VISIBILITY 5371 ~enable_shared_from_this() {} 5372public: 5373 _LIBCPP_INLINE_VISIBILITY 5374 shared_ptr<_Tp> shared_from_this() 5375 {return shared_ptr<_Tp>(__weak_this_);} 5376 _LIBCPP_INLINE_VISIBILITY 5377 shared_ptr<_Tp const> shared_from_this() const 5378 {return shared_ptr<const _Tp>(__weak_this_);} 5379 5380 template <class _Up> friend class shared_ptr; 5381}; 5382 5383template <class _Tp> 5384struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> > 5385{ 5386 typedef shared_ptr<_Tp> argument_type; 5387 typedef size_t result_type; 5388 _LIBCPP_INLINE_VISIBILITY 5389 result_type operator()(const argument_type& __ptr) const _NOEXCEPT 5390 { 5391 return hash<_Tp*>()(__ptr.get()); 5392 } 5393}; 5394 5395template<class _CharT, class _Traits, class _Yp> 5396inline _LIBCPP_INLINE_VISIBILITY 5397basic_ostream<_CharT, _Traits>& 5398operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); 5399 5400// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only 5401// enabled with clang. 5402#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) 5403 5404class _LIBCPP_TYPE_VIS __sp_mut 5405{ 5406 void* __lx; 5407public: 5408 void lock() _NOEXCEPT; 5409 void unlock() _NOEXCEPT; 5410 5411private: 5412 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; 5413 __sp_mut(const __sp_mut&); 5414 __sp_mut& operator=(const __sp_mut&); 5415 5416 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); 5417}; 5418 5419_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); 5420 5421template <class _Tp> 5422inline _LIBCPP_INLINE_VISIBILITY 5423bool 5424atomic_is_lock_free(const shared_ptr<_Tp>*) 5425{ 5426 return false; 5427} 5428 5429template <class _Tp> 5430shared_ptr<_Tp> 5431atomic_load(const shared_ptr<_Tp>* __p) 5432{ 5433 __sp_mut& __m = __get_sp_mut(__p); 5434 __m.lock(); 5435 shared_ptr<_Tp> __q = *__p; 5436 __m.unlock(); 5437 return __q; 5438} 5439 5440template <class _Tp> 5441inline _LIBCPP_INLINE_VISIBILITY 5442shared_ptr<_Tp> 5443atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) 5444{ 5445 return atomic_load(__p); 5446} 5447 5448template <class _Tp> 5449void 5450atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) 5451{ 5452 __sp_mut& __m = __get_sp_mut(__p); 5453 __m.lock(); 5454 __p->swap(__r); 5455 __m.unlock(); 5456} 5457 5458template <class _Tp> 5459inline _LIBCPP_INLINE_VISIBILITY 5460void 5461atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) 5462{ 5463 atomic_store(__p, __r); 5464} 5465 5466template <class _Tp> 5467shared_ptr<_Tp> 5468atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) 5469{ 5470 __sp_mut& __m = __get_sp_mut(__p); 5471 __m.lock(); 5472 __p->swap(__r); 5473 __m.unlock(); 5474 return __r; 5475} 5476 5477template <class _Tp> 5478inline _LIBCPP_INLINE_VISIBILITY 5479shared_ptr<_Tp> 5480atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) 5481{ 5482 return atomic_exchange(__p, __r); 5483} 5484 5485template <class _Tp> 5486bool 5487atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) 5488{ 5489 __sp_mut& __m = __get_sp_mut(__p); 5490 __m.lock(); 5491 if (__p->__owner_equivalent(*__v)) 5492 { 5493 *__p = __w; 5494 __m.unlock(); 5495 return true; 5496 } 5497 *__v = *__p; 5498 __m.unlock(); 5499 return false; 5500} 5501 5502template <class _Tp> 5503inline _LIBCPP_INLINE_VISIBILITY 5504bool 5505atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) 5506{ 5507 return atomic_compare_exchange_strong(__p, __v, __w); 5508} 5509 5510template <class _Tp> 5511inline _LIBCPP_INLINE_VISIBILITY 5512bool 5513atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, 5514 shared_ptr<_Tp> __w, memory_order, memory_order) 5515{ 5516 return atomic_compare_exchange_strong(__p, __v, __w); 5517} 5518 5519template <class _Tp> 5520inline _LIBCPP_INLINE_VISIBILITY 5521bool 5522atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, 5523 shared_ptr<_Tp> __w, memory_order, memory_order) 5524{ 5525 return atomic_compare_exchange_weak(__p, __v, __w); 5526} 5527 5528#endif // defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) 5529 5530//enum class 5531struct _LIBCPP_TYPE_VIS pointer_safety 5532{ 5533 enum __lx 5534 { 5535 relaxed, 5536 preferred, 5537 strict 5538 }; 5539 5540 __lx __v_; 5541 5542 _LIBCPP_INLINE_VISIBILITY 5543 pointer_safety(__lx __v) : __v_(__v) {} 5544 _LIBCPP_INLINE_VISIBILITY 5545 operator int() const {return __v_;} 5546}; 5547 5548_LIBCPP_FUNC_VIS void declare_reachable(void* __p); 5549_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); 5550_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); 5551_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; 5552_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); 5553 5554template <class _Tp> 5555inline _LIBCPP_INLINE_VISIBILITY 5556_Tp* 5557undeclare_reachable(_Tp* __p) 5558{ 5559 return static_cast<_Tp*>(__undeclare_reachable(__p)); 5560} 5561 5562_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); 5563 5564// --- Helper for container swap -- 5565template <typename _Alloc> 5566_LIBCPP_INLINE_VISIBILITY 5567void __swap_allocator(_Alloc & __a1, _Alloc & __a2) 5568#if _LIBCPP_STD_VER >= 14 5569 _NOEXCEPT 5570#else 5571 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 5572#endif 5573{ 5574 __swap_allocator(__a1, __a2, 5575 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); 5576} 5577 5578template <typename _Alloc> 5579_LIBCPP_INLINE_VISIBILITY 5580void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) 5581#if _LIBCPP_STD_VER >= 14 5582 _NOEXCEPT 5583#else 5584 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 5585#endif 5586{ 5587 using _VSTD::swap; 5588 swap(__a1, __a2); 5589} 5590 5591template <typename _Alloc> 5592_LIBCPP_INLINE_VISIBILITY 5593void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} 5594 5595template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > 5596struct __noexcept_move_assign_container : public integral_constant<bool, 5597 _Traits::propagate_on_container_move_assignment::value 5598#if _LIBCPP_STD_VER > 14 5599 || _Traits::is_always_equal::value 5600#else 5601 && is_nothrow_move_assignable<_Alloc>::value 5602#endif 5603 > {}; 5604 5605_LIBCPP_END_NAMESPACE_STD 5606 5607#endif // _LIBCPP_MEMORY 5608