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