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