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