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