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