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