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