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