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