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