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