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