1227825Stheraven// -*- C++ -*- 2227825Stheraven//===-------------------------- memory ------------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_MEMORY 12227825Stheraven#define _LIBCPP_MEMORY 13227825Stheraven 14227825Stheraven/* 15227825Stheraven memory synopsis 16227825Stheraven 17227825Stheravennamespace std 18227825Stheraven{ 19227825Stheraven 20227825Stheravenstruct allocator_arg_t { }; 21227825Stheravenconstexpr allocator_arg_t allocator_arg = allocator_arg_t(); 22227825Stheraven 23227825Stheraventemplate <class T, class Alloc> struct uses_allocator; 24227825Stheraven 25227825Stheraventemplate <class Ptr> 26227825Stheravenstruct pointer_traits 27227825Stheraven{ 28227825Stheraven typedef Ptr pointer; 29227825Stheraven typedef <details> element_type; 30227825Stheraven typedef <details> difference_type; 31227825Stheraven 32227825Stheraven template <class U> using rebind = <details>; 33227825Stheraven 34227825Stheraven static pointer pointer_to(<details>); 35227825Stheraven}; 36227825Stheraven 37227825Stheraventemplate <class T> 38227825Stheravenstruct pointer_traits<T*> 39227825Stheraven{ 40227825Stheraven typedef T* pointer; 41227825Stheraven typedef T element_type; 42227825Stheraven typedef ptrdiff_t difference_type; 43227825Stheraven 44227825Stheraven template <class U> using rebind = U*; 45227825Stheraven 46227825Stheraven static pointer pointer_to(<details>) noexcept; 47227825Stheraven}; 48227825Stheraven 49227825Stheraventemplate <class Alloc> 50227825Stheravenstruct allocator_traits 51227825Stheraven{ 52227825Stheraven typedef Alloc allocator_type; 53227825Stheraven typedef typename allocator_type::value_type 54227825Stheraven value_type; 55227825Stheraven 56227825Stheraven typedef Alloc::pointer | value_type* pointer; 57227825Stheraven typedef Alloc::const_pointer 58227825Stheraven | pointer_traits<pointer>::rebind<const value_type> 59227825Stheraven const_pointer; 60227825Stheraven typedef Alloc::void_pointer 61227825Stheraven | pointer_traits<pointer>::rebind<void> 62227825Stheraven void_pointer; 63227825Stheraven typedef Alloc::const_void_pointer 64227825Stheraven | pointer_traits<pointer>::rebind<const void> 65227825Stheraven const_void_pointer; 66227825Stheraven typedef Alloc::difference_type 67227825Stheraven | pointer_traits<pointer>::difference_type 68227825Stheraven difference_type; 69227825Stheraven typedef Alloc::size_type 70227825Stheraven | make_unsigned<difference_type>::type 71227825Stheraven size_type; 72227825Stheraven typedef Alloc::propagate_on_container_copy_assignment 73227825Stheraven | false_type propagate_on_container_copy_assignment; 74227825Stheraven typedef Alloc::propagate_on_container_move_assignment 75227825Stheraven | false_type propagate_on_container_move_assignment; 76227825Stheraven typedef Alloc::propagate_on_container_swap 77227825Stheraven | false_type propagate_on_container_swap; 78288943Sdim typedef Alloc::is_always_equal 79288943Sdim | is_empty is_always_equal; 80227825Stheraven 81227825Stheraven template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>; 82227825Stheraven template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; 83227825Stheraven 84227825Stheraven static pointer allocate(allocator_type& a, size_type n); 85227825Stheraven static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); 86227825Stheraven 87227825Stheraven static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; 88227825Stheraven 89227825Stheraven template <class T, class... Args> 90227825Stheraven static void construct(allocator_type& a, T* p, Args&&... args); 91227825Stheraven 92227825Stheraven template <class T> 93227825Stheraven static void destroy(allocator_type& a, T* p); 94227825Stheraven 95261272Sdim static size_type max_size(const allocator_type& a); // noexcept in C++14 96227825Stheraven 97227825Stheraven static allocator_type 98227825Stheraven select_on_container_copy_construction(const allocator_type& a); 99227825Stheraven}; 100227825Stheraven 101227825Stheraventemplate <> 102227825Stheravenclass allocator<void> 103227825Stheraven{ 104227825Stheravenpublic: 105227825Stheraven typedef void* pointer; 106227825Stheraven typedef const void* const_pointer; 107227825Stheraven typedef void value_type; 108227825Stheraven 109227825Stheraven template <class _Up> struct rebind {typedef allocator<_Up> other;}; 110227825Stheraven}; 111227825Stheraven 112227825Stheraventemplate <class T> 113227825Stheravenclass allocator 114227825Stheraven{ 115227825Stheravenpublic: 116227825Stheraven typedef size_t size_type; 117227825Stheraven typedef ptrdiff_t difference_type; 118227825Stheraven typedef T* pointer; 119227825Stheraven typedef const T* const_pointer; 120227825Stheraven typedef typename add_lvalue_reference<T>::type reference; 121227825Stheraven typedef typename add_lvalue_reference<const T>::type const_reference; 122227825Stheraven typedef T value_type; 123227825Stheraven 124227825Stheraven template <class U> struct rebind {typedef allocator<U> other;}; 125227825Stheraven 126227825Stheraven allocator() noexcept; 127227825Stheraven allocator(const allocator&) noexcept; 128227825Stheraven template <class U> allocator(const allocator<U>&) noexcept; 129227825Stheraven ~allocator(); 130227825Stheraven pointer address(reference x) const noexcept; 131227825Stheraven const_pointer address(const_reference x) const noexcept; 132227825Stheraven pointer allocate(size_type, allocator<void>::const_pointer hint = 0); 133227825Stheraven void deallocate(pointer p, size_type n) noexcept; 134227825Stheraven size_type max_size() const noexcept; 135227825Stheraven template<class U, class... Args> 136227825Stheraven void construct(U* p, Args&&... args); 137227825Stheraven template <class U> 138227825Stheraven void destroy(U* p); 139227825Stheraven}; 140227825Stheraven 141227825Stheraventemplate <class T, class U> 142227825Stheravenbool operator==(const allocator<T>&, const allocator<U>&) noexcept; 143227825Stheraven 144227825Stheraventemplate <class T, class U> 145227825Stheravenbool operator!=(const allocator<T>&, const allocator<U>&) noexcept; 146227825Stheraven 147227825Stheraventemplate <class OutputIterator, class T> 148227825Stheravenclass raw_storage_iterator 149227825Stheraven : public iterator<output_iterator_tag, 150227825Stheraven T, // purposefully not C++03 151227825Stheraven ptrdiff_t, // purposefully not C++03 152227825Stheraven T*, // purposefully not C++03 153227825Stheraven raw_storage_iterator&> // purposefully not C++03 154227825Stheraven{ 155227825Stheravenpublic: 156227825Stheraven explicit raw_storage_iterator(OutputIterator x); 157227825Stheraven raw_storage_iterator& operator*(); 158227825Stheraven raw_storage_iterator& operator=(const T& element); 159227825Stheraven raw_storage_iterator& operator++(); 160227825Stheraven raw_storage_iterator operator++(int); 161227825Stheraven}; 162227825Stheraven 163227825Stheraventemplate <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; 164227825Stheraventemplate <class T> void return_temporary_buffer(T* p) noexcept; 165227825Stheraven 166227825Stheraventemplate <class T> T* addressof(T& r) noexcept; 167227825Stheraven 168227825Stheraventemplate <class InputIterator, class ForwardIterator> 169227825StheravenForwardIterator 170227825Stheravenuninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); 171227825Stheraven 172227825Stheraventemplate <class InputIterator, class Size, class ForwardIterator> 173227825StheravenForwardIterator 174227825Stheravenuninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); 175227825Stheraven 176227825Stheraventemplate <class ForwardIterator, class T> 177227825Stheravenvoid uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); 178227825Stheraven 179227825Stheraventemplate <class ForwardIterator, class Size, class T> 180227825StheravenForwardIterator 181227825Stheravenuninitialized_fill_n(ForwardIterator first, Size n, const T& x); 182227825Stheraven 183227825Stheraventemplate <class Y> struct auto_ptr_ref {}; 184227825Stheraven 185227825Stheraventemplate<class X> 186227825Stheravenclass auto_ptr 187227825Stheraven{ 188227825Stheravenpublic: 189227825Stheraven typedef X element_type; 190227825Stheraven 191227825Stheraven explicit auto_ptr(X* p =0) throw(); 192227825Stheraven auto_ptr(auto_ptr&) throw(); 193227825Stheraven template<class Y> auto_ptr(auto_ptr<Y>&) throw(); 194227825Stheraven auto_ptr& operator=(auto_ptr&) throw(); 195227825Stheraven template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw(); 196227825Stheraven auto_ptr& operator=(auto_ptr_ref<X> r) throw(); 197227825Stheraven ~auto_ptr() throw(); 198227825Stheraven 199227825Stheraven typename add_lvalue_reference<X>::type operator*() const throw(); 200227825Stheraven X* operator->() const throw(); 201227825Stheraven X* get() const throw(); 202227825Stheraven X* release() throw(); 203227825Stheraven void reset(X* p =0) throw(); 204227825Stheraven 205227825Stheraven auto_ptr(auto_ptr_ref<X>) throw(); 206227825Stheraven template<class Y> operator auto_ptr_ref<Y>() throw(); 207227825Stheraven template<class Y> operator auto_ptr<Y>() throw(); 208227825Stheraven}; 209227825Stheraven 210227825Stheraventemplate <class T> 211227825Stheravenstruct default_delete 212227825Stheraven{ 213227825Stheraven constexpr default_delete() noexcept = default; 214227825Stheraven template <class U> default_delete(const default_delete<U>&) noexcept; 215227825Stheraven 216227825Stheraven void operator()(T*) const noexcept; 217227825Stheraven}; 218227825Stheraven 219227825Stheraventemplate <class T> 220227825Stheravenstruct default_delete<T[]> 221227825Stheraven{ 222227825Stheraven constexpr default_delete() noexcept = default; 223227825Stheraven void operator()(T*) const noexcept; 224227825Stheraven template <class U> void operator()(U*) const = delete; 225227825Stheraven}; 226227825Stheraven 227227825Stheraventemplate <class T, class D = default_delete<T>> 228227825Stheravenclass unique_ptr 229227825Stheraven{ 230227825Stheravenpublic: 231227825Stheraven typedef see below pointer; 232227825Stheraven typedef T element_type; 233227825Stheraven typedef D deleter_type; 234227825Stheraven 235227825Stheraven // constructors 236227825Stheraven constexpr unique_ptr() noexcept; 237227825Stheraven explicit unique_ptr(pointer p) noexcept; 238227825Stheraven unique_ptr(pointer p, see below d1) noexcept; 239227825Stheraven unique_ptr(pointer p, see below d2) noexcept; 240227825Stheraven unique_ptr(unique_ptr&& u) noexcept; 241227825Stheraven unique_ptr(nullptr_t) noexcept : unique_ptr() { } 242227825Stheraven template <class U, class E> 243227825Stheraven unique_ptr(unique_ptr<U, E>&& u) noexcept; 244227825Stheraven template <class U> 245227825Stheraven unique_ptr(auto_ptr<U>&& u) noexcept; 246227825Stheraven 247227825Stheraven // destructor 248227825Stheraven ~unique_ptr(); 249227825Stheraven 250227825Stheraven // assignment 251227825Stheraven unique_ptr& operator=(unique_ptr&& u) noexcept; 252227825Stheraven template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; 253227825Stheraven unique_ptr& operator=(nullptr_t) noexcept; 254227825Stheraven 255227825Stheraven // observers 256227825Stheraven typename add_lvalue_reference<T>::type operator*() const; 257227825Stheraven pointer operator->() const noexcept; 258227825Stheraven pointer get() const noexcept; 259227825Stheraven deleter_type& get_deleter() noexcept; 260227825Stheraven const deleter_type& get_deleter() const noexcept; 261227825Stheraven explicit operator bool() const noexcept; 262227825Stheraven 263227825Stheraven // modifiers 264227825Stheraven pointer release() noexcept; 265227825Stheraven void reset(pointer p = pointer()) noexcept; 266227825Stheraven void swap(unique_ptr& u) noexcept; 267227825Stheraven}; 268227825Stheraven 269227825Stheraventemplate <class T, class D> 270227825Stheravenclass unique_ptr<T[], D> 271227825Stheraven{ 272227825Stheravenpublic: 273227825Stheraven typedef implementation-defined pointer; 274227825Stheraven typedef T element_type; 275227825Stheraven typedef D deleter_type; 276227825Stheraven 277227825Stheraven // constructors 278227825Stheraven constexpr unique_ptr() noexcept; 279227825Stheraven explicit unique_ptr(pointer p) noexcept; 280227825Stheraven unique_ptr(pointer p, see below d) noexcept; 281227825Stheraven unique_ptr(pointer p, see below d) noexcept; 282227825Stheraven unique_ptr(unique_ptr&& u) noexcept; 283227825Stheraven unique_ptr(nullptr_t) noexcept : unique_ptr() { } 284227825Stheraven 285227825Stheraven // destructor 286227825Stheraven ~unique_ptr(); 287227825Stheraven 288227825Stheraven // assignment 289227825Stheraven unique_ptr& operator=(unique_ptr&& u) noexcept; 290227825Stheraven unique_ptr& operator=(nullptr_t) noexcept; 291227825Stheraven 292227825Stheraven // observers 293227825Stheraven T& operator[](size_t i) const; 294227825Stheraven pointer get() const noexcept; 295227825Stheraven deleter_type& get_deleter() noexcept; 296227825Stheraven const deleter_type& get_deleter() const noexcept; 297227825Stheraven explicit operator bool() const noexcept; 298227825Stheraven 299227825Stheraven // modifiers 300227825Stheraven pointer release() noexcept; 301227825Stheraven void reset(pointer p = pointer()) noexcept; 302227825Stheraven void reset(nullptr_t) noexcept; 303227825Stheraven template <class U> void reset(U) = delete; 304227825Stheraven void swap(unique_ptr& u) noexcept; 305227825Stheraven}; 306227825Stheraven 307227825Stheraventemplate <class T, class D> 308227825Stheraven void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; 309227825Stheraven 310227825Stheraventemplate <class T1, class D1, class T2, class D2> 311227825Stheraven bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 312227825Stheraventemplate <class T1, class D1, class T2, class D2> 313227825Stheraven bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 314227825Stheraventemplate <class T1, class D1, class T2, class D2> 315227825Stheraven bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 316227825Stheraventemplate <class T1, class D1, class T2, class D2> 317227825Stheraven bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 318227825Stheraventemplate <class T1, class D1, class T2, class D2> 319227825Stheraven bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 320227825Stheraventemplate <class T1, class D1, class T2, class D2> 321227825Stheraven bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 322227825Stheraven 323227825Stheraventemplate <class T, class D> 324227825Stheraven bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; 325227825Stheraventemplate <class T, class D> 326227825Stheraven bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; 327227825Stheraventemplate <class T, class D> 328227825Stheraven bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; 329227825Stheraventemplate <class T, class D> 330227825Stheraven bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; 331227825Stheraven 332227825Stheraventemplate <class T, class D> 333227825Stheraven bool operator<(const unique_ptr<T, D>& x, nullptr_t); 334227825Stheraventemplate <class T, class D> 335227825Stheraven bool operator<(nullptr_t, const unique_ptr<T, D>& y); 336227825Stheraventemplate <class T, class D> 337227825Stheraven bool operator<=(const unique_ptr<T, D>& x, nullptr_t); 338227825Stheraventemplate <class T, class D> 339227825Stheraven bool operator<=(nullptr_t, const unique_ptr<T, D>& y); 340227825Stheraventemplate <class T, class D> 341227825Stheraven bool operator>(const unique_ptr<T, D>& x, nullptr_t); 342227825Stheraventemplate <class T, class D> 343227825Stheraven bool operator>(nullptr_t, const unique_ptr<T, D>& y); 344227825Stheraventemplate <class T, class D> 345227825Stheraven bool operator>=(const unique_ptr<T, D>& x, nullptr_t); 346227825Stheraventemplate <class T, class D> 347227825Stheraven bool operator>=(nullptr_t, const unique_ptr<T, D>& y); 348227825Stheraven 349227825Stheravenclass bad_weak_ptr 350227825Stheraven : public std::exception 351227825Stheraven{ 352227825Stheraven bad_weak_ptr() noexcept; 353227825Stheraven}; 354227825Stheraven 355253146Stheraventemplate<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14 356253146Stheraventemplate<class T> unique_ptr<T> make_unique(size_t n); // C++14 357253146Stheraventemplate<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] 358253146Stheraven 359227825Stheraventemplate<class T> 360227825Stheravenclass shared_ptr 361227825Stheraven{ 362227825Stheravenpublic: 363227825Stheraven typedef T element_type; 364227825Stheraven 365227825Stheraven // constructors: 366227825Stheraven constexpr shared_ptr() noexcept; 367227825Stheraven template<class Y> explicit shared_ptr(Y* p); 368227825Stheraven template<class Y, class D> shared_ptr(Y* p, D d); 369227825Stheraven template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); 370227825Stheraven template <class D> shared_ptr(nullptr_t p, D d); 371227825Stheraven template <class D, class A> shared_ptr(nullptr_t p, D d, A a); 372227825Stheraven template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept; 373227825Stheraven shared_ptr(const shared_ptr& r) noexcept; 374227825Stheraven template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept; 375227825Stheraven shared_ptr(shared_ptr&& r) noexcept; 376227825Stheraven template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept; 377227825Stheraven template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); 378227825Stheraven template<class Y> shared_ptr(auto_ptr<Y>&& r); 379227825Stheraven template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); 380227825Stheraven shared_ptr(nullptr_t) : shared_ptr() { } 381227825Stheraven 382227825Stheraven // destructor: 383227825Stheraven ~shared_ptr(); 384227825Stheraven 385227825Stheraven // assignment: 386227825Stheraven shared_ptr& operator=(const shared_ptr& r) noexcept; 387227825Stheraven template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept; 388227825Stheraven shared_ptr& operator=(shared_ptr&& r) noexcept; 389227825Stheraven template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); 390227825Stheraven template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); 391227825Stheraven template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); 392227825Stheraven 393227825Stheraven // modifiers: 394227825Stheraven void swap(shared_ptr& r) noexcept; 395227825Stheraven void reset() noexcept; 396227825Stheraven template<class Y> void reset(Y* p); 397227825Stheraven template<class Y, class D> void reset(Y* p, D d); 398227825Stheraven template<class Y, class D, class A> void reset(Y* p, D d, A a); 399227825Stheraven 400227825Stheraven // observers: 401227825Stheraven T* get() const noexcept; 402227825Stheraven T& operator*() const noexcept; 403227825Stheraven T* operator->() const noexcept; 404227825Stheraven long use_count() const noexcept; 405227825Stheraven bool unique() const noexcept; 406227825Stheraven explicit operator bool() const noexcept; 407227825Stheraven template<class U> bool owner_before(shared_ptr<U> const& b) const; 408227825Stheraven template<class U> bool owner_before(weak_ptr<U> const& b) const; 409227825Stheraven}; 410227825Stheraven 411227825Stheraven// shared_ptr comparisons: 412227825Stheraventemplate<class T, class U> 413227825Stheraven bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 414227825Stheraventemplate<class T, class U> 415227825Stheraven bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 416227825Stheraventemplate<class T, class U> 417227825Stheraven bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 418227825Stheraventemplate<class T, class U> 419227825Stheraven bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 420227825Stheraventemplate<class T, class U> 421227825Stheraven bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 422227825Stheraventemplate<class T, class U> 423227825Stheraven bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 424227825Stheraven 425227825Stheraventemplate <class T> 426227825Stheraven bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; 427227825Stheraventemplate <class T> 428227825Stheraven bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; 429227825Stheraventemplate <class T> 430227825Stheraven bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; 431227825Stheraventemplate <class T> 432227825Stheraven bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; 433227825Stheraventemplate <class T> 434227825Stheraven bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; 435227825Stheraventemplate <class T> 436227825Stheravenbool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; 437227825Stheraventemplate <class T> 438227825Stheraven bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; 439227825Stheraventemplate <class T> 440227825Stheraven bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; 441227825Stheraventemplate <class T> 442227825Stheraven bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; 443227825Stheraventemplate <class T> 444227825Stheraven bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; 445227825Stheraventemplate <class T> 446227825Stheraven bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; 447227825Stheraventemplate <class T> 448227825Stheraven bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; 449227825Stheraven 450227825Stheraven// shared_ptr specialized algorithms: 451227825Stheraventemplate<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept; 452227825Stheraven 453227825Stheraven// shared_ptr casts: 454227825Stheraventemplate<class T, class U> 455227825Stheraven shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept; 456227825Stheraventemplate<class T, class U> 457227825Stheraven shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept; 458227825Stheraventemplate<class T, class U> 459227825Stheraven shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept; 460227825Stheraven 461227825Stheraven// shared_ptr I/O: 462227825Stheraventemplate<class E, class T, class Y> 463227825Stheraven basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p); 464227825Stheraven 465227825Stheraven// shared_ptr get_deleter: 466227825Stheraventemplate<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept; 467227825Stheraven 468227825Stheraventemplate<class T, class... Args> 469227825Stheraven shared_ptr<T> make_shared(Args&&... args); 470227825Stheraventemplate<class T, class A, class... Args> 471227825Stheraven shared_ptr<T> allocate_shared(const A& a, Args&&... args); 472227825Stheraven 473227825Stheraventemplate<class T> 474227825Stheravenclass weak_ptr 475227825Stheraven{ 476227825Stheravenpublic: 477227825Stheraven typedef T element_type; 478227825Stheraven 479227825Stheraven // constructors 480227825Stheraven constexpr weak_ptr() noexcept; 481227825Stheraven template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; 482227825Stheraven weak_ptr(weak_ptr const& r) noexcept; 483227825Stheraven template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; 484276792Sdim weak_ptr(weak_ptr&& r) noexcept; // C++14 485276792Sdim template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14 486227825Stheraven 487227825Stheraven // destructor 488227825Stheraven ~weak_ptr(); 489227825Stheraven 490227825Stheraven // assignment 491227825Stheraven weak_ptr& operator=(weak_ptr const& r) noexcept; 492227825Stheraven template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; 493227825Stheraven template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; 494276792Sdim weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 495276792Sdim template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14 496227825Stheraven 497227825Stheraven // modifiers 498227825Stheraven void swap(weak_ptr& r) noexcept; 499227825Stheraven void reset() noexcept; 500227825Stheraven 501227825Stheraven // observers 502227825Stheraven long use_count() const noexcept; 503227825Stheraven bool expired() const noexcept; 504227825Stheraven shared_ptr<T> lock() const noexcept; 505261272Sdim template<class U> bool owner_before(shared_ptr<U> const& b) const; 506261272Sdim template<class U> bool owner_before(weak_ptr<U> const& b) const; 507227825Stheraven}; 508227825Stheraven 509227825Stheraven// weak_ptr specialized algorithms: 510227825Stheraventemplate<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept; 511227825Stheraven 512227825Stheraven// class owner_less: 513227825Stheraventemplate<class T> struct owner_less; 514227825Stheraven 515227825Stheraventemplate<class T> 516227825Stheravenstruct owner_less<shared_ptr<T>> 517227825Stheraven : binary_function<shared_ptr<T>, shared_ptr<T>, bool> 518227825Stheraven{ 519227825Stheraven typedef bool result_type; 520227825Stheraven bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const; 521227825Stheraven bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; 522227825Stheraven bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; 523227825Stheraven}; 524227825Stheraven 525227825Stheraventemplate<class T> 526227825Stheravenstruct owner_less<weak_ptr<T>> 527227825Stheraven : binary_function<weak_ptr<T>, weak_ptr<T>, bool> 528227825Stheraven{ 529227825Stheraven typedef bool result_type; 530227825Stheraven bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const; 531227825Stheraven bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; 532227825Stheraven bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; 533227825Stheraven}; 534227825Stheraven 535227825Stheraventemplate<class T> 536227825Stheravenclass enable_shared_from_this 537227825Stheraven{ 538227825Stheravenprotected: 539227825Stheraven constexpr enable_shared_from_this() noexcept; 540227825Stheraven enable_shared_from_this(enable_shared_from_this const&) noexcept; 541227825Stheraven enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; 542227825Stheraven ~enable_shared_from_this(); 543227825Stheravenpublic: 544227825Stheraven shared_ptr<T> shared_from_this(); 545227825Stheraven shared_ptr<T const> shared_from_this() const; 546227825Stheraven}; 547227825Stheraven 548227825Stheraventemplate<class T> 549227825Stheraven bool atomic_is_lock_free(const shared_ptr<T>* p); 550227825Stheraventemplate<class T> 551227825Stheraven shared_ptr<T> atomic_load(const shared_ptr<T>* p); 552227825Stheraventemplate<class T> 553227825Stheraven shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo); 554227825Stheraventemplate<class T> 555227825Stheraven void atomic_store(shared_ptr<T>* p, shared_ptr<T> r); 556227825Stheraventemplate<class T> 557227825Stheraven void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); 558227825Stheraventemplate<class T> 559227825Stheraven shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r); 560227825Stheraventemplate<class T> 561227825Stheraven shared_ptr<T> 562227825Stheraven atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); 563227825Stheraventemplate<class T> 564227825Stheraven bool 565227825Stheraven atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); 566227825Stheraventemplate<class T> 567227825Stheraven bool 568227825Stheraven atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); 569227825Stheraventemplate<class T> 570227825Stheraven bool 571227825Stheraven atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, 572227825Stheraven shared_ptr<T> w, memory_order success, 573227825Stheraven memory_order failure); 574227825Stheraventemplate<class T> 575227825Stheraven bool 576227825Stheraven atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, 577227825Stheraven shared_ptr<T> w, memory_order success, 578227825Stheraven memory_order failure); 579227825Stheraven// Hash support 580227825Stheraventemplate <class T> struct hash; 581227825Stheraventemplate <class T, class D> struct hash<unique_ptr<T, D> >; 582227825Stheraventemplate <class T> struct hash<shared_ptr<T> >; 583227825Stheraven 584227825Stheraven// Pointer safety 585227825Stheravenenum class pointer_safety { relaxed, preferred, strict }; 586227825Stheravenvoid declare_reachable(void *p); 587227825Stheraventemplate <class T> T *undeclare_reachable(T *p); 588227825Stheravenvoid declare_no_pointers(char *p, size_t n); 589227825Stheravenvoid undeclare_no_pointers(char *p, size_t n); 590227825Stheravenpointer_safety get_pointer_safety() noexcept; 591227825Stheraven 592227825Stheravenvoid* align(size_t alignment, size_t size, void*& ptr, size_t& space); 593227825Stheraven 594227825Stheraven} // std 595227825Stheraven 596227825Stheraven*/ 597227825Stheraven 598227825Stheraven#include <__config> 599227825Stheraven#include <type_traits> 600227825Stheraven#include <typeinfo> 601227825Stheraven#include <cstddef> 602227825Stheraven#include <cstdint> 603227825Stheraven#include <new> 604227825Stheraven#include <utility> 605227825Stheraven#include <limits> 606227825Stheraven#include <iterator> 607227825Stheraven#include <__functional_base> 608227825Stheraven#include <iosfwd> 609232924Stheraven#include <tuple> 610232924Stheraven#include <cstring> 611227825Stheraven#if defined(_LIBCPP_NO_EXCEPTIONS) 612227825Stheraven #include <cassert> 613227825Stheraven#endif 614227825Stheraven 615300770Sdim#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) 616241900Sdim# include <atomic> 617241900Sdim#endif 618241900Sdim 619232924Stheraven#include <__undef_min_max> 620288943Sdim#include <__undef___deallocate> 621232924Stheraven 622227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 623227825Stheraven#pragma GCC system_header 624227825Stheraven#endif 625227825Stheraven 626227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 627227825Stheraven 628288943Sdimtemplate <class _ValueType> 629288943Sdiminline _LIBCPP_ALWAYS_INLINE 630288943Sdim_ValueType __libcpp_relaxed_load(_ValueType const* __value) { 631288943Sdim#if !defined(_LIBCPP_HAS_NO_THREADS) && \ 632288943Sdim defined(__ATOMIC_RELAXED) && \ 633288943Sdim (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) 634288943Sdim return __atomic_load_n(__value, __ATOMIC_RELAXED); 635288943Sdim#else 636288943Sdim return *__value; 637288943Sdim#endif 638288943Sdim} 639288943Sdim 640261272Sdim// addressof moved to <__functional_base> 641227825Stheraven 642227825Stheraventemplate <class _Tp> class allocator; 643227825Stheraven 644227825Stheraventemplate <> 645261272Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator<void> 646227825Stheraven{ 647227825Stheravenpublic: 648227825Stheraven typedef void* pointer; 649227825Stheraven typedef const void* const_pointer; 650227825Stheraven typedef void value_type; 651227825Stheraven 652227825Stheraven template <class _Up> struct rebind {typedef allocator<_Up> other;}; 653227825Stheraven}; 654227825Stheraven 655232924Stheraventemplate <> 656261272Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator<const void> 657232924Stheraven{ 658232924Stheravenpublic: 659232924Stheraven typedef const void* pointer; 660232924Stheraven typedef const void* const_pointer; 661232924Stheraven typedef const void value_type; 662232924Stheraven 663232924Stheraven template <class _Up> struct rebind {typedef allocator<_Up> other;}; 664232924Stheraven}; 665232924Stheraven 666227825Stheraven// pointer_traits 667227825Stheraven 668227825Stheraventemplate <class _Tp> 669227825Stheravenstruct __has_element_type 670227825Stheraven{ 671227825Stheravenprivate: 672242939Stheraven struct __two {char __lx; char __lxx;}; 673227825Stheraven template <class _Up> static __two __test(...); 674227825Stheraven template <class _Up> static char __test(typename _Up::element_type* = 0); 675227825Stheravenpublic: 676227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 677227825Stheraven}; 678227825Stheraven 679227825Stheraventemplate <class _Ptr, bool = __has_element_type<_Ptr>::value> 680227825Stheravenstruct __pointer_traits_element_type; 681227825Stheraven 682227825Stheraventemplate <class _Ptr> 683227825Stheravenstruct __pointer_traits_element_type<_Ptr, true> 684227825Stheraven{ 685227825Stheraven typedef typename _Ptr::element_type type; 686227825Stheraven}; 687227825Stheraven 688227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 689227825Stheraven 690227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args> 691227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> 692227825Stheraven{ 693227825Stheraven typedef typename _Sp<_Tp, _Args...>::element_type type; 694227825Stheraven}; 695227825Stheraven 696227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args> 697227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> 698227825Stheraven{ 699227825Stheraven typedef _Tp type; 700227825Stheraven}; 701227825Stheraven 702227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 703227825Stheraven 704227825Stheraventemplate <template <class> class _Sp, class _Tp> 705227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, true> 706227825Stheraven{ 707227825Stheraven typedef typename _Sp<_Tp>::element_type type; 708227825Stheraven}; 709227825Stheraven 710227825Stheraventemplate <template <class> class _Sp, class _Tp> 711227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, false> 712227825Stheraven{ 713227825Stheraven typedef _Tp type; 714227825Stheraven}; 715227825Stheraven 716227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0> 717227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, true> 718227825Stheraven{ 719227825Stheraven typedef typename _Sp<_Tp, _A0>::element_type type; 720227825Stheraven}; 721227825Stheraven 722227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0> 723227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, false> 724227825Stheraven{ 725227825Stheraven typedef _Tp type; 726227825Stheraven}; 727227825Stheraven 728227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> 729227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true> 730227825Stheraven{ 731227825Stheraven typedef typename _Sp<_Tp, _A0, _A1>::element_type type; 732227825Stheraven}; 733227825Stheraven 734227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> 735227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false> 736227825Stheraven{ 737227825Stheraven typedef _Tp type; 738227825Stheraven}; 739227825Stheraven 740227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0, 741227825Stheraven class _A1, class _A2> 742227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true> 743227825Stheraven{ 744227825Stheraven typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type; 745227825Stheraven}; 746227825Stheraven 747227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0, 748227825Stheraven class _A1, class _A2> 749227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false> 750227825Stheraven{ 751227825Stheraven typedef _Tp type; 752227825Stheraven}; 753227825Stheraven 754227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 755227825Stheraven 756227825Stheraventemplate <class _Tp> 757227825Stheravenstruct __has_difference_type 758227825Stheraven{ 759227825Stheravenprivate: 760242939Stheraven struct __two {char __lx; char __lxx;}; 761227825Stheraven template <class _Up> static __two __test(...); 762227825Stheraven template <class _Up> static char __test(typename _Up::difference_type* = 0); 763227825Stheravenpublic: 764227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 765227825Stheraven}; 766227825Stheraven 767227825Stheraventemplate <class _Ptr, bool = __has_difference_type<_Ptr>::value> 768227825Stheravenstruct __pointer_traits_difference_type 769227825Stheraven{ 770227825Stheraven typedef ptrdiff_t type; 771227825Stheraven}; 772227825Stheraven 773227825Stheraventemplate <class _Ptr> 774227825Stheravenstruct __pointer_traits_difference_type<_Ptr, true> 775227825Stheraven{ 776227825Stheraven typedef typename _Ptr::difference_type type; 777227825Stheraven}; 778227825Stheraven 779227825Stheraventemplate <class _Tp, class _Up> 780227825Stheravenstruct __has_rebind 781227825Stheraven{ 782227825Stheravenprivate: 783242939Stheraven struct __two {char __lx; char __lxx;}; 784227825Stheraven template <class _Xp> static __two __test(...); 785227825Stheraven template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0); 786227825Stheravenpublic: 787227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 788227825Stheraven}; 789227825Stheraven 790227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> 791227825Stheravenstruct __pointer_traits_rebind 792227825Stheraven{ 793227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 794227825Stheraven typedef typename _Tp::template rebind<_Up> type; 795227825Stheraven#else 796227825Stheraven typedef typename _Tp::template rebind<_Up>::other type; 797227825Stheraven#endif 798227825Stheraven}; 799227825Stheraven 800227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 801227825Stheraven 802227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> 803227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> 804227825Stheraven{ 805227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 806227825Stheraven typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type; 807227825Stheraven#else 808227825Stheraven typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; 809227825Stheraven#endif 810227825Stheraven}; 811227825Stheraven 812227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> 813227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> 814227825Stheraven{ 815227825Stheraven typedef _Sp<_Up, _Args...> type; 816227825Stheraven}; 817227825Stheraven 818227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 819227825Stheraven 820227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up> 821227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, true> 822227825Stheraven{ 823227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 824227825Stheraven typedef typename _Sp<_Tp>::template rebind<_Up> type; 825227825Stheraven#else 826227825Stheraven typedef typename _Sp<_Tp>::template rebind<_Up>::other type; 827227825Stheraven#endif 828227825Stheraven}; 829227825Stheraven 830227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up> 831227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, false> 832227825Stheraven{ 833227825Stheraven typedef _Sp<_Up> type; 834227825Stheraven}; 835227825Stheraven 836227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up> 837227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true> 838227825Stheraven{ 839227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 840227825Stheraven typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type; 841227825Stheraven#else 842227825Stheraven typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type; 843227825Stheraven#endif 844227825Stheraven}; 845227825Stheraven 846227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up> 847227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false> 848227825Stheraven{ 849227825Stheraven typedef _Sp<_Up, _A0> type; 850227825Stheraven}; 851227825Stheraven 852227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, 853227825Stheraven class _A1, class _Up> 854227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true> 855227825Stheraven{ 856227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 857227825Stheraven typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type; 858227825Stheraven#else 859227825Stheraven typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type; 860227825Stheraven#endif 861227825Stheraven}; 862227825Stheraven 863227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, 864227825Stheraven class _A1, class _Up> 865227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false> 866227825Stheraven{ 867227825Stheraven typedef _Sp<_Up, _A0, _A1> type; 868227825Stheraven}; 869227825Stheraven 870227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0, 871227825Stheraven class _A1, class _A2, class _Up> 872227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true> 873227825Stheraven{ 874227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 875227825Stheraven typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type; 876227825Stheraven#else 877227825Stheraven typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; 878227825Stheraven#endif 879227825Stheraven}; 880227825Stheraven 881227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0, 882227825Stheraven class _A1, class _A2, class _Up> 883227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false> 884227825Stheraven{ 885227825Stheraven typedef _Sp<_Up, _A0, _A1, _A2> type; 886227825Stheraven}; 887227825Stheraven 888227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 889227825Stheraven 890227825Stheraventemplate <class _Ptr> 891261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY pointer_traits 892227825Stheraven{ 893227825Stheraven typedef _Ptr pointer; 894227825Stheraven typedef typename __pointer_traits_element_type<pointer>::type element_type; 895227825Stheraven typedef typename __pointer_traits_difference_type<pointer>::type difference_type; 896227825Stheraven 897227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 898227825Stheraven template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; 899227825Stheraven#else 900227825Stheraven template <class _Up> struct rebind 901227825Stheraven {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;}; 902227825Stheraven#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 903227825Stheraven 904227825Stheravenprivate: 905227825Stheraven struct __nat {}; 906227825Stheravenpublic: 907227825Stheraven _LIBCPP_INLINE_VISIBILITY 908227825Stheraven static pointer pointer_to(typename conditional<is_void<element_type>::value, 909227825Stheraven __nat, element_type>::type& __r) 910227825Stheraven {return pointer::pointer_to(__r);} 911227825Stheraven}; 912227825Stheraven 913227825Stheraventemplate <class _Tp> 914261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*> 915227825Stheraven{ 916227825Stheraven typedef _Tp* pointer; 917227825Stheraven typedef _Tp element_type; 918227825Stheraven typedef ptrdiff_t difference_type; 919227825Stheraven 920227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 921227825Stheraven template <class _Up> using rebind = _Up*; 922227825Stheraven#else 923227825Stheraven template <class _Up> struct rebind {typedef _Up* other;}; 924227825Stheraven#endif 925227825Stheraven 926227825Stheravenprivate: 927227825Stheraven struct __nat {}; 928227825Stheravenpublic: 929227825Stheraven _LIBCPP_INLINE_VISIBILITY 930227825Stheraven static pointer pointer_to(typename conditional<is_void<element_type>::value, 931227825Stheraven __nat, element_type>::type& __r) _NOEXCEPT 932227825Stheraven {return _VSTD::addressof(__r);} 933227825Stheraven}; 934227825Stheraven 935300770Sdimtemplate <class _From, class _To> 936300770Sdimstruct __rebind_pointer { 937300770Sdim#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 938300770Sdim typedef typename pointer_traits<_From>::template rebind<_To> type; 939300770Sdim#else 940300770Sdim typedef typename pointer_traits<_From>::template rebind<_To>::other type; 941300770Sdim#endif 942300770Sdim}; 943300770Sdim 944227825Stheraven// allocator_traits 945227825Stheraven 946227825Stheravennamespace __has_pointer_type_imp 947227825Stheraven{ 948261272Sdim template <class _Up> static __two __test(...); 949261272Sdim template <class _Up> static char __test(typename _Up::pointer* = 0); 950227825Stheraven} 951227825Stheraven 952227825Stheraventemplate <class _Tp> 953227825Stheravenstruct __has_pointer_type 954261272Sdim : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1> 955227825Stheraven{ 956227825Stheraven}; 957227825Stheraven 958227825Stheravennamespace __pointer_type_imp 959227825Stheraven{ 960227825Stheraven 961227825Stheraventemplate <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value> 962227825Stheravenstruct __pointer_type 963227825Stheraven{ 964227825Stheraven typedef typename _Dp::pointer type; 965227825Stheraven}; 966227825Stheraven 967227825Stheraventemplate <class _Tp, class _Dp> 968227825Stheravenstruct __pointer_type<_Tp, _Dp, false> 969227825Stheraven{ 970227825Stheraven typedef _Tp* type; 971227825Stheraven}; 972227825Stheraven 973227825Stheraven} // __pointer_type_imp 974227825Stheraven 975227825Stheraventemplate <class _Tp, class _Dp> 976227825Stheravenstruct __pointer_type 977227825Stheraven{ 978227825Stheraven typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; 979227825Stheraven}; 980227825Stheraven 981227825Stheraventemplate <class _Tp> 982227825Stheravenstruct __has_const_pointer 983227825Stheraven{ 984227825Stheravenprivate: 985242939Stheraven struct __two {char __lx; char __lxx;}; 986227825Stheraven template <class _Up> static __two __test(...); 987227825Stheraven template <class _Up> static char __test(typename _Up::const_pointer* = 0); 988227825Stheravenpublic: 989227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 990227825Stheraven}; 991227825Stheraven 992227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> 993227825Stheravenstruct __const_pointer 994227825Stheraven{ 995227825Stheraven typedef typename _Alloc::const_pointer type; 996227825Stheraven}; 997227825Stheraven 998227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc> 999227825Stheravenstruct __const_pointer<_Tp, _Ptr, _Alloc, false> 1000227825Stheraven{ 1001227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1002227825Stheraven typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type; 1003227825Stheraven#else 1004227825Stheraven typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type; 1005227825Stheraven#endif 1006227825Stheraven}; 1007227825Stheraven 1008227825Stheraventemplate <class _Tp> 1009227825Stheravenstruct __has_void_pointer 1010227825Stheraven{ 1011227825Stheravenprivate: 1012242939Stheraven struct __two {char __lx; char __lxx;}; 1013227825Stheraven template <class _Up> static __two __test(...); 1014227825Stheraven template <class _Up> static char __test(typename _Up::void_pointer* = 0); 1015227825Stheravenpublic: 1016227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 1017227825Stheraven}; 1018227825Stheraven 1019227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> 1020227825Stheravenstruct __void_pointer 1021227825Stheraven{ 1022227825Stheraven typedef typename _Alloc::void_pointer type; 1023227825Stheraven}; 1024227825Stheraven 1025227825Stheraventemplate <class _Ptr, class _Alloc> 1026227825Stheravenstruct __void_pointer<_Ptr, _Alloc, false> 1027227825Stheraven{ 1028227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1029227825Stheraven typedef typename pointer_traits<_Ptr>::template rebind<void> type; 1030227825Stheraven#else 1031227825Stheraven typedef typename pointer_traits<_Ptr>::template rebind<void>::other type; 1032227825Stheraven#endif 1033227825Stheraven}; 1034227825Stheraven 1035227825Stheraventemplate <class _Tp> 1036227825Stheravenstruct __has_const_void_pointer 1037227825Stheraven{ 1038227825Stheravenprivate: 1039242939Stheraven struct __two {char __lx; char __lxx;}; 1040227825Stheraven template <class _Up> static __two __test(...); 1041227825Stheraven template <class _Up> static char __test(typename _Up::const_void_pointer* = 0); 1042227825Stheravenpublic: 1043227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 1044227825Stheraven}; 1045227825Stheraven 1046227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> 1047227825Stheravenstruct __const_void_pointer 1048227825Stheraven{ 1049227825Stheraven typedef typename _Alloc::const_void_pointer type; 1050227825Stheraven}; 1051227825Stheraven 1052227825Stheraventemplate <class _Ptr, class _Alloc> 1053227825Stheravenstruct __const_void_pointer<_Ptr, _Alloc, false> 1054227825Stheraven{ 1055227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1056227825Stheraven typedef typename pointer_traits<_Ptr>::template rebind<const void> type; 1057227825Stheraven#else 1058227825Stheraven typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type; 1059227825Stheraven#endif 1060227825Stheraven}; 1061227825Stheraven 1062232924Stheraventemplate <class _Tp> 1063227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1064232924Stheraven_Tp* 1065232924Stheraven__to_raw_pointer(_Tp* __p) _NOEXCEPT 1066227825Stheraven{ 1067227825Stheraven return __p; 1068227825Stheraven} 1069227825Stheraven 1070227825Stheraventemplate <class _Pointer> 1071227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1072227825Stheraventypename pointer_traits<_Pointer>::element_type* 1073227825Stheraven__to_raw_pointer(_Pointer __p) _NOEXCEPT 1074227825Stheraven{ 1075227825Stheraven return _VSTD::__to_raw_pointer(__p.operator->()); 1076227825Stheraven} 1077227825Stheraven 1078227825Stheraventemplate <class _Tp> 1079227825Stheravenstruct __has_size_type 1080227825Stheraven{ 1081227825Stheravenprivate: 1082242939Stheraven struct __two {char __lx; char __lxx;}; 1083227825Stheraven template <class _Up> static __two __test(...); 1084227825Stheraven template <class _Up> static char __test(typename _Up::size_type* = 0); 1085227825Stheravenpublic: 1086227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 1087227825Stheraven}; 1088227825Stheraven 1089227825Stheraventemplate <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> 1090227825Stheravenstruct __size_type 1091227825Stheraven{ 1092227825Stheraven typedef typename make_unsigned<_DiffType>::type type; 1093227825Stheraven}; 1094227825Stheraven 1095227825Stheraventemplate <class _Alloc, class _DiffType> 1096227825Stheravenstruct __size_type<_Alloc, _DiffType, true> 1097227825Stheraven{ 1098227825Stheraven typedef typename _Alloc::size_type type; 1099227825Stheraven}; 1100227825Stheraven 1101227825Stheraventemplate <class _Tp> 1102227825Stheravenstruct __has_propagate_on_container_copy_assignment 1103227825Stheraven{ 1104227825Stheravenprivate: 1105242939Stheraven struct __two {char __lx; char __lxx;}; 1106227825Stheraven template <class _Up> static __two __test(...); 1107227825Stheraven template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0); 1108227825Stheravenpublic: 1109227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 1110227825Stheraven}; 1111227825Stheraven 1112227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> 1113227825Stheravenstruct __propagate_on_container_copy_assignment 1114227825Stheraven{ 1115227825Stheraven typedef false_type type; 1116227825Stheraven}; 1117227825Stheraven 1118227825Stheraventemplate <class _Alloc> 1119227825Stheravenstruct __propagate_on_container_copy_assignment<_Alloc, true> 1120227825Stheraven{ 1121227825Stheraven typedef typename _Alloc::propagate_on_container_copy_assignment type; 1122227825Stheraven}; 1123227825Stheraven 1124227825Stheraventemplate <class _Tp> 1125227825Stheravenstruct __has_propagate_on_container_move_assignment 1126227825Stheraven{ 1127227825Stheravenprivate: 1128242939Stheraven struct __two {char __lx; char __lxx;}; 1129227825Stheraven template <class _Up> static __two __test(...); 1130227825Stheraven template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0); 1131227825Stheravenpublic: 1132227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 1133227825Stheraven}; 1134227825Stheraven 1135227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value> 1136227825Stheravenstruct __propagate_on_container_move_assignment 1137227825Stheraven{ 1138227825Stheraven typedef false_type type; 1139227825Stheraven}; 1140227825Stheraven 1141227825Stheraventemplate <class _Alloc> 1142227825Stheravenstruct __propagate_on_container_move_assignment<_Alloc, true> 1143227825Stheraven{ 1144227825Stheraven typedef typename _Alloc::propagate_on_container_move_assignment type; 1145227825Stheraven}; 1146227825Stheraven 1147227825Stheraventemplate <class _Tp> 1148227825Stheravenstruct __has_propagate_on_container_swap 1149227825Stheraven{ 1150227825Stheravenprivate: 1151242939Stheraven struct __two {char __lx; char __lxx;}; 1152227825Stheraven template <class _Up> static __two __test(...); 1153227825Stheraven template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0); 1154227825Stheravenpublic: 1155227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 1156227825Stheraven}; 1157227825Stheraven 1158227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value> 1159227825Stheravenstruct __propagate_on_container_swap 1160227825Stheraven{ 1161227825Stheraven typedef false_type type; 1162227825Stheraven}; 1163227825Stheraven 1164227825Stheraventemplate <class _Alloc> 1165227825Stheravenstruct __propagate_on_container_swap<_Alloc, true> 1166227825Stheraven{ 1167227825Stheraven typedef typename _Alloc::propagate_on_container_swap type; 1168227825Stheraven}; 1169227825Stheraven 1170288943Sdimtemplate <class _Tp> 1171288943Sdimstruct __has_is_always_equal 1172288943Sdim{ 1173288943Sdimprivate: 1174288943Sdim struct __two {char __lx; char __lxx;}; 1175288943Sdim template <class _Up> static __two __test(...); 1176288943Sdim template <class _Up> static char __test(typename _Up::is_always_equal* = 0); 1177288943Sdimpublic: 1178288943Sdim static const bool value = sizeof(__test<_Tp>(0)) == 1; 1179288943Sdim}; 1180288943Sdim 1181288943Sdimtemplate <class _Alloc, bool = __has_is_always_equal<_Alloc>::value> 1182288943Sdimstruct __is_always_equal 1183288943Sdim{ 1184288943Sdim typedef typename _VSTD::is_empty<_Alloc>::type type; 1185288943Sdim}; 1186288943Sdim 1187288943Sdimtemplate <class _Alloc> 1188288943Sdimstruct __is_always_equal<_Alloc, true> 1189288943Sdim{ 1190288943Sdim typedef typename _Alloc::is_always_equal type; 1191288943Sdim}; 1192288943Sdim 1193227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> 1194227825Stheravenstruct __has_rebind_other 1195227825Stheraven{ 1196227825Stheravenprivate: 1197242939Stheraven struct __two {char __lx; char __lxx;}; 1198227825Stheraven template <class _Xp> static __two __test(...); 1199227825Stheraven template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0); 1200227825Stheravenpublic: 1201227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 1202227825Stheraven}; 1203227825Stheraven 1204227825Stheraventemplate <class _Tp, class _Up> 1205227825Stheravenstruct __has_rebind_other<_Tp, _Up, false> 1206227825Stheraven{ 1207227825Stheraven static const bool value = false; 1208227825Stheraven}; 1209227825Stheraven 1210227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> 1211227825Stheravenstruct __allocator_traits_rebind 1212227825Stheraven{ 1213227825Stheraven typedef typename _Tp::template rebind<_Up>::other type; 1214227825Stheraven}; 1215227825Stheraven 1216227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 1217227825Stheraven 1218227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> 1219227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> 1220227825Stheraven{ 1221227825Stheraven typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type; 1222227825Stheraven}; 1223227825Stheraven 1224227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> 1225227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> 1226227825Stheraven{ 1227227825Stheraven typedef _Alloc<_Up, _Args...> type; 1228227825Stheraven}; 1229227825Stheraven 1230227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 1231227825Stheraven 1232227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up> 1233227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true> 1234227825Stheraven{ 1235227825Stheraven typedef typename _Alloc<_Tp>::template rebind<_Up>::other type; 1236227825Stheraven}; 1237227825Stheraven 1238227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up> 1239227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false> 1240227825Stheraven{ 1241227825Stheraven typedef _Alloc<_Up> type; 1242227825Stheraven}; 1243227825Stheraven 1244227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> 1245227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true> 1246227825Stheraven{ 1247227825Stheraven typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type; 1248227825Stheraven}; 1249227825Stheraven 1250227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> 1251227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false> 1252227825Stheraven{ 1253227825Stheraven typedef _Alloc<_Up, _A0> type; 1254227825Stheraven}; 1255227825Stheraven 1256227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0, 1257227825Stheraven class _A1, class _Up> 1258227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true> 1259227825Stheraven{ 1260227825Stheraven typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type; 1261227825Stheraven}; 1262227825Stheraven 1263227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0, 1264227825Stheraven class _A1, class _Up> 1265227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false> 1266227825Stheraven{ 1267227825Stheraven typedef _Alloc<_Up, _A0, _A1> type; 1268227825Stheraven}; 1269227825Stheraven 1270227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0, 1271227825Stheraven class _A1, class _A2, class _Up> 1272227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true> 1273227825Stheraven{ 1274227825Stheraven typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; 1275227825Stheraven}; 1276227825Stheraven 1277227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0, 1278227825Stheraven class _A1, class _A2, class _Up> 1279227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false> 1280227825Stheraven{ 1281227825Stheraven typedef _Alloc<_Up, _A0, _A1, _A2> type; 1282227825Stheraven}; 1283227825Stheraven 1284227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 1285227825Stheraven 1286227825Stheraven#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE 1287227825Stheraven 1288227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr> 1289227825Stheravenauto 1290227825Stheraven__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) 1291227825Stheraven -> decltype(__a.allocate(__sz, __p), true_type()); 1292227825Stheraven 1293227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr> 1294227825Stheravenauto 1295227825Stheraven__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) 1296227825Stheraven -> false_type; 1297227825Stheraven 1298227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr> 1299227825Stheravenstruct __has_allocate_hint 1300227825Stheraven : integral_constant<bool, 1301227825Stheraven is_same< 1302227825Stheraven decltype(__has_allocate_hint_test(declval<_Alloc>(), 1303227825Stheraven declval<_SizeType>(), 1304227825Stheraven declval<_ConstVoidPtr>())), 1305227825Stheraven true_type>::value> 1306227825Stheraven{ 1307227825Stheraven}; 1308227825Stheraven 1309227825Stheraven#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE 1310227825Stheraven 1311227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr> 1312227825Stheravenstruct __has_allocate_hint 1313227825Stheraven : true_type 1314227825Stheraven{ 1315227825Stheraven}; 1316227825Stheraven 1317227825Stheraven#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE 1318227825Stheraven 1319227825Stheraven#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1320227825Stheraven 1321227825Stheraventemplate <class _Alloc, class _Tp, class ..._Args> 1322227825Stheravendecltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(), 1323227825Stheraven _VSTD::declval<_Args>()...), 1324227825Stheraven true_type()) 1325227825Stheraven__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args); 1326227825Stheraven 1327227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args> 1328227825Stheravenfalse_type 1329227825Stheraven__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args); 1330227825Stheraven 1331227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args> 1332227825Stheravenstruct __has_construct 1333227825Stheraven : integral_constant<bool, 1334227825Stheraven is_same< 1335227825Stheraven decltype(__has_construct_test(declval<_Alloc>(), 1336227825Stheraven declval<_Pointer>(), 1337227825Stheraven declval<_Args>()...)), 1338227825Stheraven true_type>::value> 1339227825Stheraven{ 1340227825Stheraven}; 1341227825Stheraven 1342227825Stheraventemplate <class _Alloc, class _Pointer> 1343227825Stheravenauto 1344227825Stheraven__has_destroy_test(_Alloc&& __a, _Pointer&& __p) 1345227825Stheraven -> decltype(__a.destroy(__p), true_type()); 1346227825Stheraven 1347227825Stheraventemplate <class _Alloc, class _Pointer> 1348227825Stheravenauto 1349227825Stheraven__has_destroy_test(const _Alloc& __a, _Pointer&& __p) 1350227825Stheraven -> false_type; 1351227825Stheraven 1352227825Stheraventemplate <class _Alloc, class _Pointer> 1353227825Stheravenstruct __has_destroy 1354227825Stheraven : integral_constant<bool, 1355227825Stheraven is_same< 1356227825Stheraven decltype(__has_destroy_test(declval<_Alloc>(), 1357227825Stheraven declval<_Pointer>())), 1358227825Stheraven true_type>::value> 1359227825Stheraven{ 1360227825Stheraven}; 1361227825Stheraven 1362227825Stheraventemplate <class _Alloc> 1363227825Stheravenauto 1364227825Stheraven__has_max_size_test(_Alloc&& __a) 1365227825Stheraven -> decltype(__a.max_size(), true_type()); 1366227825Stheraven 1367227825Stheraventemplate <class _Alloc> 1368227825Stheravenauto 1369227825Stheraven__has_max_size_test(const volatile _Alloc& __a) 1370227825Stheraven -> false_type; 1371227825Stheraven 1372227825Stheraventemplate <class _Alloc> 1373227825Stheravenstruct __has_max_size 1374227825Stheraven : integral_constant<bool, 1375227825Stheraven is_same< 1376227825Stheraven decltype(__has_max_size_test(declval<_Alloc&>())), 1377227825Stheraven true_type>::value> 1378227825Stheraven{ 1379227825Stheraven}; 1380227825Stheraven 1381227825Stheraventemplate <class _Alloc> 1382227825Stheravenauto 1383227825Stheraven__has_select_on_container_copy_construction_test(_Alloc&& __a) 1384227825Stheraven -> decltype(__a.select_on_container_copy_construction(), true_type()); 1385227825Stheraven 1386227825Stheraventemplate <class _Alloc> 1387227825Stheravenauto 1388227825Stheraven__has_select_on_container_copy_construction_test(const volatile _Alloc& __a) 1389227825Stheraven -> false_type; 1390227825Stheraven 1391227825Stheraventemplate <class _Alloc> 1392227825Stheravenstruct __has_select_on_container_copy_construction 1393227825Stheraven : integral_constant<bool, 1394227825Stheraven is_same< 1395227825Stheraven decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())), 1396227825Stheraven true_type>::value> 1397227825Stheraven{ 1398227825Stheraven}; 1399227825Stheraven 1400227825Stheraven#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE 1401227825Stheraven 1402227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 1403227825Stheraven 1404227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args> 1405227825Stheravenstruct __has_construct 1406227825Stheraven : false_type 1407227825Stheraven{ 1408227825Stheraven}; 1409227825Stheraven 1410232924Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 1411232924Stheraven 1412232924Stheraventemplate <class _Alloc, class _Pointer, class _Args> 1413232924Stheravenstruct __has_construct 1414232924Stheraven : false_type 1415232924Stheraven{ 1416232924Stheraven}; 1417232924Stheraven 1418227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 1419227825Stheraven 1420227825Stheraventemplate <class _Alloc, class _Pointer> 1421227825Stheravenstruct __has_destroy 1422227825Stheraven : false_type 1423227825Stheraven{ 1424227825Stheraven}; 1425227825Stheraven 1426227825Stheraventemplate <class _Alloc> 1427227825Stheravenstruct __has_max_size 1428227825Stheraven : true_type 1429227825Stheraven{ 1430227825Stheraven}; 1431227825Stheraven 1432227825Stheraventemplate <class _Alloc> 1433227825Stheravenstruct __has_select_on_container_copy_construction 1434227825Stheraven : false_type 1435227825Stheraven{ 1436227825Stheraven}; 1437227825Stheraven 1438227825Stheraven#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE 1439227825Stheraven 1440227825Stheraventemplate <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> 1441227825Stheravenstruct __alloc_traits_difference_type 1442227825Stheraven{ 1443227825Stheraven typedef typename pointer_traits<_Ptr>::difference_type type; 1444227825Stheraven}; 1445227825Stheraven 1446227825Stheraventemplate <class _Alloc, class _Ptr> 1447227825Stheravenstruct __alloc_traits_difference_type<_Alloc, _Ptr, true> 1448227825Stheraven{ 1449227825Stheraven typedef typename _Alloc::difference_type type; 1450227825Stheraven}; 1451227825Stheraven 1452227825Stheraventemplate <class _Alloc> 1453261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY allocator_traits 1454227825Stheraven{ 1455227825Stheraven typedef _Alloc allocator_type; 1456227825Stheraven typedef typename allocator_type::value_type value_type; 1457227825Stheraven 1458227825Stheraven typedef typename __pointer_type<value_type, allocator_type>::type pointer; 1459227825Stheraven typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer; 1460227825Stheraven typedef typename __void_pointer<pointer, allocator_type>::type void_pointer; 1461227825Stheraven typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer; 1462227825Stheraven 1463227825Stheraven typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type; 1464227825Stheraven typedef typename __size_type<allocator_type, difference_type>::type size_type; 1465227825Stheraven 1466227825Stheraven typedef typename __propagate_on_container_copy_assignment<allocator_type>::type 1467227825Stheraven propagate_on_container_copy_assignment; 1468227825Stheraven typedef typename __propagate_on_container_move_assignment<allocator_type>::type 1469227825Stheraven propagate_on_container_move_assignment; 1470227825Stheraven typedef typename __propagate_on_container_swap<allocator_type>::type 1471227825Stheraven propagate_on_container_swap; 1472288943Sdim typedef typename __is_always_equal<allocator_type>::type 1473288943Sdim is_always_equal; 1474227825Stheraven 1475227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1476227825Stheraven template <class _Tp> using rebind_alloc = 1477227825Stheraven typename __allocator_traits_rebind<allocator_type, _Tp>::type; 1478227825Stheraven template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; 1479227825Stheraven#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1480227825Stheraven template <class _Tp> struct rebind_alloc 1481227825Stheraven {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; 1482227825Stheraven template <class _Tp> struct rebind_traits 1483227825Stheraven {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;}; 1484227825Stheraven#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1485227825Stheraven 1486227825Stheraven _LIBCPP_INLINE_VISIBILITY 1487227825Stheraven static pointer allocate(allocator_type& __a, size_type __n) 1488227825Stheraven {return __a.allocate(__n);} 1489227825Stheraven _LIBCPP_INLINE_VISIBILITY 1490227825Stheraven static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) 1491227825Stheraven {return allocate(__a, __n, __hint, 1492227825Stheraven __has_allocate_hint<allocator_type, size_type, const_void_pointer>());} 1493227825Stheraven 1494227825Stheraven _LIBCPP_INLINE_VISIBILITY 1495227825Stheraven static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT 1496227825Stheraven {__a.deallocate(__p, __n);} 1497227825Stheraven 1498227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 1499227825Stheraven template <class _Tp, class... _Args> 1500227825Stheraven _LIBCPP_INLINE_VISIBILITY 1501227825Stheraven static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) 1502276792Sdim {__construct(__has_construct<allocator_type, _Tp*, _Args...>(), 1503227825Stheraven __a, __p, _VSTD::forward<_Args>(__args)...);} 1504227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 1505227825Stheraven template <class _Tp> 1506227825Stheraven _LIBCPP_INLINE_VISIBILITY 1507227825Stheraven static void construct(allocator_type& __a, _Tp* __p) 1508227825Stheraven { 1509227825Stheraven ::new ((void*)__p) _Tp(); 1510227825Stheraven } 1511227825Stheraven template <class _Tp, class _A0> 1512227825Stheraven _LIBCPP_INLINE_VISIBILITY 1513227825Stheraven static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0) 1514227825Stheraven { 1515227825Stheraven ::new ((void*)__p) _Tp(__a0); 1516227825Stheraven } 1517227825Stheraven template <class _Tp, class _A0, class _A1> 1518227825Stheraven _LIBCPP_INLINE_VISIBILITY 1519227825Stheraven static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0, 1520227825Stheraven const _A1& __a1) 1521227825Stheraven { 1522227825Stheraven ::new ((void*)__p) _Tp(__a0, __a1); 1523227825Stheraven } 1524227825Stheraven template <class _Tp, class _A0, class _A1, class _A2> 1525227825Stheraven _LIBCPP_INLINE_VISIBILITY 1526227825Stheraven static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0, 1527227825Stheraven const _A1& __a1, const _A2& __a2) 1528227825Stheraven { 1529227825Stheraven ::new ((void*)__p) _Tp(__a0, __a1, __a2); 1530227825Stheraven } 1531227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 1532227825Stheraven 1533227825Stheraven template <class _Tp> 1534227825Stheraven _LIBCPP_INLINE_VISIBILITY 1535227825Stheraven static void destroy(allocator_type& __a, _Tp* __p) 1536227825Stheraven {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);} 1537227825Stheraven 1538227825Stheraven _LIBCPP_INLINE_VISIBILITY 1539261272Sdim static size_type max_size(const allocator_type& __a) _NOEXCEPT 1540227825Stheraven {return __max_size(__has_max_size<const allocator_type>(), __a);} 1541227825Stheraven 1542227825Stheraven _LIBCPP_INLINE_VISIBILITY 1543227825Stheraven static allocator_type 1544227825Stheraven select_on_container_copy_construction(const allocator_type& __a) 1545227825Stheraven {return select_on_container_copy_construction( 1546227825Stheraven __has_select_on_container_copy_construction<const allocator_type>(), 1547227825Stheraven __a);} 1548227825Stheraven 1549232924Stheraven template <class _Ptr> 1550232924Stheraven _LIBCPP_INLINE_VISIBILITY 1551232924Stheraven static 1552232924Stheraven void 1553232924Stheraven __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) 1554232924Stheraven { 1555232924Stheraven for (; __begin1 != __end1; ++__begin1, ++__begin2) 1556232924Stheraven construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1)); 1557232924Stheraven } 1558232924Stheraven 1559232924Stheraven template <class _Tp> 1560232924Stheraven _LIBCPP_INLINE_VISIBILITY 1561232924Stheraven static 1562232924Stheraven typename enable_if 1563232924Stheraven < 1564232924Stheraven (is_same<allocator_type, allocator<_Tp> >::value 1565232924Stheraven || !__has_construct<allocator_type, _Tp*, _Tp>::value) && 1566232924Stheraven is_trivially_move_constructible<_Tp>::value, 1567232924Stheraven void 1568232924Stheraven >::type 1569232924Stheraven __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) 1570232924Stheraven { 1571232924Stheraven ptrdiff_t _Np = __end1 - __begin1; 1572288943Sdim if (_Np > 0) 1573288943Sdim { 1574288943Sdim _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); 1575288943Sdim __begin2 += _Np; 1576288943Sdim } 1577232924Stheraven } 1578232924Stheraven 1579288943Sdim template <class _Iter, class _Ptr> 1580288943Sdim _LIBCPP_INLINE_VISIBILITY 1581288943Sdim static 1582288943Sdim void 1583288943Sdim __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) 1584288943Sdim { 1585288943Sdim for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) 1586288943Sdim construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1); 1587288943Sdim } 1588288943Sdim 1589288943Sdim template <class _Tp> 1590288943Sdim _LIBCPP_INLINE_VISIBILITY 1591288943Sdim static 1592288943Sdim typename enable_if 1593288943Sdim < 1594288943Sdim (is_same<allocator_type, allocator<_Tp> >::value 1595288943Sdim || !__has_construct<allocator_type, _Tp*, _Tp>::value) && 1596288943Sdim is_trivially_move_constructible<_Tp>::value, 1597288943Sdim void 1598288943Sdim >::type 1599288943Sdim __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) 1600288943Sdim { 1601288943Sdim typedef typename remove_const<_Tp>::type _Vp; 1602288943Sdim ptrdiff_t _Np = __end1 - __begin1; 1603288943Sdim if (_Np > 0) 1604288943Sdim { 1605288943Sdim _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp)); 1606288943Sdim __begin2 += _Np; 1607288943Sdim } 1608288943Sdim } 1609288943Sdim 1610232924Stheraven template <class _Ptr> 1611232924Stheraven _LIBCPP_INLINE_VISIBILITY 1612232924Stheraven static 1613232924Stheraven void 1614232924Stheraven __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) 1615232924Stheraven { 1616232924Stheraven while (__end1 != __begin1) 1617246468Stheraven { 1618246468Stheraven construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1)); 1619246468Stheraven --__end2; 1620246468Stheraven } 1621232924Stheraven } 1622232924Stheraven 1623232924Stheraven template <class _Tp> 1624232924Stheraven _LIBCPP_INLINE_VISIBILITY 1625232924Stheraven static 1626232924Stheraven typename enable_if 1627232924Stheraven < 1628232924Stheraven (is_same<allocator_type, allocator<_Tp> >::value 1629232924Stheraven || !__has_construct<allocator_type, _Tp*, _Tp>::value) && 1630232924Stheraven is_trivially_move_constructible<_Tp>::value, 1631232924Stheraven void 1632232924Stheraven >::type 1633232924Stheraven __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) 1634232924Stheraven { 1635232924Stheraven ptrdiff_t _Np = __end1 - __begin1; 1636232924Stheraven __end2 -= _Np; 1637288943Sdim if (_Np > 0) 1638288943Sdim _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); 1639232924Stheraven } 1640232924Stheraven 1641227825Stheravenprivate: 1642227825Stheraven 1643227825Stheraven _LIBCPP_INLINE_VISIBILITY 1644227825Stheraven static pointer allocate(allocator_type& __a, size_type __n, 1645227825Stheraven const_void_pointer __hint, true_type) 1646227825Stheraven {return __a.allocate(__n, __hint);} 1647227825Stheraven _LIBCPP_INLINE_VISIBILITY 1648227825Stheraven static pointer allocate(allocator_type& __a, size_type __n, 1649232924Stheraven const_void_pointer, false_type) 1650227825Stheraven {return __a.allocate(__n);} 1651227825Stheraven 1652227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 1653227825Stheraven template <class _Tp, class... _Args> 1654227825Stheraven _LIBCPP_INLINE_VISIBILITY 1655227825Stheraven static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args) 1656227825Stheraven {__a.construct(__p, _VSTD::forward<_Args>(__args)...);} 1657227825Stheraven template <class _Tp, class... _Args> 1658227825Stheraven _LIBCPP_INLINE_VISIBILITY 1659227825Stheraven static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args) 1660227825Stheraven { 1661227825Stheraven ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...); 1662227825Stheraven } 1663227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 1664227825Stheraven 1665227825Stheraven template <class _Tp> 1666227825Stheraven _LIBCPP_INLINE_VISIBILITY 1667227825Stheraven static void __destroy(true_type, allocator_type& __a, _Tp* __p) 1668227825Stheraven {__a.destroy(__p);} 1669227825Stheraven template <class _Tp> 1670227825Stheraven _LIBCPP_INLINE_VISIBILITY 1671227825Stheraven static void __destroy(false_type, allocator_type&, _Tp* __p) 1672227825Stheraven { 1673227825Stheraven __p->~_Tp(); 1674227825Stheraven } 1675227825Stheraven 1676227825Stheraven _LIBCPP_INLINE_VISIBILITY 1677227825Stheraven static size_type __max_size(true_type, const allocator_type& __a) 1678227825Stheraven {return __a.max_size();} 1679227825Stheraven _LIBCPP_INLINE_VISIBILITY 1680227825Stheraven static size_type __max_size(false_type, const allocator_type&) 1681300770Sdim {return numeric_limits<size_type>::max() / sizeof(value_type);} 1682227825Stheraven 1683227825Stheraven _LIBCPP_INLINE_VISIBILITY 1684227825Stheraven static allocator_type 1685227825Stheraven select_on_container_copy_construction(true_type, const allocator_type& __a) 1686227825Stheraven {return __a.select_on_container_copy_construction();} 1687227825Stheraven _LIBCPP_INLINE_VISIBILITY 1688227825Stheraven static allocator_type 1689227825Stheraven select_on_container_copy_construction(false_type, const allocator_type& __a) 1690227825Stheraven {return __a;} 1691227825Stheraven}; 1692227825Stheraven 1693288943Sdimtemplate <class _Traits, class _Tp> 1694288943Sdimstruct __rebind_alloc_helper 1695288943Sdim{ 1696288943Sdim#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1697288943Sdim typedef typename _Traits::template rebind_alloc<_Tp> type; 1698288943Sdim#else 1699288943Sdim typedef typename _Traits::template rebind_alloc<_Tp>::other type; 1700288943Sdim#endif 1701288943Sdim}; 1702288943Sdim 1703232924Stheraven// allocator 1704227825Stheraven 1705227825Stheraventemplate <class _Tp> 1706261272Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator 1707227825Stheraven{ 1708227825Stheravenpublic: 1709232924Stheraven typedef size_t size_type; 1710232924Stheraven typedef ptrdiff_t difference_type; 1711232924Stheraven typedef _Tp* pointer; 1712232924Stheraven typedef const _Tp* const_pointer; 1713232924Stheraven typedef _Tp& reference; 1714232924Stheraven typedef const _Tp& const_reference; 1715232924Stheraven typedef _Tp value_type; 1716227825Stheraven 1717232924Stheraven typedef true_type propagate_on_container_move_assignment; 1718288943Sdim typedef true_type is_always_equal; 1719227825Stheraven 1720232924Stheraven template <class _Up> struct rebind {typedef allocator<_Up> other;}; 1721227825Stheraven 1722232924Stheraven _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {} 1723232924Stheraven template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {} 1724232924Stheraven _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT 1725232924Stheraven {return _VSTD::addressof(__x);} 1726232924Stheraven _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT 1727232924Stheraven {return _VSTD::addressof(__x);} 1728232924Stheraven _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) 1729276792Sdim {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} 1730232924Stheraven _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT 1731276792Sdim {_VSTD::__deallocate((void*)__p);} 1732232924Stheraven _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT 1733232924Stheraven {return size_type(~0) / sizeof(_Tp);} 1734232924Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1735232924Stheraven template <class _Up, class... _Args> 1736232924Stheraven _LIBCPP_INLINE_VISIBILITY 1737232924Stheraven void 1738232924Stheraven construct(_Up* __p, _Args&&... __args) 1739232924Stheraven { 1740232924Stheraven ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); 1741232924Stheraven } 1742232924Stheraven#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1743232924Stheraven _LIBCPP_INLINE_VISIBILITY 1744232924Stheraven void 1745232924Stheraven construct(pointer __p) 1746232924Stheraven { 1747232924Stheraven ::new((void*)__p) _Tp(); 1748232924Stheraven } 1749232924Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 1750234959Stheraven 1751232924Stheraven template <class _A0> 1752232924Stheraven _LIBCPP_INLINE_VISIBILITY 1753234959Stheraven void 1754232924Stheraven construct(pointer __p, _A0& __a0) 1755232924Stheraven { 1756232924Stheraven ::new((void*)__p) _Tp(__a0); 1757232924Stheraven } 1758232924Stheraven template <class _A0> 1759232924Stheraven _LIBCPP_INLINE_VISIBILITY 1760234959Stheraven void 1761232924Stheraven construct(pointer __p, const _A0& __a0) 1762232924Stheraven { 1763232924Stheraven ::new((void*)__p) _Tp(__a0); 1764232924Stheraven } 1765232924Stheraven# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 1766232924Stheraven template <class _A0, class _A1> 1767232924Stheraven _LIBCPP_INLINE_VISIBILITY 1768232924Stheraven void 1769232924Stheraven construct(pointer __p, _A0& __a0, _A1& __a1) 1770232924Stheraven { 1771232924Stheraven ::new((void*)__p) _Tp(__a0, __a1); 1772232924Stheraven } 1773232924Stheraven template <class _A0, class _A1> 1774232924Stheraven _LIBCPP_INLINE_VISIBILITY 1775232924Stheraven void 1776232924Stheraven construct(pointer __p, const _A0& __a0, _A1& __a1) 1777232924Stheraven { 1778232924Stheraven ::new((void*)__p) _Tp(__a0, __a1); 1779232924Stheraven } 1780232924Stheraven template <class _A0, class _A1> 1781232924Stheraven _LIBCPP_INLINE_VISIBILITY 1782232924Stheraven void 1783232924Stheraven construct(pointer __p, _A0& __a0, const _A1& __a1) 1784232924Stheraven { 1785232924Stheraven ::new((void*)__p) _Tp(__a0, __a1); 1786232924Stheraven } 1787232924Stheraven template <class _A0, class _A1> 1788232924Stheraven _LIBCPP_INLINE_VISIBILITY 1789232924Stheraven void 1790232924Stheraven construct(pointer __p, const _A0& __a0, const _A1& __a1) 1791232924Stheraven { 1792232924Stheraven ::new((void*)__p) _Tp(__a0, __a1); 1793232924Stheraven } 1794232924Stheraven#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1795232924Stheraven _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} 1796227825Stheraven}; 1797227825Stheraven 1798227825Stheraventemplate <class _Tp> 1799261272Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp> 1800227825Stheraven{ 1801227825Stheravenpublic: 1802227825Stheraven typedef size_t size_type; 1803227825Stheraven typedef ptrdiff_t difference_type; 1804232924Stheraven typedef const _Tp* pointer; 1805227825Stheraven typedef const _Tp* const_pointer; 1806232924Stheraven typedef const _Tp& reference; 1807227825Stheraven typedef const _Tp& const_reference; 1808253146Stheraven typedef const _Tp value_type; 1809227825Stheraven 1810227825Stheraven typedef true_type propagate_on_container_move_assignment; 1811288943Sdim typedef true_type is_always_equal; 1812227825Stheraven 1813227825Stheraven template <class _Up> struct rebind {typedef allocator<_Up> other;}; 1814227825Stheraven 1815227825Stheraven _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {} 1816227825Stheraven template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {} 1817227825Stheraven _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT 1818227825Stheraven {return _VSTD::addressof(__x);} 1819227825Stheraven _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) 1820276792Sdim {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} 1821227825Stheraven _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT 1822276792Sdim {_VSTD::__deallocate((void*)__p);} 1823227825Stheraven _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT 1824227825Stheraven {return size_type(~0) / sizeof(_Tp);} 1825227825Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1826227825Stheraven template <class _Up, class... _Args> 1827227825Stheraven _LIBCPP_INLINE_VISIBILITY 1828227825Stheraven void 1829227825Stheraven construct(_Up* __p, _Args&&... __args) 1830227825Stheraven { 1831227825Stheraven ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); 1832227825Stheraven } 1833227825Stheraven#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1834227825Stheraven _LIBCPP_INLINE_VISIBILITY 1835227825Stheraven void 1836227825Stheraven construct(pointer __p) 1837227825Stheraven { 1838227825Stheraven ::new((void*)__p) _Tp(); 1839227825Stheraven } 1840227825Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 1841234959Stheraven 1842227825Stheraven template <class _A0> 1843227825Stheraven _LIBCPP_INLINE_VISIBILITY 1844234959Stheraven void 1845227825Stheraven construct(pointer __p, _A0& __a0) 1846227825Stheraven { 1847227825Stheraven ::new((void*)__p) _Tp(__a0); 1848227825Stheraven } 1849227825Stheraven template <class _A0> 1850227825Stheraven _LIBCPP_INLINE_VISIBILITY 1851234959Stheraven void 1852227825Stheraven construct(pointer __p, const _A0& __a0) 1853227825Stheraven { 1854227825Stheraven ::new((void*)__p) _Tp(__a0); 1855227825Stheraven } 1856227825Stheraven# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 1857227825Stheraven template <class _A0, class _A1> 1858227825Stheraven _LIBCPP_INLINE_VISIBILITY 1859227825Stheraven void 1860227825Stheraven construct(pointer __p, _A0& __a0, _A1& __a1) 1861227825Stheraven { 1862227825Stheraven ::new((void*)__p) _Tp(__a0, __a1); 1863227825Stheraven } 1864227825Stheraven template <class _A0, class _A1> 1865227825Stheraven _LIBCPP_INLINE_VISIBILITY 1866227825Stheraven void 1867227825Stheraven construct(pointer __p, const _A0& __a0, _A1& __a1) 1868227825Stheraven { 1869227825Stheraven ::new((void*)__p) _Tp(__a0, __a1); 1870227825Stheraven } 1871227825Stheraven template <class _A0, class _A1> 1872227825Stheraven _LIBCPP_INLINE_VISIBILITY 1873227825Stheraven void 1874227825Stheraven construct(pointer __p, _A0& __a0, const _A1& __a1) 1875227825Stheraven { 1876227825Stheraven ::new((void*)__p) _Tp(__a0, __a1); 1877227825Stheraven } 1878227825Stheraven template <class _A0, class _A1> 1879227825Stheraven _LIBCPP_INLINE_VISIBILITY 1880227825Stheraven void 1881227825Stheraven construct(pointer __p, const _A0& __a0, const _A1& __a1) 1882227825Stheraven { 1883227825Stheraven ::new((void*)__p) _Tp(__a0, __a1); 1884227825Stheraven } 1885227825Stheraven#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) 1886227825Stheraven _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} 1887227825Stheraven}; 1888227825Stheraven 1889227825Stheraventemplate <class _Tp, class _Up> 1890227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1891227825Stheravenbool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} 1892227825Stheraven 1893227825Stheraventemplate <class _Tp, class _Up> 1894227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1895227825Stheravenbool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} 1896227825Stheraven 1897227825Stheraventemplate <class _OutputIterator, class _Tp> 1898261272Sdimclass _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator 1899227825Stheraven : public iterator<output_iterator_tag, 1900227825Stheraven _Tp, // purposefully not C++03 1901227825Stheraven ptrdiff_t, // purposefully not C++03 1902227825Stheraven _Tp*, // purposefully not C++03 1903227825Stheraven raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 1904227825Stheraven{ 1905227825Stheravenprivate: 1906227825Stheraven _OutputIterator __x_; 1907227825Stheravenpublic: 1908227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} 1909227825Stheraven _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} 1910227825Stheraven _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) 1911227825Stheraven {::new(&*__x_) _Tp(__element); return *this;} 1912300770Sdim#if _LIBCPP_STD_VER >= 14 1913300770Sdim _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) 1914300770Sdim {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;} 1915300770Sdim#endif 1916227825Stheraven _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} 1917227825Stheraven _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) 1918227825Stheraven {raw_storage_iterator __t(*this); ++__x_; return __t;} 1919288943Sdim#if _LIBCPP_STD_VER >= 14 1920288943Sdim _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } 1921288943Sdim#endif 1922227825Stheraven}; 1923227825Stheraven 1924227825Stheraventemplate <class _Tp> 1925227825Stheravenpair<_Tp*, ptrdiff_t> 1926227825Stheravenget_temporary_buffer(ptrdiff_t __n) _NOEXCEPT 1927227825Stheraven{ 1928227825Stheraven pair<_Tp*, ptrdiff_t> __r(0, 0); 1929227825Stheraven const ptrdiff_t __m = (~ptrdiff_t(0) ^ 1930227825Stheraven ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) 1931227825Stheraven / sizeof(_Tp); 1932227825Stheraven if (__n > __m) 1933227825Stheraven __n = __m; 1934227825Stheraven while (__n > 0) 1935227825Stheraven { 1936227825Stheraven __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); 1937227825Stheraven if (__r.first) 1938227825Stheraven { 1939227825Stheraven __r.second = __n; 1940227825Stheraven break; 1941227825Stheraven } 1942227825Stheraven __n /= 2; 1943227825Stheraven } 1944227825Stheraven return __r; 1945227825Stheraven} 1946227825Stheraven 1947227825Stheraventemplate <class _Tp> 1948227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1949227825Stheravenvoid return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);} 1950227825Stheraven 1951227825Stheraventemplate <class _Tp> 1952227825Stheravenstruct auto_ptr_ref 1953227825Stheraven{ 1954227825Stheraven _Tp* __ptr_; 1955227825Stheraven}; 1956227825Stheraven 1957227825Stheraventemplate<class _Tp> 1958261272Sdimclass _LIBCPP_TYPE_VIS_ONLY auto_ptr 1959227825Stheraven{ 1960227825Stheravenprivate: 1961227825Stheraven _Tp* __ptr_; 1962227825Stheravenpublic: 1963227825Stheraven typedef _Tp element_type; 1964227825Stheraven 1965227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {} 1966227825Stheraven _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {} 1967227825Stheraven template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw() 1968227825Stheraven : __ptr_(__p.release()) {} 1969227825Stheraven _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw() 1970227825Stheraven {reset(__p.release()); return *this;} 1971227825Stheraven template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw() 1972227825Stheraven {reset(__p.release()); return *this;} 1973227825Stheraven _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw() 1974227825Stheraven {reset(__p.__ptr_); return *this;} 1975227825Stheraven _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;} 1976227825Stheraven 1977227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw() 1978227825Stheraven {return *__ptr_;} 1979227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;} 1980227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;} 1981227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp* release() throw() 1982227825Stheraven { 1983227825Stheraven _Tp* __t = __ptr_; 1984227825Stheraven __ptr_ = 0; 1985227825Stheraven return __t; 1986227825Stheraven } 1987227825Stheraven _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw() 1988227825Stheraven { 1989227825Stheraven if (__ptr_ != __p) 1990227825Stheraven delete __ptr_; 1991227825Stheraven __ptr_ = __p; 1992227825Stheraven } 1993227825Stheraven 1994227825Stheraven _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {} 1995227825Stheraven template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw() 1996227825Stheraven {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} 1997227825Stheraven template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw() 1998227825Stheraven {return auto_ptr<_Up>(release());} 1999227825Stheraven}; 2000227825Stheraven 2001227825Stheraventemplate <> 2002261272Sdimclass _LIBCPP_TYPE_VIS_ONLY auto_ptr<void> 2003227825Stheraven{ 2004227825Stheravenpublic: 2005227825Stheraven typedef void element_type; 2006227825Stheraven}; 2007227825Stheraven 2008227825Stheraventemplate <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type, 2009227825Stheraven typename remove_cv<_T2>::type>::value, 2010232924Stheraven bool = is_empty<_T1>::value 2011288943Sdim && !__libcpp_is_final<_T1>::value, 2012232924Stheraven bool = is_empty<_T2>::value 2013288943Sdim && !__libcpp_is_final<_T2>::value 2014232924Stheraven > 2015227825Stheravenstruct __libcpp_compressed_pair_switch; 2016227825Stheraven 2017227825Stheraventemplate <class _T1, class _T2, bool IsSame> 2018227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};}; 2019227825Stheraven 2020227825Stheraventemplate <class _T1, class _T2, bool IsSame> 2021227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};}; 2022227825Stheraven 2023227825Stheraventemplate <class _T1, class _T2, bool IsSame> 2024227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};}; 2025227825Stheraven 2026227825Stheraventemplate <class _T1, class _T2> 2027227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};}; 2028227825Stheraven 2029227825Stheraventemplate <class _T1, class _T2> 2030227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};}; 2031227825Stheraven 2032227825Stheraventemplate <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value> 2033227825Stheravenclass __libcpp_compressed_pair_imp; 2034227825Stheraven 2035227825Stheraventemplate <class _T1, class _T2> 2036227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 0> 2037227825Stheraven{ 2038227825Stheravenprivate: 2039227825Stheraven _T1 __first_; 2040227825Stheraven _T2 __second_; 2041227825Stheravenpublic: 2042227825Stheraven typedef _T1 _T1_param; 2043227825Stheraven typedef _T2 _T2_param; 2044227825Stheraven 2045227825Stheraven typedef typename remove_reference<_T1>::type& _T1_reference; 2046227825Stheraven typedef typename remove_reference<_T2>::type& _T2_reference; 2047227825Stheraven 2048227825Stheraven typedef const typename remove_reference<_T1>::type& _T1_const_reference; 2049227825Stheraven typedef const typename remove_reference<_T2>::type& _T2_const_reference; 2050227825Stheraven 2051288943Sdim _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {} 2052232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) 2053288943Sdim : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {} 2054232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) 2055288943Sdim : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {} 2056227825Stheraven _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) 2057227825Stheraven : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {} 2058227825Stheraven 2059261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2060227825Stheraven 2061227825Stheraven _LIBCPP_INLINE_VISIBILITY 2062227825Stheraven __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) 2063227825Stheraven _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2064227825Stheraven is_nothrow_copy_constructible<_T2>::value) 2065227825Stheraven : __first_(__p.first()), 2066227825Stheraven __second_(__p.second()) {} 2067227825Stheraven 2068227825Stheraven _LIBCPP_INLINE_VISIBILITY 2069227825Stheraven __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) 2070227825Stheraven _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2071227825Stheraven is_nothrow_copy_assignable<_T2>::value) 2072227825Stheraven { 2073227825Stheraven __first_ = __p.first(); 2074227825Stheraven __second_ = __p.second(); 2075227825Stheraven return *this; 2076227825Stheraven } 2077227825Stheraven 2078227825Stheraven _LIBCPP_INLINE_VISIBILITY 2079227825Stheraven __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) 2080227825Stheraven _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2081227825Stheraven is_nothrow_move_constructible<_T2>::value) 2082227825Stheraven : __first_(_VSTD::forward<_T1>(__p.first())), 2083227825Stheraven __second_(_VSTD::forward<_T2>(__p.second())) {} 2084227825Stheraven 2085227825Stheraven _LIBCPP_INLINE_VISIBILITY 2086227825Stheraven __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) 2087227825Stheraven _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2088227825Stheraven is_nothrow_move_assignable<_T2>::value) 2089227825Stheraven { 2090227825Stheraven __first_ = _VSTD::forward<_T1>(__p.first()); 2091227825Stheraven __second_ = _VSTD::forward<_T2>(__p.second()); 2092227825Stheraven return *this; 2093227825Stheraven } 2094227825Stheraven 2095261272Sdim#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2096253146Stheraven 2097232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 2098232924Stheraven 2099232924Stheraven template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 2100232924Stheraven _LIBCPP_INLINE_VISIBILITY 2101232924Stheraven __libcpp_compressed_pair_imp(piecewise_construct_t __pc, 2102232924Stheraven tuple<_Args1...> __first_args, 2103232924Stheraven tuple<_Args2...> __second_args, 2104232924Stheraven __tuple_indices<_I1...>, 2105232924Stheraven __tuple_indices<_I2...>) 2106276792Sdim : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), 2107276792Sdim __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) 2108232924Stheraven {} 2109232924Stheraven 2110232924Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 2111232924Stheraven 2112227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} 2113227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} 2114227825Stheraven 2115227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} 2116227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} 2117227825Stheraven 2118227825Stheraven _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) 2119227825Stheraven _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2120276792Sdim __is_nothrow_swappable<_T2>::value) 2121227825Stheraven { 2122227825Stheraven using _VSTD::swap; 2123227825Stheraven swap(__first_, __x.__first_); 2124227825Stheraven swap(__second_, __x.__second_); 2125227825Stheraven } 2126227825Stheraven}; 2127227825Stheraven 2128227825Stheraventemplate <class _T1, class _T2> 2129227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 1> 2130227825Stheraven : private _T1 2131227825Stheraven{ 2132227825Stheravenprivate: 2133227825Stheraven _T2 __second_; 2134227825Stheravenpublic: 2135227825Stheraven typedef _T1 _T1_param; 2136227825Stheraven typedef _T2 _T2_param; 2137227825Stheraven 2138227825Stheraven typedef _T1& _T1_reference; 2139227825Stheraven typedef typename remove_reference<_T2>::type& _T2_reference; 2140227825Stheraven 2141227825Stheraven typedef const _T1& _T1_const_reference; 2142227825Stheraven typedef const typename remove_reference<_T2>::type& _T2_const_reference; 2143227825Stheraven 2144288943Sdim _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {} 2145232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) 2146288943Sdim : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {} 2147232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) 2148227825Stheraven : __second_(_VSTD::forward<_T2_param>(__t2)) {} 2149227825Stheraven _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) 2150227825Stheraven : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {} 2151227825Stheraven 2152261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2153227825Stheraven 2154227825Stheraven _LIBCPP_INLINE_VISIBILITY 2155227825Stheraven __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) 2156227825Stheraven _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2157227825Stheraven is_nothrow_copy_constructible<_T2>::value) 2158227825Stheraven : _T1(__p.first()), __second_(__p.second()) {} 2159227825Stheraven 2160227825Stheraven _LIBCPP_INLINE_VISIBILITY 2161227825Stheraven __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) 2162227825Stheraven _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2163227825Stheraven is_nothrow_copy_assignable<_T2>::value) 2164227825Stheraven { 2165227825Stheraven _T1::operator=(__p.first()); 2166227825Stheraven __second_ = __p.second(); 2167227825Stheraven return *this; 2168227825Stheraven } 2169227825Stheraven 2170227825Stheraven _LIBCPP_INLINE_VISIBILITY 2171227825Stheraven __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) 2172227825Stheraven _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2173227825Stheraven is_nothrow_move_constructible<_T2>::value) 2174227825Stheraven : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {} 2175227825Stheraven 2176227825Stheraven _LIBCPP_INLINE_VISIBILITY 2177227825Stheraven __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) 2178227825Stheraven _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2179227825Stheraven is_nothrow_move_assignable<_T2>::value) 2180227825Stheraven { 2181227825Stheraven _T1::operator=(_VSTD::move(__p.first())); 2182227825Stheraven __second_ = _VSTD::forward<_T2>(__p.second()); 2183227825Stheraven return *this; 2184227825Stheraven } 2185227825Stheraven 2186261272Sdim#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2187253146Stheraven 2188232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 2189232924Stheraven 2190232924Stheraven template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 2191232924Stheraven _LIBCPP_INLINE_VISIBILITY 2192232924Stheraven __libcpp_compressed_pair_imp(piecewise_construct_t __pc, 2193232924Stheraven tuple<_Args1...> __first_args, 2194232924Stheraven tuple<_Args2...> __second_args, 2195232924Stheraven __tuple_indices<_I1...>, 2196232924Stheraven __tuple_indices<_I2...>) 2197276792Sdim : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), 2198276792Sdim __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) 2199232924Stheraven {} 2200232924Stheraven 2201232924Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 2202232924Stheraven 2203227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} 2204227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} 2205227825Stheraven 2206227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} 2207227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} 2208227825Stheraven 2209227825Stheraven _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) 2210227825Stheraven _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2211276792Sdim __is_nothrow_swappable<_T2>::value) 2212227825Stheraven { 2213227825Stheraven using _VSTD::swap; 2214227825Stheraven swap(__second_, __x.__second_); 2215227825Stheraven } 2216227825Stheraven}; 2217227825Stheraven 2218227825Stheraventemplate <class _T1, class _T2> 2219227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 2> 2220227825Stheraven : private _T2 2221227825Stheraven{ 2222227825Stheravenprivate: 2223227825Stheraven _T1 __first_; 2224227825Stheravenpublic: 2225227825Stheraven typedef _T1 _T1_param; 2226227825Stheraven typedef _T2 _T2_param; 2227227825Stheraven 2228227825Stheraven typedef typename remove_reference<_T1>::type& _T1_reference; 2229227825Stheraven typedef _T2& _T2_reference; 2230227825Stheraven 2231227825Stheraven typedef const typename remove_reference<_T1>::type& _T1_const_reference; 2232227825Stheraven typedef const _T2& _T2_const_reference; 2233227825Stheraven 2234288943Sdim _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {} 2235227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) 2236227825Stheraven : __first_(_VSTD::forward<_T1_param>(__t1)) {} 2237227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) 2238288943Sdim : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {} 2239227825Stheraven _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) 2240227825Stheraven _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2241227825Stheraven is_nothrow_move_constructible<_T2>::value) 2242227825Stheraven : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {} 2243227825Stheraven 2244261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2245227825Stheraven 2246227825Stheraven _LIBCPP_INLINE_VISIBILITY 2247227825Stheraven __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) 2248227825Stheraven _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2249227825Stheraven is_nothrow_copy_constructible<_T2>::value) 2250227825Stheraven : _T2(__p.second()), __first_(__p.first()) {} 2251227825Stheraven 2252227825Stheraven _LIBCPP_INLINE_VISIBILITY 2253227825Stheraven __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) 2254227825Stheraven _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2255227825Stheraven is_nothrow_copy_assignable<_T2>::value) 2256227825Stheraven { 2257227825Stheraven _T2::operator=(__p.second()); 2258227825Stheraven __first_ = __p.first(); 2259227825Stheraven return *this; 2260227825Stheraven } 2261227825Stheraven 2262227825Stheraven _LIBCPP_INLINE_VISIBILITY 2263227825Stheraven __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) 2264227825Stheraven _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2265227825Stheraven is_nothrow_move_constructible<_T2>::value) 2266227825Stheraven : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {} 2267227825Stheraven 2268227825Stheraven _LIBCPP_INLINE_VISIBILITY 2269227825Stheraven __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) 2270227825Stheraven _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2271227825Stheraven is_nothrow_move_assignable<_T2>::value) 2272227825Stheraven { 2273227825Stheraven _T2::operator=(_VSTD::forward<_T2>(__p.second())); 2274227825Stheraven __first_ = _VSTD::move(__p.first()); 2275227825Stheraven return *this; 2276227825Stheraven } 2277227825Stheraven 2278261272Sdim#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2279253146Stheraven 2280232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 2281232924Stheraven 2282232924Stheraven template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 2283232924Stheraven _LIBCPP_INLINE_VISIBILITY 2284232924Stheraven __libcpp_compressed_pair_imp(piecewise_construct_t __pc, 2285232924Stheraven tuple<_Args1...> __first_args, 2286232924Stheraven tuple<_Args2...> __second_args, 2287232924Stheraven __tuple_indices<_I1...>, 2288232924Stheraven __tuple_indices<_I2...>) 2289276792Sdim : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...), 2290276792Sdim __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...) 2291232924Stheraven 2292232924Stheraven {} 2293232924Stheraven 2294232924Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 2295232924Stheraven 2296227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} 2297227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} 2298227825Stheraven 2299227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} 2300227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} 2301227825Stheraven 2302227825Stheraven _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) 2303227825Stheraven _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2304276792Sdim __is_nothrow_swappable<_T2>::value) 2305227825Stheraven { 2306227825Stheraven using _VSTD::swap; 2307227825Stheraven swap(__first_, __x.__first_); 2308227825Stheraven } 2309227825Stheraven}; 2310227825Stheraven 2311227825Stheraventemplate <class _T1, class _T2> 2312227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 3> 2313227825Stheraven : private _T1, 2314227825Stheraven private _T2 2315227825Stheraven{ 2316227825Stheravenpublic: 2317227825Stheraven typedef _T1 _T1_param; 2318227825Stheraven typedef _T2 _T2_param; 2319227825Stheraven 2320227825Stheraven typedef _T1& _T1_reference; 2321227825Stheraven typedef _T2& _T2_reference; 2322227825Stheraven 2323227825Stheraven typedef const _T1& _T1_const_reference; 2324227825Stheraven typedef const _T2& _T2_const_reference; 2325227825Stheraven 2326227825Stheraven _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} 2327227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) 2328227825Stheraven : _T1(_VSTD::forward<_T1_param>(__t1)) {} 2329227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) 2330227825Stheraven : _T2(_VSTD::forward<_T2_param>(__t2)) {} 2331227825Stheraven _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) 2332227825Stheraven : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {} 2333227825Stheraven 2334261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2335227825Stheraven 2336227825Stheraven _LIBCPP_INLINE_VISIBILITY 2337227825Stheraven __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) 2338227825Stheraven _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2339227825Stheraven is_nothrow_copy_constructible<_T2>::value) 2340227825Stheraven : _T1(__p.first()), _T2(__p.second()) {} 2341227825Stheraven 2342227825Stheraven _LIBCPP_INLINE_VISIBILITY 2343227825Stheraven __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) 2344227825Stheraven _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2345227825Stheraven is_nothrow_copy_assignable<_T2>::value) 2346227825Stheraven { 2347227825Stheraven _T1::operator=(__p.first()); 2348227825Stheraven _T2::operator=(__p.second()); 2349227825Stheraven return *this; 2350227825Stheraven } 2351227825Stheraven 2352227825Stheraven _LIBCPP_INLINE_VISIBILITY 2353227825Stheraven __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) 2354227825Stheraven _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2355227825Stheraven is_nothrow_move_constructible<_T2>::value) 2356227825Stheraven : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {} 2357227825Stheraven 2358227825Stheraven _LIBCPP_INLINE_VISIBILITY 2359227825Stheraven __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) 2360227825Stheraven _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2361227825Stheraven is_nothrow_move_assignable<_T2>::value) 2362227825Stheraven { 2363227825Stheraven _T1::operator=(_VSTD::move(__p.first())); 2364227825Stheraven _T2::operator=(_VSTD::move(__p.second())); 2365227825Stheraven return *this; 2366227825Stheraven } 2367227825Stheraven 2368261272Sdim#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2369253146Stheraven 2370232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 2371232924Stheraven 2372232924Stheraven template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 2373232924Stheraven _LIBCPP_INLINE_VISIBILITY 2374232924Stheraven __libcpp_compressed_pair_imp(piecewise_construct_t __pc, 2375232924Stheraven tuple<_Args1...> __first_args, 2376232924Stheraven tuple<_Args2...> __second_args, 2377232924Stheraven __tuple_indices<_I1...>, 2378232924Stheraven __tuple_indices<_I2...>) 2379276792Sdim : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), 2380276792Sdim _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) 2381232924Stheraven {} 2382232924Stheraven 2383232924Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 2384232924Stheraven 2385227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} 2386227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} 2387227825Stheraven 2388227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} 2389227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} 2390227825Stheraven 2391232924Stheraven _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&) 2392227825Stheraven _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2393276792Sdim __is_nothrow_swappable<_T2>::value) 2394227825Stheraven { 2395227825Stheraven } 2396227825Stheraven}; 2397227825Stheraven 2398227825Stheraventemplate <class _T1, class _T2> 2399227825Stheravenclass __compressed_pair 2400227825Stheraven : private __libcpp_compressed_pair_imp<_T1, _T2> 2401227825Stheraven{ 2402227825Stheraven typedef __libcpp_compressed_pair_imp<_T1, _T2> base; 2403227825Stheravenpublic: 2404227825Stheraven typedef typename base::_T1_param _T1_param; 2405227825Stheraven typedef typename base::_T2_param _T2_param; 2406227825Stheraven 2407227825Stheraven typedef typename base::_T1_reference _T1_reference; 2408227825Stheraven typedef typename base::_T2_reference _T2_reference; 2409227825Stheraven 2410227825Stheraven typedef typename base::_T1_const_reference _T1_const_reference; 2411227825Stheraven typedef typename base::_T2_const_reference _T2_const_reference; 2412227825Stheraven 2413227825Stheraven _LIBCPP_INLINE_VISIBILITY __compressed_pair() {} 2414232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1) 2415227825Stheraven : base(_VSTD::forward<_T1_param>(__t1)) {} 2416232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2) 2417227825Stheraven : base(_VSTD::forward<_T2_param>(__t2)) {} 2418227825Stheraven _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2) 2419227825Stheraven : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {} 2420227825Stheraven 2421261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2422227825Stheraven 2423227825Stheraven _LIBCPP_INLINE_VISIBILITY 2424227825Stheraven __compressed_pair(const __compressed_pair& __p) 2425227825Stheraven _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && 2426227825Stheraven is_nothrow_copy_constructible<_T2>::value) 2427227825Stheraven : base(__p) {} 2428227825Stheraven 2429227825Stheraven _LIBCPP_INLINE_VISIBILITY 2430227825Stheraven __compressed_pair& operator=(const __compressed_pair& __p) 2431227825Stheraven _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && 2432227825Stheraven is_nothrow_copy_assignable<_T2>::value) 2433227825Stheraven { 2434227825Stheraven base::operator=(__p); 2435227825Stheraven return *this; 2436227825Stheraven } 2437227825Stheraven 2438227825Stheraven _LIBCPP_INLINE_VISIBILITY 2439227825Stheraven __compressed_pair(__compressed_pair&& __p) 2440227825Stheraven _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && 2441227825Stheraven is_nothrow_move_constructible<_T2>::value) 2442227825Stheraven : base(_VSTD::move(__p)) {} 2443227825Stheraven 2444227825Stheraven _LIBCPP_INLINE_VISIBILITY 2445227825Stheraven __compressed_pair& operator=(__compressed_pair&& __p) 2446227825Stheraven _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && 2447227825Stheraven is_nothrow_move_assignable<_T2>::value) 2448227825Stheraven { 2449227825Stheraven base::operator=(_VSTD::move(__p)); 2450227825Stheraven return *this; 2451227825Stheraven } 2452232924Stheraven 2453261272Sdim#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 2454253146Stheraven 2455232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 2456232924Stheraven 2457232924Stheraven template <class... _Args1, class... _Args2> 2458232924Stheraven _LIBCPP_INLINE_VISIBILITY 2459232924Stheraven __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, 2460232924Stheraven tuple<_Args2...> __second_args) 2461232924Stheraven : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args), 2462232924Stheraven typename __make_tuple_indices<sizeof...(_Args1)>::type(), 2463232924Stheraven typename __make_tuple_indices<sizeof...(_Args2) >::type()) 2464232924Stheraven {} 2465232924Stheraven 2466232924Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 2467232924Stheraven 2468227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();} 2469227825Stheraven _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();} 2470227825Stheraven 2471227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();} 2472227825Stheraven _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();} 2473227825Stheraven 2474227825Stheraven _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) 2475227825Stheraven _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2476276792Sdim __is_nothrow_swappable<_T2>::value) 2477227825Stheraven {base::swap(__x);} 2478227825Stheraven}; 2479227825Stheraven 2480227825Stheraventemplate <class _T1, class _T2> 2481227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 2482227825Stheravenvoid 2483227825Stheravenswap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) 2484227825Stheraven _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && 2485276792Sdim __is_nothrow_swappable<_T2>::value) 2486227825Stheraven {__x.swap(__y);} 2487227825Stheraven 2488232924Stheraven// __same_or_less_cv_qualified 2489232924Stheraven 2490232924Stheraventemplate <class _Ptr1, class _Ptr2, 2491232924Stheraven bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type, 2492232924Stheraven typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type 2493232924Stheraven >::value 2494232924Stheraven > 2495232924Stheravenstruct __same_or_less_cv_qualified_imp 2496232924Stheraven : is_convertible<_Ptr1, _Ptr2> {}; 2497232924Stheraven 2498232924Stheraventemplate <class _Ptr1, class _Ptr2> 2499232924Stheravenstruct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false> 2500232924Stheraven : false_type {}; 2501232924Stheraven 2502276792Sdimtemplate <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value || 2503276792Sdim is_same<_Ptr1, _Ptr2>::value || 2504276792Sdim __has_element_type<_Ptr1>::value> 2505232924Stheravenstruct __same_or_less_cv_qualified 2506232924Stheraven : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {}; 2507232924Stheraven 2508232924Stheraventemplate <class _Ptr1, class _Ptr2> 2509276792Sdimstruct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false> 2510232924Stheraven : false_type {}; 2511232924Stheraven 2512232924Stheraven// default_delete 2513232924Stheraven 2514227825Stheraventemplate <class _Tp> 2515261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY default_delete 2516227825Stheraven{ 2517241900Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2518241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default; 2519241900Sdim#else 2520241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {} 2521241900Sdim#endif 2522227825Stheraven template <class _Up> 2523227825Stheraven _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&, 2524227825Stheraven typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} 2525227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT 2526227825Stheraven { 2527227825Stheraven static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); 2528249989Sdim static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type"); 2529227825Stheraven delete __ptr; 2530227825Stheraven } 2531227825Stheraven}; 2532227825Stheraven 2533227825Stheraventemplate <class _Tp> 2534261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]> 2535227825Stheraven{ 2536232924Stheravenpublic: 2537241900Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2538241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default; 2539241900Sdim#else 2540241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {} 2541241900Sdim#endif 2542232924Stheraven template <class _Up> 2543232924Stheraven _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&, 2544232924Stheraven typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} 2545232924Stheraven template <class _Up> 2546232924Stheraven _LIBCPP_INLINE_VISIBILITY 2547232924Stheraven void operator() (_Up* __ptr, 2548232924Stheraven typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT 2549227825Stheraven { 2550227825Stheraven static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); 2551249989Sdim static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type"); 2552227825Stheraven delete [] __ptr; 2553227825Stheraven } 2554227825Stheraven}; 2555227825Stheraven 2556227825Stheraventemplate <class _Tp, class _Dp = default_delete<_Tp> > 2557261272Sdimclass _LIBCPP_TYPE_VIS_ONLY unique_ptr 2558227825Stheraven{ 2559227825Stheravenpublic: 2560227825Stheraven typedef _Tp element_type; 2561227825Stheraven typedef _Dp deleter_type; 2562227825Stheraven typedef typename __pointer_type<_Tp, deleter_type>::type pointer; 2563227825Stheravenprivate: 2564227825Stheraven __compressed_pair<pointer, deleter_type> __ptr_; 2565227825Stheraven 2566232924Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2567227825Stheraven unique_ptr(unique_ptr&); 2568227825Stheraven template <class _Up, class _Ep> 2569227825Stheraven unique_ptr(unique_ptr<_Up, _Ep>&); 2570227825Stheraven unique_ptr& operator=(unique_ptr&); 2571227825Stheraven template <class _Up, class _Ep> 2572227825Stheraven unique_ptr& operator=(unique_ptr<_Up, _Ep>&); 2573227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2574227825Stheraven 2575227825Stheraven struct __nat {int __for_bool_;}; 2576227825Stheraven 2577227825Stheraven typedef typename remove_reference<deleter_type>::type& _Dp_reference; 2578227825Stheraven typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; 2579227825Stheravenpublic: 2580241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT 2581227825Stheraven : __ptr_(pointer()) 2582227825Stheraven { 2583227825Stheraven static_assert(!is_pointer<deleter_type>::value, 2584227825Stheraven "unique_ptr constructed with null function pointer deleter"); 2585227825Stheraven } 2586241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT 2587227825Stheraven : __ptr_(pointer()) 2588227825Stheraven { 2589227825Stheraven static_assert(!is_pointer<deleter_type>::value, 2590227825Stheraven "unique_ptr constructed with null function pointer deleter"); 2591227825Stheraven } 2592227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT 2593227825Stheraven : __ptr_(_VSTD::move(__p)) 2594227825Stheraven { 2595227825Stheraven static_assert(!is_pointer<deleter_type>::value, 2596227825Stheraven "unique_ptr constructed with null function pointer deleter"); 2597227825Stheraven } 2598227825Stheraven 2599227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2600227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional< 2601227825Stheraven is_reference<deleter_type>::value, 2602227825Stheraven deleter_type, 2603227825Stheraven typename add_lvalue_reference<const deleter_type>::type>::type __d) 2604227825Stheraven _NOEXCEPT 2605227825Stheraven : __ptr_(__p, __d) {} 2606227825Stheraven 2607227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d) 2608227825Stheraven _NOEXCEPT 2609227825Stheraven : __ptr_(__p, _VSTD::move(__d)) 2610227825Stheraven { 2611227825Stheraven static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); 2612227825Stheraven } 2613227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT 2614227825Stheraven : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} 2615227825Stheraven template <class _Up, class _Ep> 2616227825Stheraven _LIBCPP_INLINE_VISIBILITY 2617227825Stheraven unique_ptr(unique_ptr<_Up, _Ep>&& __u, 2618227825Stheraven typename enable_if 2619227825Stheraven < 2620227825Stheraven !is_array<_Up>::value && 2621227825Stheraven is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && 2622227825Stheraven is_convertible<_Ep, deleter_type>::value && 2623227825Stheraven ( 2624227825Stheraven !is_reference<deleter_type>::value || 2625227825Stheraven is_same<deleter_type, _Ep>::value 2626227825Stheraven ), 2627227825Stheraven __nat 2628227825Stheraven >::type = __nat()) _NOEXCEPT 2629227825Stheraven : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} 2630227825Stheraven 2631227825Stheraven template <class _Up> 2632227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p, 2633227825Stheraven typename enable_if< 2634227825Stheraven is_convertible<_Up*, _Tp*>::value && 2635227825Stheraven is_same<_Dp, default_delete<_Tp> >::value, 2636227825Stheraven __nat 2637227825Stheraven >::type = __nat()) _NOEXCEPT 2638227825Stheraven : __ptr_(__p.release()) 2639227825Stheraven { 2640227825Stheraven } 2641227825Stheraven 2642227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT 2643227825Stheraven { 2644227825Stheraven reset(__u.release()); 2645227825Stheraven __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); 2646227825Stheraven return *this; 2647227825Stheraven } 2648227825Stheraven 2649227825Stheraven template <class _Up, class _Ep> 2650227825Stheraven _LIBCPP_INLINE_VISIBILITY 2651227825Stheraven typename enable_if 2652227825Stheraven < 2653232924Stheraven !is_array<_Up>::value && 2654232924Stheraven is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && 2655232924Stheraven is_assignable<deleter_type&, _Ep&&>::value, 2656227825Stheraven unique_ptr& 2657227825Stheraven >::type 2658227825Stheraven operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT 2659227825Stheraven { 2660227825Stheraven reset(__u.release()); 2661227825Stheraven __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); 2662227825Stheraven return *this; 2663227825Stheraven } 2664227825Stheraven#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2665227825Stheraven 2666227825Stheraven _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() 2667227825Stheraven { 2668227825Stheraven return __rv<unique_ptr>(*this); 2669227825Stheraven } 2670227825Stheraven 2671227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) 2672227825Stheraven : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {} 2673227825Stheraven 2674227825Stheraven template <class _Up, class _Ep> 2675300770Sdim _LIBCPP_INLINE_VISIBILITY 2676300770Sdim typename enable_if< 2677300770Sdim !is_array<_Up>::value && 2678300770Sdim is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && 2679300770Sdim is_assignable<deleter_type&, _Ep&>::value, 2680300770Sdim unique_ptr& 2681300770Sdim >::type 2682300770Sdim operator=(unique_ptr<_Up, _Ep> __u) 2683227825Stheraven { 2684227825Stheraven reset(__u.release()); 2685300770Sdim __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); 2686227825Stheraven return *this; 2687227825Stheraven } 2688227825Stheraven 2689227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) 2690227825Stheraven : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {} 2691227825Stheraven 2692227825Stheraven template <class _Up> 2693227825Stheraven _LIBCPP_INLINE_VISIBILITY 2694227825Stheraven typename enable_if< 2695227825Stheraven is_convertible<_Up*, _Tp*>::value && 2696227825Stheraven is_same<_Dp, default_delete<_Tp> >::value, 2697227825Stheraven unique_ptr& 2698227825Stheraven >::type 2699227825Stheraven operator=(auto_ptr<_Up> __p) 2700227825Stheraven {reset(__p.release()); return *this;} 2701227825Stheraven 2702227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2703227825Stheraven _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} 2704227825Stheraven 2705227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT 2706227825Stheraven { 2707227825Stheraven reset(); 2708227825Stheraven return *this; 2709227825Stheraven } 2710227825Stheraven 2711227825Stheraven _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const 2712227825Stheraven {return *__ptr_.first();} 2713227825Stheraven _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();} 2714227825Stheraven _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} 2715227825Stheraven _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT 2716227825Stheraven {return __ptr_.second();} 2717227825Stheraven _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT 2718227825Stheraven {return __ptr_.second();} 2719232924Stheraven _LIBCPP_INLINE_VISIBILITY 2720232924Stheraven _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT 2721232924Stheraven {return __ptr_.first() != nullptr;} 2722227825Stheraven 2723227825Stheraven _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT 2724227825Stheraven { 2725227825Stheraven pointer __t = __ptr_.first(); 2726227825Stheraven __ptr_.first() = pointer(); 2727227825Stheraven return __t; 2728227825Stheraven } 2729227825Stheraven 2730227825Stheraven _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT 2731227825Stheraven { 2732227825Stheraven pointer __tmp = __ptr_.first(); 2733227825Stheraven __ptr_.first() = __p; 2734227825Stheraven if (__tmp) 2735227825Stheraven __ptr_.second()(__tmp); 2736227825Stheraven } 2737227825Stheraven 2738227825Stheraven _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT 2739227825Stheraven {__ptr_.swap(__u.__ptr_);} 2740227825Stheraven}; 2741227825Stheraven 2742227825Stheraventemplate <class _Tp, class _Dp> 2743261272Sdimclass _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp> 2744227825Stheraven{ 2745227825Stheravenpublic: 2746227825Stheraven typedef _Tp element_type; 2747227825Stheraven typedef _Dp deleter_type; 2748227825Stheraven typedef typename __pointer_type<_Tp, deleter_type>::type pointer; 2749227825Stheravenprivate: 2750227825Stheraven __compressed_pair<pointer, deleter_type> __ptr_; 2751227825Stheraven 2752232924Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2753227825Stheraven unique_ptr(unique_ptr&); 2754227825Stheraven template <class _Up> 2755227825Stheraven unique_ptr(unique_ptr<_Up>&); 2756227825Stheraven unique_ptr& operator=(unique_ptr&); 2757227825Stheraven template <class _Up> 2758227825Stheraven unique_ptr& operator=(unique_ptr<_Up>&); 2759227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2760227825Stheraven 2761227825Stheraven struct __nat {int __for_bool_;}; 2762227825Stheraven 2763227825Stheraven typedef typename remove_reference<deleter_type>::type& _Dp_reference; 2764227825Stheraven typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; 2765227825Stheravenpublic: 2766241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT 2767227825Stheraven : __ptr_(pointer()) 2768227825Stheraven { 2769227825Stheraven static_assert(!is_pointer<deleter_type>::value, 2770227825Stheraven "unique_ptr constructed with null function pointer deleter"); 2771227825Stheraven } 2772241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT 2773227825Stheraven : __ptr_(pointer()) 2774227825Stheraven { 2775227825Stheraven static_assert(!is_pointer<deleter_type>::value, 2776227825Stheraven "unique_ptr constructed with null function pointer deleter"); 2777227825Stheraven } 2778227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2779276792Sdim template <class _Pp> 2780276792Sdim _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p, 2781276792Sdim typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT 2782227825Stheraven : __ptr_(__p) 2783227825Stheraven { 2784227825Stheraven static_assert(!is_pointer<deleter_type>::value, 2785227825Stheraven "unique_ptr constructed with null function pointer deleter"); 2786227825Stheraven } 2787227825Stheraven 2788276792Sdim template <class _Pp> 2789232924Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional< 2790227825Stheraven is_reference<deleter_type>::value, 2791227825Stheraven deleter_type, 2792276792Sdim typename add_lvalue_reference<const deleter_type>::type>::type __d, 2793276792Sdim typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) 2794227825Stheraven _NOEXCEPT 2795227825Stheraven : __ptr_(__p, __d) {} 2796227825Stheraven 2797227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional< 2798227825Stheraven is_reference<deleter_type>::value, 2799227825Stheraven deleter_type, 2800227825Stheraven typename add_lvalue_reference<const deleter_type>::type>::type __d) 2801227825Stheraven _NOEXCEPT 2802227825Stheraven : __ptr_(pointer(), __d) {} 2803227825Stheraven 2804276792Sdim template <class _Pp> 2805276792Sdim _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, 2806276792Sdim typename remove_reference<deleter_type>::type&& __d, 2807276792Sdim typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) 2808227825Stheraven _NOEXCEPT 2809227825Stheraven : __ptr_(__p, _VSTD::move(__d)) 2810227825Stheraven { 2811227825Stheraven static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); 2812227825Stheraven } 2813227825Stheraven 2814227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d) 2815227825Stheraven _NOEXCEPT 2816227825Stheraven : __ptr_(pointer(), _VSTD::move(__d)) 2817227825Stheraven { 2818227825Stheraven static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); 2819227825Stheraven } 2820227825Stheraven 2821227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT 2822227825Stheraven : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} 2823227825Stheraven 2824227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT 2825227825Stheraven { 2826227825Stheraven reset(__u.release()); 2827227825Stheraven __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); 2828227825Stheraven return *this; 2829227825Stheraven } 2830232924Stheraven 2831232924Stheraven template <class _Up, class _Ep> 2832232924Stheraven _LIBCPP_INLINE_VISIBILITY 2833232924Stheraven unique_ptr(unique_ptr<_Up, _Ep>&& __u, 2834232924Stheraven typename enable_if 2835232924Stheraven < 2836232924Stheraven is_array<_Up>::value && 2837232924Stheraven __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value 2838232924Stheraven && is_convertible<_Ep, deleter_type>::value && 2839232924Stheraven ( 2840232924Stheraven !is_reference<deleter_type>::value || 2841232924Stheraven is_same<deleter_type, _Ep>::value 2842232924Stheraven ), 2843232924Stheraven __nat 2844232924Stheraven >::type = __nat() 2845232924Stheraven ) _NOEXCEPT 2846232924Stheraven : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} 2847232924Stheraven 2848232924Stheraven 2849232924Stheraven template <class _Up, class _Ep> 2850232924Stheraven _LIBCPP_INLINE_VISIBILITY 2851232924Stheraven typename enable_if 2852232924Stheraven < 2853232924Stheraven is_array<_Up>::value && 2854232924Stheraven __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && 2855232924Stheraven is_assignable<deleter_type&, _Ep&&>::value, 2856232924Stheraven unique_ptr& 2857232924Stheraven >::type 2858232924Stheraven operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT 2859232924Stheraven { 2860232924Stheraven reset(__u.release()); 2861232924Stheraven __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); 2862232924Stheraven return *this; 2863232924Stheraven } 2864227825Stheraven#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2865227825Stheraven 2866227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) 2867227825Stheraven : __ptr_(__p) 2868227825Stheraven { 2869227825Stheraven static_assert(!is_pointer<deleter_type>::value, 2870227825Stheraven "unique_ptr constructed with null function pointer deleter"); 2871227825Stheraven } 2872227825Stheraven 2873227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) 2874227825Stheraven : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {} 2875227825Stheraven 2876227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d) 2877227825Stheraven : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {} 2878227825Stheraven 2879227825Stheraven _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() 2880227825Stheraven { 2881227825Stheraven return __rv<unique_ptr>(*this); 2882227825Stheraven } 2883227825Stheraven 2884227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) 2885227825Stheraven : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {} 2886227825Stheraven 2887227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u) 2888227825Stheraven { 2889227825Stheraven reset(__u->release()); 2890227825Stheraven __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter()); 2891227825Stheraven return *this; 2892227825Stheraven } 2893227825Stheraven 2894227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2895227825Stheraven _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} 2896227825Stheraven 2897227825Stheraven _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT 2898227825Stheraven { 2899227825Stheraven reset(); 2900227825Stheraven return *this; 2901227825Stheraven } 2902227825Stheraven 2903227825Stheraven _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const 2904227825Stheraven {return __ptr_.first()[__i];} 2905227825Stheraven _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} 2906227825Stheraven _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT 2907227825Stheraven {return __ptr_.second();} 2908227825Stheraven _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT 2909227825Stheraven {return __ptr_.second();} 2910232924Stheraven _LIBCPP_INLINE_VISIBILITY 2911232924Stheraven _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT 2912232924Stheraven {return __ptr_.first() != nullptr;} 2913227825Stheraven 2914227825Stheraven _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT 2915227825Stheraven { 2916227825Stheraven pointer __t = __ptr_.first(); 2917227825Stheraven __ptr_.first() = pointer(); 2918227825Stheraven return __t; 2919227825Stheraven } 2920227825Stheraven 2921227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2922276792Sdim template <class _Pp> 2923276792Sdim _LIBCPP_INLINE_VISIBILITY 2924276792Sdim typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type 2925276792Sdim reset(_Pp __p) _NOEXCEPT 2926227825Stheraven { 2927227825Stheraven pointer __tmp = __ptr_.first(); 2928227825Stheraven __ptr_.first() = __p; 2929227825Stheraven if (__tmp) 2930227825Stheraven __ptr_.second()(__tmp); 2931227825Stheraven } 2932227825Stheraven _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT 2933227825Stheraven { 2934227825Stheraven pointer __tmp = __ptr_.first(); 2935227825Stheraven __ptr_.first() = nullptr; 2936227825Stheraven if (__tmp) 2937227825Stheraven __ptr_.second()(__tmp); 2938227825Stheraven } 2939227825Stheraven _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT 2940227825Stheraven { 2941227825Stheraven pointer __tmp = __ptr_.first(); 2942227825Stheraven __ptr_.first() = nullptr; 2943227825Stheraven if (__tmp) 2944227825Stheraven __ptr_.second()(__tmp); 2945227825Stheraven } 2946227825Stheraven#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2947227825Stheraven _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) 2948227825Stheraven { 2949227825Stheraven pointer __tmp = __ptr_.first(); 2950227825Stheraven __ptr_.first() = __p; 2951227825Stheraven if (__tmp) 2952227825Stheraven __ptr_.second()(__tmp); 2953227825Stheraven } 2954227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2955227825Stheraven 2956227825Stheraven _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);} 2957227825Stheravenprivate: 2958227825Stheraven 2959227825Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2960227825Stheraven template <class _Up> 2961227825Stheraven explicit unique_ptr(_Up); 2962227825Stheraven template <class _Up> 2963227825Stheraven unique_ptr(_Up __u, 2964227825Stheraven typename conditional< 2965227825Stheraven is_reference<deleter_type>::value, 2966227825Stheraven deleter_type, 2967227825Stheraven typename add_lvalue_reference<const deleter_type>::type>::type, 2968227825Stheraven typename enable_if 2969227825Stheraven < 2970227825Stheraven is_convertible<_Up, pointer>::value, 2971227825Stheraven __nat 2972227825Stheraven >::type = __nat()); 2973227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2974227825Stheraven}; 2975227825Stheraven 2976227825Stheraventemplate <class _Tp, class _Dp> 2977227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 2978227825Stheravenvoid 2979227825Stheravenswap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);} 2980227825Stheraven 2981227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2> 2982227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 2983227825Stheravenbool 2984227825Stheravenoperator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} 2985227825Stheraven 2986227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2> 2987227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 2988227825Stheravenbool 2989227825Stheravenoperator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} 2990227825Stheraven 2991227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2> 2992227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 2993227825Stheravenbool 2994232924Stheravenoperator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) 2995232924Stheraven{ 2996232924Stheraven typedef typename unique_ptr<_T1, _D1>::pointer _P1; 2997232924Stheraven typedef typename unique_ptr<_T2, _D2>::pointer _P2; 2998288943Sdim typedef typename common_type<_P1, _P2>::type _Vp; 2999288943Sdim return less<_Vp>()(__x.get(), __y.get()); 3000232924Stheraven} 3001227825Stheraven 3002227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2> 3003227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 3004227825Stheravenbool 3005227825Stheravenoperator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} 3006227825Stheraven 3007227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2> 3008227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 3009227825Stheravenbool 3010227825Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} 3011227825Stheraven 3012227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2> 3013227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 3014227825Stheravenbool 3015227825Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} 3016227825Stheraven 3017232924Stheraventemplate <class _T1, class _D1> 3018232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3019232924Stheravenbool 3020241900Sdimoperator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT 3021232924Stheraven{ 3022232924Stheraven return !__x; 3023232924Stheraven} 3024232924Stheraven 3025232924Stheraventemplate <class _T1, class _D1> 3026232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3027232924Stheravenbool 3028241900Sdimoperator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT 3029232924Stheraven{ 3030232924Stheraven return !__x; 3031232924Stheraven} 3032232924Stheraven 3033232924Stheraventemplate <class _T1, class _D1> 3034232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3035232924Stheravenbool 3036241900Sdimoperator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT 3037232924Stheraven{ 3038232924Stheraven return static_cast<bool>(__x); 3039232924Stheraven} 3040232924Stheraven 3041232924Stheraventemplate <class _T1, class _D1> 3042232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3043232924Stheravenbool 3044241900Sdimoperator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT 3045232924Stheraven{ 3046232924Stheraven return static_cast<bool>(__x); 3047232924Stheraven} 3048232924Stheraven 3049232924Stheraventemplate <class _T1, class _D1> 3050232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3051232924Stheravenbool 3052232924Stheravenoperator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) 3053232924Stheraven{ 3054232924Stheraven typedef typename unique_ptr<_T1, _D1>::pointer _P1; 3055232924Stheraven return less<_P1>()(__x.get(), nullptr); 3056232924Stheraven} 3057232924Stheraven 3058232924Stheraventemplate <class _T1, class _D1> 3059232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3060232924Stheravenbool 3061232924Stheravenoperator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) 3062232924Stheraven{ 3063232924Stheraven typedef typename unique_ptr<_T1, _D1>::pointer _P1; 3064232924Stheraven return less<_P1>()(nullptr, __x.get()); 3065232924Stheraven} 3066232924Stheraven 3067232924Stheraventemplate <class _T1, class _D1> 3068232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3069232924Stheravenbool 3070232924Stheravenoperator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) 3071232924Stheraven{ 3072232924Stheraven return nullptr < __x; 3073232924Stheraven} 3074232924Stheraven 3075232924Stheraventemplate <class _T1, class _D1> 3076232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3077232924Stheravenbool 3078232924Stheravenoperator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) 3079232924Stheraven{ 3080232924Stheraven return __x < nullptr; 3081232924Stheraven} 3082232924Stheraven 3083232924Stheraventemplate <class _T1, class _D1> 3084232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3085232924Stheravenbool 3086232924Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) 3087232924Stheraven{ 3088232924Stheraven return !(nullptr < __x); 3089232924Stheraven} 3090232924Stheraven 3091232924Stheraventemplate <class _T1, class _D1> 3092232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3093232924Stheravenbool 3094232924Stheravenoperator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) 3095232924Stheraven{ 3096232924Stheraven return !(__x < nullptr); 3097232924Stheraven} 3098232924Stheraven 3099232924Stheraventemplate <class _T1, class _D1> 3100232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3101232924Stheravenbool 3102232924Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) 3103232924Stheraven{ 3104232924Stheraven return !(__x < nullptr); 3105232924Stheraven} 3106232924Stheraven 3107232924Stheraventemplate <class _T1, class _D1> 3108232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 3109232924Stheravenbool 3110232924Stheravenoperator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) 3111232924Stheraven{ 3112232924Stheraven return !(nullptr < __x); 3113232924Stheraven} 3114232924Stheraven 3115234959Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3116234959Stheraven 3117234959Stheraventemplate <class _Tp, class _Dp> 3118234959Stheraveninline _LIBCPP_INLINE_VISIBILITY 3119234959Stheravenunique_ptr<_Tp, _Dp> 3120234959Stheravenmove(unique_ptr<_Tp, _Dp>& __t) 3121234959Stheraven{ 3122234959Stheraven return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t)); 3123234959Stheraven} 3124234959Stheraven 3125234959Stheraven#endif 3126234959Stheraven 3127253146Stheraven#if _LIBCPP_STD_VER > 11 3128253146Stheraven 3129253146Stheraventemplate<class _Tp> 3130253146Stheravenstruct __unique_if 3131253146Stheraven{ 3132253146Stheraven typedef unique_ptr<_Tp> __unique_single; 3133253146Stheraven}; 3134253146Stheraven 3135253146Stheraventemplate<class _Tp> 3136253146Stheravenstruct __unique_if<_Tp[]> 3137253146Stheraven{ 3138253146Stheraven typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; 3139253146Stheraven}; 3140253146Stheraven 3141253146Stheraventemplate<class _Tp, size_t _Np> 3142253146Stheravenstruct __unique_if<_Tp[_Np]> 3143253146Stheraven{ 3144253146Stheraven typedef void __unique_array_known_bound; 3145253146Stheraven}; 3146253146Stheraven 3147253146Stheraventemplate<class _Tp, class... _Args> 3148253146Stheraveninline _LIBCPP_INLINE_VISIBILITY 3149253146Stheraventypename __unique_if<_Tp>::__unique_single 3150253146Stheravenmake_unique(_Args&&... __args) 3151253146Stheraven{ 3152253146Stheraven return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); 3153253146Stheraven} 3154253146Stheraven 3155253146Stheraventemplate<class _Tp> 3156253146Stheraveninline _LIBCPP_INLINE_VISIBILITY 3157253146Stheraventypename __unique_if<_Tp>::__unique_array_unknown_bound 3158253146Stheravenmake_unique(size_t __n) 3159253146Stheraven{ 3160253146Stheraven typedef typename remove_extent<_Tp>::type _Up; 3161253146Stheraven return unique_ptr<_Tp>(new _Up[__n]()); 3162253146Stheraven} 3163253146Stheraven 3164253146Stheraventemplate<class _Tp, class... _Args> 3165253146Stheraven typename __unique_if<_Tp>::__unique_array_known_bound 3166253146Stheraven make_unique(_Args&&...) = delete; 3167253146Stheraven 3168253146Stheraven#endif // _LIBCPP_STD_VER > 11 3169253146Stheraven 3170227825Stheraventemplate <class _Tp> struct hash; 3171227825Stheraven 3172253146Stheraventemplate <class _Size> 3173253146Stheraveninline _LIBCPP_INLINE_VISIBILITY 3174253146Stheraven_Size 3175253146Stheraven__loadword(const void* __p) 3176253146Stheraven{ 3177253146Stheraven _Size __r; 3178253146Stheraven std::memcpy(&__r, __p, sizeof(__r)); 3179253146Stheraven return __r; 3180253146Stheraven} 3181253146Stheraven 3182232924Stheraven// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t 3183232924Stheraven// is 64 bits. This is because cityhash64 uses 64bit x 64bit 3184232924Stheraven// multiplication, which can be very slow on 32-bit systems. 3185232924Stheraventemplate <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__> 3186232924Stheravenstruct __murmur2_or_cityhash; 3187232924Stheraven 3188232924Stheraventemplate <class _Size> 3189232924Stheravenstruct __murmur2_or_cityhash<_Size, 32> 3190227825Stheraven{ 3191232924Stheraven _Size operator()(const void* __key, _Size __len); 3192232924Stheraven}; 3193232924Stheraven 3194232924Stheraven// murmur2 3195232924Stheraventemplate <class _Size> 3196232924Stheraven_Size 3197300770Sdim__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 3198232924Stheraven{ 3199232924Stheraven const _Size __m = 0x5bd1e995; 3200232924Stheraven const _Size __r = 24; 3201232924Stheraven _Size __h = __len; 3202232924Stheraven const unsigned char* __data = static_cast<const unsigned char*>(__key); 3203232924Stheraven for (; __len >= 4; __data += 4, __len -= 4) 3204232924Stheraven { 3205253146Stheraven _Size __k = __loadword<_Size>(__data); 3206232924Stheraven __k *= __m; 3207232924Stheraven __k ^= __k >> __r; 3208232924Stheraven __k *= __m; 3209232924Stheraven __h *= __m; 3210232924Stheraven __h ^= __k; 3211232924Stheraven } 3212232924Stheraven switch (__len) 3213232924Stheraven { 3214232924Stheraven case 3: 3215232924Stheraven __h ^= __data[2] << 16; 3216232924Stheraven case 2: 3217232924Stheraven __h ^= __data[1] << 8; 3218232924Stheraven case 1: 3219232924Stheraven __h ^= __data[0]; 3220232924Stheraven __h *= __m; 3221232924Stheraven } 3222232924Stheraven __h ^= __h >> 13; 3223232924Stheraven __h *= __m; 3224232924Stheraven __h ^= __h >> 15; 3225232924Stheraven return __h; 3226232924Stheraven} 3227232924Stheraven 3228232924Stheraventemplate <class _Size> 3229232924Stheravenstruct __murmur2_or_cityhash<_Size, 64> 3230232924Stheraven{ 3231232924Stheraven _Size operator()(const void* __key, _Size __len); 3232232924Stheraven 3233232924Stheraven private: 3234232924Stheraven // Some primes between 2^63 and 2^64. 3235232924Stheraven static const _Size __k0 = 0xc3a5c85c97cb3127ULL; 3236232924Stheraven static const _Size __k1 = 0xb492b66fbe98f273ULL; 3237232924Stheraven static const _Size __k2 = 0x9ae16a3b2f90404fULL; 3238232924Stheraven static const _Size __k3 = 0xc949d7c7509e6557ULL; 3239232924Stheraven 3240232924Stheraven static _Size __rotate(_Size __val, int __shift) { 3241232924Stheraven return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); 3242232924Stheraven } 3243232924Stheraven 3244232924Stheraven static _Size __rotate_by_at_least_1(_Size __val, int __shift) { 3245232924Stheraven return (__val >> __shift) | (__val << (64 - __shift)); 3246232924Stheraven } 3247232924Stheraven 3248232924Stheraven static _Size __shift_mix(_Size __val) { 3249232924Stheraven return __val ^ (__val >> 47); 3250232924Stheraven } 3251232924Stheraven 3252232924Stheraven static _Size __hash_len_16(_Size __u, _Size __v) { 3253232924Stheraven const _Size __mul = 0x9ddfea08eb382d69ULL; 3254232924Stheraven _Size __a = (__u ^ __v) * __mul; 3255232924Stheraven __a ^= (__a >> 47); 3256232924Stheraven _Size __b = (__v ^ __a) * __mul; 3257232924Stheraven __b ^= (__b >> 47); 3258232924Stheraven __b *= __mul; 3259232924Stheraven return __b; 3260232924Stheraven } 3261232924Stheraven 3262232924Stheraven static _Size __hash_len_0_to_16(const char* __s, _Size __len) { 3263232924Stheraven if (__len > 8) { 3264253146Stheraven const _Size __a = __loadword<_Size>(__s); 3265253146Stheraven const _Size __b = __loadword<_Size>(__s + __len - 8); 3266232924Stheraven return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; 3267232924Stheraven } 3268232924Stheraven if (__len >= 4) { 3269253146Stheraven const uint32_t __a = __loadword<uint32_t>(__s); 3270253146Stheraven const uint32_t __b = __loadword<uint32_t>(__s + __len - 4); 3271232924Stheraven return __hash_len_16(__len + (__a << 3), __b); 3272232924Stheraven } 3273232924Stheraven if (__len > 0) { 3274232924Stheraven const unsigned char __a = __s[0]; 3275232924Stheraven const unsigned char __b = __s[__len >> 1]; 3276232924Stheraven const unsigned char __c = __s[__len - 1]; 3277232924Stheraven const uint32_t __y = static_cast<uint32_t>(__a) + 3278232924Stheraven (static_cast<uint32_t>(__b) << 8); 3279232924Stheraven const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2); 3280232924Stheraven return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; 3281232924Stheraven } 3282232924Stheraven return __k2; 3283232924Stheraven } 3284232924Stheraven 3285232924Stheraven static _Size __hash_len_17_to_32(const char *__s, _Size __len) { 3286253146Stheraven const _Size __a = __loadword<_Size>(__s) * __k1; 3287253146Stheraven const _Size __b = __loadword<_Size>(__s + 8); 3288253146Stheraven const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2; 3289253146Stheraven const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0; 3290232924Stheraven return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d, 3291232924Stheraven __a + __rotate(__b ^ __k3, 20) - __c + __len); 3292232924Stheraven } 3293232924Stheraven 3294232924Stheraven // Return a 16-byte hash for 48 bytes. Quick and dirty. 3295232924Stheraven // Callers do best to use "random-looking" values for a and b. 3296232924Stheraven static pair<_Size, _Size> __weak_hash_len_32_with_seeds( 3297232924Stheraven _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) { 3298232924Stheraven __a += __w; 3299232924Stheraven __b = __rotate(__b + __a + __z, 21); 3300232924Stheraven const _Size __c = __a; 3301232924Stheraven __a += __x; 3302232924Stheraven __a += __y; 3303232924Stheraven __b += __rotate(__a, 44); 3304232924Stheraven return pair<_Size, _Size>(__a + __z, __b + __c); 3305232924Stheraven } 3306232924Stheraven 3307232924Stheraven // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. 3308232924Stheraven static pair<_Size, _Size> __weak_hash_len_32_with_seeds( 3309232924Stheraven const char* __s, _Size __a, _Size __b) { 3310253146Stheraven return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s), 3311253146Stheraven __loadword<_Size>(__s + 8), 3312253146Stheraven __loadword<_Size>(__s + 16), 3313253146Stheraven __loadword<_Size>(__s + 24), 3314232924Stheraven __a, 3315232924Stheraven __b); 3316232924Stheraven } 3317232924Stheraven 3318232924Stheraven // Return an 8-byte hash for 33 to 64 bytes. 3319232924Stheraven static _Size __hash_len_33_to_64(const char *__s, size_t __len) { 3320253146Stheraven _Size __z = __loadword<_Size>(__s + 24); 3321253146Stheraven _Size __a = __loadword<_Size>(__s) + 3322253146Stheraven (__len + __loadword<_Size>(__s + __len - 16)) * __k0; 3323232924Stheraven _Size __b = __rotate(__a + __z, 52); 3324232924Stheraven _Size __c = __rotate(__a, 37); 3325253146Stheraven __a += __loadword<_Size>(__s + 8); 3326232924Stheraven __c += __rotate(__a, 7); 3327253146Stheraven __a += __loadword<_Size>(__s + 16); 3328232924Stheraven _Size __vf = __a + __z; 3329232924Stheraven _Size __vs = __b + __rotate(__a, 31) + __c; 3330253146Stheraven __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32); 3331253146Stheraven __z += __loadword<_Size>(__s + __len - 8); 3332232924Stheraven __b = __rotate(__a + __z, 52); 3333232924Stheraven __c = __rotate(__a, 37); 3334253146Stheraven __a += __loadword<_Size>(__s + __len - 24); 3335232924Stheraven __c += __rotate(__a, 7); 3336253146Stheraven __a += __loadword<_Size>(__s + __len - 16); 3337232924Stheraven _Size __wf = __a + __z; 3338232924Stheraven _Size __ws = __b + __rotate(__a, 31) + __c; 3339232924Stheraven _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); 3340232924Stheraven return __shift_mix(__r * __k0 + __vs) * __k2; 3341232924Stheraven } 3342232924Stheraven}; 3343232924Stheraven 3344232924Stheraven// cityhash64 3345232924Stheraventemplate <class _Size> 3346232924Stheraven_Size 3347300770Sdim__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 3348232924Stheraven{ 3349232924Stheraven const char* __s = static_cast<const char*>(__key); 3350232924Stheraven if (__len <= 32) { 3351232924Stheraven if (__len <= 16) { 3352232924Stheraven return __hash_len_0_to_16(__s, __len); 3353232924Stheraven } else { 3354232924Stheraven return __hash_len_17_to_32(__s, __len); 3355232924Stheraven } 3356232924Stheraven } else if (__len <= 64) { 3357232924Stheraven return __hash_len_33_to_64(__s, __len); 3358232924Stheraven } 3359232924Stheraven 3360232924Stheraven // For strings over 64 bytes we hash the end first, and then as we 3361232924Stheraven // loop we keep 56 bytes of state: v, w, x, y, and z. 3362253146Stheraven _Size __x = __loadword<_Size>(__s + __len - 40); 3363253146Stheraven _Size __y = __loadword<_Size>(__s + __len - 16) + 3364253146Stheraven __loadword<_Size>(__s + __len - 56); 3365253146Stheraven _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len, 3366253146Stheraven __loadword<_Size>(__s + __len - 24)); 3367232924Stheraven pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); 3368232924Stheraven pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); 3369253146Stheraven __x = __x * __k1 + __loadword<_Size>(__s); 3370232924Stheraven 3371232924Stheraven // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. 3372232924Stheraven __len = (__len - 1) & ~static_cast<_Size>(63); 3373232924Stheraven do { 3374253146Stheraven __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1; 3375253146Stheraven __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; 3376232924Stheraven __x ^= __w.second; 3377253146Stheraven __y += __v.first + __loadword<_Size>(__s + 40); 3378232924Stheraven __z = __rotate(__z + __w.first, 33) * __k1; 3379232924Stheraven __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); 3380232924Stheraven __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, 3381253146Stheraven __y + __loadword<_Size>(__s + 16)); 3382232924Stheraven std::swap(__z, __x); 3383232924Stheraven __s += 64; 3384232924Stheraven __len -= 64; 3385232924Stheraven } while (__len != 0); 3386232924Stheraven return __hash_len_16( 3387232924Stheraven __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, 3388232924Stheraven __hash_len_16(__v.second, __w.second) + __x); 3389232924Stheraven} 3390232924Stheraven 3391232924Stheraventemplate <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)> 3392232924Stheravenstruct __scalar_hash; 3393232924Stheraven 3394232924Stheraventemplate <class _Tp> 3395232924Stheravenstruct __scalar_hash<_Tp, 0> 3396232924Stheraven : public unary_function<_Tp, size_t> 3397232924Stheraven{ 3398227825Stheraven _LIBCPP_INLINE_VISIBILITY 3399232924Stheraven size_t operator()(_Tp __v) const _NOEXCEPT 3400227825Stheraven { 3401232924Stheraven union 3402232924Stheraven { 3403232924Stheraven _Tp __t; 3404232924Stheraven size_t __a; 3405232924Stheraven } __u; 3406232924Stheraven __u.__a = 0; 3407232924Stheraven __u.__t = __v; 3408232924Stheraven return __u.__a; 3409227825Stheraven } 3410227825Stheraven}; 3411227825Stheraven 3412232924Stheraventemplate <class _Tp> 3413232924Stheravenstruct __scalar_hash<_Tp, 1> 3414232924Stheraven : public unary_function<_Tp, size_t> 3415232924Stheraven{ 3416232924Stheraven _LIBCPP_INLINE_VISIBILITY 3417232924Stheraven size_t operator()(_Tp __v) const _NOEXCEPT 3418232924Stheraven { 3419232924Stheraven union 3420232924Stheraven { 3421232924Stheraven _Tp __t; 3422232924Stheraven size_t __a; 3423232924Stheraven } __u; 3424232924Stheraven __u.__t = __v; 3425232924Stheraven return __u.__a; 3426232924Stheraven } 3427232924Stheraven}; 3428232924Stheraven 3429232924Stheraventemplate <class _Tp> 3430232924Stheravenstruct __scalar_hash<_Tp, 2> 3431232924Stheraven : public unary_function<_Tp, size_t> 3432232924Stheraven{ 3433232924Stheraven _LIBCPP_INLINE_VISIBILITY 3434232924Stheraven size_t operator()(_Tp __v) const _NOEXCEPT 3435232924Stheraven { 3436232924Stheraven union 3437232924Stheraven { 3438232924Stheraven _Tp __t; 3439232924Stheraven struct 3440232924Stheraven { 3441232924Stheraven size_t __a; 3442232924Stheraven size_t __b; 3443289082Sdim } __s; 3444232924Stheraven } __u; 3445232924Stheraven __u.__t = __v; 3446232924Stheraven return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 3447232924Stheraven } 3448232924Stheraven}; 3449232924Stheraven 3450232924Stheraventemplate <class _Tp> 3451232924Stheravenstruct __scalar_hash<_Tp, 3> 3452232924Stheraven : public unary_function<_Tp, size_t> 3453232924Stheraven{ 3454232924Stheraven _LIBCPP_INLINE_VISIBILITY 3455232924Stheraven size_t operator()(_Tp __v) const _NOEXCEPT 3456232924Stheraven { 3457232924Stheraven union 3458232924Stheraven { 3459232924Stheraven _Tp __t; 3460232924Stheraven struct 3461232924Stheraven { 3462232924Stheraven size_t __a; 3463232924Stheraven size_t __b; 3464232924Stheraven size_t __c; 3465289082Sdim } __s; 3466232924Stheraven } __u; 3467232924Stheraven __u.__t = __v; 3468232924Stheraven return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 3469232924Stheraven } 3470232924Stheraven}; 3471232924Stheraven 3472232924Stheraventemplate <class _Tp> 3473232924Stheravenstruct __scalar_hash<_Tp, 4> 3474232924Stheraven : public unary_function<_Tp, size_t> 3475232924Stheraven{ 3476232924Stheraven _LIBCPP_INLINE_VISIBILITY 3477232924Stheraven size_t operator()(_Tp __v) const _NOEXCEPT 3478232924Stheraven { 3479232924Stheraven union 3480232924Stheraven { 3481232924Stheraven _Tp __t; 3482232924Stheraven struct 3483232924Stheraven { 3484232924Stheraven size_t __a; 3485232924Stheraven size_t __b; 3486232924Stheraven size_t __c; 3487232924Stheraven size_t __d; 3488289082Sdim } __s; 3489232924Stheraven } __u; 3490232924Stheraven __u.__t = __v; 3491232924Stheraven return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 3492232924Stheraven } 3493232924Stheraven}; 3494232924Stheraven 3495232924Stheraventemplate<class _Tp> 3496261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*> 3497241900Sdim : public unary_function<_Tp*, size_t> 3498232924Stheraven{ 3499241900Sdim _LIBCPP_INLINE_VISIBILITY 3500241900Sdim size_t operator()(_Tp* __v) const _NOEXCEPT 3501241900Sdim { 3502241900Sdim union 3503241900Sdim { 3504241900Sdim _Tp* __t; 3505241900Sdim size_t __a; 3506241900Sdim } __u; 3507241900Sdim __u.__t = __v; 3508241900Sdim return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 3509241900Sdim } 3510232924Stheraven}; 3511232924Stheraven 3512227825Stheraventemplate <class _Tp, class _Dp> 3513261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> > 3514227825Stheraven{ 3515227825Stheraven typedef unique_ptr<_Tp, _Dp> argument_type; 3516227825Stheraven typedef size_t result_type; 3517227825Stheraven _LIBCPP_INLINE_VISIBILITY 3518227825Stheraven result_type operator()(const argument_type& __ptr) const _NOEXCEPT 3519227825Stheraven { 3520227825Stheraven typedef typename argument_type::pointer pointer; 3521227825Stheraven return hash<pointer>()(__ptr.get()); 3522227825Stheraven } 3523227825Stheraven}; 3524227825Stheraven 3525227825Stheravenstruct __destruct_n 3526227825Stheraven{ 3527227825Stheravenprivate: 3528227825Stheraven size_t size; 3529227825Stheraven 3530227825Stheraven template <class _Tp> 3531227825Stheraven _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT 3532227825Stheraven {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();} 3533227825Stheraven 3534227825Stheraven template <class _Tp> 3535227825Stheraven _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT 3536227825Stheraven {} 3537227825Stheraven 3538227825Stheraven _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT 3539227825Stheraven {++size;} 3540227825Stheraven _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT 3541227825Stheraven {} 3542227825Stheraven 3543227825Stheraven _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT 3544227825Stheraven {size = __s;} 3545227825Stheraven _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT 3546227825Stheraven {} 3547227825Stheravenpublic: 3548227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT 3549227825Stheraven : size(__s) {} 3550227825Stheraven 3551227825Stheraven template <class _Tp> 3552227825Stheraven _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT 3553227825Stheraven {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 3554227825Stheraven 3555227825Stheraven template <class _Tp> 3556227825Stheraven _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT 3557227825Stheraven {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 3558227825Stheraven 3559227825Stheraven template <class _Tp> 3560227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT 3561227825Stheraven {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 3562227825Stheraven}; 3563227825Stheraven 3564227825Stheraventemplate <class _Alloc> 3565227825Stheravenclass __allocator_destructor 3566227825Stheraven{ 3567227825Stheraven typedef allocator_traits<_Alloc> __alloc_traits; 3568227825Stheravenpublic: 3569227825Stheraven typedef typename __alloc_traits::pointer pointer; 3570227825Stheraven typedef typename __alloc_traits::size_type size_type; 3571227825Stheravenprivate: 3572227825Stheraven _Alloc& __alloc_; 3573227825Stheraven size_type __s_; 3574227825Stheravenpublic: 3575227825Stheraven _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) 3576227825Stheraven _NOEXCEPT 3577227825Stheraven : __alloc_(__a), __s_(__s) {} 3578227825Stheraven _LIBCPP_INLINE_VISIBILITY 3579227825Stheraven void operator()(pointer __p) _NOEXCEPT 3580227825Stheraven {__alloc_traits::deallocate(__alloc_, __p, __s_);} 3581227825Stheraven}; 3582227825Stheraven 3583227825Stheraventemplate <class _InputIterator, class _ForwardIterator> 3584227825Stheraven_ForwardIterator 3585227825Stheravenuninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) 3586227825Stheraven{ 3587227825Stheraven typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 3588232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 3589232924Stheraven _ForwardIterator __s = __r; 3590232924Stheraven try 3591232924Stheraven { 3592232924Stheraven#endif 3593288943Sdim for (; __f != __l; ++__f, (void) ++__r) 3594288943Sdim ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); 3595232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 3596232924Stheraven } 3597232924Stheraven catch (...) 3598232924Stheraven { 3599232924Stheraven for (; __s != __r; ++__s) 3600232924Stheraven __s->~value_type(); 3601232924Stheraven throw; 3602232924Stheraven } 3603232924Stheraven#endif 3604227825Stheraven return __r; 3605227825Stheraven} 3606227825Stheraven 3607227825Stheraventemplate <class _InputIterator, class _Size, class _ForwardIterator> 3608227825Stheraven_ForwardIterator 3609227825Stheravenuninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) 3610227825Stheraven{ 3611227825Stheraven typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 3612232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 3613232924Stheraven _ForwardIterator __s = __r; 3614232924Stheraven try 3615232924Stheraven { 3616232924Stheraven#endif 3617288943Sdim for (; __n > 0; ++__f, (void) ++__r, (void) --__n) 3618288943Sdim ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); 3619232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 3620232924Stheraven } 3621232924Stheraven catch (...) 3622232924Stheraven { 3623232924Stheraven for (; __s != __r; ++__s) 3624232924Stheraven __s->~value_type(); 3625232924Stheraven throw; 3626232924Stheraven } 3627232924Stheraven#endif 3628227825Stheraven return __r; 3629227825Stheraven} 3630227825Stheraven 3631227825Stheraventemplate <class _ForwardIterator, class _Tp> 3632227825Stheravenvoid 3633227825Stheravenuninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) 3634227825Stheraven{ 3635227825Stheraven typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 3636232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 3637232924Stheraven _ForwardIterator __s = __f; 3638232924Stheraven try 3639232924Stheraven { 3640232924Stheraven#endif 3641232924Stheraven for (; __f != __l; ++__f) 3642288943Sdim ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); 3643232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 3644232924Stheraven } 3645232924Stheraven catch (...) 3646232924Stheraven { 3647232924Stheraven for (; __s != __f; ++__s) 3648232924Stheraven __s->~value_type(); 3649232924Stheraven throw; 3650232924Stheraven } 3651232924Stheraven#endif 3652227825Stheraven} 3653227825Stheraven 3654227825Stheraventemplate <class _ForwardIterator, class _Size, class _Tp> 3655227825Stheraven_ForwardIterator 3656227825Stheravenuninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) 3657227825Stheraven{ 3658227825Stheraven typedef typename iterator_traits<_ForwardIterator>::value_type value_type; 3659232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 3660232924Stheraven _ForwardIterator __s = __f; 3661232924Stheraven try 3662232924Stheraven { 3663232924Stheraven#endif 3664288943Sdim for (; __n > 0; ++__f, (void) --__n) 3665288943Sdim ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); 3666232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 3667232924Stheraven } 3668232924Stheraven catch (...) 3669232924Stheraven { 3670232924Stheraven for (; __s != __f; ++__s) 3671232924Stheraven __s->~value_type(); 3672232924Stheraven throw; 3673232924Stheraven } 3674232924Stheraven#endif 3675227825Stheraven return __f; 3676227825Stheraven} 3677227825Stheraven 3678227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_weak_ptr 3679227825Stheraven : public std::exception 3680227825Stheraven{ 3681227825Stheravenpublic: 3682227825Stheraven virtual ~bad_weak_ptr() _NOEXCEPT; 3683227825Stheraven virtual const char* what() const _NOEXCEPT; 3684227825Stheraven}; 3685227825Stheraven 3686261272Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr; 3687227825Stheraven 3688261272Sdimclass _LIBCPP_TYPE_VIS __shared_count 3689227825Stheraven{ 3690227825Stheraven __shared_count(const __shared_count&); 3691227825Stheraven __shared_count& operator=(const __shared_count&); 3692227825Stheraven 3693227825Stheravenprotected: 3694227825Stheraven long __shared_owners_; 3695227825Stheraven virtual ~__shared_count(); 3696227825Stheravenprivate: 3697227825Stheraven virtual void __on_zero_shared() _NOEXCEPT = 0; 3698227825Stheraven 3699227825Stheravenpublic: 3700227825Stheraven _LIBCPP_INLINE_VISIBILITY 3701227825Stheraven explicit __shared_count(long __refs = 0) _NOEXCEPT 3702227825Stheraven : __shared_owners_(__refs) {} 3703227825Stheraven 3704227825Stheraven void __add_shared() _NOEXCEPT; 3705227825Stheraven bool __release_shared() _NOEXCEPT; 3706227825Stheraven _LIBCPP_INLINE_VISIBILITY 3707288943Sdim long use_count() const _NOEXCEPT { 3708288943Sdim return __libcpp_relaxed_load(&__shared_owners_) + 1; 3709288943Sdim } 3710227825Stheraven}; 3711227825Stheraven 3712261272Sdimclass _LIBCPP_TYPE_VIS __shared_weak_count 3713227825Stheraven : private __shared_count 3714227825Stheraven{ 3715227825Stheraven long __shared_weak_owners_; 3716227825Stheraven 3717227825Stheravenpublic: 3718227825Stheraven _LIBCPP_INLINE_VISIBILITY 3719227825Stheraven explicit __shared_weak_count(long __refs = 0) _NOEXCEPT 3720227825Stheraven : __shared_count(__refs), 3721227825Stheraven __shared_weak_owners_(__refs) {} 3722227825Stheravenprotected: 3723227825Stheraven virtual ~__shared_weak_count(); 3724227825Stheraven 3725227825Stheravenpublic: 3726227825Stheraven void __add_shared() _NOEXCEPT; 3727227825Stheraven void __add_weak() _NOEXCEPT; 3728227825Stheraven void __release_shared() _NOEXCEPT; 3729227825Stheraven void __release_weak() _NOEXCEPT; 3730227825Stheraven _LIBCPP_INLINE_VISIBILITY 3731227825Stheraven long use_count() const _NOEXCEPT {return __shared_count::use_count();} 3732227825Stheraven __shared_weak_count* lock() _NOEXCEPT; 3733227825Stheraven 3734249989Sdim // Define the function out only if we build static libc++ without RTTI. 3735249989Sdim // Otherwise we may break clients who need to compile their projects with 3736249989Sdim // -fno-rtti and yet link against a libc++.dylib compiled 3737249989Sdim // without -fno-rtti. 3738249989Sdim#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) 3739227825Stheraven virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; 3740249989Sdim#endif 3741227825Stheravenprivate: 3742227825Stheraven virtual void __on_zero_shared_weak() _NOEXCEPT = 0; 3743227825Stheraven}; 3744227825Stheraven 3745227825Stheraventemplate <class _Tp, class _Dp, class _Alloc> 3746227825Stheravenclass __shared_ptr_pointer 3747227825Stheraven : public __shared_weak_count 3748227825Stheraven{ 3749227825Stheraven __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; 3750227825Stheravenpublic: 3751227825Stheraven _LIBCPP_INLINE_VISIBILITY 3752227825Stheraven __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) 3753227825Stheraven : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} 3754227825Stheraven 3755227825Stheraven#ifndef _LIBCPP_NO_RTTI 3756227825Stheraven virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; 3757227825Stheraven#endif 3758227825Stheraven 3759227825Stheravenprivate: 3760227825Stheraven virtual void __on_zero_shared() _NOEXCEPT; 3761227825Stheraven virtual void __on_zero_shared_weak() _NOEXCEPT; 3762227825Stheraven}; 3763227825Stheraven 3764227825Stheraven#ifndef _LIBCPP_NO_RTTI 3765227825Stheraven 3766227825Stheraventemplate <class _Tp, class _Dp, class _Alloc> 3767227825Stheravenconst void* 3768227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT 3769227825Stheraven{ 3770276792Sdim return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0; 3771227825Stheraven} 3772227825Stheraven 3773227825Stheraven#endif // _LIBCPP_NO_RTTI 3774227825Stheraven 3775227825Stheraventemplate <class _Tp, class _Dp, class _Alloc> 3776227825Stheravenvoid 3777227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT 3778227825Stheraven{ 3779227825Stheraven __data_.first().second()(__data_.first().first()); 3780227825Stheraven __data_.first().second().~_Dp(); 3781227825Stheraven} 3782227825Stheraven 3783227825Stheraventemplate <class _Tp, class _Dp, class _Alloc> 3784227825Stheravenvoid 3785227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT 3786227825Stheraven{ 3787288943Sdim typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; 3788288943Sdim typedef allocator_traits<_Al> _ATraits; 3789276792Sdim typedef pointer_traits<typename _ATraits::pointer> _PTraits; 3790276792Sdim 3791288943Sdim _Al __a(__data_.second()); 3792227825Stheraven __data_.second().~_Alloc(); 3793276792Sdim __a.deallocate(_PTraits::pointer_to(*this), 1); 3794227825Stheraven} 3795227825Stheraven 3796227825Stheraventemplate <class _Tp, class _Alloc> 3797227825Stheravenclass __shared_ptr_emplace 3798227825Stheraven : public __shared_weak_count 3799227825Stheraven{ 3800227825Stheraven __compressed_pair<_Alloc, _Tp> __data_; 3801227825Stheravenpublic: 3802227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 3803227825Stheraven 3804227825Stheraven _LIBCPP_INLINE_VISIBILITY 3805227825Stheraven __shared_ptr_emplace(_Alloc __a) 3806227825Stheraven : __data_(_VSTD::move(__a)) {} 3807227825Stheraven 3808227825Stheraven template <class ..._Args> 3809227825Stheraven _LIBCPP_INLINE_VISIBILITY 3810227825Stheraven __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) 3811232924Stheraven : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), 3812232924Stheraven _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} 3813227825Stheraven 3814227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 3815227825Stheraven 3816227825Stheraven _LIBCPP_INLINE_VISIBILITY 3817227825Stheraven __shared_ptr_emplace(_Alloc __a) 3818227825Stheraven : __data_(__a) {} 3819227825Stheraven 3820227825Stheraven template <class _A0> 3821227825Stheraven _LIBCPP_INLINE_VISIBILITY 3822227825Stheraven __shared_ptr_emplace(_Alloc __a, _A0& __a0) 3823227825Stheraven : __data_(__a, _Tp(__a0)) {} 3824227825Stheraven 3825227825Stheraven template <class _A0, class _A1> 3826227825Stheraven _LIBCPP_INLINE_VISIBILITY 3827227825Stheraven __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) 3828227825Stheraven : __data_(__a, _Tp(__a0, __a1)) {} 3829227825Stheraven 3830227825Stheraven template <class _A0, class _A1, class _A2> 3831227825Stheraven _LIBCPP_INLINE_VISIBILITY 3832227825Stheraven __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) 3833227825Stheraven : __data_(__a, _Tp(__a0, __a1, __a2)) {} 3834227825Stheraven 3835227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 3836227825Stheraven 3837227825Stheravenprivate: 3838227825Stheraven virtual void __on_zero_shared() _NOEXCEPT; 3839227825Stheraven virtual void __on_zero_shared_weak() _NOEXCEPT; 3840227825Stheravenpublic: 3841227825Stheraven _LIBCPP_INLINE_VISIBILITY 3842227825Stheraven _Tp* get() _NOEXCEPT {return &__data_.second();} 3843227825Stheraven}; 3844227825Stheraven 3845227825Stheraventemplate <class _Tp, class _Alloc> 3846227825Stheravenvoid 3847227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT 3848227825Stheraven{ 3849227825Stheraven __data_.second().~_Tp(); 3850227825Stheraven} 3851227825Stheraven 3852227825Stheraventemplate <class _Tp, class _Alloc> 3853227825Stheravenvoid 3854227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT 3855227825Stheraven{ 3856288943Sdim typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; 3857288943Sdim typedef allocator_traits<_Al> _ATraits; 3858276792Sdim typedef pointer_traits<typename _ATraits::pointer> _PTraits; 3859288943Sdim _Al __a(__data_.first()); 3860227825Stheraven __data_.first().~_Alloc(); 3861276792Sdim __a.deallocate(_PTraits::pointer_to(*this), 1); 3862227825Stheraven} 3863227825Stheraven 3864261272Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this; 3865227825Stheraven 3866227825Stheraventemplate<class _Tp> 3867261272Sdimclass _LIBCPP_TYPE_VIS_ONLY shared_ptr 3868227825Stheraven{ 3869227825Stheravenpublic: 3870227825Stheraven typedef _Tp element_type; 3871227825Stheravenprivate: 3872227825Stheraven element_type* __ptr_; 3873227825Stheraven __shared_weak_count* __cntrl_; 3874227825Stheraven 3875227825Stheraven struct __nat {int __for_bool_;}; 3876227825Stheravenpublic: 3877300770Sdim _LIBCPP_INLINE_VISIBILITY 3878241900Sdim _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; 3879300770Sdim _LIBCPP_INLINE_VISIBILITY 3880241900Sdim _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; 3881276792Sdim template<class _Yp> 3882276792Sdim explicit shared_ptr(_Yp* __p, 3883276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3884276792Sdim template<class _Yp, class _Dp> 3885276792Sdim shared_ptr(_Yp* __p, _Dp __d, 3886276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3887276792Sdim template<class _Yp, class _Dp, class _Alloc> 3888276792Sdim shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, 3889276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3890227825Stheraven template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); 3891227825Stheraven template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); 3892300770Sdim template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; 3893300770Sdim _LIBCPP_INLINE_VISIBILITY 3894227825Stheraven shared_ptr(const shared_ptr& __r) _NOEXCEPT; 3895227825Stheraven template<class _Yp> 3896300770Sdim _LIBCPP_INLINE_VISIBILITY 3897227825Stheraven shared_ptr(const shared_ptr<_Yp>& __r, 3898227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) 3899227825Stheraven _NOEXCEPT; 3900227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3901300770Sdim _LIBCPP_INLINE_VISIBILITY 3902227825Stheraven shared_ptr(shared_ptr&& __r) _NOEXCEPT; 3903300770Sdim template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, 3904227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) 3905227825Stheraven _NOEXCEPT; 3906227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3907227825Stheraven template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, 3908227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat()); 3909227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3910276792Sdim template<class _Yp> 3911276792Sdim shared_ptr(auto_ptr<_Yp>&& __r, 3912276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3913227825Stheraven#else 3914276792Sdim template<class _Yp> 3915276792Sdim shared_ptr(auto_ptr<_Yp> __r, 3916276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); 3917227825Stheraven#endif 3918227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3919276792Sdim template <class _Yp, class _Dp> 3920276792Sdim shared_ptr(unique_ptr<_Yp, _Dp>&&, 3921276792Sdim typename enable_if 3922276792Sdim < 3923276792Sdim !is_lvalue_reference<_Dp>::value && 3924276792Sdim !is_array<_Yp>::value && 3925276792Sdim is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3926276792Sdim __nat 3927276792Sdim >::type = __nat()); 3928276792Sdim template <class _Yp, class _Dp> 3929276792Sdim shared_ptr(unique_ptr<_Yp, _Dp>&&, 3930276792Sdim typename enable_if 3931276792Sdim < 3932276792Sdim is_lvalue_reference<_Dp>::value && 3933276792Sdim !is_array<_Yp>::value && 3934276792Sdim is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3935276792Sdim __nat 3936276792Sdim >::type = __nat()); 3937227825Stheraven#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3938276792Sdim template <class _Yp, class _Dp> 3939276792Sdim shared_ptr(unique_ptr<_Yp, _Dp>, 3940276792Sdim typename enable_if 3941276792Sdim < 3942276792Sdim !is_lvalue_reference<_Dp>::value && 3943276792Sdim !is_array<_Yp>::value && 3944276792Sdim is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3945276792Sdim __nat 3946276792Sdim >::type = __nat()); 3947276792Sdim template <class _Yp, class _Dp> 3948276792Sdim shared_ptr(unique_ptr<_Yp, _Dp>, 3949276792Sdim typename enable_if 3950276792Sdim < 3951276792Sdim is_lvalue_reference<_Dp>::value && 3952276792Sdim !is_array<_Yp>::value && 3953276792Sdim is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 3954276792Sdim __nat 3955276792Sdim >::type = __nat()); 3956227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3957227825Stheraven 3958227825Stheraven ~shared_ptr(); 3959227825Stheraven 3960300770Sdim _LIBCPP_INLINE_VISIBILITY 3961227825Stheraven shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; 3962232924Stheraven template<class _Yp> 3963232924Stheraven typename enable_if 3964232924Stheraven < 3965232924Stheraven is_convertible<_Yp*, element_type*>::value, 3966232924Stheraven shared_ptr& 3967232924Stheraven >::type 3968300770Sdim _LIBCPP_INLINE_VISIBILITY 3969232924Stheraven operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; 3970227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3971300770Sdim _LIBCPP_INLINE_VISIBILITY 3972227825Stheraven shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; 3973232924Stheraven template<class _Yp> 3974232924Stheraven typename enable_if 3975232924Stheraven < 3976232924Stheraven is_convertible<_Yp*, element_type*>::value, 3977232924Stheraven shared_ptr<_Tp>& 3978232924Stheraven >::type 3979300770Sdim _LIBCPP_INLINE_VISIBILITY 3980232924Stheraven operator=(shared_ptr<_Yp>&& __r); 3981232924Stheraven template<class _Yp> 3982232924Stheraven typename enable_if 3983232924Stheraven < 3984232924Stheraven !is_array<_Yp>::value && 3985232924Stheraven is_convertible<_Yp*, element_type*>::value, 3986261272Sdim shared_ptr 3987261272Sdim >::type& 3988300770Sdim _LIBCPP_INLINE_VISIBILITY 3989232924Stheraven operator=(auto_ptr<_Yp>&& __r); 3990227825Stheraven#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3991232924Stheraven template<class _Yp> 3992232924Stheraven typename enable_if 3993232924Stheraven < 3994232924Stheraven !is_array<_Yp>::value && 3995232924Stheraven is_convertible<_Yp*, element_type*>::value, 3996232924Stheraven shared_ptr& 3997232924Stheraven >::type 3998300770Sdim _LIBCPP_INLINE_VISIBILITY 3999232924Stheraven operator=(auto_ptr<_Yp> __r); 4000227825Stheraven#endif 4001232924Stheraven template <class _Yp, class _Dp> 4002232924Stheraven typename enable_if 4003232924Stheraven < 4004232924Stheraven !is_array<_Yp>::value && 4005232924Stheraven is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 4006232924Stheraven shared_ptr& 4007232924Stheraven >::type 4008227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4009300770Sdim _LIBCPP_INLINE_VISIBILITY 4010232924Stheraven operator=(unique_ptr<_Yp, _Dp>&& __r); 4011227825Stheraven#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4012300770Sdim _LIBCPP_INLINE_VISIBILITY 4013232924Stheraven operator=(unique_ptr<_Yp, _Dp> __r); 4014227825Stheraven#endif 4015227825Stheraven 4016300770Sdim _LIBCPP_INLINE_VISIBILITY 4017227825Stheraven void swap(shared_ptr& __r) _NOEXCEPT; 4018300770Sdim _LIBCPP_INLINE_VISIBILITY 4019227825Stheraven void reset() _NOEXCEPT; 4020232924Stheraven template<class _Yp> 4021232924Stheraven typename enable_if 4022232924Stheraven < 4023232924Stheraven is_convertible<_Yp*, element_type*>::value, 4024232924Stheraven void 4025232924Stheraven >::type 4026300770Sdim _LIBCPP_INLINE_VISIBILITY 4027232924Stheraven reset(_Yp* __p); 4028232924Stheraven template<class _Yp, class _Dp> 4029232924Stheraven typename enable_if 4030232924Stheraven < 4031232924Stheraven is_convertible<_Yp*, element_type*>::value, 4032232924Stheraven void 4033232924Stheraven >::type 4034300770Sdim _LIBCPP_INLINE_VISIBILITY 4035232924Stheraven reset(_Yp* __p, _Dp __d); 4036232924Stheraven template<class _Yp, class _Dp, class _Alloc> 4037232924Stheraven typename enable_if 4038232924Stheraven < 4039232924Stheraven is_convertible<_Yp*, element_type*>::value, 4040232924Stheraven void 4041232924Stheraven >::type 4042300770Sdim _LIBCPP_INLINE_VISIBILITY 4043232924Stheraven reset(_Yp* __p, _Dp __d, _Alloc __a); 4044227825Stheraven 4045227825Stheraven _LIBCPP_INLINE_VISIBILITY 4046227825Stheraven element_type* get() const _NOEXCEPT {return __ptr_;} 4047227825Stheraven _LIBCPP_INLINE_VISIBILITY 4048227825Stheraven typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT 4049227825Stheraven {return *__ptr_;} 4050227825Stheraven _LIBCPP_INLINE_VISIBILITY 4051227825Stheraven element_type* operator->() const _NOEXCEPT {return __ptr_;} 4052227825Stheraven _LIBCPP_INLINE_VISIBILITY 4053227825Stheraven long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} 4054227825Stheraven _LIBCPP_INLINE_VISIBILITY 4055227825Stheraven bool unique() const _NOEXCEPT {return use_count() == 1;} 4056227825Stheraven _LIBCPP_INLINE_VISIBILITY 4057232924Stheraven _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} 4058232924Stheraven template <class _Up> 4059227825Stheraven _LIBCPP_INLINE_VISIBILITY 4060232924Stheraven bool owner_before(shared_ptr<_Up> const& __p) const 4061227825Stheraven {return __cntrl_ < __p.__cntrl_;} 4062232924Stheraven template <class _Up> 4063227825Stheraven _LIBCPP_INLINE_VISIBILITY 4064232924Stheraven bool owner_before(weak_ptr<_Up> const& __p) const 4065227825Stheraven {return __cntrl_ < __p.__cntrl_;} 4066241900Sdim _LIBCPP_INLINE_VISIBILITY 4067241900Sdim bool 4068241900Sdim __owner_equivalent(const shared_ptr& __p) const 4069241900Sdim {return __cntrl_ == __p.__cntrl_;} 4070227825Stheraven 4071227825Stheraven#ifndef _LIBCPP_NO_RTTI 4072227825Stheraven template <class _Dp> 4073227825Stheraven _LIBCPP_INLINE_VISIBILITY 4074227825Stheraven _Dp* __get_deleter() const _NOEXCEPT 4075227825Stheraven {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);} 4076227825Stheraven#endif // _LIBCPP_NO_RTTI 4077227825Stheraven 4078227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 4079227825Stheraven 4080227825Stheraven template<class ..._Args> 4081227825Stheraven static 4082227825Stheraven shared_ptr<_Tp> 4083227825Stheraven make_shared(_Args&& ...__args); 4084227825Stheraven 4085227825Stheraven template<class _Alloc, class ..._Args> 4086227825Stheraven static 4087227825Stheraven shared_ptr<_Tp> 4088227825Stheraven allocate_shared(const _Alloc& __a, _Args&& ...__args); 4089227825Stheraven 4090227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 4091227825Stheraven 4092227825Stheraven static shared_ptr<_Tp> make_shared(); 4093227825Stheraven 4094227825Stheraven template<class _A0> 4095227825Stheraven static shared_ptr<_Tp> make_shared(_A0&); 4096227825Stheraven 4097227825Stheraven template<class _A0, class _A1> 4098227825Stheraven static shared_ptr<_Tp> make_shared(_A0&, _A1&); 4099227825Stheraven 4100227825Stheraven template<class _A0, class _A1, class _A2> 4101227825Stheraven static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); 4102227825Stheraven 4103227825Stheraven template<class _Alloc> 4104227825Stheraven static shared_ptr<_Tp> 4105227825Stheraven allocate_shared(const _Alloc& __a); 4106227825Stheraven 4107227825Stheraven template<class _Alloc, class _A0> 4108227825Stheraven static shared_ptr<_Tp> 4109227825Stheraven allocate_shared(const _Alloc& __a, _A0& __a0); 4110227825Stheraven 4111227825Stheraven template<class _Alloc, class _A0, class _A1> 4112227825Stheraven static shared_ptr<_Tp> 4113227825Stheraven allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); 4114227825Stheraven 4115227825Stheraven template<class _Alloc, class _A0, class _A1, class _A2> 4116227825Stheraven static shared_ptr<_Tp> 4117227825Stheraven allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); 4118227825Stheraven 4119227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 4120227825Stheraven 4121227825Stheravenprivate: 4122227825Stheraven 4123227825Stheraven template <class _Yp> 4124227825Stheraven _LIBCPP_INLINE_VISIBILITY 4125227825Stheraven void 4126227825Stheraven __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT 4127227825Stheraven { 4128227825Stheraven if (__e) 4129288943Sdim { 4130288943Sdim __e->__weak_this_.__ptr_ = const_cast<_Yp*>(static_cast<const _Yp*>(__e)); 4131288943Sdim __e->__weak_this_.__cntrl_ = __cntrl_; 4132288943Sdim __cntrl_->__add_weak(); 4133288943Sdim } 4134227825Stheraven } 4135227825Stheraven 4136227825Stheraven _LIBCPP_INLINE_VISIBILITY 4137288943Sdim void __enable_weak_this(const volatile void*) _NOEXCEPT {} 4138227825Stheraven 4139261272Sdim template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr; 4140261272Sdim template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr; 4141227825Stheraven}; 4142227825Stheraven 4143227825Stheraventemplate<class _Tp> 4144300770Sdiminline 4145241900Sdim_LIBCPP_CONSTEXPR 4146227825Stheravenshared_ptr<_Tp>::shared_ptr() _NOEXCEPT 4147227825Stheraven : __ptr_(0), 4148227825Stheraven __cntrl_(0) 4149227825Stheraven{ 4150227825Stheraven} 4151227825Stheraven 4152227825Stheraventemplate<class _Tp> 4153300770Sdiminline 4154241900Sdim_LIBCPP_CONSTEXPR 4155227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT 4156227825Stheraven : __ptr_(0), 4157227825Stheraven __cntrl_(0) 4158227825Stheraven{ 4159227825Stheraven} 4160227825Stheraven 4161227825Stheraventemplate<class _Tp> 4162276792Sdimtemplate<class _Yp> 4163276792Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p, 4164276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4165227825Stheraven : __ptr_(__p) 4166227825Stheraven{ 4167227825Stheraven unique_ptr<_Yp> __hold(__p); 4168227825Stheraven typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; 4169227825Stheraven __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>()); 4170227825Stheraven __hold.release(); 4171227825Stheraven __enable_weak_this(__p); 4172227825Stheraven} 4173227825Stheraven 4174227825Stheraventemplate<class _Tp> 4175276792Sdimtemplate<class _Yp, class _Dp> 4176276792Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, 4177276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4178227825Stheraven : __ptr_(__p) 4179227825Stheraven{ 4180227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4181227825Stheraven try 4182227825Stheraven { 4183227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4184227825Stheraven typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; 4185227825Stheraven __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>()); 4186227825Stheraven __enable_weak_this(__p); 4187227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4188227825Stheraven } 4189227825Stheraven catch (...) 4190227825Stheraven { 4191227825Stheraven __d(__p); 4192227825Stheraven throw; 4193227825Stheraven } 4194227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4195227825Stheraven} 4196227825Stheraven 4197227825Stheraventemplate<class _Tp> 4198227825Stheraventemplate<class _Dp> 4199227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) 4200227825Stheraven : __ptr_(0) 4201227825Stheraven{ 4202227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4203227825Stheraven try 4204227825Stheraven { 4205227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4206227825Stheraven typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk; 4207227825Stheraven __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>()); 4208227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4209227825Stheraven } 4210227825Stheraven catch (...) 4211227825Stheraven { 4212227825Stheraven __d(__p); 4213227825Stheraven throw; 4214227825Stheraven } 4215227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4216227825Stheraven} 4217227825Stheraven 4218227825Stheraventemplate<class _Tp> 4219276792Sdimtemplate<class _Yp, class _Dp, class _Alloc> 4220276792Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, 4221276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4222227825Stheraven : __ptr_(__p) 4223227825Stheraven{ 4224227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4225227825Stheraven try 4226227825Stheraven { 4227227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4228227825Stheraven typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; 4229276792Sdim typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4230227825Stheraven typedef __allocator_destructor<_A2> _D2; 4231227825Stheraven _A2 __a2(__a); 4232227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4233276792Sdim ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4234276792Sdim _CntrlBlk(__p, __d, __a); 4235276792Sdim __cntrl_ = _VSTD::addressof(*__hold2.release()); 4236227825Stheraven __enable_weak_this(__p); 4237227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4238227825Stheraven } 4239227825Stheraven catch (...) 4240227825Stheraven { 4241227825Stheraven __d(__p); 4242227825Stheraven throw; 4243227825Stheraven } 4244227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4245227825Stheraven} 4246227825Stheraven 4247227825Stheraventemplate<class _Tp> 4248227825Stheraventemplate<class _Dp, class _Alloc> 4249227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) 4250227825Stheraven : __ptr_(0) 4251227825Stheraven{ 4252227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4253227825Stheraven try 4254227825Stheraven { 4255227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4256227825Stheraven typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; 4257276792Sdim typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4258227825Stheraven typedef __allocator_destructor<_A2> _D2; 4259227825Stheraven _A2 __a2(__a); 4260227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4261276792Sdim ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4262276792Sdim _CntrlBlk(__p, __d, __a); 4263276792Sdim __cntrl_ = _VSTD::addressof(*__hold2.release()); 4264227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4265227825Stheraven } 4266227825Stheraven catch (...) 4267227825Stheraven { 4268227825Stheraven __d(__p); 4269227825Stheraven throw; 4270227825Stheraven } 4271227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4272227825Stheraven} 4273227825Stheraven 4274227825Stheraventemplate<class _Tp> 4275227825Stheraventemplate<class _Yp> 4276300770Sdiminline 4277227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT 4278227825Stheraven : __ptr_(__p), 4279227825Stheraven __cntrl_(__r.__cntrl_) 4280227825Stheraven{ 4281227825Stheraven if (__cntrl_) 4282227825Stheraven __cntrl_->__add_shared(); 4283227825Stheraven} 4284227825Stheraven 4285227825Stheraventemplate<class _Tp> 4286300770Sdiminline 4287227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT 4288227825Stheraven : __ptr_(__r.__ptr_), 4289227825Stheraven __cntrl_(__r.__cntrl_) 4290227825Stheraven{ 4291227825Stheraven if (__cntrl_) 4292227825Stheraven __cntrl_->__add_shared(); 4293227825Stheraven} 4294227825Stheraven 4295227825Stheraventemplate<class _Tp> 4296227825Stheraventemplate<class _Yp> 4297300770Sdiminline 4298227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, 4299227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) 4300227825Stheraven _NOEXCEPT 4301227825Stheraven : __ptr_(__r.__ptr_), 4302227825Stheraven __cntrl_(__r.__cntrl_) 4303227825Stheraven{ 4304227825Stheraven if (__cntrl_) 4305227825Stheraven __cntrl_->__add_shared(); 4306227825Stheraven} 4307227825Stheraven 4308227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4309227825Stheraven 4310227825Stheraventemplate<class _Tp> 4311300770Sdiminline 4312227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT 4313227825Stheraven : __ptr_(__r.__ptr_), 4314227825Stheraven __cntrl_(__r.__cntrl_) 4315227825Stheraven{ 4316227825Stheraven __r.__ptr_ = 0; 4317227825Stheraven __r.__cntrl_ = 0; 4318227825Stheraven} 4319227825Stheraven 4320227825Stheraventemplate<class _Tp> 4321227825Stheraventemplate<class _Yp> 4322300770Sdiminline 4323227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, 4324227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) 4325227825Stheraven _NOEXCEPT 4326227825Stheraven : __ptr_(__r.__ptr_), 4327227825Stheraven __cntrl_(__r.__cntrl_) 4328227825Stheraven{ 4329227825Stheraven __r.__ptr_ = 0; 4330227825Stheraven __r.__cntrl_ = 0; 4331227825Stheraven} 4332227825Stheraven 4333227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4334227825Stheraven 4335227825Stheraventemplate<class _Tp> 4336276792Sdimtemplate<class _Yp> 4337227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4338276792Sdimshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, 4339227825Stheraven#else 4340276792Sdimshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, 4341227825Stheraven#endif 4342276792Sdim typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) 4343227825Stheraven : __ptr_(__r.get()) 4344227825Stheraven{ 4345227825Stheraven typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; 4346227825Stheraven __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); 4347227825Stheraven __enable_weak_this(__r.get()); 4348227825Stheraven __r.release(); 4349227825Stheraven} 4350227825Stheraven 4351227825Stheraventemplate<class _Tp> 4352276792Sdimtemplate <class _Yp, class _Dp> 4353227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4354227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, 4355227825Stheraven#else 4356227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, 4357227825Stheraven#endif 4358276792Sdim typename enable_if 4359276792Sdim < 4360276792Sdim !is_lvalue_reference<_Dp>::value && 4361276792Sdim !is_array<_Yp>::value && 4362276792Sdim is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 4363276792Sdim __nat 4364276792Sdim >::type) 4365227825Stheraven : __ptr_(__r.get()) 4366227825Stheraven{ 4367288943Sdim#if _LIBCPP_STD_VER > 11 4368288943Sdim if (__ptr_ == nullptr) 4369288943Sdim __cntrl_ = nullptr; 4370288943Sdim else 4371288943Sdim#endif 4372288943Sdim { 4373288943Sdim typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; 4374288943Sdim __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); 4375288943Sdim __enable_weak_this(__r.get()); 4376288943Sdim } 4377227825Stheraven __r.release(); 4378227825Stheraven} 4379227825Stheraven 4380227825Stheraventemplate<class _Tp> 4381276792Sdimtemplate <class _Yp, class _Dp> 4382227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4383227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, 4384227825Stheraven#else 4385227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, 4386227825Stheraven#endif 4387276792Sdim typename enable_if 4388276792Sdim < 4389276792Sdim is_lvalue_reference<_Dp>::value && 4390276792Sdim !is_array<_Yp>::value && 4391276792Sdim is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, 4392276792Sdim __nat 4393276792Sdim >::type) 4394227825Stheraven : __ptr_(__r.get()) 4395227825Stheraven{ 4396288943Sdim#if _LIBCPP_STD_VER > 11 4397288943Sdim if (__ptr_ == nullptr) 4398288943Sdim __cntrl_ = nullptr; 4399288943Sdim else 4400288943Sdim#endif 4401288943Sdim { 4402288943Sdim typedef __shared_ptr_pointer<_Yp*, 4403288943Sdim reference_wrapper<typename remove_reference<_Dp>::type>, 4404288943Sdim allocator<_Yp> > _CntrlBlk; 4405288943Sdim __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); 4406288943Sdim __enable_weak_this(__r.get()); 4407288943Sdim } 4408227825Stheraven __r.release(); 4409227825Stheraven} 4410227825Stheraven 4411227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 4412227825Stheraven 4413227825Stheraventemplate<class _Tp> 4414227825Stheraventemplate<class ..._Args> 4415227825Stheravenshared_ptr<_Tp> 4416227825Stheravenshared_ptr<_Tp>::make_shared(_Args&& ...__args) 4417227825Stheraven{ 4418227825Stheraven typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4419227825Stheraven typedef allocator<_CntrlBlk> _A2; 4420227825Stheraven typedef __allocator_destructor<_A2> _D2; 4421227825Stheraven _A2 __a2; 4422227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4423227825Stheraven ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); 4424227825Stheraven shared_ptr<_Tp> __r; 4425227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4426227825Stheraven __r.__cntrl_ = __hold2.release(); 4427227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4428227825Stheraven return __r; 4429227825Stheraven} 4430227825Stheraven 4431227825Stheraventemplate<class _Tp> 4432227825Stheraventemplate<class _Alloc, class ..._Args> 4433227825Stheravenshared_ptr<_Tp> 4434227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) 4435227825Stheraven{ 4436227825Stheraven typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4437276792Sdim typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; 4438227825Stheraven typedef __allocator_destructor<_A2> _D2; 4439227825Stheraven _A2 __a2(__a); 4440227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); 4441276792Sdim ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4442276792Sdim _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); 4443227825Stheraven shared_ptr<_Tp> __r; 4444227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4445276792Sdim __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4446227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4447227825Stheraven return __r; 4448227825Stheraven} 4449227825Stheraven 4450227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 4451227825Stheraven 4452227825Stheraventemplate<class _Tp> 4453227825Stheravenshared_ptr<_Tp> 4454227825Stheravenshared_ptr<_Tp>::make_shared() 4455227825Stheraven{ 4456227825Stheraven typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4457227825Stheraven typedef allocator<_CntrlBlk> _Alloc2; 4458227825Stheraven typedef __allocator_destructor<_Alloc2> _D2; 4459227825Stheraven _Alloc2 __alloc2; 4460227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4461227825Stheraven ::new(__hold2.get()) _CntrlBlk(__alloc2); 4462227825Stheraven shared_ptr<_Tp> __r; 4463227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4464227825Stheraven __r.__cntrl_ = __hold2.release(); 4465227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4466227825Stheraven return __r; 4467227825Stheraven} 4468227825Stheraven 4469227825Stheraventemplate<class _Tp> 4470227825Stheraventemplate<class _A0> 4471227825Stheravenshared_ptr<_Tp> 4472227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0) 4473227825Stheraven{ 4474227825Stheraven typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4475227825Stheraven typedef allocator<_CntrlBlk> _Alloc2; 4476227825Stheraven typedef __allocator_destructor<_Alloc2> _D2; 4477227825Stheraven _Alloc2 __alloc2; 4478227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4479227825Stheraven ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); 4480227825Stheraven shared_ptr<_Tp> __r; 4481227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4482227825Stheraven __r.__cntrl_ = __hold2.release(); 4483227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4484227825Stheraven return __r; 4485227825Stheraven} 4486227825Stheraven 4487227825Stheraventemplate<class _Tp> 4488227825Stheraventemplate<class _A0, class _A1> 4489227825Stheravenshared_ptr<_Tp> 4490227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) 4491227825Stheraven{ 4492227825Stheraven typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4493227825Stheraven typedef allocator<_CntrlBlk> _Alloc2; 4494227825Stheraven typedef __allocator_destructor<_Alloc2> _D2; 4495227825Stheraven _Alloc2 __alloc2; 4496227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4497227825Stheraven ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); 4498227825Stheraven shared_ptr<_Tp> __r; 4499227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4500227825Stheraven __r.__cntrl_ = __hold2.release(); 4501227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4502227825Stheraven return __r; 4503227825Stheraven} 4504227825Stheraven 4505227825Stheraventemplate<class _Tp> 4506227825Stheraventemplate<class _A0, class _A1, class _A2> 4507227825Stheravenshared_ptr<_Tp> 4508227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) 4509227825Stheraven{ 4510227825Stheraven typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; 4511227825Stheraven typedef allocator<_CntrlBlk> _Alloc2; 4512227825Stheraven typedef __allocator_destructor<_Alloc2> _D2; 4513227825Stheraven _Alloc2 __alloc2; 4514227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4515227825Stheraven ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); 4516227825Stheraven shared_ptr<_Tp> __r; 4517227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4518227825Stheraven __r.__cntrl_ = __hold2.release(); 4519227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4520227825Stheraven return __r; 4521227825Stheraven} 4522227825Stheraven 4523227825Stheraventemplate<class _Tp> 4524227825Stheraventemplate<class _Alloc> 4525227825Stheravenshared_ptr<_Tp> 4526227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a) 4527227825Stheraven{ 4528227825Stheraven typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4529276792Sdim typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; 4530227825Stheraven typedef __allocator_destructor<_Alloc2> _D2; 4531227825Stheraven _Alloc2 __alloc2(__a); 4532227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4533276792Sdim ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4534276792Sdim _CntrlBlk(__a); 4535227825Stheraven shared_ptr<_Tp> __r; 4536227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4537276792Sdim __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4538227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4539227825Stheraven return __r; 4540227825Stheraven} 4541227825Stheraven 4542227825Stheraventemplate<class _Tp> 4543227825Stheraventemplate<class _Alloc, class _A0> 4544227825Stheravenshared_ptr<_Tp> 4545227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) 4546227825Stheraven{ 4547227825Stheraven typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4548276792Sdim typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; 4549227825Stheraven typedef __allocator_destructor<_Alloc2> _D2; 4550227825Stheraven _Alloc2 __alloc2(__a); 4551227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4552276792Sdim ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4553276792Sdim _CntrlBlk(__a, __a0); 4554227825Stheraven shared_ptr<_Tp> __r; 4555227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4556276792Sdim __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4557227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4558227825Stheraven return __r; 4559227825Stheraven} 4560227825Stheraven 4561227825Stheraventemplate<class _Tp> 4562227825Stheraventemplate<class _Alloc, class _A0, class _A1> 4563227825Stheravenshared_ptr<_Tp> 4564227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) 4565227825Stheraven{ 4566227825Stheraven typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4567276792Sdim typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; 4568227825Stheraven typedef __allocator_destructor<_Alloc2> _D2; 4569227825Stheraven _Alloc2 __alloc2(__a); 4570227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4571276792Sdim ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4572276792Sdim _CntrlBlk(__a, __a0, __a1); 4573227825Stheraven shared_ptr<_Tp> __r; 4574227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4575276792Sdim __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4576227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4577227825Stheraven return __r; 4578227825Stheraven} 4579227825Stheraven 4580227825Stheraventemplate<class _Tp> 4581227825Stheraventemplate<class _Alloc, class _A0, class _A1, class _A2> 4582227825Stheravenshared_ptr<_Tp> 4583227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) 4584227825Stheraven{ 4585227825Stheraven typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; 4586276792Sdim typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; 4587227825Stheraven typedef __allocator_destructor<_Alloc2> _D2; 4588227825Stheraven _Alloc2 __alloc2(__a); 4589227825Stheraven unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); 4590276792Sdim ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) 4591276792Sdim _CntrlBlk(__a, __a0, __a1, __a2); 4592227825Stheraven shared_ptr<_Tp> __r; 4593227825Stheraven __r.__ptr_ = __hold2.get()->get(); 4594276792Sdim __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); 4595227825Stheraven __r.__enable_weak_this(__r.__ptr_); 4596227825Stheraven return __r; 4597227825Stheraven} 4598227825Stheraven 4599227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 4600227825Stheraven 4601227825Stheraventemplate<class _Tp> 4602227825Stheravenshared_ptr<_Tp>::~shared_ptr() 4603227825Stheraven{ 4604227825Stheraven if (__cntrl_) 4605227825Stheraven __cntrl_->__release_shared(); 4606227825Stheraven} 4607227825Stheraven 4608227825Stheraventemplate<class _Tp> 4609300770Sdiminline 4610227825Stheravenshared_ptr<_Tp>& 4611227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT 4612227825Stheraven{ 4613227825Stheraven shared_ptr(__r).swap(*this); 4614227825Stheraven return *this; 4615227825Stheraven} 4616227825Stheraven 4617227825Stheraventemplate<class _Tp> 4618227825Stheraventemplate<class _Yp> 4619300770Sdiminline 4620232924Stheraventypename enable_if 4621232924Stheraven< 4622232924Stheraven is_convertible<_Yp*, _Tp*>::value, 4623232924Stheraven shared_ptr<_Tp>& 4624232924Stheraven>::type 4625227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT 4626227825Stheraven{ 4627227825Stheraven shared_ptr(__r).swap(*this); 4628227825Stheraven return *this; 4629227825Stheraven} 4630227825Stheraven 4631227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4632227825Stheraven 4633227825Stheraventemplate<class _Tp> 4634300770Sdiminline 4635227825Stheravenshared_ptr<_Tp>& 4636227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT 4637227825Stheraven{ 4638227825Stheraven shared_ptr(_VSTD::move(__r)).swap(*this); 4639227825Stheraven return *this; 4640227825Stheraven} 4641227825Stheraven 4642227825Stheraventemplate<class _Tp> 4643227825Stheraventemplate<class _Yp> 4644300770Sdiminline 4645232924Stheraventypename enable_if 4646232924Stheraven< 4647232924Stheraven is_convertible<_Yp*, _Tp*>::value, 4648232924Stheraven shared_ptr<_Tp>& 4649232924Stheraven>::type 4650227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) 4651227825Stheraven{ 4652227825Stheraven shared_ptr(_VSTD::move(__r)).swap(*this); 4653227825Stheraven return *this; 4654227825Stheraven} 4655227825Stheraven 4656227825Stheraventemplate<class _Tp> 4657227825Stheraventemplate<class _Yp> 4658300770Sdiminline 4659232924Stheraventypename enable_if 4660232924Stheraven< 4661232924Stheraven !is_array<_Yp>::value && 4662232924Stheraven is_convertible<_Yp*, _Tp*>::value, 4663261272Sdim shared_ptr<_Tp> 4664261272Sdim>::type& 4665227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) 4666227825Stheraven{ 4667227825Stheraven shared_ptr(_VSTD::move(__r)).swap(*this); 4668227825Stheraven return *this; 4669227825Stheraven} 4670227825Stheraven 4671227825Stheraventemplate<class _Tp> 4672227825Stheraventemplate <class _Yp, class _Dp> 4673300770Sdiminline 4674232924Stheraventypename enable_if 4675232924Stheraven< 4676232924Stheraven !is_array<_Yp>::value && 4677232924Stheraven is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value, 4678232924Stheraven shared_ptr<_Tp>& 4679232924Stheraven>::type 4680227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) 4681227825Stheraven{ 4682227825Stheraven shared_ptr(_VSTD::move(__r)).swap(*this); 4683227825Stheraven return *this; 4684227825Stheraven} 4685227825Stheraven 4686227825Stheraven#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4687227825Stheraven 4688227825Stheraventemplate<class _Tp> 4689227825Stheraventemplate<class _Yp> 4690227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4691232924Stheraventypename enable_if 4692232924Stheraven< 4693232924Stheraven !is_array<_Yp>::value && 4694232924Stheraven is_convertible<_Yp*, _Tp*>::value, 4695232924Stheraven shared_ptr<_Tp>& 4696232924Stheraven>::type 4697227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) 4698227825Stheraven{ 4699227825Stheraven shared_ptr(__r).swap(*this); 4700227825Stheraven return *this; 4701227825Stheraven} 4702227825Stheraven 4703227825Stheraventemplate<class _Tp> 4704227825Stheraventemplate <class _Yp, class _Dp> 4705227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4706232924Stheraventypename enable_if 4707232924Stheraven< 4708232924Stheraven !is_array<_Yp>::value && 4709232924Stheraven is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value, 4710232924Stheraven shared_ptr<_Tp>& 4711232924Stheraven>::type 4712227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) 4713227825Stheraven{ 4714227825Stheraven shared_ptr(_VSTD::move(__r)).swap(*this); 4715227825Stheraven return *this; 4716227825Stheraven} 4717227825Stheraven 4718227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4719227825Stheraven 4720227825Stheraventemplate<class _Tp> 4721300770Sdiminline 4722227825Stheravenvoid 4723227825Stheravenshared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT 4724227825Stheraven{ 4725227825Stheraven _VSTD::swap(__ptr_, __r.__ptr_); 4726227825Stheraven _VSTD::swap(__cntrl_, __r.__cntrl_); 4727227825Stheraven} 4728227825Stheraven 4729227825Stheraventemplate<class _Tp> 4730300770Sdiminline 4731227825Stheravenvoid 4732227825Stheravenshared_ptr<_Tp>::reset() _NOEXCEPT 4733227825Stheraven{ 4734227825Stheraven shared_ptr().swap(*this); 4735227825Stheraven} 4736227825Stheraven 4737227825Stheraventemplate<class _Tp> 4738227825Stheraventemplate<class _Yp> 4739300770Sdiminline 4740232924Stheraventypename enable_if 4741232924Stheraven< 4742232924Stheraven is_convertible<_Yp*, _Tp*>::value, 4743232924Stheraven void 4744232924Stheraven>::type 4745227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p) 4746227825Stheraven{ 4747227825Stheraven shared_ptr(__p).swap(*this); 4748227825Stheraven} 4749227825Stheraven 4750227825Stheraventemplate<class _Tp> 4751227825Stheraventemplate<class _Yp, class _Dp> 4752300770Sdiminline 4753232924Stheraventypename enable_if 4754232924Stheraven< 4755232924Stheraven is_convertible<_Yp*, _Tp*>::value, 4756232924Stheraven void 4757232924Stheraven>::type 4758227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) 4759227825Stheraven{ 4760227825Stheraven shared_ptr(__p, __d).swap(*this); 4761227825Stheraven} 4762227825Stheraven 4763227825Stheraventemplate<class _Tp> 4764227825Stheraventemplate<class _Yp, class _Dp, class _Alloc> 4765300770Sdiminline 4766232924Stheraventypename enable_if 4767232924Stheraven< 4768232924Stheraven is_convertible<_Yp*, _Tp*>::value, 4769232924Stheraven void 4770232924Stheraven>::type 4771227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) 4772227825Stheraven{ 4773227825Stheraven shared_ptr(__p, __d, __a).swap(*this); 4774227825Stheraven} 4775227825Stheraven 4776227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS 4777227825Stheraven 4778227825Stheraventemplate<class _Tp, class ..._Args> 4779227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4780232924Stheraventypename enable_if 4781232924Stheraven< 4782232924Stheraven !is_array<_Tp>::value, 4783232924Stheraven shared_ptr<_Tp> 4784232924Stheraven>::type 4785227825Stheravenmake_shared(_Args&& ...__args) 4786227825Stheraven{ 4787227825Stheraven return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...); 4788227825Stheraven} 4789227825Stheraven 4790227825Stheraventemplate<class _Tp, class _Alloc, class ..._Args> 4791227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4792232924Stheraventypename enable_if 4793232924Stheraven< 4794232924Stheraven !is_array<_Tp>::value, 4795232924Stheraven shared_ptr<_Tp> 4796232924Stheraven>::type 4797227825Stheravenallocate_shared(const _Alloc& __a, _Args&& ...__args) 4798227825Stheraven{ 4799227825Stheraven return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...); 4800227825Stheraven} 4801227825Stheraven 4802227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 4803227825Stheraven 4804227825Stheraventemplate<class _Tp> 4805227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4806227825Stheravenshared_ptr<_Tp> 4807227825Stheravenmake_shared() 4808227825Stheraven{ 4809227825Stheraven return shared_ptr<_Tp>::make_shared(); 4810227825Stheraven} 4811227825Stheraven 4812227825Stheraventemplate<class _Tp, class _A0> 4813227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4814227825Stheravenshared_ptr<_Tp> 4815227825Stheravenmake_shared(_A0& __a0) 4816227825Stheraven{ 4817227825Stheraven return shared_ptr<_Tp>::make_shared(__a0); 4818227825Stheraven} 4819227825Stheraven 4820227825Stheraventemplate<class _Tp, class _A0, class _A1> 4821227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4822227825Stheravenshared_ptr<_Tp> 4823227825Stheravenmake_shared(_A0& __a0, _A1& __a1) 4824227825Stheraven{ 4825227825Stheraven return shared_ptr<_Tp>::make_shared(__a0, __a1); 4826227825Stheraven} 4827227825Stheraven 4828227825Stheraventemplate<class _Tp, class _A0, class _A1, class _A2> 4829227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4830227825Stheravenshared_ptr<_Tp> 4831227825Stheravenmake_shared(_A0& __a0, _A1& __a1, _A2& __a2) 4832227825Stheraven{ 4833227825Stheraven return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); 4834227825Stheraven} 4835227825Stheraven 4836227825Stheraventemplate<class _Tp, class _Alloc> 4837227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4838227825Stheravenshared_ptr<_Tp> 4839227825Stheravenallocate_shared(const _Alloc& __a) 4840227825Stheraven{ 4841227825Stheraven return shared_ptr<_Tp>::allocate_shared(__a); 4842227825Stheraven} 4843227825Stheraven 4844227825Stheraventemplate<class _Tp, class _Alloc, class _A0> 4845227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4846227825Stheravenshared_ptr<_Tp> 4847227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0) 4848227825Stheraven{ 4849227825Stheraven return shared_ptr<_Tp>::allocate_shared(__a, __a0); 4850227825Stheraven} 4851227825Stheraven 4852227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1> 4853227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4854227825Stheravenshared_ptr<_Tp> 4855227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) 4856227825Stheraven{ 4857227825Stheraven return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); 4858227825Stheraven} 4859227825Stheraven 4860227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1, class _A2> 4861227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4862227825Stheravenshared_ptr<_Tp> 4863227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) 4864227825Stheraven{ 4865227825Stheraven return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); 4866227825Stheraven} 4867227825Stheraven 4868227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 4869227825Stheraven 4870227825Stheraventemplate<class _Tp, class _Up> 4871227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4872227825Stheravenbool 4873227825Stheravenoperator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4874227825Stheraven{ 4875227825Stheraven return __x.get() == __y.get(); 4876227825Stheraven} 4877227825Stheraven 4878227825Stheraventemplate<class _Tp, class _Up> 4879227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4880227825Stheravenbool 4881227825Stheravenoperator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4882227825Stheraven{ 4883227825Stheraven return !(__x == __y); 4884227825Stheraven} 4885227825Stheraven 4886227825Stheraventemplate<class _Tp, class _Up> 4887227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4888227825Stheravenbool 4889227825Stheravenoperator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4890227825Stheraven{ 4891288943Sdim typedef typename common_type<_Tp*, _Up*>::type _Vp; 4892288943Sdim return less<_Vp>()(__x.get(), __y.get()); 4893227825Stheraven} 4894227825Stheraven 4895232924Stheraventemplate<class _Tp, class _Up> 4896232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4897232924Stheravenbool 4898232924Stheravenoperator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4899232924Stheraven{ 4900232924Stheraven return __y < __x; 4901232924Stheraven} 4902232924Stheraven 4903232924Stheraventemplate<class _Tp, class _Up> 4904232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4905232924Stheravenbool 4906232924Stheravenoperator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4907232924Stheraven{ 4908232924Stheraven return !(__y < __x); 4909232924Stheraven} 4910232924Stheraven 4911232924Stheraventemplate<class _Tp, class _Up> 4912232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4913232924Stheravenbool 4914232924Stheravenoperator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT 4915232924Stheraven{ 4916232924Stheraven return !(__x < __y); 4917232924Stheraven} 4918232924Stheraven 4919227825Stheraventemplate<class _Tp> 4920227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 4921232924Stheravenbool 4922232924Stheravenoperator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4923232924Stheraven{ 4924232924Stheraven return !__x; 4925232924Stheraven} 4926232924Stheraven 4927232924Stheraventemplate<class _Tp> 4928232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4929232924Stheravenbool 4930232924Stheravenoperator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4931232924Stheraven{ 4932232924Stheraven return !__x; 4933232924Stheraven} 4934232924Stheraven 4935232924Stheraventemplate<class _Tp> 4936232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4937232924Stheravenbool 4938232924Stheravenoperator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4939232924Stheraven{ 4940232924Stheraven return static_cast<bool>(__x); 4941232924Stheraven} 4942232924Stheraven 4943232924Stheraventemplate<class _Tp> 4944232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4945232924Stheravenbool 4946232924Stheravenoperator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4947232924Stheraven{ 4948232924Stheraven return static_cast<bool>(__x); 4949232924Stheraven} 4950232924Stheraven 4951232924Stheraventemplate<class _Tp> 4952232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4953232924Stheravenbool 4954232924Stheravenoperator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4955232924Stheraven{ 4956232924Stheraven return less<_Tp*>()(__x.get(), nullptr); 4957232924Stheraven} 4958232924Stheraven 4959232924Stheraventemplate<class _Tp> 4960232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4961232924Stheravenbool 4962232924Stheravenoperator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4963232924Stheraven{ 4964232924Stheraven return less<_Tp*>()(nullptr, __x.get()); 4965232924Stheraven} 4966232924Stheraven 4967232924Stheraventemplate<class _Tp> 4968232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4969232924Stheravenbool 4970232924Stheravenoperator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4971232924Stheraven{ 4972232924Stheraven return nullptr < __x; 4973232924Stheraven} 4974232924Stheraven 4975232924Stheraventemplate<class _Tp> 4976232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4977232924Stheravenbool 4978232924Stheravenoperator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4979232924Stheraven{ 4980232924Stheraven return __x < nullptr; 4981232924Stheraven} 4982232924Stheraven 4983232924Stheraventemplate<class _Tp> 4984232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4985232924Stheravenbool 4986232924Stheravenoperator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 4987232924Stheraven{ 4988232924Stheraven return !(nullptr < __x); 4989232924Stheraven} 4990232924Stheraven 4991232924Stheraventemplate<class _Tp> 4992232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 4993232924Stheravenbool 4994232924Stheravenoperator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 4995232924Stheraven{ 4996232924Stheraven return !(__x < nullptr); 4997232924Stheraven} 4998232924Stheraven 4999232924Stheraventemplate<class _Tp> 5000232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 5001232924Stheravenbool 5002232924Stheravenoperator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT 5003232924Stheraven{ 5004232924Stheraven return !(__x < nullptr); 5005232924Stheraven} 5006232924Stheraven 5007232924Stheraventemplate<class _Tp> 5008232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 5009232924Stheravenbool 5010232924Stheravenoperator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT 5011232924Stheraven{ 5012232924Stheraven return !(nullptr < __x); 5013232924Stheraven} 5014232924Stheraven 5015232924Stheraventemplate<class _Tp> 5016232924Stheraveninline _LIBCPP_INLINE_VISIBILITY 5017227825Stheravenvoid 5018227825Stheravenswap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT 5019227825Stheraven{ 5020227825Stheraven __x.swap(__y); 5021227825Stheraven} 5022227825Stheraven 5023227825Stheraventemplate<class _Tp, class _Up> 5024227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 5025232924Stheraventypename enable_if 5026232924Stheraven< 5027232924Stheraven !is_array<_Tp>::value && !is_array<_Up>::value, 5028232924Stheraven shared_ptr<_Tp> 5029232924Stheraven>::type 5030227825Stheravenstatic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 5031227825Stheraven{ 5032227825Stheraven return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); 5033227825Stheraven} 5034227825Stheraven 5035227825Stheraventemplate<class _Tp, class _Up> 5036227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 5037232924Stheraventypename enable_if 5038232924Stheraven< 5039232924Stheraven !is_array<_Tp>::value && !is_array<_Up>::value, 5040232924Stheraven shared_ptr<_Tp> 5041232924Stheraven>::type 5042227825Stheravendynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 5043227825Stheraven{ 5044227825Stheraven _Tp* __p = dynamic_cast<_Tp*>(__r.get()); 5045227825Stheraven return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); 5046227825Stheraven} 5047227825Stheraven 5048227825Stheraventemplate<class _Tp, class _Up> 5049232924Stheraventypename enable_if 5050232924Stheraven< 5051232924Stheraven is_array<_Tp>::value == is_array<_Up>::value, 5052232924Stheraven shared_ptr<_Tp> 5053232924Stheraven>::type 5054227825Stheravenconst_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT 5055227825Stheraven{ 5056232924Stheraven typedef typename remove_extent<_Tp>::type _RTp; 5057232924Stheraven return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); 5058227825Stheraven} 5059227825Stheraven 5060227825Stheraven#ifndef _LIBCPP_NO_RTTI 5061227825Stheraven 5062227825Stheraventemplate<class _Dp, class _Tp> 5063227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 5064227825Stheraven_Dp* 5065227825Stheravenget_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT 5066227825Stheraven{ 5067227825Stheraven return __p.template __get_deleter<_Dp>(); 5068227825Stheraven} 5069227825Stheraven 5070227825Stheraven#endif // _LIBCPP_NO_RTTI 5071227825Stheraven 5072227825Stheraventemplate<class _Tp> 5073261272Sdimclass _LIBCPP_TYPE_VIS_ONLY weak_ptr 5074227825Stheraven{ 5075227825Stheravenpublic: 5076227825Stheraven typedef _Tp element_type; 5077227825Stheravenprivate: 5078227825Stheraven element_type* __ptr_; 5079227825Stheraven __shared_weak_count* __cntrl_; 5080227825Stheraven 5081227825Stheravenpublic: 5082300770Sdim _LIBCPP_INLINE_VISIBILITY 5083241900Sdim _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; 5084300770Sdim template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r, 5085227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 5086227825Stheraven _NOEXCEPT; 5087300770Sdim _LIBCPP_INLINE_VISIBILITY 5088227825Stheraven weak_ptr(weak_ptr const& __r) _NOEXCEPT; 5089300770Sdim template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r, 5090227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 5091227825Stheraven _NOEXCEPT; 5092227825Stheraven 5093232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5094300770Sdim _LIBCPP_INLINE_VISIBILITY 5095232924Stheraven weak_ptr(weak_ptr&& __r) _NOEXCEPT; 5096300770Sdim template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r, 5097232924Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) 5098232924Stheraven _NOEXCEPT; 5099232924Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5100227825Stheraven ~weak_ptr(); 5101227825Stheraven 5102300770Sdim _LIBCPP_INLINE_VISIBILITY 5103227825Stheraven weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; 5104232924Stheraven template<class _Yp> 5105232924Stheraven typename enable_if 5106232924Stheraven < 5107232924Stheraven is_convertible<_Yp*, element_type*>::value, 5108232924Stheraven weak_ptr& 5109232924Stheraven >::type 5110300770Sdim _LIBCPP_INLINE_VISIBILITY 5111232924Stheraven operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; 5112227825Stheraven 5113232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5114232924Stheraven 5115300770Sdim _LIBCPP_INLINE_VISIBILITY 5116232924Stheraven weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; 5117232924Stheraven template<class _Yp> 5118232924Stheraven typename enable_if 5119232924Stheraven < 5120232924Stheraven is_convertible<_Yp*, element_type*>::value, 5121232924Stheraven weak_ptr& 5122232924Stheraven >::type 5123300770Sdim _LIBCPP_INLINE_VISIBILITY 5124232924Stheraven operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; 5125232924Stheraven 5126232924Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5127232924Stheraven 5128232924Stheraven template<class _Yp> 5129232924Stheraven typename enable_if 5130232924Stheraven < 5131232924Stheraven is_convertible<_Yp*, element_type*>::value, 5132232924Stheraven weak_ptr& 5133232924Stheraven >::type 5134300770Sdim _LIBCPP_INLINE_VISIBILITY 5135232924Stheraven operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; 5136232924Stheraven 5137300770Sdim _LIBCPP_INLINE_VISIBILITY 5138227825Stheraven void swap(weak_ptr& __r) _NOEXCEPT; 5139300770Sdim _LIBCPP_INLINE_VISIBILITY 5140227825Stheraven void reset() _NOEXCEPT; 5141227825Stheraven 5142227825Stheraven _LIBCPP_INLINE_VISIBILITY 5143227825Stheraven long use_count() const _NOEXCEPT 5144227825Stheraven {return __cntrl_ ? __cntrl_->use_count() : 0;} 5145227825Stheraven _LIBCPP_INLINE_VISIBILITY 5146227825Stheraven bool expired() const _NOEXCEPT 5147227825Stheraven {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} 5148227825Stheraven shared_ptr<_Tp> lock() const _NOEXCEPT; 5149227825Stheraven template<class _Up> 5150227825Stheraven _LIBCPP_INLINE_VISIBILITY 5151227825Stheraven bool owner_before(const shared_ptr<_Up>& __r) const 5152227825Stheraven {return __cntrl_ < __r.__cntrl_;} 5153227825Stheraven template<class _Up> 5154227825Stheraven _LIBCPP_INLINE_VISIBILITY 5155227825Stheraven bool owner_before(const weak_ptr<_Up>& __r) const 5156227825Stheraven {return __cntrl_ < __r.__cntrl_;} 5157227825Stheraven 5158261272Sdim template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr; 5159261272Sdim template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr; 5160227825Stheraven}; 5161227825Stheraven 5162227825Stheraventemplate<class _Tp> 5163300770Sdiminline 5164241900Sdim_LIBCPP_CONSTEXPR 5165227825Stheravenweak_ptr<_Tp>::weak_ptr() _NOEXCEPT 5166227825Stheraven : __ptr_(0), 5167227825Stheraven __cntrl_(0) 5168227825Stheraven{ 5169227825Stheraven} 5170227825Stheraven 5171227825Stheraventemplate<class _Tp> 5172300770Sdiminline 5173227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT 5174227825Stheraven : __ptr_(__r.__ptr_), 5175227825Stheraven __cntrl_(__r.__cntrl_) 5176227825Stheraven{ 5177227825Stheraven if (__cntrl_) 5178227825Stheraven __cntrl_->__add_weak(); 5179227825Stheraven} 5180227825Stheraven 5181227825Stheraventemplate<class _Tp> 5182227825Stheraventemplate<class _Yp> 5183300770Sdiminline 5184227825Stheravenweak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, 5185227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 5186227825Stheraven _NOEXCEPT 5187227825Stheraven : __ptr_(__r.__ptr_), 5188227825Stheraven __cntrl_(__r.__cntrl_) 5189227825Stheraven{ 5190227825Stheraven if (__cntrl_) 5191227825Stheraven __cntrl_->__add_weak(); 5192227825Stheraven} 5193227825Stheraven 5194227825Stheraventemplate<class _Tp> 5195227825Stheraventemplate<class _Yp> 5196300770Sdiminline 5197227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, 5198227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 5199227825Stheraven _NOEXCEPT 5200227825Stheraven : __ptr_(__r.__ptr_), 5201227825Stheraven __cntrl_(__r.__cntrl_) 5202227825Stheraven{ 5203227825Stheraven if (__cntrl_) 5204227825Stheraven __cntrl_->__add_weak(); 5205227825Stheraven} 5206227825Stheraven 5207232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5208232924Stheraven 5209227825Stheraventemplate<class _Tp> 5210300770Sdiminline 5211232924Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT 5212232924Stheraven : __ptr_(__r.__ptr_), 5213232924Stheraven __cntrl_(__r.__cntrl_) 5214232924Stheraven{ 5215232924Stheraven __r.__ptr_ = 0; 5216232924Stheraven __r.__cntrl_ = 0; 5217232924Stheraven} 5218232924Stheraven 5219232924Stheraventemplate<class _Tp> 5220232924Stheraventemplate<class _Yp> 5221300770Sdiminline 5222232924Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, 5223232924Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) 5224232924Stheraven _NOEXCEPT 5225232924Stheraven : __ptr_(__r.__ptr_), 5226232924Stheraven __cntrl_(__r.__cntrl_) 5227232924Stheraven{ 5228232924Stheraven __r.__ptr_ = 0; 5229232924Stheraven __r.__cntrl_ = 0; 5230232924Stheraven} 5231232924Stheraven 5232232924Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5233232924Stheraven 5234232924Stheraventemplate<class _Tp> 5235227825Stheravenweak_ptr<_Tp>::~weak_ptr() 5236227825Stheraven{ 5237227825Stheraven if (__cntrl_) 5238227825Stheraven __cntrl_->__release_weak(); 5239227825Stheraven} 5240227825Stheraven 5241227825Stheraventemplate<class _Tp> 5242300770Sdiminline 5243227825Stheravenweak_ptr<_Tp>& 5244227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT 5245227825Stheraven{ 5246227825Stheraven weak_ptr(__r).swap(*this); 5247227825Stheraven return *this; 5248227825Stheraven} 5249227825Stheraven 5250227825Stheraventemplate<class _Tp> 5251227825Stheraventemplate<class _Yp> 5252300770Sdiminline 5253232924Stheraventypename enable_if 5254232924Stheraven< 5255232924Stheraven is_convertible<_Yp*, _Tp*>::value, 5256232924Stheraven weak_ptr<_Tp>& 5257232924Stheraven>::type 5258227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT 5259227825Stheraven{ 5260227825Stheraven weak_ptr(__r).swap(*this); 5261227825Stheraven return *this; 5262227825Stheraven} 5263227825Stheraven 5264232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5265232924Stheraven 5266227825Stheraventemplate<class _Tp> 5267300770Sdiminline 5268232924Stheravenweak_ptr<_Tp>& 5269232924Stheravenweak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT 5270232924Stheraven{ 5271232924Stheraven weak_ptr(_VSTD::move(__r)).swap(*this); 5272232924Stheraven return *this; 5273232924Stheraven} 5274232924Stheraven 5275232924Stheraventemplate<class _Tp> 5276227825Stheraventemplate<class _Yp> 5277300770Sdiminline 5278232924Stheraventypename enable_if 5279232924Stheraven< 5280232924Stheraven is_convertible<_Yp*, _Tp*>::value, 5281232924Stheraven weak_ptr<_Tp>& 5282232924Stheraven>::type 5283232924Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT 5284232924Stheraven{ 5285232924Stheraven weak_ptr(_VSTD::move(__r)).swap(*this); 5286232924Stheraven return *this; 5287232924Stheraven} 5288232924Stheraven 5289232924Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5290232924Stheraven 5291232924Stheraventemplate<class _Tp> 5292232924Stheraventemplate<class _Yp> 5293300770Sdiminline 5294232924Stheraventypename enable_if 5295232924Stheraven< 5296232924Stheraven is_convertible<_Yp*, _Tp*>::value, 5297232924Stheraven weak_ptr<_Tp>& 5298232924Stheraven>::type 5299227825Stheravenweak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT 5300227825Stheraven{ 5301227825Stheraven weak_ptr(__r).swap(*this); 5302227825Stheraven return *this; 5303227825Stheraven} 5304227825Stheraven 5305227825Stheraventemplate<class _Tp> 5306300770Sdiminline 5307227825Stheravenvoid 5308227825Stheravenweak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT 5309227825Stheraven{ 5310227825Stheraven _VSTD::swap(__ptr_, __r.__ptr_); 5311227825Stheraven _VSTD::swap(__cntrl_, __r.__cntrl_); 5312227825Stheraven} 5313227825Stheraven 5314227825Stheraventemplate<class _Tp> 5315227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 5316227825Stheravenvoid 5317227825Stheravenswap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT 5318227825Stheraven{ 5319227825Stheraven __x.swap(__y); 5320227825Stheraven} 5321227825Stheraven 5322227825Stheraventemplate<class _Tp> 5323300770Sdiminline 5324227825Stheravenvoid 5325227825Stheravenweak_ptr<_Tp>::reset() _NOEXCEPT 5326227825Stheraven{ 5327227825Stheraven weak_ptr().swap(*this); 5328227825Stheraven} 5329227825Stheraven 5330227825Stheraventemplate<class _Tp> 5331227825Stheraventemplate<class _Yp> 5332227825Stheravenshared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, 5333227825Stheraven typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) 5334227825Stheraven : __ptr_(__r.__ptr_), 5335227825Stheraven __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) 5336227825Stheraven{ 5337227825Stheraven if (__cntrl_ == 0) 5338227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 5339227825Stheraven throw bad_weak_ptr(); 5340227825Stheraven#else 5341227825Stheraven assert(!"bad_weak_ptr"); 5342227825Stheraven#endif 5343227825Stheraven} 5344227825Stheraven 5345227825Stheraventemplate<class _Tp> 5346227825Stheravenshared_ptr<_Tp> 5347227825Stheravenweak_ptr<_Tp>::lock() const _NOEXCEPT 5348227825Stheraven{ 5349227825Stheraven shared_ptr<_Tp> __r; 5350227825Stheraven __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; 5351227825Stheraven if (__r.__cntrl_) 5352227825Stheraven __r.__ptr_ = __ptr_; 5353227825Stheraven return __r; 5354227825Stheraven} 5355227825Stheraven 5356300770Sdim#if _LIBCPP_STD_VER > 14 5357300770Sdimtemplate <class _Tp = void> struct owner_less; 5358300770Sdim#else 5359227825Stheraventemplate <class _Tp> struct owner_less; 5360300770Sdim#endif 5361227825Stheraven 5362227825Stheraventemplate <class _Tp> 5363261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> > 5364227825Stheraven : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> 5365227825Stheraven{ 5366227825Stheraven typedef bool result_type; 5367227825Stheraven _LIBCPP_INLINE_VISIBILITY 5368227825Stheraven bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const 5369227825Stheraven {return __x.owner_before(__y);} 5370227825Stheraven _LIBCPP_INLINE_VISIBILITY 5371227825Stheraven bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const 5372227825Stheraven {return __x.owner_before(__y);} 5373227825Stheraven _LIBCPP_INLINE_VISIBILITY 5374227825Stheraven bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const 5375227825Stheraven {return __x.owner_before(__y);} 5376227825Stheraven}; 5377227825Stheraven 5378227825Stheraventemplate <class _Tp> 5379261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> > 5380227825Stheraven : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> 5381227825Stheraven{ 5382227825Stheraven typedef bool result_type; 5383227825Stheraven _LIBCPP_INLINE_VISIBILITY 5384227825Stheraven bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const 5385227825Stheraven {return __x.owner_before(__y);} 5386227825Stheraven _LIBCPP_INLINE_VISIBILITY 5387227825Stheraven bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const 5388227825Stheraven {return __x.owner_before(__y);} 5389227825Stheraven _LIBCPP_INLINE_VISIBILITY 5390227825Stheraven bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const 5391227825Stheraven {return __x.owner_before(__y);} 5392227825Stheraven}; 5393227825Stheraven 5394300770Sdim#if _LIBCPP_STD_VER > 14 5395300770Sdimtemplate <> 5396300770Sdimstruct _LIBCPP_TYPE_VIS_ONLY owner_less<void> 5397300770Sdim{ 5398300770Sdim template <class _Tp, class _Up> 5399300770Sdim _LIBCPP_INLINE_VISIBILITY 5400300770Sdim bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const 5401300770Sdim {return __x.owner_before(__y);} 5402300770Sdim template <class _Tp, class _Up> 5403300770Sdim _LIBCPP_INLINE_VISIBILITY 5404300770Sdim bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const 5405300770Sdim {return __x.owner_before(__y);} 5406300770Sdim template <class _Tp, class _Up> 5407300770Sdim _LIBCPP_INLINE_VISIBILITY 5408300770Sdim bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const 5409300770Sdim {return __x.owner_before(__y);} 5410300770Sdim template <class _Tp, class _Up> 5411300770Sdim _LIBCPP_INLINE_VISIBILITY 5412300770Sdim bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const 5413300770Sdim {return __x.owner_before(__y);} 5414300770Sdim typedef void is_transparent; 5415300770Sdim}; 5416300770Sdim#endif 5417300770Sdim 5418227825Stheraventemplate<class _Tp> 5419261272Sdimclass _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this 5420227825Stheraven{ 5421227825Stheraven mutable weak_ptr<_Tp> __weak_this_; 5422227825Stheravenprotected: 5423241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 5424227825Stheraven enable_shared_from_this() _NOEXCEPT {} 5425227825Stheraven _LIBCPP_INLINE_VISIBILITY 5426227825Stheraven enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} 5427227825Stheraven _LIBCPP_INLINE_VISIBILITY 5428227825Stheraven enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT 5429227825Stheraven {return *this;} 5430227825Stheraven _LIBCPP_INLINE_VISIBILITY 5431227825Stheraven ~enable_shared_from_this() {} 5432227825Stheravenpublic: 5433227825Stheraven _LIBCPP_INLINE_VISIBILITY 5434227825Stheraven shared_ptr<_Tp> shared_from_this() 5435227825Stheraven {return shared_ptr<_Tp>(__weak_this_);} 5436227825Stheraven _LIBCPP_INLINE_VISIBILITY 5437227825Stheraven shared_ptr<_Tp const> shared_from_this() const 5438227825Stheraven {return shared_ptr<const _Tp>(__weak_this_);} 5439227825Stheraven 5440227825Stheraven template <class _Up> friend class shared_ptr; 5441227825Stheraven}; 5442227825Stheraven 5443227825Stheraventemplate <class _Tp> 5444261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> > 5445227825Stheraven{ 5446227825Stheraven typedef shared_ptr<_Tp> argument_type; 5447227825Stheraven typedef size_t result_type; 5448227825Stheraven _LIBCPP_INLINE_VISIBILITY 5449227825Stheraven result_type operator()(const argument_type& __ptr) const _NOEXCEPT 5450227825Stheraven { 5451227825Stheraven return hash<_Tp*>()(__ptr.get()); 5452227825Stheraven } 5453227825Stheraven}; 5454227825Stheraven 5455232924Stheraventemplate<class _CharT, class _Traits, class _Yp> 5456227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 5457227825Stheravenbasic_ostream<_CharT, _Traits>& 5458232924Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); 5459227825Stheraven 5460300770Sdim// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only 5461300770Sdim// enabled with clang. 5462300770Sdim#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) 5463241900Sdim 5464261272Sdimclass _LIBCPP_TYPE_VIS __sp_mut 5465241900Sdim{ 5466242939Stheraven void* __lx; 5467241900Sdimpublic: 5468241900Sdim void lock() _NOEXCEPT; 5469241900Sdim void unlock() _NOEXCEPT; 5470241900Sdim 5471241900Sdimprivate: 5472241900Sdim _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; 5473241900Sdim __sp_mut(const __sp_mut&); 5474241900Sdim __sp_mut& operator=(const __sp_mut&); 5475241900Sdim 5476249989Sdim friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); 5477241900Sdim}; 5478241900Sdim 5479249989Sdim_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); 5480241900Sdim 5481241900Sdimtemplate <class _Tp> 5482241900Sdiminline _LIBCPP_INLINE_VISIBILITY 5483241900Sdimbool 5484241900Sdimatomic_is_lock_free(const shared_ptr<_Tp>*) 5485241900Sdim{ 5486241900Sdim return false; 5487241900Sdim} 5488241900Sdim 5489241900Sdimtemplate <class _Tp> 5490241900Sdimshared_ptr<_Tp> 5491241900Sdimatomic_load(const shared_ptr<_Tp>* __p) 5492241900Sdim{ 5493241900Sdim __sp_mut& __m = __get_sp_mut(__p); 5494241900Sdim __m.lock(); 5495241900Sdim shared_ptr<_Tp> __q = *__p; 5496241900Sdim __m.unlock(); 5497241900Sdim return __q; 5498241900Sdim} 5499241900Sdim 5500241900Sdimtemplate <class _Tp> 5501241900Sdiminline _LIBCPP_INLINE_VISIBILITY 5502241900Sdimshared_ptr<_Tp> 5503241900Sdimatomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) 5504241900Sdim{ 5505241900Sdim return atomic_load(__p); 5506241900Sdim} 5507241900Sdim 5508241900Sdimtemplate <class _Tp> 5509241900Sdimvoid 5510241900Sdimatomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) 5511241900Sdim{ 5512241900Sdim __sp_mut& __m = __get_sp_mut(__p); 5513241900Sdim __m.lock(); 5514241900Sdim __p->swap(__r); 5515241900Sdim __m.unlock(); 5516241900Sdim} 5517241900Sdim 5518241900Sdimtemplate <class _Tp> 5519241900Sdiminline _LIBCPP_INLINE_VISIBILITY 5520241900Sdimvoid 5521241900Sdimatomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) 5522241900Sdim{ 5523241900Sdim atomic_store(__p, __r); 5524241900Sdim} 5525241900Sdim 5526241900Sdimtemplate <class _Tp> 5527241900Sdimshared_ptr<_Tp> 5528241900Sdimatomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) 5529241900Sdim{ 5530241900Sdim __sp_mut& __m = __get_sp_mut(__p); 5531241900Sdim __m.lock(); 5532241900Sdim __p->swap(__r); 5533241900Sdim __m.unlock(); 5534241900Sdim return __r; 5535241900Sdim} 5536241900Sdim 5537241900Sdimtemplate <class _Tp> 5538241900Sdiminline _LIBCPP_INLINE_VISIBILITY 5539241900Sdimshared_ptr<_Tp> 5540241900Sdimatomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) 5541241900Sdim{ 5542241900Sdim return atomic_exchange(__p, __r); 5543241900Sdim} 5544241900Sdim 5545241900Sdimtemplate <class _Tp> 5546241900Sdimbool 5547241900Sdimatomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) 5548241900Sdim{ 5549241900Sdim __sp_mut& __m = __get_sp_mut(__p); 5550241900Sdim __m.lock(); 5551241900Sdim if (__p->__owner_equivalent(*__v)) 5552241900Sdim { 5553241900Sdim *__p = __w; 5554241900Sdim __m.unlock(); 5555241900Sdim return true; 5556241900Sdim } 5557241900Sdim *__v = *__p; 5558241900Sdim __m.unlock(); 5559241900Sdim return false; 5560241900Sdim} 5561241900Sdim 5562241900Sdimtemplate <class _Tp> 5563241900Sdiminline _LIBCPP_INLINE_VISIBILITY 5564241900Sdimbool 5565241900Sdimatomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) 5566241900Sdim{ 5567241900Sdim return atomic_compare_exchange_strong(__p, __v, __w); 5568241900Sdim} 5569241900Sdim 5570241900Sdimtemplate <class _Tp> 5571241900Sdiminline _LIBCPP_INLINE_VISIBILITY 5572241900Sdimbool 5573241900Sdimatomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, 5574241900Sdim shared_ptr<_Tp> __w, memory_order, memory_order) 5575241900Sdim{ 5576241900Sdim return atomic_compare_exchange_strong(__p, __v, __w); 5577241900Sdim} 5578241900Sdim 5579241900Sdimtemplate <class _Tp> 5580241900Sdiminline _LIBCPP_INLINE_VISIBILITY 5581241900Sdimbool 5582241900Sdimatomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, 5583241900Sdim shared_ptr<_Tp> __w, memory_order, memory_order) 5584241900Sdim{ 5585241900Sdim return atomic_compare_exchange_weak(__p, __v, __w); 5586241900Sdim} 5587241900Sdim 5588300770Sdim#endif // defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) 5589241900Sdim 5590227825Stheraven//enum class 5591249989Sdimstruct _LIBCPP_TYPE_VIS pointer_safety 5592227825Stheraven{ 5593242939Stheraven enum __lx 5594227825Stheraven { 5595227825Stheraven relaxed, 5596227825Stheraven preferred, 5597227825Stheraven strict 5598227825Stheraven }; 5599227825Stheraven 5600242939Stheraven __lx __v_; 5601227825Stheraven 5602227825Stheraven _LIBCPP_INLINE_VISIBILITY 5603242939Stheraven pointer_safety(__lx __v) : __v_(__v) {} 5604227825Stheraven _LIBCPP_INLINE_VISIBILITY 5605227825Stheraven operator int() const {return __v_;} 5606227825Stheraven}; 5607227825Stheraven 5608261272Sdim_LIBCPP_FUNC_VIS void declare_reachable(void* __p); 5609261272Sdim_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); 5610261272Sdim_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); 5611261272Sdim_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; 5612261272Sdim_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); 5613227825Stheraven 5614227825Stheraventemplate <class _Tp> 5615227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 5616227825Stheraven_Tp* 5617227825Stheravenundeclare_reachable(_Tp* __p) 5618227825Stheraven{ 5619227825Stheraven return static_cast<_Tp*>(__undeclare_reachable(__p)); 5620227825Stheraven} 5621227825Stheraven 5622261272Sdim_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); 5623227825Stheraven 5624288943Sdim// --- Helper for container swap -- 5625288943Sdimtemplate <typename _Alloc> 5626288943Sdim_LIBCPP_INLINE_VISIBILITY 5627288943Sdimvoid __swap_allocator(_Alloc & __a1, _Alloc & __a2) 5628288943Sdim#if _LIBCPP_STD_VER >= 14 5629288943Sdim _NOEXCEPT 5630288943Sdim#else 5631288943Sdim _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 5632288943Sdim#endif 5633288943Sdim{ 5634288943Sdim __swap_allocator(__a1, __a2, 5635288943Sdim integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); 5636288943Sdim} 5637288943Sdim 5638288943Sdimtemplate <typename _Alloc> 5639288943Sdim_LIBCPP_INLINE_VISIBILITY 5640288943Sdimvoid __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) 5641288943Sdim#if _LIBCPP_STD_VER >= 14 5642288943Sdim _NOEXCEPT 5643288943Sdim#else 5644288943Sdim _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 5645288943Sdim#endif 5646288943Sdim{ 5647288943Sdim using _VSTD::swap; 5648288943Sdim swap(__a1, __a2); 5649288943Sdim} 5650288943Sdim 5651288943Sdimtemplate <typename _Alloc> 5652288943Sdim_LIBCPP_INLINE_VISIBILITY 5653288943Sdimvoid __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} 5654288943Sdim 5655300770Sdimtemplate <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > 5656300770Sdimstruct __noexcept_move_assign_container : public integral_constant<bool, 5657300770Sdim _Traits::propagate_on_container_move_assignment::value 5658300770Sdim#if _LIBCPP_STD_VER > 14 5659300770Sdim || _Traits::is_always_equal::value 5660300770Sdim#else 5661300770Sdim && is_nothrow_move_assignable<_Alloc>::value 5662300770Sdim#endif 5663300770Sdim > {}; 5664288943Sdim 5665227825Stheraven_LIBCPP_END_NAMESPACE_STD 5666227825Stheraven 5667227825Stheraven#endif // _LIBCPP_MEMORY 5668