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