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