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