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