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