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; |
| 78 | |
| 79 | template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>; |
| 80 | template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; |
| 81 | |
| 82 | static pointer allocate(allocator_type& a, size_type n); |
| 83 | static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); |
| 84 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 85 | static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | |
| 87 | template <class T, class... Args> |
| 88 | static void construct(allocator_type& a, T* p, Args&&... args); |
| 89 | |
| 90 | template <class T> |
| 91 | static void destroy(allocator_type& a, T* p); |
| 92 | |
| 93 | static size_type max_size(const allocator_type& a); |
| 94 | |
| 95 | static allocator_type |
| 96 | select_on_container_copy_construction(const allocator_type& a); |
| 97 | }; |
| 98 | |
| 99 | template <> |
| 100 | class allocator<void> |
| 101 | { |
| 102 | public: |
| 103 | typedef void* pointer; |
| 104 | typedef const void* const_pointer; |
| 105 | typedef void value_type; |
| 106 | |
| 107 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 108 | }; |
| 109 | |
| 110 | template <class T> |
| 111 | class allocator |
| 112 | { |
| 113 | public: |
| 114 | typedef size_t size_type; |
| 115 | typedef ptrdiff_t difference_type; |
| 116 | typedef T* pointer; |
| 117 | typedef const T* const_pointer; |
| 118 | typedef typename add_lvalue_reference<T>::type reference; |
| 119 | typedef typename add_lvalue_reference<const T>::type const_reference; |
| 120 | typedef T value_type; |
| 121 | |
| 122 | template <class U> struct rebind {typedef allocator<U> other;}; |
| 123 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 124 | allocator() noexcept; |
| 125 | allocator(const allocator&) noexcept; |
| 126 | template <class U> allocator(const allocator<U>&) noexcept; |
| 127 | ~allocator(); |
| 128 | pointer address(reference x) const noexcept; |
| 129 | const_pointer address(const_reference x) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 130 | pointer allocate(size_type, allocator<void>::const_pointer hint = 0); |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 131 | void deallocate(pointer p, size_type n) noexcept; |
| 132 | size_type max_size() const noexcept; |
| 133 | template<class U, class... Args> |
| 134 | void construct(U* p, Args&&... args); |
| 135 | template <class U> |
| 136 | void destroy(U* p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | template <class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 140 | bool operator==(const allocator<T>&, const allocator<U>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 141 | |
| 142 | template <class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 143 | bool operator!=(const allocator<T>&, const allocator<U>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | |
| 145 | template <class OutputIterator, class T> |
| 146 | class raw_storage_iterator |
| 147 | : public iterator<output_iterator_tag, |
| 148 | T, // purposefully not C++03 |
| 149 | ptrdiff_t, // purposefully not C++03 |
| 150 | T*, // purposefully not C++03 |
| 151 | raw_storage_iterator&> // purposefully not C++03 |
| 152 | { |
| 153 | public: |
| 154 | explicit raw_storage_iterator(OutputIterator x); |
| 155 | raw_storage_iterator& operator*(); |
| 156 | raw_storage_iterator& operator=(const T& element); |
| 157 | raw_storage_iterator& operator++(); |
| 158 | raw_storage_iterator operator++(int); |
| 159 | }; |
| 160 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 161 | template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; |
| 162 | template <class T> void return_temporary_buffer(T* p) noexcept; |
| 163 | |
| 164 | template <class T> T* addressof(T& r) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 165 | |
| 166 | template <class InputIterator, class ForwardIterator> |
| 167 | ForwardIterator |
| 168 | uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); |
| 169 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 170 | template <class InputIterator, class Size, class ForwardIterator> |
| 171 | ForwardIterator |
| 172 | uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); |
| 173 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 174 | template <class ForwardIterator, class T> |
| 175 | void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); |
| 176 | |
| 177 | template <class ForwardIterator, class Size, class T> |
Howard Hinnant | 2f6a627 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 178 | ForwardIterator |
| 179 | uninitialized_fill_n(ForwardIterator first, Size n, const T& x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 180 | |
| 181 | template <class Y> struct auto_ptr_ref {}; |
| 182 | |
| 183 | template<class X> |
| 184 | class auto_ptr |
| 185 | { |
| 186 | public: |
| 187 | typedef X element_type; |
| 188 | |
| 189 | explicit auto_ptr(X* p =0) throw(); |
| 190 | auto_ptr(auto_ptr&) throw(); |
| 191 | template<class Y> auto_ptr(auto_ptr<Y>&) throw(); |
| 192 | auto_ptr& operator=(auto_ptr&) throw(); |
| 193 | template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw(); |
| 194 | auto_ptr& operator=(auto_ptr_ref<X> r) throw(); |
| 195 | ~auto_ptr() throw(); |
| 196 | |
| 197 | typename add_lvalue_reference<X>::type operator*() const throw(); |
| 198 | X* operator->() const throw(); |
| 199 | X* get() const throw(); |
| 200 | X* release() throw(); |
| 201 | void reset(X* p =0) throw(); |
| 202 | |
| 203 | auto_ptr(auto_ptr_ref<X>) throw(); |
| 204 | template<class Y> operator auto_ptr_ref<Y>() throw(); |
| 205 | template<class Y> operator auto_ptr<Y>() throw(); |
| 206 | }; |
| 207 | |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 208 | template <class T> |
| 209 | struct default_delete |
| 210 | { |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 211 | constexpr default_delete() noexcept = default; |
| 212 | template <class U> default_delete(const default_delete<U>&) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 213 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 214 | void operator()(T*) const noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | template <class T> |
| 218 | struct default_delete<T[]> |
| 219 | { |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 220 | constexpr default_delete() noexcept = default; |
| 221 | void operator()(T*) const noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 222 | template <class U> void operator()(U*) const = delete; |
| 223 | }; |
| 224 | |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 225 | template <class T, class D = default_delete<T>> |
| 226 | class unique_ptr |
| 227 | { |
| 228 | public: |
| 229 | typedef see below pointer; |
| 230 | typedef T element_type; |
| 231 | typedef D deleter_type; |
| 232 | |
| 233 | // constructors |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 234 | constexpr unique_ptr() noexcept; |
| 235 | explicit unique_ptr(pointer p) noexcept; |
| 236 | unique_ptr(pointer p, see below d1) noexcept; |
| 237 | unique_ptr(pointer p, see below d2) noexcept; |
| 238 | unique_ptr(unique_ptr&& u) noexcept; |
| 239 | unique_ptr(nullptr_t) noexcept : unique_ptr() { } |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 240 | template <class U, class E> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 241 | unique_ptr(unique_ptr<U, E>&& u) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 242 | template <class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 243 | unique_ptr(auto_ptr<U>&& u) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 244 | |
| 245 | // destructor |
| 246 | ~unique_ptr(); |
| 247 | |
| 248 | // assignment |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 249 | unique_ptr& operator=(unique_ptr&& u) noexcept; |
| 250 | template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; |
| 251 | unique_ptr& operator=(nullptr_t) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 252 | |
| 253 | // observers |
| 254 | typename add_lvalue_reference<T>::type operator*() const; |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 255 | pointer operator->() const noexcept; |
| 256 | pointer get() const noexcept; |
| 257 | deleter_type& get_deleter() noexcept; |
| 258 | const deleter_type& get_deleter() const noexcept; |
| 259 | explicit operator bool() const noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 260 | |
| 261 | // modifiers |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 262 | pointer release() noexcept; |
| 263 | void reset(pointer p = pointer()) noexcept; |
| 264 | void swap(unique_ptr& u) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | template <class T, class D> |
| 268 | class unique_ptr<T[], D> |
| 269 | { |
| 270 | public: |
| 271 | typedef implementation-defined pointer; |
| 272 | typedef T element_type; |
| 273 | typedef D deleter_type; |
| 274 | |
| 275 | // constructors |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 276 | constexpr unique_ptr() noexcept; |
| 277 | explicit unique_ptr(pointer p) noexcept; |
| 278 | unique_ptr(pointer p, see below d) noexcept; |
| 279 | unique_ptr(pointer p, see below d) noexcept; |
| 280 | unique_ptr(unique_ptr&& u) noexcept; |
| 281 | unique_ptr(nullptr_t) noexcept : unique_ptr() { } |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 282 | |
| 283 | // destructor |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 284 | ~unique_ptr(); |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 285 | |
| 286 | // assignment |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 287 | unique_ptr& operator=(unique_ptr&& u) noexcept; |
| 288 | unique_ptr& operator=(nullptr_t) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 289 | |
| 290 | // observers |
| 291 | T& operator[](size_t i) const; |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 292 | pointer get() const noexcept; |
| 293 | deleter_type& get_deleter() noexcept; |
| 294 | const deleter_type& get_deleter() const noexcept; |
| 295 | explicit operator bool() const noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 296 | |
| 297 | // modifiers |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 298 | pointer release() noexcept; |
| 299 | void reset(pointer p = pointer()) noexcept; |
| 300 | void reset(nullptr_t) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 301 | template <class U> void reset(U) = delete; |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 302 | void swap(unique_ptr& u) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | template <class T, class D> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 306 | 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] | 307 | |
| 308 | template <class T1, class D1, class T2, class D2> |
| 309 | bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 310 | template <class T1, class D1, class T2, class D2> |
| 311 | bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 312 | template <class T1, class D1, class T2, class D2> |
| 313 | bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 314 | template <class T1, class D1, class T2, class D2> |
| 315 | bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 316 | template <class T1, class D1, class T2, class D2> |
| 317 | bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 318 | template <class T1, class D1, class T2, class D2> |
| 319 | bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 320 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 321 | template <class T, class D> |
| 322 | bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; |
| 323 | template <class T, class D> |
| 324 | bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; |
| 325 | template <class T, class D> |
| 326 | bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; |
| 327 | template <class T, class D> |
| 328 | bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; |
| 329 | |
| 330 | template <class T, class D> |
| 331 | bool operator<(const unique_ptr<T, D>& x, nullptr_t); |
| 332 | template <class T, class D> |
| 333 | bool operator<(nullptr_t, const unique_ptr<T, D>& y); |
| 334 | template <class T, class D> |
| 335 | bool operator<=(const unique_ptr<T, D>& x, nullptr_t); |
| 336 | template <class T, class D> |
| 337 | bool operator<=(nullptr_t, const unique_ptr<T, D>& y); |
| 338 | template <class T, class D> |
| 339 | bool operator>(const unique_ptr<T, D>& x, nullptr_t); |
| 340 | template <class T, class D> |
| 341 | bool operator>(nullptr_t, const unique_ptr<T, D>& y); |
| 342 | template <class T, class D> |
| 343 | bool operator>=(const unique_ptr<T, D>& x, nullptr_t); |
| 344 | template <class T, class D> |
| 345 | bool operator>=(nullptr_t, const unique_ptr<T, D>& y); |
| 346 | |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 347 | class bad_weak_ptr |
| 348 | : public std::exception |
| 349 | { |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 350 | bad_weak_ptr() noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | template<class T> |
| 354 | class shared_ptr |
| 355 | { |
| 356 | public: |
| 357 | typedef T element_type; |
| 358 | |
| 359 | // constructors: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 360 | constexpr shared_ptr() noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 361 | template<class Y> explicit shared_ptr(Y* p); |
| 362 | template<class Y, class D> shared_ptr(Y* p, D d); |
| 363 | template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); |
| 364 | template <class D> shared_ptr(nullptr_t p, D d); |
| 365 | 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^] | 366 | template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept; |
| 367 | shared_ptr(const shared_ptr& r) noexcept; |
| 368 | template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept; |
| 369 | shared_ptr(shared_ptr&& r) noexcept; |
| 370 | template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 371 | template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); |
| 372 | template<class Y> shared_ptr(auto_ptr<Y>&& r); |
| 373 | template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); |
| 374 | shared_ptr(nullptr_t) : shared_ptr() { } |
| 375 | |
| 376 | // destructor: |
| 377 | ~shared_ptr(); |
| 378 | |
| 379 | // assignment: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 380 | shared_ptr& operator=(const shared_ptr& r) noexcept; |
| 381 | template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept; |
| 382 | shared_ptr& operator=(shared_ptr&& r) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 383 | template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); |
| 384 | template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); |
| 385 | template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); |
| 386 | |
| 387 | // modifiers: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 388 | void swap(shared_ptr& r) noexcept; |
| 389 | void reset() noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 390 | template<class Y> void reset(Y* p); |
| 391 | template<class Y, class D> void reset(Y* p, D d); |
| 392 | template<class Y, class D, class A> void reset(Y* p, D d, A a); |
| 393 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 394 | // observers: |
| 395 | T* get() const noexcept; |
| 396 | T& operator*() const noexcept; |
| 397 | T* operator->() const noexcept; |
| 398 | long use_count() const noexcept; |
| 399 | bool unique() const noexcept; |
| 400 | explicit operator bool() const noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 401 | template<class U> bool owner_before(shared_ptr<U> const& b) const; |
| 402 | template<class U> bool owner_before(weak_ptr<U> const& b) const; |
| 403 | }; |
| 404 | |
| 405 | // shared_ptr comparisons: |
| 406 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 407 | 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] | 408 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 409 | 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] | 410 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 411 | 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] | 412 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 413 | 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] | 414 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 415 | 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] | 416 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 417 | bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
| 418 | |
| 419 | template <class T> |
| 420 | bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 421 | template <class T> |
| 422 | bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 423 | template <class T> |
| 424 | bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 425 | template <class T> |
| 426 | bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 427 | template <class T> |
| 428 | bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 429 | template <class T> |
| 430 | bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 431 | template <class T> |
| 432 | bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 433 | template <class T> |
| 434 | bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 435 | template <class T> |
| 436 | bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 437 | template <class T> |
| 438 | bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 439 | template <class T> |
| 440 | bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 441 | template <class T> |
| 442 | bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 443 | |
| 444 | // shared_ptr specialized algorithms: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 445 | 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] | 446 | |
| 447 | // shared_ptr casts: |
| 448 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 449 | shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 450 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 451 | shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 452 | template<class T, class U> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 453 | shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 454 | |
| 455 | // shared_ptr I/O: |
| 456 | template<class E, class T, class Y> |
| 457 | basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p); |
| 458 | |
| 459 | // shared_ptr get_deleter: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 460 | 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] | 461 | |
| 462 | template<class T, class... Args> |
| 463 | shared_ptr<T> make_shared(Args&&... args); |
| 464 | template<class T, class A, class... Args> |
| 465 | shared_ptr<T> allocate_shared(const A& a, Args&&... args); |
| 466 | |
| 467 | template<class T> |
| 468 | class weak_ptr |
| 469 | { |
| 470 | public: |
| 471 | typedef T element_type; |
| 472 | |
| 473 | // constructors |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 474 | constexpr weak_ptr() noexcept; |
| 475 | template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; |
| 476 | weak_ptr(weak_ptr const& r) noexcept; |
| 477 | template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 478 | |
| 479 | // destructor |
| 480 | ~weak_ptr(); |
| 481 | |
| 482 | // assignment |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 483 | weak_ptr& operator=(weak_ptr const& r) noexcept; |
| 484 | template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; |
| 485 | template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 486 | |
| 487 | // modifiers |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 488 | void swap(weak_ptr& r) noexcept; |
| 489 | void reset() noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 490 | |
| 491 | // observers |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 492 | long use_count() const noexcept; |
| 493 | bool expired() const noexcept; |
| 494 | shared_ptr<T> lock() const noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 495 | template<class U> bool owner_before(shared_ptr<U> const& b); |
| 496 | template<class U> bool owner_before(weak_ptr<U> const& b); |
| 497 | }; |
| 498 | |
| 499 | // weak_ptr specialized algorithms: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 500 | 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] | 501 | |
| 502 | // class owner_less: |
| 503 | template<class T> struct owner_less; |
| 504 | |
| 505 | template<class T> |
| 506 | struct owner_less<shared_ptr<T>> |
| 507 | : binary_function<shared_ptr<T>, shared_ptr<T>, bool> |
| 508 | { |
| 509 | typedef bool result_type; |
| 510 | bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const; |
| 511 | bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; |
| 512 | bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; |
| 513 | }; |
| 514 | |
| 515 | template<class T> |
| 516 | struct owner_less<weak_ptr<T>> |
| 517 | : binary_function<weak_ptr<T>, weak_ptr<T>, bool> |
| 518 | { |
| 519 | typedef bool result_type; |
| 520 | bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const; |
| 521 | bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; |
| 522 | bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; |
| 523 | }; |
| 524 | |
| 525 | template<class T> |
| 526 | class enable_shared_from_this |
| 527 | { |
| 528 | protected: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 529 | constexpr enable_shared_from_this() noexcept; |
| 530 | enable_shared_from_this(enable_shared_from_this const&) noexcept; |
| 531 | enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 532 | ~enable_shared_from_this(); |
| 533 | public: |
| 534 | shared_ptr<T> shared_from_this(); |
| 535 | shared_ptr<T const> shared_from_this() const; |
| 536 | }; |
| 537 | |
| 538 | template<class T> |
| 539 | bool atomic_is_lock_free(const shared_ptr<T>* p); |
| 540 | template<class T> |
| 541 | shared_ptr<T> atomic_load(const shared_ptr<T>* p); |
| 542 | template<class T> |
| 543 | shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo); |
| 544 | template<class T> |
| 545 | void atomic_store(shared_ptr<T>* p, shared_ptr<T> r); |
| 546 | template<class T> |
| 547 | void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); |
| 548 | template<class T> |
| 549 | shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r); |
| 550 | template<class T> |
| 551 | shared_ptr<T> |
| 552 | atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); |
| 553 | template<class T> |
| 554 | bool |
| 555 | atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); |
| 556 | template<class T> |
| 557 | bool |
| 558 | atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); |
| 559 | template<class T> |
| 560 | bool |
| 561 | atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, |
| 562 | shared_ptr<T> w, memory_order success, |
| 563 | memory_order failure); |
| 564 | template<class T> |
| 565 | bool |
| 566 | atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, |
| 567 | shared_ptr<T> w, memory_order success, |
| 568 | memory_order failure); |
| 569 | // Hash support |
| 570 | template <class T> struct hash; |
| 571 | template <class T, class D> struct hash<unique_ptr<T, D> >; |
| 572 | template <class T> struct hash<shared_ptr<T> >; |
| 573 | |
| 574 | // Pointer safety |
| 575 | enum class pointer_safety { relaxed, preferred, strict }; |
| 576 | void declare_reachable(void *p); |
| 577 | template <class T> T *undeclare_reachable(T *p); |
| 578 | void declare_no_pointers(char *p, size_t n); |
| 579 | void undeclare_no_pointers(char *p, size_t n); |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 580 | pointer_safety get_pointer_safety() noexcept; |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 581 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 582 | void* align(size_t alignment, size_t size, void*& ptr, size_t& space); |
| 583 | |
| 584 | } // std |
| 585 | |
| 586 | */ |
| 587 | |
| 588 | #include <__config> |
| 589 | #include <type_traits> |
| 590 | #include <typeinfo> |
| 591 | #include <cstddef> |
| 592 | #include <cstdint> |
| 593 | #include <new> |
| 594 | #include <utility> |
| 595 | #include <limits> |
| 596 | #include <iterator> |
| 597 | #include <__functional_base> |
| 598 | #if defined(_LIBCPP_NO_EXCEPTIONS) |
| 599 | #include <cassert> |
| 600 | #endif |
| 601 | |
| 602 | #pragma GCC system_header |
| 603 | |
| 604 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 605 | |
| 606 | // allocator_arg_t |
| 607 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 608 | struct _LIBCPP_VISIBLE allocator_arg_t { }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 609 | |
| 610 | extern const allocator_arg_t allocator_arg; |
| 611 | |
| 612 | // addressof |
| 613 | |
| 614 | template <class _Tp> |
| 615 | inline _LIBCPP_INLINE_VISIBILITY |
| 616 | _Tp* |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 617 | addressof(_Tp& __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 618 | { |
| 619 | return (_Tp*)&(char&)__x; |
| 620 | } |
| 621 | |
| 622 | template <class _Tp> class allocator; |
| 623 | |
| 624 | template <> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 625 | class _LIBCPP_VISIBLE allocator<void> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | { |
| 627 | public: |
| 628 | typedef void* pointer; |
| 629 | typedef const void* const_pointer; |
| 630 | typedef void value_type; |
| 631 | |
| 632 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 633 | }; |
| 634 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 635 | // pointer_traits |
| 636 | |
| 637 | template <class _Tp> |
| 638 | struct __has_element_type |
| 639 | { |
| 640 | private: |
| 641 | struct __two {char _; char __;}; |
| 642 | template <class _Up> static __two __test(...); |
| 643 | template <class _Up> static char __test(typename _Up::element_type* = 0); |
| 644 | public: |
| 645 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 646 | }; |
| 647 | |
| 648 | template <class _Ptr, bool = __has_element_type<_Ptr>::value> |
| 649 | struct __pointer_traits_element_type; |
| 650 | |
| 651 | template <class _Ptr> |
| 652 | struct __pointer_traits_element_type<_Ptr, true> |
| 653 | { |
| 654 | typedef typename _Ptr::element_type type; |
| 655 | }; |
| 656 | |
| 657 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 658 | |
| 659 | template <template <class, class...> class _Sp, class _Tp, class ..._Args> |
| 660 | struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> |
| 661 | { |
| 662 | typedef typename _Sp<_Tp, _Args...>::element_type type; |
| 663 | }; |
| 664 | |
| 665 | template <template <class, class...> class _Sp, class _Tp, class ..._Args> |
| 666 | struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> |
| 667 | { |
| 668 | typedef _Tp type; |
| 669 | }; |
| 670 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 671 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 672 | |
| 673 | template <template <class> class _Sp, class _Tp> |
| 674 | struct __pointer_traits_element_type<_Sp<_Tp>, true> |
| 675 | { |
| 676 | typedef typename _Sp<_Tp>::element_type type; |
| 677 | }; |
| 678 | |
| 679 | template <template <class> class _Sp, class _Tp> |
| 680 | struct __pointer_traits_element_type<_Sp<_Tp>, false> |
| 681 | { |
| 682 | typedef _Tp type; |
| 683 | }; |
| 684 | |
| 685 | template <template <class, class> class _Sp, class _Tp, class _A0> |
| 686 | struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true> |
| 687 | { |
| 688 | typedef typename _Sp<_Tp, _A0>::element_type type; |
| 689 | }; |
| 690 | |
| 691 | template <template <class, class> class _Sp, class _Tp, class _A0> |
| 692 | struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false> |
| 693 | { |
| 694 | typedef _Tp type; |
| 695 | }; |
| 696 | |
| 697 | template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> |
| 698 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true> |
| 699 | { |
| 700 | typedef typename _Sp<_Tp, _A0, _A1>::element_type type; |
| 701 | }; |
| 702 | |
| 703 | template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> |
| 704 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false> |
| 705 | { |
| 706 | typedef _Tp type; |
| 707 | }; |
| 708 | |
| 709 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 710 | class _A1, class _A2> |
| 711 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true> |
| 712 | { |
| 713 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type; |
| 714 | }; |
| 715 | |
| 716 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 717 | class _A1, class _A2> |
| 718 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false> |
| 719 | { |
| 720 | typedef _Tp type; |
| 721 | }; |
| 722 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 723 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 724 | |
| 725 | template <class _Tp> |
| 726 | struct __has_difference_type |
| 727 | { |
| 728 | private: |
| 729 | struct __two {char _; char __;}; |
| 730 | template <class _Up> static __two __test(...); |
| 731 | template <class _Up> static char __test(typename _Up::difference_type* = 0); |
| 732 | public: |
| 733 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 734 | }; |
| 735 | |
| 736 | template <class _Ptr, bool = __has_difference_type<_Ptr>::value> |
| 737 | struct __pointer_traits_difference_type |
| 738 | { |
| 739 | typedef ptrdiff_t type; |
| 740 | }; |
| 741 | |
| 742 | template <class _Ptr> |
| 743 | struct __pointer_traits_difference_type<_Ptr, true> |
| 744 | { |
| 745 | typedef typename _Ptr::difference_type type; |
| 746 | }; |
| 747 | |
| 748 | template <class _Tp, class _Up> |
| 749 | struct __has_rebind |
| 750 | { |
| 751 | private: |
| 752 | struct __two {char _; char __;}; |
| 753 | template <class _Xp> static __two __test(...); |
| 754 | template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0); |
| 755 | public: |
| 756 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 757 | }; |
| 758 | |
| 759 | template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> |
| 760 | struct __pointer_traits_rebind |
| 761 | { |
| 762 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 763 | typedef typename _Tp::template rebind<_Up> type; |
| 764 | #else |
| 765 | typedef typename _Tp::template rebind<_Up>::other type; |
| 766 | #endif |
| 767 | }; |
| 768 | |
| 769 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 770 | |
| 771 | template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> |
| 772 | struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> |
| 773 | { |
| 774 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 775 | typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type; |
| 776 | #else |
| 777 | typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; |
| 778 | #endif |
| 779 | }; |
| 780 | |
| 781 | template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> |
| 782 | struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> |
| 783 | { |
| 784 | typedef _Sp<_Up, _Args...> type; |
| 785 | }; |
| 786 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 787 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 788 | |
| 789 | template <template <class> class _Sp, class _Tp, class _Up> |
| 790 | struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true> |
| 791 | { |
| 792 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 793 | typedef typename _Sp<_Tp>::template rebind<_Up> type; |
| 794 | #else |
| 795 | typedef typename _Sp<_Tp>::template rebind<_Up>::other type; |
| 796 | #endif |
| 797 | }; |
| 798 | |
| 799 | template <template <class> class _Sp, class _Tp, class _Up> |
| 800 | struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false> |
| 801 | { |
| 802 | typedef _Sp<_Up> type; |
| 803 | }; |
| 804 | |
| 805 | template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> |
| 806 | struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true> |
| 807 | { |
| 808 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 809 | typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type; |
| 810 | #else |
| 811 | typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type; |
| 812 | #endif |
| 813 | }; |
| 814 | |
| 815 | template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> |
| 816 | struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false> |
| 817 | { |
| 818 | typedef _Sp<_Up, _A0> type; |
| 819 | }; |
| 820 | |
| 821 | template <template <class, class, class> class _Sp, class _Tp, class _A0, |
| 822 | class _A1, class _Up> |
| 823 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true> |
| 824 | { |
| 825 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 826 | typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type; |
| 827 | #else |
| 828 | typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type; |
| 829 | #endif |
| 830 | }; |
| 831 | |
| 832 | template <template <class, class, class> class _Sp, class _Tp, class _A0, |
| 833 | class _A1, class _Up> |
| 834 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false> |
| 835 | { |
| 836 | typedef _Sp<_Up, _A0, _A1> type; |
| 837 | }; |
| 838 | |
| 839 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 840 | class _A1, class _A2, class _Up> |
| 841 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true> |
| 842 | { |
| 843 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 844 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type; |
| 845 | #else |
| 846 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; |
| 847 | #endif |
| 848 | }; |
| 849 | |
| 850 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 851 | class _A1, class _A2, class _Up> |
| 852 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false> |
| 853 | { |
| 854 | typedef _Sp<_Up, _A0, _A1, _A2> type; |
| 855 | }; |
| 856 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 857 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 858 | |
| 859 | template <class _Ptr> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 860 | struct _LIBCPP_VISIBLE pointer_traits |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 861 | { |
| 862 | typedef _Ptr pointer; |
| 863 | typedef typename __pointer_traits_element_type<pointer>::type element_type; |
| 864 | typedef typename __pointer_traits_difference_type<pointer>::type difference_type; |
| 865 | |
| 866 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | 6b41c60 | 2011-05-11 20:21:19 +0000 | [diff] [blame] | 867 | template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | #else |
| 869 | template <class _Up> struct rebind |
| 870 | {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;}; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 871 | #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 872 | |
| 873 | private: |
| 874 | struct __nat {}; |
| 875 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 876 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 877 | static pointer pointer_to(typename conditional<is_void<element_type>::value, |
| 878 | __nat, element_type>::type& __r) |
| 879 | {return pointer::pointer_to(__r);} |
| 880 | }; |
| 881 | |
| 882 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 883 | struct _LIBCPP_VISIBLE pointer_traits<_Tp*> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | { |
| 885 | typedef _Tp* pointer; |
| 886 | typedef _Tp element_type; |
| 887 | typedef ptrdiff_t difference_type; |
| 888 | |
| 889 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 890 | template <class _Up> using rebind = _Up*; |
| 891 | #else |
| 892 | template <class _Up> struct rebind {typedef _Up* other;}; |
| 893 | #endif |
| 894 | |
| 895 | private: |
| 896 | struct __nat {}; |
| 897 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 898 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 899 | static pointer pointer_to(typename conditional<is_void<element_type>::value, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 900 | __nat, element_type>::type& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 901 | {return _STD::addressof(__r);} |
| 902 | }; |
| 903 | |
| 904 | // allocator_traits |
| 905 | |
| 906 | namespace __has_pointer_type_imp |
| 907 | { |
| 908 | template <class _Up> static __two test(...); |
| 909 | template <class _Up> static char test(typename _Up::pointer* = 0); |
| 910 | } |
| 911 | |
| 912 | template <class _Tp> |
| 913 | struct __has_pointer_type |
| 914 | : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1> |
| 915 | { |
| 916 | }; |
| 917 | |
| 918 | namespace __pointer_type_imp |
| 919 | { |
| 920 | |
| 921 | template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value> |
| 922 | struct __pointer_type |
| 923 | { |
| 924 | typedef typename _Dp::pointer type; |
| 925 | }; |
| 926 | |
| 927 | template <class _Tp, class _Dp> |
| 928 | struct __pointer_type<_Tp, _Dp, false> |
| 929 | { |
| 930 | typedef _Tp* type; |
| 931 | }; |
| 932 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 933 | } // __pointer_type_imp |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 934 | |
| 935 | template <class _Tp, class _Dp> |
| 936 | struct __pointer_type |
| 937 | { |
| 938 | typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; |
| 939 | }; |
| 940 | |
| 941 | template <class _Tp> |
| 942 | struct __has_const_pointer |
| 943 | { |
| 944 | private: |
| 945 | struct __two {char _; char __;}; |
| 946 | template <class _Up> static __two __test(...); |
| 947 | template <class _Up> static char __test(typename _Up::const_pointer* = 0); |
| 948 | public: |
| 949 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 950 | }; |
| 951 | |
| 952 | template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> |
| 953 | struct __const_pointer |
| 954 | { |
| 955 | typedef typename _Alloc::const_pointer type; |
| 956 | }; |
| 957 | |
| 958 | template <class _Tp, class _Ptr, class _Alloc> |
| 959 | struct __const_pointer<_Tp, _Ptr, _Alloc, false> |
| 960 | { |
| 961 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 962 | typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type; |
| 963 | #else |
| 964 | typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type; |
| 965 | #endif |
| 966 | }; |
| 967 | |
| 968 | template <class _Tp> |
| 969 | struct __has_void_pointer |
| 970 | { |
| 971 | private: |
| 972 | struct __two {char _; char __;}; |
| 973 | template <class _Up> static __two __test(...); |
| 974 | template <class _Up> static char __test(typename _Up::void_pointer* = 0); |
| 975 | public: |
| 976 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 977 | }; |
| 978 | |
| 979 | template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> |
| 980 | struct __void_pointer |
| 981 | { |
| 982 | typedef typename _Alloc::void_pointer type; |
| 983 | }; |
| 984 | |
| 985 | template <class _Ptr, class _Alloc> |
| 986 | struct __void_pointer<_Ptr, _Alloc, false> |
| 987 | { |
| 988 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 989 | typedef typename pointer_traits<_Ptr>::template rebind<void> type; |
| 990 | #else |
| 991 | typedef typename pointer_traits<_Ptr>::template rebind<void>::other type; |
| 992 | #endif |
| 993 | }; |
| 994 | |
| 995 | template <class _Tp> |
| 996 | struct __has_const_void_pointer |
| 997 | { |
| 998 | private: |
| 999 | struct __two {char _; char __;}; |
| 1000 | template <class _Up> static __two __test(...); |
| 1001 | template <class _Up> static char __test(typename _Up::const_void_pointer* = 0); |
| 1002 | public: |
| 1003 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1004 | }; |
| 1005 | |
| 1006 | template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> |
| 1007 | struct __const_void_pointer |
| 1008 | { |
| 1009 | typedef typename _Alloc::const_void_pointer type; |
| 1010 | }; |
| 1011 | |
| 1012 | template <class _Ptr, class _Alloc> |
| 1013 | struct __const_void_pointer<_Ptr, _Alloc, false> |
| 1014 | { |
| 1015 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1016 | typedef typename pointer_traits<_Ptr>::template rebind<const void> type; |
| 1017 | #else |
| 1018 | typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type; |
| 1019 | #endif |
| 1020 | }; |
| 1021 | |
| 1022 | template <class _T> |
| 1023 | inline _LIBCPP_INLINE_VISIBILITY |
| 1024 | _T* |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1025 | __to_raw_pointer(_T* __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1026 | { |
| 1027 | return __p; |
| 1028 | } |
| 1029 | |
| 1030 | template <class _Pointer> |
| 1031 | inline _LIBCPP_INLINE_VISIBILITY |
| 1032 | typename pointer_traits<_Pointer>::element_type* |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1033 | __to_raw_pointer(_Pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1034 | { |
| 1035 | return _STD::__to_raw_pointer(__p.operator->()); |
| 1036 | } |
| 1037 | |
| 1038 | template <class _Tp> |
| 1039 | struct __has_size_type |
| 1040 | { |
| 1041 | private: |
| 1042 | struct __two {char _; char __;}; |
| 1043 | template <class _Up> static __two __test(...); |
| 1044 | template <class _Up> static char __test(typename _Up::size_type* = 0); |
| 1045 | public: |
| 1046 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1047 | }; |
| 1048 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1049 | template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1050 | struct __size_type |
| 1051 | { |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1052 | typedef typename make_unsigned<_DiffType>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1053 | }; |
| 1054 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1055 | template <class _Alloc, class _DiffType> |
| 1056 | struct __size_type<_Alloc, _DiffType, true> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1057 | { |
| 1058 | typedef typename _Alloc::size_type type; |
| 1059 | }; |
| 1060 | |
| 1061 | template <class _Tp> |
| 1062 | struct __has_propagate_on_container_copy_assignment |
| 1063 | { |
| 1064 | private: |
| 1065 | struct __two {char _; char __;}; |
| 1066 | template <class _Up> static __two __test(...); |
| 1067 | template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0); |
| 1068 | public: |
| 1069 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1070 | }; |
| 1071 | |
| 1072 | template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> |
| 1073 | struct __propagate_on_container_copy_assignment |
| 1074 | { |
| 1075 | typedef false_type type; |
| 1076 | }; |
| 1077 | |
| 1078 | template <class _Alloc> |
| 1079 | struct __propagate_on_container_copy_assignment<_Alloc, true> |
| 1080 | { |
| 1081 | typedef typename _Alloc::propagate_on_container_copy_assignment type; |
| 1082 | }; |
| 1083 | |
| 1084 | template <class _Tp> |
| 1085 | struct __has_propagate_on_container_move_assignment |
| 1086 | { |
| 1087 | private: |
| 1088 | struct __two {char _; char __;}; |
| 1089 | template <class _Up> static __two __test(...); |
| 1090 | template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0); |
| 1091 | public: |
| 1092 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1093 | }; |
| 1094 | |
| 1095 | template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value> |
| 1096 | struct __propagate_on_container_move_assignment |
| 1097 | { |
| 1098 | typedef false_type type; |
| 1099 | }; |
| 1100 | |
| 1101 | template <class _Alloc> |
| 1102 | struct __propagate_on_container_move_assignment<_Alloc, true> |
| 1103 | { |
| 1104 | typedef typename _Alloc::propagate_on_container_move_assignment type; |
| 1105 | }; |
| 1106 | |
| 1107 | template <class _Tp> |
| 1108 | struct __has_propagate_on_container_swap |
| 1109 | { |
| 1110 | private: |
| 1111 | struct __two {char _; char __;}; |
| 1112 | template <class _Up> static __two __test(...); |
| 1113 | template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0); |
| 1114 | public: |
| 1115 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1116 | }; |
| 1117 | |
| 1118 | template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value> |
| 1119 | struct __propagate_on_container_swap |
| 1120 | { |
| 1121 | typedef false_type type; |
| 1122 | }; |
| 1123 | |
| 1124 | template <class _Alloc> |
| 1125 | struct __propagate_on_container_swap<_Alloc, true> |
| 1126 | { |
| 1127 | typedef typename _Alloc::propagate_on_container_swap type; |
| 1128 | }; |
| 1129 | |
| 1130 | template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> |
| 1131 | struct __has_rebind_other |
| 1132 | { |
| 1133 | private: |
| 1134 | struct __two {char _; char __;}; |
| 1135 | template <class _Xp> static __two __test(...); |
| 1136 | template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0); |
| 1137 | public: |
| 1138 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1139 | }; |
| 1140 | |
| 1141 | template <class _Tp, class _Up> |
| 1142 | struct __has_rebind_other<_Tp, _Up, false> |
| 1143 | { |
| 1144 | static const bool value = false; |
| 1145 | }; |
| 1146 | |
| 1147 | template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> |
| 1148 | struct __allocator_traits_rebind |
| 1149 | { |
| 1150 | typedef typename _Tp::template rebind<_Up>::other type; |
| 1151 | }; |
| 1152 | |
| 1153 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1154 | |
| 1155 | template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> |
| 1156 | struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> |
| 1157 | { |
| 1158 | typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type; |
| 1159 | }; |
| 1160 | |
| 1161 | template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> |
| 1162 | struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> |
| 1163 | { |
| 1164 | typedef _Alloc<_Up, _Args...> type; |
| 1165 | }; |
| 1166 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1167 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1168 | |
| 1169 | template <template <class> class _Alloc, class _Tp, class _Up> |
| 1170 | struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true> |
| 1171 | { |
| 1172 | typedef typename _Alloc<_Tp>::template rebind<_Up>::other type; |
| 1173 | }; |
| 1174 | |
| 1175 | template <template <class> class _Alloc, class _Tp, class _Up> |
| 1176 | struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false> |
| 1177 | { |
| 1178 | typedef _Alloc<_Up> type; |
| 1179 | }; |
| 1180 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1181 | template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> |
| 1182 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true> |
| 1183 | { |
| 1184 | typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type; |
| 1185 | }; |
| 1186 | |
| 1187 | template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> |
| 1188 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false> |
| 1189 | { |
| 1190 | typedef _Alloc<_Up, _A0> type; |
| 1191 | }; |
| 1192 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1193 | template <template <class, class, class> class _Alloc, class _Tp, class _A0, |
| 1194 | class _A1, class _Up> |
| 1195 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true> |
| 1196 | { |
| 1197 | typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type; |
| 1198 | }; |
| 1199 | |
| 1200 | template <template <class, class, class> class _Alloc, class _Tp, class _A0, |
| 1201 | class _A1, class _Up> |
| 1202 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false> |
| 1203 | { |
| 1204 | typedef _Alloc<_Up, _A0, _A1> type; |
| 1205 | }; |
| 1206 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1207 | template <template <class, class, class, class> class _Alloc, class _Tp, class _A0, |
| 1208 | class _A1, class _A2, class _Up> |
| 1209 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true> |
| 1210 | { |
| 1211 | typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; |
| 1212 | }; |
| 1213 | |
| 1214 | template <template <class, class, class, class> class _Alloc, class _Tp, class _A0, |
| 1215 | class _A1, class _A2, class _Up> |
| 1216 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false> |
| 1217 | { |
| 1218 | typedef _Alloc<_Up, _A0, _A1, _A2> type; |
| 1219 | }; |
| 1220 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1221 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1222 | |
| 1223 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
| 1224 | |
| 1225 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1226 | auto |
| 1227 | __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) |
| 1228 | -> decltype(__a.allocate(__sz, __p), true_type()); |
| 1229 | |
| 1230 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1231 | auto |
| 1232 | __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) |
| 1233 | -> false_type; |
| 1234 | |
| 1235 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1236 | struct __has_allocate_hint |
| 1237 | : integral_constant<bool, |
| 1238 | is_same< |
| 1239 | decltype(__has_allocate_hint_test(declval<_Alloc>(), |
| 1240 | declval<_SizeType>(), |
| 1241 | declval<_ConstVoidPtr>())), |
| 1242 | true_type>::value> |
| 1243 | { |
| 1244 | }; |
| 1245 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1246 | #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1247 | |
| 1248 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1249 | struct __has_allocate_hint |
| 1250 | : true_type |
| 1251 | { |
| 1252 | }; |
| 1253 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1254 | #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1255 | |
| 1256 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
| 1257 | |
| 1258 | template <class _Alloc, class _Tp, class ..._Args> |
| 1259 | decltype(_STD::declval<_Alloc>().construct(_STD::declval<_Tp*>(), |
| 1260 | _STD::declval<_Args>()...), |
| 1261 | true_type()) |
| 1262 | __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args); |
| 1263 | |
| 1264 | template <class _Alloc, class _Pointer, class ..._Args> |
| 1265 | false_type |
| 1266 | __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args); |
| 1267 | |
| 1268 | template <class _Alloc, class _Pointer, class ..._Args> |
| 1269 | struct __has_construct |
| 1270 | : integral_constant<bool, |
| 1271 | is_same< |
| 1272 | decltype(__has_construct_test(declval<_Alloc>(), |
| 1273 | declval<_Pointer>(), |
| 1274 | declval<_Args>()...)), |
| 1275 | true_type>::value> |
| 1276 | { |
| 1277 | }; |
| 1278 | |
| 1279 | template <class _Alloc, class _Pointer> |
| 1280 | auto |
| 1281 | __has_destroy_test(_Alloc&& __a, _Pointer&& __p) |
| 1282 | -> decltype(__a.destroy(__p), true_type()); |
| 1283 | |
| 1284 | template <class _Alloc, class _Pointer> |
| 1285 | auto |
| 1286 | __has_destroy_test(const _Alloc& __a, _Pointer&& __p) |
| 1287 | -> false_type; |
| 1288 | |
| 1289 | template <class _Alloc, class _Pointer> |
| 1290 | struct __has_destroy |
| 1291 | : integral_constant<bool, |
| 1292 | is_same< |
| 1293 | decltype(__has_destroy_test(declval<_Alloc>(), |
| 1294 | declval<_Pointer>())), |
| 1295 | true_type>::value> |
| 1296 | { |
| 1297 | }; |
| 1298 | |
| 1299 | template <class _Alloc> |
| 1300 | auto |
| 1301 | __has_max_size_test(_Alloc&& __a) |
| 1302 | -> decltype(__a.max_size(), true_type()); |
| 1303 | |
| 1304 | template <class _Alloc> |
| 1305 | auto |
| 1306 | __has_max_size_test(const volatile _Alloc& __a) |
| 1307 | -> false_type; |
| 1308 | |
| 1309 | template <class _Alloc> |
| 1310 | struct __has_max_size |
| 1311 | : integral_constant<bool, |
| 1312 | is_same< |
| 1313 | decltype(__has_max_size_test(declval<_Alloc&>())), |
| 1314 | true_type>::value> |
| 1315 | { |
| 1316 | }; |
| 1317 | |
| 1318 | template <class _Alloc> |
| 1319 | auto |
| 1320 | __has_select_on_container_copy_construction_test(_Alloc&& __a) |
| 1321 | -> decltype(__a.select_on_container_copy_construction(), true_type()); |
| 1322 | |
| 1323 | template <class _Alloc> |
| 1324 | auto |
| 1325 | __has_select_on_container_copy_construction_test(const volatile _Alloc& __a) |
| 1326 | -> false_type; |
| 1327 | |
| 1328 | template <class _Alloc> |
| 1329 | struct __has_select_on_container_copy_construction |
| 1330 | : integral_constant<bool, |
| 1331 | is_same< |
| 1332 | decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())), |
| 1333 | true_type>::value> |
| 1334 | { |
| 1335 | }; |
| 1336 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1337 | #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | |
| 1339 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1340 | |
| 1341 | template <class _Alloc, class _Pointer, class ..._Args> |
| 1342 | struct __has_construct |
| 1343 | : false_type |
| 1344 | { |
| 1345 | }; |
| 1346 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1347 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1348 | |
| 1349 | template <class _Alloc, class _Pointer> |
| 1350 | struct __has_destroy |
| 1351 | : false_type |
| 1352 | { |
| 1353 | }; |
| 1354 | |
| 1355 | template <class _Alloc> |
| 1356 | struct __has_max_size |
| 1357 | : true_type |
| 1358 | { |
| 1359 | }; |
| 1360 | |
| 1361 | template <class _Alloc> |
| 1362 | struct __has_select_on_container_copy_construction |
| 1363 | : false_type |
| 1364 | { |
| 1365 | }; |
| 1366 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1367 | #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1368 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1369 | template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> |
| 1370 | struct __alloc_traits_difference_type |
| 1371 | { |
| 1372 | typedef typename pointer_traits<_Ptr>::difference_type type; |
| 1373 | }; |
| 1374 | |
| 1375 | template <class _Alloc, class _Ptr> |
| 1376 | struct __alloc_traits_difference_type<_Alloc, _Ptr, true> |
| 1377 | { |
| 1378 | typedef typename _Alloc::difference_type type; |
| 1379 | }; |
| 1380 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1381 | template <class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1382 | struct _LIBCPP_VISIBLE allocator_traits |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1383 | { |
| 1384 | typedef _Alloc allocator_type; |
| 1385 | typedef typename allocator_type::value_type value_type; |
| 1386 | |
| 1387 | typedef typename __pointer_type<value_type, allocator_type>::type pointer; |
| 1388 | typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer; |
| 1389 | typedef typename __void_pointer<pointer, allocator_type>::type void_pointer; |
| 1390 | typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer; |
| 1391 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1392 | typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type; |
| 1393 | typedef typename __size_type<allocator_type, difference_type>::type size_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1394 | |
| 1395 | typedef typename __propagate_on_container_copy_assignment<allocator_type>::type |
| 1396 | propagate_on_container_copy_assignment; |
| 1397 | typedef typename __propagate_on_container_move_assignment<allocator_type>::type |
| 1398 | propagate_on_container_move_assignment; |
| 1399 | typedef typename __propagate_on_container_swap<allocator_type>::type |
| 1400 | propagate_on_container_swap; |
| 1401 | |
| 1402 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1403 | template <class _Tp> using rebind_alloc = |
Howard Hinnant | 6b41c60 | 2011-05-11 20:21:19 +0000 | [diff] [blame] | 1404 | typename __allocator_traits_rebind<allocator_type, _Tp>::type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1405 | template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1406 | #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1407 | template <class _Tp> struct rebind_alloc |
| 1408 | {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; |
| 1409 | template <class _Tp> struct rebind_traits |
| 1410 | {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;}; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1411 | #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1412 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1413 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1414 | static pointer allocate(allocator_type& __a, size_type __n) |
| 1415 | {return __a.allocate(__n);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1416 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1417 | static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) |
| 1418 | {return allocate(__a, __n, __hint, |
| 1419 | __has_allocate_hint<allocator_type, size_type, const_void_pointer>());} |
| 1420 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1421 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1422 | static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | {__a.deallocate(__p, __n);} |
| 1424 | |
| 1425 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1426 | template <class _Tp, class... _Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1427 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1428 | static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) |
| 1429 | {__construct(__has_construct<allocator_type, pointer, _Args...>(), |
| 1430 | __a, __p, _STD::forward<_Args>(__args)...);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1431 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1432 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1433 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1434 | static void construct(allocator_type& __a, _Tp* __p) |
| 1435 | { |
| 1436 | ::new ((void*)__p) _Tp(); |
| 1437 | } |
| 1438 | template <class _Tp, class _A0> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1439 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1440 | static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0) |
| 1441 | { |
| 1442 | ::new ((void*)__p) _Tp(__a0); |
| 1443 | } |
| 1444 | template <class _Tp, class _A0, class _A1> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1445 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1446 | static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0, |
| 1447 | const _A1& __a1) |
| 1448 | { |
| 1449 | ::new ((void*)__p) _Tp(__a0, __a1); |
| 1450 | } |
| 1451 | template <class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1452 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1453 | static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0, |
| 1454 | const _A1& __a1, const _A2& __a2) |
| 1455 | { |
| 1456 | ::new ((void*)__p) _Tp(__a0, __a1, __a2); |
| 1457 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1458 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1459 | |
| 1460 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1461 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | static void destroy(allocator_type& __a, _Tp* __p) |
| 1463 | {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);} |
| 1464 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1465 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1466 | static size_type max_size(const allocator_type& __a) |
| 1467 | {return __max_size(__has_max_size<const allocator_type>(), __a);} |
| 1468 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1469 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1470 | static allocator_type |
| 1471 | select_on_container_copy_construction(const allocator_type& __a) |
| 1472 | {return select_on_container_copy_construction( |
| 1473 | __has_select_on_container_copy_construction<const allocator_type>(), |
| 1474 | __a);} |
| 1475 | |
| 1476 | private: |
| 1477 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1478 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1479 | static pointer allocate(allocator_type& __a, size_type __n, |
| 1480 | const_void_pointer __hint, true_type) |
| 1481 | {return __a.allocate(__n, __hint);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1483 | static pointer allocate(allocator_type& __a, size_type __n, |
| 1484 | const_void_pointer __hint, false_type) |
| 1485 | {return __a.allocate(__n);} |
| 1486 | |
| 1487 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1488 | template <class _Tp, class... _Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1489 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1490 | static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args) |
| 1491 | {__a.construct(__p, _STD::forward<_Args>(__args)...);} |
| 1492 | template <class _Tp, class... _Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1493 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1494 | static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args) |
| 1495 | { |
| 1496 | ::new ((void*)__p) _Tp(_STD::forward<_Args>(__args)...); |
| 1497 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1498 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1499 | |
| 1500 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1501 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1502 | static void __destroy(true_type, allocator_type& __a, _Tp* __p) |
| 1503 | {__a.destroy(__p);} |
| 1504 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1505 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1506 | static void __destroy(false_type, allocator_type&, _Tp* __p) |
| 1507 | { |
| 1508 | __p->~_Tp(); |
| 1509 | } |
| 1510 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1511 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1512 | static size_type __max_size(true_type, const allocator_type& __a) |
| 1513 | {return __a.max_size();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1515 | static size_type __max_size(false_type, const allocator_type&) |
| 1516 | {return numeric_limits<size_type>::max();} |
| 1517 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1518 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1519 | static allocator_type |
| 1520 | select_on_container_copy_construction(true_type, const allocator_type& __a) |
| 1521 | {return __a.select_on_container_copy_construction();} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1522 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1523 | static allocator_type |
| 1524 | select_on_container_copy_construction(false_type, const allocator_type& __a) |
| 1525 | {return __a;} |
| 1526 | }; |
| 1527 | |
| 1528 | // uses_allocator |
| 1529 | |
| 1530 | template <class _Tp> |
| 1531 | struct __has_allocator_type |
| 1532 | { |
| 1533 | private: |
| 1534 | struct __two {char _; char __;}; |
| 1535 | template <class _Up> static __two __test(...); |
| 1536 | template <class _Up> static char __test(typename _Up::allocator_type* = 0); |
| 1537 | public: |
| 1538 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1539 | }; |
| 1540 | |
| 1541 | template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value> |
| 1542 | struct __uses_allocator |
| 1543 | : public integral_constant<bool, |
| 1544 | is_convertible<_Alloc, typename _Tp::allocator_type>::value> |
| 1545 | { |
| 1546 | }; |
| 1547 | |
| 1548 | template <class _Tp, class _Alloc> |
| 1549 | struct __uses_allocator<_Tp, _Alloc, false> |
| 1550 | : public false_type |
| 1551 | { |
| 1552 | }; |
| 1553 | |
| 1554 | template <class _Tp, class _Alloc> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1555 | struct _LIBCPP_VISIBLE uses_allocator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1556 | : public __uses_allocator<_Tp, _Alloc> |
| 1557 | { |
| 1558 | }; |
| 1559 | |
Howard Hinnant | ac38bae | 2011-01-11 20:02:45 +0000 | [diff] [blame] | 1560 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1561 | |
| 1562 | // uses-allocator construction |
| 1563 | |
| 1564 | template <class _Tp, class _Alloc, class ..._Args> |
| 1565 | struct __uses_alloc_ctor_imp |
| 1566 | { |
| 1567 | static const bool __ua = uses_allocator<_Tp, _Alloc>::value; |
| 1568 | static const bool __ic = |
| 1569 | is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; |
| 1570 | static const int value = __ua ? 2 - __ic : 0; |
| 1571 | }; |
| 1572 | |
| 1573 | template <class _Tp, class _Alloc, class ..._Args> |
| 1574 | struct __uses_alloc_ctor |
| 1575 | : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> |
| 1576 | {}; |
| 1577 | |
Howard Hinnant | ac38bae | 2011-01-11 20:02:45 +0000 | [diff] [blame] | 1578 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1579 | |
| 1580 | // allocator |
| 1581 | |
| 1582 | template <class _Tp> |
Howard Hinnant | 36cdf02 | 2010-09-10 16:42:26 +0000 | [diff] [blame] | 1583 | class _LIBCPP_VISIBLE allocator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1584 | { |
| 1585 | public: |
| 1586 | typedef size_t size_type; |
| 1587 | typedef ptrdiff_t difference_type; |
| 1588 | typedef _Tp* pointer; |
| 1589 | typedef const _Tp* const_pointer; |
| 1590 | typedef _Tp& reference; |
| 1591 | typedef const _Tp& const_reference; |
| 1592 | typedef _Tp value_type; |
| 1593 | |
| 1594 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 1595 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1596 | _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {} |
| 1597 | template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {} |
| 1598 | _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT |
| 1599 | {return _STD::addressof(__x);} |
| 1600 | _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT |
| 1601 | {return _STD::addressof(__x);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1602 | _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) |
| 1603 | {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1604 | _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT |
| 1605 | {::operator delete((void*)__p);} |
| 1606 | _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT |
| 1607 | {return size_type(~0) / sizeof(_Tp);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1608 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1609 | template <class _Up, class... _Args> |
| 1610 | _LIBCPP_INLINE_VISIBILITY |
| 1611 | void |
| 1612 | construct(_Up* __p, _Args&&... __args) |
| 1613 | { |
| 1614 | ::new((void*)__p) _Up(_STD::forward<_Args>(__args)...); |
| 1615 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1616 | #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1617 | _LIBCPP_INLINE_VISIBILITY |
| 1618 | void |
| 1619 | construct(pointer __p) |
| 1620 | { |
| 1621 | ::new((void*)__p) _Tp(); |
| 1622 | } |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1623 | # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1624 | template <class _A0> |
| 1625 | _LIBCPP_INLINE_VISIBILITY |
| 1626 | typename enable_if |
| 1627 | < |
| 1628 | !is_convertible<_A0, __rv<_A0> >::value, |
| 1629 | void |
| 1630 | >::type |
| 1631 | construct(pointer __p, _A0& __a0) |
| 1632 | { |
| 1633 | ::new((void*)__p) _Tp(__a0); |
| 1634 | } |
| 1635 | template <class _A0> |
| 1636 | _LIBCPP_INLINE_VISIBILITY |
| 1637 | typename enable_if |
| 1638 | < |
| 1639 | !is_convertible<_A0, __rv<_A0> >::value, |
| 1640 | void |
| 1641 | >::type |
| 1642 | construct(pointer __p, const _A0& __a0) |
| 1643 | { |
| 1644 | ::new((void*)__p) _Tp(__a0); |
| 1645 | } |
| 1646 | template <class _A0> |
| 1647 | _LIBCPP_INLINE_VISIBILITY |
| 1648 | typename enable_if |
| 1649 | < |
| 1650 | is_convertible<_A0, __rv<_A0> >::value, |
| 1651 | void |
| 1652 | >::type |
| 1653 | construct(pointer __p, _A0 __a0) |
| 1654 | { |
| 1655 | ::new((void*)__p) _Tp(_STD::move(__a0)); |
| 1656 | } |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1657 | # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1658 | template <class _A0, class _A1> |
| 1659 | _LIBCPP_INLINE_VISIBILITY |
| 1660 | void |
| 1661 | construct(pointer __p, _A0& __a0, _A1& __a1) |
| 1662 | { |
| 1663 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1664 | } |
| 1665 | template <class _A0, class _A1> |
| 1666 | _LIBCPP_INLINE_VISIBILITY |
| 1667 | void |
| 1668 | construct(pointer __p, const _A0& __a0, _A1& __a1) |
| 1669 | { |
| 1670 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1671 | } |
| 1672 | template <class _A0, class _A1> |
| 1673 | _LIBCPP_INLINE_VISIBILITY |
| 1674 | void |
| 1675 | construct(pointer __p, _A0& __a0, const _A1& __a1) |
| 1676 | { |
| 1677 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1678 | } |
| 1679 | template <class _A0, class _A1> |
| 1680 | _LIBCPP_INLINE_VISIBILITY |
| 1681 | void |
| 1682 | construct(pointer __p, const _A0& __a0, const _A1& __a1) |
| 1683 | { |
| 1684 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1685 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1686 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1687 | _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} |
| 1688 | }; |
| 1689 | |
| 1690 | template <class _Tp, class _Up> |
| 1691 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1692 | bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1693 | |
| 1694 | template <class _Tp, class _Up> |
| 1695 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1696 | bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1697 | |
| 1698 | template <class _OutputIterator, class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1699 | class _LIBCPP_VISIBLE raw_storage_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1700 | : public iterator<output_iterator_tag, |
| 1701 | _Tp, // purposefully not C++03 |
| 1702 | ptrdiff_t, // purposefully not C++03 |
| 1703 | _Tp*, // purposefully not C++03 |
| 1704 | raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 |
| 1705 | { |
| 1706 | private: |
| 1707 | _OutputIterator __x_; |
| 1708 | public: |
| 1709 | _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} |
| 1710 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} |
| 1711 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) |
| 1712 | {::new(&*__x_) _Tp(__element); return *this;} |
| 1713 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} |
| 1714 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) |
| 1715 | {raw_storage_iterator __t(*this); ++__x_; return __t;} |
| 1716 | }; |
| 1717 | |
| 1718 | template <class _Tp> |
| 1719 | pair<_Tp*, ptrdiff_t> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1720 | get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1721 | { |
| 1722 | pair<_Tp*, ptrdiff_t> __r(0, 0); |
| 1723 | const ptrdiff_t __m = (~ptrdiff_t(0) ^ |
| 1724 | ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) |
| 1725 | / sizeof(_Tp); |
| 1726 | if (__n > __m) |
| 1727 | __n = __m; |
| 1728 | while (__n > 0) |
| 1729 | { |
| 1730 | __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); |
| 1731 | if (__r.first) |
| 1732 | { |
| 1733 | __r.second = __n; |
| 1734 | break; |
| 1735 | } |
| 1736 | __n /= 2; |
| 1737 | } |
| 1738 | return __r; |
| 1739 | } |
| 1740 | |
| 1741 | template <class _Tp> |
| 1742 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1743 | void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1744 | |
| 1745 | template <class _Tp> |
| 1746 | struct auto_ptr_ref |
| 1747 | { |
| 1748 | _Tp* __ptr_; |
| 1749 | }; |
| 1750 | |
| 1751 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1752 | class _LIBCPP_VISIBLE auto_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1753 | { |
| 1754 | private: |
| 1755 | _Tp* __ptr_; |
| 1756 | public: |
| 1757 | typedef _Tp element_type; |
| 1758 | |
| 1759 | _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {} |
| 1760 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {} |
| 1761 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw() |
| 1762 | : __ptr_(__p.release()) {} |
| 1763 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw() |
| 1764 | {reset(__p.release()); return *this;} |
| 1765 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw() |
| 1766 | {reset(__p.release()); return *this;} |
| 1767 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw() |
| 1768 | {reset(__p.__ptr_); return *this;} |
| 1769 | _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;} |
| 1770 | |
| 1771 | _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw() |
| 1772 | {return *__ptr_;} |
| 1773 | _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;} |
| 1774 | _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;} |
| 1775 | _LIBCPP_INLINE_VISIBILITY _Tp* release() throw() |
| 1776 | { |
| 1777 | _Tp* __t = __ptr_; |
| 1778 | __ptr_ = 0; |
| 1779 | return __t; |
| 1780 | } |
| 1781 | _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw() |
| 1782 | { |
| 1783 | if (__ptr_ != __p) |
| 1784 | delete __ptr_; |
| 1785 | __ptr_ = __p; |
| 1786 | } |
| 1787 | |
| 1788 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {} |
| 1789 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw() |
| 1790 | {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} |
| 1791 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw() |
| 1792 | {return auto_ptr<_Up>(release());} |
| 1793 | }; |
| 1794 | |
| 1795 | template <> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1796 | class _LIBCPP_VISIBLE auto_ptr<void> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1797 | { |
| 1798 | public: |
| 1799 | typedef void element_type; |
| 1800 | }; |
| 1801 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1802 | template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type, |
| 1803 | typename remove_cv<_T2>::type>::value, |
| 1804 | bool = is_empty<_T1>::value, |
| 1805 | bool = is_empty<_T2>::value> |
| 1806 | struct __libcpp_compressed_pair_switch; |
| 1807 | |
| 1808 | template <class _T1, class _T2, bool IsSame> |
| 1809 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};}; |
| 1810 | |
| 1811 | template <class _T1, class _T2, bool IsSame> |
| 1812 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};}; |
| 1813 | |
| 1814 | template <class _T1, class _T2, bool IsSame> |
| 1815 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};}; |
| 1816 | |
| 1817 | template <class _T1, class _T2> |
| 1818 | struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};}; |
| 1819 | |
| 1820 | template <class _T1, class _T2> |
| 1821 | struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};}; |
| 1822 | |
| 1823 | template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value> |
| 1824 | class __libcpp_compressed_pair_imp; |
| 1825 | |
| 1826 | template <class _T1, class _T2> |
| 1827 | class __libcpp_compressed_pair_imp<_T1, _T2, 0> |
| 1828 | { |
| 1829 | private: |
| 1830 | _T1 __first_; |
| 1831 | _T2 __second_; |
| 1832 | public: |
| 1833 | typedef _T1 _T1_param; |
| 1834 | typedef _T2 _T2_param; |
| 1835 | |
| 1836 | typedef typename remove_reference<_T1>::type& _T1_reference; |
| 1837 | typedef typename remove_reference<_T2>::type& _T2_reference; |
| 1838 | |
| 1839 | typedef const typename remove_reference<_T1>::type& _T1_const_reference; |
| 1840 | typedef const typename remove_reference<_T2>::type& _T2_const_reference; |
| 1841 | |
| 1842 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1843 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0) |
| 1844 | : __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1845 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0) |
| 1846 | : __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1847 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1848 | : __first_(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1849 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1850 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1851 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1852 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 1853 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1854 | : __first_(_STD::forward<_T1>(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1855 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1856 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1857 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} |
| 1858 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1860 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} |
| 1861 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 | |
| 1863 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1864 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 1865 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1866 | { |
| 1867 | using _STD::swap; |
| 1868 | swap(__first_, __x.__first_); |
| 1869 | swap(__second_, __x.__second_); |
| 1870 | } |
| 1871 | }; |
| 1872 | |
| 1873 | template <class _T1, class _T2> |
| 1874 | class __libcpp_compressed_pair_imp<_T1, _T2, 1> |
| 1875 | : private _T1 |
| 1876 | { |
| 1877 | private: |
| 1878 | _T2 __second_; |
| 1879 | public: |
| 1880 | typedef _T1 _T1_param; |
| 1881 | typedef _T2 _T2_param; |
| 1882 | |
| 1883 | typedef _T1& _T1_reference; |
| 1884 | typedef typename remove_reference<_T2>::type& _T2_reference; |
| 1885 | |
| 1886 | typedef const _T1& _T1_const_reference; |
| 1887 | typedef const typename remove_reference<_T2>::type& _T2_const_reference; |
| 1888 | |
| 1889 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1890 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0) |
| 1891 | : _T1(_STD::forward<_T1_param>(__t1)) {} |
| 1892 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0) |
| 1893 | : __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1894 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1895 | : _T1(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1896 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1897 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1898 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1899 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 1900 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1901 | : _T1(_STD::move(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1902 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1903 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1904 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} |
| 1905 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1906 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1907 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} |
| 1908 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1909 | |
| 1910 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1911 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 1912 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1913 | { |
| 1914 | using _STD::swap; |
| 1915 | swap(__second_, __x.__second_); |
| 1916 | } |
| 1917 | }; |
| 1918 | |
| 1919 | template <class _T1, class _T2> |
| 1920 | class __libcpp_compressed_pair_imp<_T1, _T2, 2> |
| 1921 | : private _T2 |
| 1922 | { |
| 1923 | private: |
| 1924 | _T1 __first_; |
| 1925 | public: |
| 1926 | typedef _T1 _T1_param; |
| 1927 | typedef _T2 _T2_param; |
| 1928 | |
| 1929 | typedef typename remove_reference<_T1>::type& _T1_reference; |
| 1930 | typedef _T2& _T2_reference; |
| 1931 | |
| 1932 | typedef const typename remove_reference<_T1>::type& _T1_const_reference; |
| 1933 | typedef const _T2& _T2_const_reference; |
| 1934 | |
| 1935 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1936 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) |
| 1937 | : __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1938 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) |
| 1939 | : _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1940 | _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^] | 1941 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 1942 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1943 | : _T2(_STD::forward<_T2_param>(__t2)), __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1944 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1945 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1946 | __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
| 1947 | : _T2(_STD::forward<_T2>(__p.second())), __first_(_STD::move(__p.first())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1948 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1949 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1950 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} |
| 1951 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1952 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1953 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} |
| 1954 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1955 | |
| 1956 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1957 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 1958 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1959 | { |
| 1960 | using _STD::swap; |
| 1961 | swap(__first_, __x.__first_); |
| 1962 | } |
| 1963 | }; |
| 1964 | |
| 1965 | template <class _T1, class _T2> |
| 1966 | class __libcpp_compressed_pair_imp<_T1, _T2, 3> |
| 1967 | : private _T1, |
| 1968 | private _T2 |
| 1969 | { |
| 1970 | public: |
| 1971 | typedef _T1 _T1_param; |
| 1972 | typedef _T2 _T2_param; |
| 1973 | |
| 1974 | typedef _T1& _T1_reference; |
| 1975 | typedef _T2& _T2_reference; |
| 1976 | |
| 1977 | typedef const _T1& _T1_const_reference; |
| 1978 | typedef const _T2& _T2_const_reference; |
| 1979 | |
| 1980 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1981 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) |
| 1982 | : _T1(_STD::forward<_T1_param>(__t1)) {} |
| 1983 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) |
| 1984 | : _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1985 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1986 | : _T1(_STD::forward<_T1_param>(__t1)), _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1987 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1988 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1989 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1990 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 1991 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1992 | : _T1(_STD::move(__p.first())), _T2(_STD::move(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1993 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1994 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1995 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} |
| 1996 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 1998 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} |
| 1999 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2000 | |
| 2001 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2002 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2003 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2004 | { |
| 2005 | } |
| 2006 | }; |
| 2007 | |
| 2008 | template <class _T1, class _T2> |
| 2009 | class __compressed_pair |
| 2010 | : private __libcpp_compressed_pair_imp<_T1, _T2> |
| 2011 | { |
| 2012 | typedef __libcpp_compressed_pair_imp<_T1, _T2> base; |
| 2013 | public: |
| 2014 | typedef typename base::_T1_param _T1_param; |
| 2015 | typedef typename base::_T2_param _T2_param; |
| 2016 | |
| 2017 | typedef typename base::_T1_reference _T1_reference; |
| 2018 | typedef typename base::_T2_reference _T2_reference; |
| 2019 | |
| 2020 | typedef typename base::_T1_const_reference _T1_const_reference; |
| 2021 | typedef typename base::_T2_const_reference _T2_const_reference; |
| 2022 | |
| 2023 | _LIBCPP_INLINE_VISIBILITY __compressed_pair() {} |
| 2024 | _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1, int = 0) |
| 2025 | : base(_STD::forward<_T1_param>(__t1)) {} |
| 2026 | _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2, int* = 0) |
| 2027 | : base(_STD::forward<_T2_param>(__t2)) {} |
| 2028 | _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2) |
| 2029 | : base(_STD::forward<_T1_param>(__t1), _STD::forward<_T2_param>(__t2)) {} |
| 2030 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2031 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2032 | __compressed_pair(__compressed_pair&& __p) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2033 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 2034 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2035 | : base(_STD::move(__p)) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2036 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2037 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2038 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();} |
| 2039 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2040 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2041 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();} |
| 2042 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2043 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2044 | _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) |
| 2045 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2046 | __is_nothrow_swappable<_T1>::value) |
| 2047 | {base::swap(__x);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2048 | }; |
| 2049 | |
| 2050 | template <class _T1, class _T2> |
| 2051 | inline _LIBCPP_INLINE_VISIBILITY |
| 2052 | void |
| 2053 | swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2054 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2055 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2056 | {__x.swap(__y);} |
| 2057 | |
| 2058 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2059 | struct _LIBCPP_VISIBLE default_delete |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2060 | { |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2061 | _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2062 | template <class _Up> |
| 2063 | _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2064 | typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} |
| 2065 | _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2066 | { |
| 2067 | static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); |
| 2068 | delete __ptr; |
| 2069 | } |
| 2070 | }; |
| 2071 | |
| 2072 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2073 | struct _LIBCPP_VISIBLE default_delete<_Tp[]> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2074 | { |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2075 | _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | { |
| 2077 | static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); |
| 2078 | delete [] __ptr; |
| 2079 | } |
| 2080 | private: |
| 2081 | template <class _Up> void operator() (_Up*) const; |
| 2082 | }; |
| 2083 | |
| 2084 | template <class _Tp, class _Dp = default_delete<_Tp> > |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2085 | class _LIBCPP_VISIBLE unique_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2086 | { |
| 2087 | public: |
| 2088 | typedef _Tp element_type; |
| 2089 | typedef _Dp deleter_type; |
| 2090 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2091 | private: |
| 2092 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 2093 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2094 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2095 | unique_ptr(const unique_ptr&); |
| 2096 | unique_ptr& operator=(const unique_ptr&); |
| 2097 | template <class _Up, class _Ep> |
| 2098 | unique_ptr(const unique_ptr<_Up, _Ep>&); |
| 2099 | template <class _Up, class _Ep> |
| 2100 | unique_ptr& operator=(const unique_ptr<_Up, _Ep>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2101 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2102 | unique_ptr(unique_ptr&); |
| 2103 | template <class _Up, class _Ep> |
| 2104 | unique_ptr(unique_ptr<_Up, _Ep>&); |
| 2105 | unique_ptr& operator=(unique_ptr&); |
| 2106 | template <class _Up, class _Ep> |
| 2107 | unique_ptr& operator=(unique_ptr<_Up, _Ep>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2108 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2109 | |
| 2110 | struct __nat {int __for_bool_;}; |
| 2111 | |
| 2112 | typedef typename remove_reference<deleter_type>::type& _Dp_reference; |
| 2113 | typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; |
| 2114 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2115 | _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2116 | : __ptr_(pointer()) |
| 2117 | { |
| 2118 | static_assert(!is_pointer<deleter_type>::value, |
| 2119 | "unique_ptr constructed with null function pointer deleter"); |
| 2120 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2121 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2122 | : __ptr_(pointer()) |
| 2123 | { |
| 2124 | static_assert(!is_pointer<deleter_type>::value, |
| 2125 | "unique_ptr constructed with null function pointer deleter"); |
| 2126 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2127 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2128 | : __ptr_(_STD::move(__p)) |
| 2129 | { |
| 2130 | static_assert(!is_pointer<deleter_type>::value, |
| 2131 | "unique_ptr constructed with null function pointer deleter"); |
| 2132 | } |
| 2133 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2134 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2135 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional< |
| 2136 | is_reference<deleter_type>::value, |
| 2137 | deleter_type, |
| 2138 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2139 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2140 | : __ptr_(__p, __d) {} |
| 2141 | |
| 2142 | _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^] | 2143 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2144 | : __ptr_(__p, _STD::move(__d)) |
| 2145 | { |
| 2146 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2147 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2148 | _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2149 | : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {} |
| 2150 | template <class _Up, class _Ep> |
| 2151 | _LIBCPP_INLINE_VISIBILITY |
| 2152 | unique_ptr(unique_ptr<_Up, _Ep>&& __u, |
| 2153 | typename enable_if |
| 2154 | < |
| 2155 | !is_array<_Up>::value && |
| 2156 | is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && |
| 2157 | is_convertible<_Ep, deleter_type>::value && |
| 2158 | ( |
| 2159 | !is_reference<deleter_type>::value || |
| 2160 | is_same<deleter_type, _Ep>::value |
| 2161 | ), |
| 2162 | __nat |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2163 | >::type = __nat()) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2164 | : __ptr_(__u.release(), _STD::forward<_Ep>(__u.get_deleter())) {} |
| 2165 | |
| 2166 | template <class _Up> |
| 2167 | _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p, |
| 2168 | typename enable_if< |
| 2169 | is_convertible<_Up*, _Tp*>::value && |
| 2170 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2171 | __nat |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2172 | >::type = __nat()) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2173 | : __ptr_(__p.release()) |
| 2174 | { |
| 2175 | } |
| 2176 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2177 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2178 | { |
| 2179 | reset(__u.release()); |
| 2180 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2181 | return *this; |
| 2182 | } |
| 2183 | |
| 2184 | template <class _Up, class _Ep> |
| 2185 | _LIBCPP_INLINE_VISIBILITY |
| 2186 | typename enable_if |
| 2187 | < |
| 2188 | !is_array<_Up>::value, |
| 2189 | unique_ptr& |
| 2190 | >::type |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2191 | operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2192 | { |
| 2193 | reset(__u.release()); |
| 2194 | __ptr_.second() = _STD::forward<_Ep>(__u.get_deleter()); |
| 2195 | return *this; |
| 2196 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2197 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2198 | |
| 2199 | _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() |
| 2200 | { |
| 2201 | return __rv<unique_ptr>(*this); |
| 2202 | } |
| 2203 | |
| 2204 | _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) |
| 2205 | : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {} |
| 2206 | |
| 2207 | template <class _Up, class _Ep> |
| 2208 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u) |
| 2209 | { |
| 2210 | reset(__u.release()); |
| 2211 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2212 | return *this; |
| 2213 | } |
| 2214 | |
| 2215 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) |
| 2216 | : __ptr_(_STD::move(__p), _STD::move(__d)) {} |
| 2217 | |
| 2218 | template <class _Up> |
| 2219 | _LIBCPP_INLINE_VISIBILITY |
| 2220 | typename enable_if< |
| 2221 | is_convertible<_Up*, _Tp*>::value && |
| 2222 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2223 | unique_ptr& |
| 2224 | >::type |
| 2225 | operator=(auto_ptr<_Up> __p) |
| 2226 | {reset(__p.release()); return *this;} |
| 2227 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2228 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2229 | _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} |
| 2230 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2231 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2232 | { |
| 2233 | reset(); |
| 2234 | return *this; |
| 2235 | } |
| 2236 | |
| 2237 | _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const |
| 2238 | {return *__ptr_.first();} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2239 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();} |
| 2240 | _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} |
| 2241 | _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT |
| 2242 | {return __ptr_.second();} |
| 2243 | _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT |
| 2244 | {return __ptr_.second();} |
| 2245 | _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const |
| 2246 | _NOEXCEPT |
| 2247 | {return __ptr_.first() ? &__nat::__for_bool_ : 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2248 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2249 | _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2250 | { |
| 2251 | pointer __t = __ptr_.first(); |
| 2252 | __ptr_.first() = pointer(); |
| 2253 | return __t; |
| 2254 | } |
| 2255 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2256 | _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2257 | { |
| 2258 | pointer __tmp = __ptr_.first(); |
| 2259 | __ptr_.first() = __p; |
| 2260 | if (__tmp) |
| 2261 | __ptr_.second()(__tmp); |
| 2262 | } |
| 2263 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2264 | _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT |
| 2265 | {__ptr_.swap(__u.__ptr_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2266 | }; |
| 2267 | |
| 2268 | template <class _Tp, class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2269 | class _LIBCPP_VISIBLE unique_ptr<_Tp[], _Dp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2270 | { |
| 2271 | public: |
| 2272 | typedef _Tp element_type; |
| 2273 | typedef _Dp deleter_type; |
| 2274 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2275 | private: |
| 2276 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 2277 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2278 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2279 | unique_ptr(const unique_ptr&); |
| 2280 | unique_ptr& operator=(const unique_ptr&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2281 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2282 | unique_ptr(unique_ptr&); |
| 2283 | template <class _Up> |
| 2284 | unique_ptr(unique_ptr<_Up>&); |
| 2285 | unique_ptr& operator=(unique_ptr&); |
| 2286 | template <class _Up> |
| 2287 | unique_ptr& operator=(unique_ptr<_Up>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2288 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2289 | |
| 2290 | struct __nat {int __for_bool_;}; |
| 2291 | |
| 2292 | typedef typename remove_reference<deleter_type>::type& _Dp_reference; |
| 2293 | typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; |
| 2294 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2295 | _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2296 | : __ptr_(pointer()) |
| 2297 | { |
| 2298 | static_assert(!is_pointer<deleter_type>::value, |
| 2299 | "unique_ptr constructed with null function pointer deleter"); |
| 2300 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2301 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2302 | : __ptr_(pointer()) |
| 2303 | { |
| 2304 | static_assert(!is_pointer<deleter_type>::value, |
| 2305 | "unique_ptr constructed with null function pointer deleter"); |
| 2306 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2307 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2308 | template <class _P, |
| 2309 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2310 | > |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2311 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_P __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2312 | : __ptr_(__p) |
| 2313 | { |
| 2314 | static_assert(!is_pointer<deleter_type>::value, |
| 2315 | "unique_ptr constructed with null function pointer deleter"); |
| 2316 | } |
| 2317 | |
| 2318 | template <class _P, |
| 2319 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2320 | > |
| 2321 | _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename conditional< |
| 2322 | is_reference<deleter_type>::value, |
| 2323 | deleter_type, |
| 2324 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2325 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2326 | : __ptr_(__p, __d) {} |
| 2327 | |
| 2328 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional< |
| 2329 | is_reference<deleter_type>::value, |
| 2330 | deleter_type, |
| 2331 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2332 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2333 | : __ptr_(pointer(), __d) {} |
| 2334 | |
| 2335 | template <class _P, |
| 2336 | class = typename enable_if<is_same<_P, pointer>::value || |
| 2337 | is_same<_P, nullptr_t>::value>::type |
| 2338 | > |
| 2339 | _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename remove_reference<deleter_type>::type&& __d) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2340 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2341 | : __ptr_(__p, _STD::move(__d)) |
| 2342 | { |
| 2343 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2344 | } |
| 2345 | |
| 2346 | _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^] | 2347 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2348 | : __ptr_(pointer(), _STD::move(__d)) |
| 2349 | { |
| 2350 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2351 | } |
| 2352 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2353 | _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2354 | : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {} |
| 2355 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2356 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2357 | { |
| 2358 | reset(__u.release()); |
| 2359 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2360 | return *this; |
| 2361 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2362 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2363 | |
| 2364 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) |
| 2365 | : __ptr_(__p) |
| 2366 | { |
| 2367 | static_assert(!is_pointer<deleter_type>::value, |
| 2368 | "unique_ptr constructed with null function pointer deleter"); |
| 2369 | } |
| 2370 | |
| 2371 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) |
| 2372 | : __ptr_(__p, _STD::forward<deleter_type>(__d)) {} |
| 2373 | |
| 2374 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d) |
| 2375 | : __ptr_(pointer(), _STD::forward<deleter_type>(__d)) {} |
| 2376 | |
| 2377 | _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() |
| 2378 | { |
| 2379 | return __rv<unique_ptr>(*this); |
| 2380 | } |
| 2381 | |
| 2382 | _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) |
| 2383 | : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {} |
| 2384 | |
| 2385 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u) |
| 2386 | { |
| 2387 | reset(__u->release()); |
| 2388 | __ptr_.second() = _STD::forward<deleter_type>(__u->get_deleter()); |
| 2389 | return *this; |
| 2390 | } |
| 2391 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2392 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2393 | _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} |
| 2394 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2395 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2396 | { |
| 2397 | reset(); |
| 2398 | return *this; |
| 2399 | } |
| 2400 | |
| 2401 | _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const |
| 2402 | {return __ptr_.first()[__i];} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2403 | _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} |
| 2404 | _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT |
| 2405 | {return __ptr_.second();} |
| 2406 | _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT |
| 2407 | {return __ptr_.second();} |
| 2408 | _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const _NOEXCEPT |
| 2409 | {return __ptr_.first() ? &__nat::__for_bool_ : 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2411 | _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2412 | { |
| 2413 | pointer __t = __ptr_.first(); |
| 2414 | __ptr_.first() = pointer(); |
| 2415 | return __t; |
| 2416 | } |
| 2417 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2418 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2419 | template <class _P, |
| 2420 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2421 | > |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2422 | _LIBCPP_INLINE_VISIBILITY void reset(_P __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2423 | { |
| 2424 | pointer __tmp = __ptr_.first(); |
| 2425 | __ptr_.first() = __p; |
| 2426 | if (__tmp) |
| 2427 | __ptr_.second()(__tmp); |
| 2428 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2429 | _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2430 | { |
| 2431 | pointer __tmp = __ptr_.first(); |
| 2432 | __ptr_.first() = nullptr; |
| 2433 | if (__tmp) |
| 2434 | __ptr_.second()(__tmp); |
| 2435 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2436 | _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2437 | { |
| 2438 | pointer __tmp = __ptr_.first(); |
| 2439 | __ptr_.first() = nullptr; |
| 2440 | if (__tmp) |
| 2441 | __ptr_.second()(__tmp); |
| 2442 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2443 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2444 | _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) |
| 2445 | { |
| 2446 | pointer __tmp = __ptr_.first(); |
| 2447 | __ptr_.first() = __p; |
| 2448 | if (__tmp) |
| 2449 | __ptr_.second()(__tmp); |
| 2450 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2451 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2452 | |
| 2453 | _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);} |
| 2454 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2455 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2456 | #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2457 | template <class _Up> |
| 2458 | explicit unique_ptr(_Up); |
| 2459 | template <class _Up> |
| 2460 | unique_ptr(_Up __u, |
| 2461 | typename conditional< |
| 2462 | is_reference<deleter_type>::value, |
| 2463 | deleter_type, |
| 2464 | typename add_lvalue_reference<const deleter_type>::type>::type, |
| 2465 | typename enable_if |
| 2466 | < |
| 2467 | is_convertible<_Up, pointer>::value, |
| 2468 | __nat |
| 2469 | >::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2470 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2471 | }; |
| 2472 | |
| 2473 | template <class _Tp, class _Dp> |
| 2474 | inline _LIBCPP_INLINE_VISIBILITY |
| 2475 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2476 | 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] | 2477 | |
| 2478 | template <class _T1, class _D1, class _T2, class _D2> |
| 2479 | inline _LIBCPP_INLINE_VISIBILITY |
| 2480 | bool |
| 2481 | operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} |
| 2482 | |
| 2483 | template <class _T1, class _D1, class _T2, class _D2> |
| 2484 | inline _LIBCPP_INLINE_VISIBILITY |
| 2485 | bool |
| 2486 | operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} |
| 2487 | |
| 2488 | template <class _T1, class _D1, class _T2, class _D2> |
| 2489 | inline _LIBCPP_INLINE_VISIBILITY |
| 2490 | bool |
| 2491 | operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() < __y.get();} |
| 2492 | |
| 2493 | template <class _T1, class _D1, class _T2, class _D2> |
| 2494 | inline _LIBCPP_INLINE_VISIBILITY |
| 2495 | bool |
| 2496 | operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} |
| 2497 | |
| 2498 | template <class _T1, class _D1, class _T2, class _D2> |
| 2499 | inline _LIBCPP_INLINE_VISIBILITY |
| 2500 | bool |
| 2501 | operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} |
| 2502 | |
| 2503 | template <class _T1, class _D1, class _T2, class _D2> |
| 2504 | inline _LIBCPP_INLINE_VISIBILITY |
| 2505 | bool |
| 2506 | operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} |
| 2507 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2508 | template <class> struct hash; |
| 2509 | |
| 2510 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2511 | struct _LIBCPP_VISIBLE hash<_Tp*> |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2512 | : public unary_function<_Tp*, size_t> |
| 2513 | { |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2515 | size_t operator()(_Tp* __v) const _NOEXCEPT |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2516 | { |
| 2517 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 2518 | return *__p; |
| 2519 | } |
| 2520 | }; |
| 2521 | |
| 2522 | template <class _Tp, class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2523 | struct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> > |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2524 | { |
| 2525 | typedef unique_ptr<_Tp, _Dp> argument_type; |
| 2526 | typedef size_t result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2528 | result_type operator()(const argument_type& __ptr) const _NOEXCEPT |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2529 | { |
| 2530 | typedef typename argument_type::pointer pointer; |
| 2531 | return hash<pointer>()(__ptr.get()); |
| 2532 | } |
| 2533 | }; |
| 2534 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2535 | struct __destruct_n |
| 2536 | { |
| 2537 | private: |
| 2538 | size_t size; |
| 2539 | |
| 2540 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2541 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2542 | {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();} |
| 2543 | |
| 2544 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2545 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2546 | {} |
| 2547 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2548 | _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2549 | {++size;} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2550 | _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2551 | {} |
| 2552 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2553 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2554 | {size = __s;} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2555 | _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2556 | {} |
| 2557 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2558 | _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT |
| 2559 | : size(__s) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2560 | |
| 2561 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2562 | _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2563 | {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2564 | |
| 2565 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2566 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2567 | {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2568 | |
| 2569 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2570 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2571 | {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2572 | }; |
| 2573 | |
| 2574 | template <class _Alloc> |
| 2575 | class __allocator_destructor |
| 2576 | { |
| 2577 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 2578 | public: |
| 2579 | typedef typename __alloc_traits::pointer pointer; |
| 2580 | typedef typename __alloc_traits::size_type size_type; |
| 2581 | private: |
| 2582 | _Alloc& __alloc_; |
| 2583 | size_type __s_; |
| 2584 | public: |
| 2585 | _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2586 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2587 | : __alloc_(__a), __s_(__s) {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2588 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2589 | void operator()(pointer __p) _NOEXCEPT |
| 2590 | {__alloc_traits::deallocate(__alloc_, __p, __s_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2591 | }; |
| 2592 | |
| 2593 | template <class _InputIterator, class _ForwardIterator> |
| 2594 | _ForwardIterator |
| 2595 | uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) |
| 2596 | { |
| 2597 | __destruct_n __d(0); |
| 2598 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2599 | unique_ptr<value_type, __destruct_n&> __h(&*__r, __d); |
| 2600 | for (; __f != __l; ++__f, ++__r, __d.__incr((value_type*)0)) |
| 2601 | ::new(&*__r) value_type(*__f); |
| 2602 | __h.release(); |
| 2603 | return __r; |
| 2604 | } |
| 2605 | |
| 2606 | template <class _InputIterator, class _Size, class _ForwardIterator> |
| 2607 | _ForwardIterator |
| 2608 | uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) |
| 2609 | { |
| 2610 | __destruct_n __d(0); |
| 2611 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2612 | unique_ptr<value_type, __destruct_n&> __h(&*__r, __d); |
| 2613 | for (; __n > 0; ++__f, ++__r, __d.__incr((value_type*)0), --__n) |
| 2614 | ::new(&*__r) value_type(*__f); |
| 2615 | __h.release(); |
| 2616 | return __r; |
| 2617 | } |
| 2618 | |
| 2619 | template <class _ForwardIterator, class _Tp> |
| 2620 | void |
| 2621 | uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) |
| 2622 | { |
| 2623 | __destruct_n __d(0); |
| 2624 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2625 | unique_ptr<value_type, __destruct_n&> __h(&*__f, __d); |
| 2626 | for (; __f != __l; ++__f, __d.__incr((value_type*)0)) |
| 2627 | ::new(&*__f) value_type(__x); |
| 2628 | __h.release(); |
| 2629 | } |
| 2630 | |
| 2631 | template <class _ForwardIterator, class _Size, class _Tp> |
Howard Hinnant | 2f6a627 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 2632 | _ForwardIterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2633 | uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) |
| 2634 | { |
| 2635 | __destruct_n __d(0); |
| 2636 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2637 | unique_ptr<value_type, __destruct_n&> __h(&*__f, __d); |
| 2638 | for (; __n > 0; ++__f, --__n, __d.__incr((value_type*)0)) |
| 2639 | ::new(&*__f) value_type(__x); |
| 2640 | __h.release(); |
Howard Hinnant | 2f6a627 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 2641 | return __f; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2644 | class _LIBCPP_EXCEPTION_ABI bad_weak_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2645 | : public std::exception |
| 2646 | { |
| 2647 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2648 | virtual ~bad_weak_ptr() _NOEXCEPT; |
| 2649 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2650 | }; |
| 2651 | |
| 2652 | template<class _Tp> class weak_ptr; |
| 2653 | |
| 2654 | class __shared_count |
| 2655 | { |
| 2656 | __shared_count(const __shared_count&); |
| 2657 | __shared_count& operator=(const __shared_count&); |
| 2658 | |
| 2659 | protected: |
| 2660 | long __shared_owners_; |
| 2661 | virtual ~__shared_count(); |
| 2662 | private: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2663 | virtual void __on_zero_shared() _NOEXCEPT = 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2664 | |
| 2665 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2666 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2667 | explicit __shared_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2668 | : __shared_owners_(__refs) {} |
| 2669 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2670 | void __add_shared() _NOEXCEPT; |
| 2671 | bool __release_shared() _NOEXCEPT; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2672 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2673 | long use_count() const _NOEXCEPT {return __shared_owners_ + 1;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2674 | }; |
| 2675 | |
| 2676 | class __shared_weak_count |
| 2677 | : private __shared_count |
| 2678 | { |
| 2679 | long __shared_weak_owners_; |
| 2680 | |
| 2681 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2682 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2683 | explicit __shared_weak_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2684 | : __shared_count(__refs), |
| 2685 | __shared_weak_owners_(__refs) {} |
| 2686 | protected: |
| 2687 | virtual ~__shared_weak_count(); |
| 2688 | |
| 2689 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2690 | void __add_shared() _NOEXCEPT; |
| 2691 | void __add_weak() _NOEXCEPT; |
| 2692 | void __release_shared() _NOEXCEPT; |
| 2693 | void __release_weak() _NOEXCEPT; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2694 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2695 | long use_count() const _NOEXCEPT {return __shared_count::use_count();} |
| 2696 | __shared_weak_count* lock() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2697 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2698 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2699 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2700 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2701 | private: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2702 | virtual void __on_zero_shared_weak() _NOEXCEPT = 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2703 | }; |
| 2704 | |
| 2705 | template <class _Tp, class _Dp, class _Alloc> |
| 2706 | class __shared_ptr_pointer |
| 2707 | : public __shared_weak_count |
| 2708 | { |
| 2709 | __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; |
| 2710 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2711 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2712 | __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) |
| 2713 | : __data_(__compressed_pair<_Tp, _Dp>(__p, _STD::move(__d)), _STD::move(__a)) {} |
| 2714 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2715 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2716 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2717 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2718 | |
| 2719 | private: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2720 | virtual void __on_zero_shared() _NOEXCEPT; |
| 2721 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2722 | }; |
| 2723 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2724 | #ifndef _LIBCPP_NO_RTTI |
| 2725 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2726 | template <class _Tp, class _Dp, class _Alloc> |
| 2727 | const void* |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2728 | __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] | 2729 | { |
| 2730 | return __t == typeid(_Dp) ? &__data_.first().second() : 0; |
| 2731 | } |
| 2732 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2733 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2734 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2735 | template <class _Tp, class _Dp, class _Alloc> |
| 2736 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2737 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2738 | { |
| 2739 | __data_.first().second()(__data_.first().first()); |
| 2740 | __data_.first().second().~_Dp(); |
| 2741 | } |
| 2742 | |
| 2743 | template <class _Tp, class _Dp, class _Alloc> |
| 2744 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2745 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2746 | { |
| 2747 | typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second()); |
| 2748 | __data_.second().~_Alloc(); |
| 2749 | __a.deallocate(this, 1); |
| 2750 | } |
| 2751 | |
| 2752 | template <class _Tp, class _Alloc> |
| 2753 | class __shared_ptr_emplace |
| 2754 | : public __shared_weak_count |
| 2755 | { |
| 2756 | __compressed_pair<_Alloc, _Tp> __data_; |
| 2757 | public: |
| 2758 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 2759 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2760 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2761 | __shared_ptr_emplace(_Alloc __a) |
| 2762 | : __data_(_STD::move(__a)) {} |
| 2763 | |
| 2764 | template <class ..._Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2765 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2766 | __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) |
| 2767 | : __data_(_STD::move(__a), _Tp(_STD::forward<_Args>(__args)...)) {} |
| 2768 | |
| 2769 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 2770 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2771 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2772 | __shared_ptr_emplace(_Alloc __a) |
| 2773 | : __data_(__a) {} |
| 2774 | |
| 2775 | template <class _A0> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2776 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2777 | __shared_ptr_emplace(_Alloc __a, _A0& __a0) |
| 2778 | : __data_(__a, _Tp(__a0)) {} |
| 2779 | |
| 2780 | template <class _A0, class _A1> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2781 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2782 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) |
| 2783 | : __data_(__a, _Tp(__a0, __a1)) {} |
| 2784 | |
| 2785 | template <class _A0, class _A1, class _A2> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2786 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2787 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 2788 | : __data_(__a, _Tp(__a0, __a1, __a2)) {} |
| 2789 | |
| 2790 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2791 | |
| 2792 | private: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2793 | virtual void __on_zero_shared() _NOEXCEPT; |
| 2794 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2795 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2796 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2797 | _Tp* get() _NOEXCEPT {return &__data_.second();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2798 | }; |
| 2799 | |
| 2800 | template <class _Tp, class _Alloc> |
| 2801 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2802 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2803 | { |
| 2804 | __data_.second().~_Tp(); |
| 2805 | } |
| 2806 | |
| 2807 | template <class _Tp, class _Alloc> |
| 2808 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2809 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2810 | { |
| 2811 | typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first()); |
| 2812 | __data_.first().~_Alloc(); |
| 2813 | __a.deallocate(this, 1); |
| 2814 | } |
| 2815 | |
| 2816 | template<class _Tp> class enable_shared_from_this; |
| 2817 | |
| 2818 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2819 | class _LIBCPP_VISIBLE shared_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2820 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2821 | public: |
| 2822 | typedef _Tp element_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2823 | private: |
| 2824 | element_type* __ptr_; |
| 2825 | __shared_weak_count* __cntrl_; |
| 2826 | |
| 2827 | struct __nat {int __for_bool_;}; |
| 2828 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2829 | shared_ptr() _NOEXCEPT; |
| 2830 | shared_ptr(nullptr_t) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2831 | template<class _Yp> explicit shared_ptr(_Yp* __p); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2832 | template<class _Yp, class _Dp> shared_ptr(_Yp* __p, _Dp __d); |
| 2833 | template<class _Yp, class _Dp, class _Alloc> shared_ptr(_Yp* __p, _Dp __d, _Alloc __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2834 | template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); |
| 2835 | template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2836 | template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; |
| 2837 | shared_ptr(const shared_ptr& __r) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2838 | template<class _Yp> |
| 2839 | shared_ptr(const shared_ptr<_Yp>& __r, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2840 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) |
| 2841 | _NOEXCEPT; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2842 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2843 | shared_ptr(shared_ptr&& __r) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2844 | template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2845 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) |
| 2846 | _NOEXCEPT; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2847 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2848 | template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2849 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2850 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2851 | template<class _Yp> shared_ptr(auto_ptr<_Yp>&& __r); |
| 2852 | #else |
| 2853 | template<class _Yp> shared_ptr(auto_ptr<_Yp> __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2854 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2855 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2856 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2857 | template <class _Yp, class _Dp> shared_ptr(const unique_ptr<_Yp, _Dp>& __r);// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2858 | public: |
| 2859 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 2860 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
| 2861 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 2862 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2863 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2864 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>, |
| 2865 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
| 2866 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>, |
| 2867 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2868 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2869 | |
| 2870 | ~shared_ptr(); |
| 2871 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2872 | shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; |
| 2873 | template<class _Yp> shared_ptr& operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2874 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2875 | shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2876 | template<class _Yp> shared_ptr& operator=(shared_ptr<_Yp>&& __r); |
| 2877 | template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp>&& __r); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2878 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2879 | template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp> __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2880 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2881 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2882 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2883 | template <class _Yp, class _Dp> shared_ptr& operator=(const unique_ptr<_Yp, _Dp>& __r);// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2884 | public: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2885 | template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp>&& __r); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2886 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2887 | template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp> __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2888 | #endif |
| 2889 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2890 | void swap(shared_ptr& __r) _NOEXCEPT; |
| 2891 | void reset() _NOEXCEPT; |
| 2892 | template<class _Yp> void reset(_Yp* __p) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2893 | template<class _Yp, class _Dp> void reset(_Yp* __p, _Dp __d); |
| 2894 | template<class _Yp, class _Dp, class _Alloc> void reset(_Yp* __p, _Dp __d, _Alloc __a); |
| 2895 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2896 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2897 | element_type* get() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2898 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2899 | typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT |
| 2900 | {return *__ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2901 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2902 | element_type* operator->() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2904 | long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2905 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2906 | bool unique() const _NOEXCEPT {return use_count() == 1;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2907 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2908 | /*explicit*/ operator bool() const _NOEXCEPT {return get() != 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2909 | template <class _U> |
| 2910 | _LIBCPP_INLINE_VISIBILITY |
| 2911 | bool owner_before(shared_ptr<_U> const& __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2912 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2913 | template <class _U> |
| 2914 | _LIBCPP_INLINE_VISIBILITY |
| 2915 | bool owner_before(weak_ptr<_U> const& __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2916 | {return __cntrl_ < __p.__cntrl_;} |
| 2917 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2918 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2919 | template <class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2920 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2921 | _Dp* __get_deleter() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2922 | {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2923 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2924 | |
| 2925 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 2926 | |
| 2927 | template<class ..._Args> |
| 2928 | static |
| 2929 | shared_ptr<_Tp> |
| 2930 | make_shared(_Args&& ...__args); |
| 2931 | |
| 2932 | template<class _Alloc, class ..._Args> |
| 2933 | static |
| 2934 | shared_ptr<_Tp> |
| 2935 | allocate_shared(const _Alloc& __a, _Args&& ...__args); |
| 2936 | |
| 2937 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 2938 | |
| 2939 | static shared_ptr<_Tp> make_shared(); |
| 2940 | |
| 2941 | template<class _A0> |
| 2942 | static shared_ptr<_Tp> make_shared(_A0&); |
| 2943 | |
| 2944 | template<class _A0, class _A1> |
| 2945 | static shared_ptr<_Tp> make_shared(_A0&, _A1&); |
| 2946 | |
| 2947 | template<class _A0, class _A1, class _A2> |
| 2948 | static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); |
| 2949 | |
| 2950 | template<class _Alloc> |
| 2951 | static shared_ptr<_Tp> |
| 2952 | allocate_shared(const _Alloc& __a); |
| 2953 | |
| 2954 | template<class _Alloc, class _A0> |
| 2955 | static shared_ptr<_Tp> |
| 2956 | allocate_shared(const _Alloc& __a, _A0& __a0); |
| 2957 | |
| 2958 | template<class _Alloc, class _A0, class _A1> |
| 2959 | static shared_ptr<_Tp> |
| 2960 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); |
| 2961 | |
| 2962 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 2963 | static shared_ptr<_Tp> |
| 2964 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); |
| 2965 | |
| 2966 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2967 | |
| 2968 | private: |
| 2969 | |
| 2970 | template <class _Yp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2971 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2972 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2973 | __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2974 | { |
| 2975 | if (__e) |
| 2976 | __e->__weak_this_ = *this; |
| 2977 | } |
| 2978 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2979 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2980 | void __enable_weak_this(const void*) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2981 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2982 | template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr; |
| 2983 | template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2984 | }; |
| 2985 | |
| 2986 | template<class _Tp> |
| 2987 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2988 | shared_ptr<_Tp>::shared_ptr() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2989 | : __ptr_(0), |
| 2990 | __cntrl_(0) |
| 2991 | { |
| 2992 | } |
| 2993 | |
| 2994 | template<class _Tp> |
| 2995 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 2996 | shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2997 | : __ptr_(0), |
| 2998 | __cntrl_(0) |
| 2999 | { |
| 3000 | } |
| 3001 | |
| 3002 | template<class _Tp> |
| 3003 | template<class _Yp> |
| 3004 | shared_ptr<_Tp>::shared_ptr(_Yp* __p) |
| 3005 | : __ptr_(__p) |
| 3006 | { |
| 3007 | unique_ptr<_Yp> __hold(__p); |
| 3008 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 3009 | __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>()); |
| 3010 | __hold.release(); |
| 3011 | __enable_weak_this(__p); |
| 3012 | } |
| 3013 | |
| 3014 | template<class _Tp> |
| 3015 | template<class _Yp, class _Dp> |
| 3016 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d) |
| 3017 | : __ptr_(__p) |
| 3018 | { |
| 3019 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3020 | try |
| 3021 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3022 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3023 | typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; |
| 3024 | __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>()); |
| 3025 | __enable_weak_this(__p); |
| 3026 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3027 | } |
| 3028 | catch (...) |
| 3029 | { |
| 3030 | __d(__p); |
| 3031 | throw; |
| 3032 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3033 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | template<class _Tp> |
| 3037 | template<class _Dp> |
| 3038 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) |
| 3039 | : __ptr_(0) |
| 3040 | { |
| 3041 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3042 | try |
| 3043 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3044 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3045 | typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk; |
| 3046 | __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>()); |
| 3047 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3048 | } |
| 3049 | catch (...) |
| 3050 | { |
| 3051 | __d(__p); |
| 3052 | throw; |
| 3053 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3054 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | template<class _Tp> |
| 3058 | template<class _Yp, class _Dp, class _Alloc> |
| 3059 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) |
| 3060 | : __ptr_(__p) |
| 3061 | { |
| 3062 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3063 | try |
| 3064 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3065 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3066 | typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; |
| 3067 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 3068 | typedef __allocator_destructor<_A2> _D2; |
| 3069 | _A2 __a2(__a); |
| 3070 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3071 | ::new(__hold2.get()) _CntrlBlk(__p, __d, __a); |
| 3072 | __cntrl_ = __hold2.release(); |
| 3073 | __enable_weak_this(__p); |
| 3074 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3075 | } |
| 3076 | catch (...) |
| 3077 | { |
| 3078 | __d(__p); |
| 3079 | throw; |
| 3080 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3081 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
| 3084 | template<class _Tp> |
| 3085 | template<class _Dp, class _Alloc> |
| 3086 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) |
| 3087 | : __ptr_(0) |
| 3088 | { |
| 3089 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3090 | try |
| 3091 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3092 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3093 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; |
| 3094 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 3095 | typedef __allocator_destructor<_A2> _D2; |
| 3096 | _A2 __a2(__a); |
| 3097 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3098 | ::new(__hold2.get()) _CntrlBlk(__p, __d, __a); |
| 3099 | __cntrl_ = __hold2.release(); |
| 3100 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3101 | } |
| 3102 | catch (...) |
| 3103 | { |
| 3104 | __d(__p); |
| 3105 | throw; |
| 3106 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3107 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | template<class _Tp> |
| 3111 | template<class _Yp> |
| 3112 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3113 | 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] | 3114 | : __ptr_(__p), |
| 3115 | __cntrl_(__r.__cntrl_) |
| 3116 | { |
| 3117 | if (__cntrl_) |
| 3118 | __cntrl_->__add_shared(); |
| 3119 | } |
| 3120 | |
| 3121 | template<class _Tp> |
| 3122 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3123 | shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3124 | : __ptr_(__r.__ptr_), |
| 3125 | __cntrl_(__r.__cntrl_) |
| 3126 | { |
| 3127 | if (__cntrl_) |
| 3128 | __cntrl_->__add_shared(); |
| 3129 | } |
| 3130 | |
| 3131 | template<class _Tp> |
| 3132 | template<class _Yp> |
| 3133 | inline _LIBCPP_INLINE_VISIBILITY |
| 3134 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, |
| 3135 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3136 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3137 | : __ptr_(__r.__ptr_), |
| 3138 | __cntrl_(__r.__cntrl_) |
| 3139 | { |
| 3140 | if (__cntrl_) |
| 3141 | __cntrl_->__add_shared(); |
| 3142 | } |
| 3143 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3144 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3145 | |
| 3146 | template<class _Tp> |
| 3147 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3148 | shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3149 | : __ptr_(__r.__ptr_), |
| 3150 | __cntrl_(__r.__cntrl_) |
| 3151 | { |
| 3152 | __r.__ptr_ = 0; |
| 3153 | __r.__cntrl_ = 0; |
| 3154 | } |
| 3155 | |
| 3156 | template<class _Tp> |
| 3157 | template<class _Yp> |
| 3158 | inline _LIBCPP_INLINE_VISIBILITY |
| 3159 | shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, |
| 3160 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3161 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3162 | : __ptr_(__r.__ptr_), |
| 3163 | __cntrl_(__r.__cntrl_) |
| 3164 | { |
| 3165 | __r.__ptr_ = 0; |
| 3166 | __r.__cntrl_ = 0; |
| 3167 | } |
| 3168 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3169 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3170 | |
| 3171 | template<class _Tp> |
| 3172 | template<class _Yp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3173 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3174 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r) |
| 3175 | #else |
Howard Hinnant | 92172b8 | 2010-08-21 21:14:53 +0000 | [diff] [blame] | 3176 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3177 | #endif |
| 3178 | : __ptr_(__r.get()) |
| 3179 | { |
| 3180 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 3181 | __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); |
| 3182 | __enable_weak_this(__r.get()); |
| 3183 | __r.release(); |
| 3184 | } |
| 3185 | |
| 3186 | template<class _Tp> |
| 3187 | template <class _Yp, class _Dp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3188 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3189 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 3190 | #else |
| 3191 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 3192 | #endif |
| 3193 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type) |
| 3194 | : __ptr_(__r.get()) |
| 3195 | { |
| 3196 | typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; |
| 3197 | __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); |
| 3198 | __enable_weak_this(__r.get()); |
| 3199 | __r.release(); |
| 3200 | } |
| 3201 | |
| 3202 | template<class _Tp> |
| 3203 | template <class _Yp, class _Dp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3204 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3205 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 3206 | #else |
| 3207 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 3208 | #endif |
| 3209 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type) |
| 3210 | : __ptr_(__r.get()) |
| 3211 | { |
| 3212 | typedef __shared_ptr_pointer<_Yp*, |
| 3213 | reference_wrapper<typename remove_reference<_Dp>::type>, |
| 3214 | allocator<_Yp> > _CntrlBlk; |
| 3215 | __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); |
| 3216 | __enable_weak_this(__r.get()); |
| 3217 | __r.release(); |
| 3218 | } |
| 3219 | |
| 3220 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3221 | |
| 3222 | template<class _Tp> |
| 3223 | template<class ..._Args> |
| 3224 | shared_ptr<_Tp> |
| 3225 | shared_ptr<_Tp>::make_shared(_Args&& ...__args) |
| 3226 | { |
| 3227 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3228 | typedef allocator<_CntrlBlk> _A2; |
| 3229 | typedef __allocator_destructor<_A2> _D2; |
| 3230 | _A2 __a2; |
| 3231 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3232 | ::new(__hold2.get()) _CntrlBlk(__a2, _STD::forward<_Args>(__args)...); |
| 3233 | shared_ptr<_Tp> __r; |
| 3234 | __r.__ptr_ = __hold2.get()->get(); |
| 3235 | __r.__cntrl_ = __hold2.release(); |
| 3236 | __r.__enable_weak_this(__r.__ptr_); |
| 3237 | return __r; |
| 3238 | } |
| 3239 | |
| 3240 | template<class _Tp> |
| 3241 | template<class _Alloc, class ..._Args> |
| 3242 | shared_ptr<_Tp> |
| 3243 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 3244 | { |
| 3245 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3246 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 3247 | typedef __allocator_destructor<_A2> _D2; |
| 3248 | _A2 __a2(__a); |
| 3249 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3250 | ::new(__hold2.get()) _CntrlBlk(__a, _STD::forward<_Args>(__args)...); |
| 3251 | shared_ptr<_Tp> __r; |
| 3252 | __r.__ptr_ = __hold2.get()->get(); |
| 3253 | __r.__cntrl_ = __hold2.release(); |
| 3254 | __r.__enable_weak_this(__r.__ptr_); |
| 3255 | return __r; |
| 3256 | } |
| 3257 | |
| 3258 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3259 | |
| 3260 | template<class _Tp> |
| 3261 | shared_ptr<_Tp> |
| 3262 | shared_ptr<_Tp>::make_shared() |
| 3263 | { |
| 3264 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3265 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3266 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3267 | _Alloc2 __alloc2; |
| 3268 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3269 | ::new(__hold2.get()) _CntrlBlk(__alloc2); |
| 3270 | shared_ptr<_Tp> __r; |
| 3271 | __r.__ptr_ = __hold2.get()->get(); |
| 3272 | __r.__cntrl_ = __hold2.release(); |
| 3273 | __r.__enable_weak_this(__r.__ptr_); |
| 3274 | return __r; |
| 3275 | } |
| 3276 | |
| 3277 | template<class _Tp> |
| 3278 | template<class _A0> |
| 3279 | shared_ptr<_Tp> |
| 3280 | shared_ptr<_Tp>::make_shared(_A0& __a0) |
| 3281 | { |
| 3282 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3283 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3284 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3285 | _Alloc2 __alloc2; |
| 3286 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3287 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); |
| 3288 | shared_ptr<_Tp> __r; |
| 3289 | __r.__ptr_ = __hold2.get()->get(); |
| 3290 | __r.__cntrl_ = __hold2.release(); |
| 3291 | __r.__enable_weak_this(__r.__ptr_); |
| 3292 | return __r; |
| 3293 | } |
| 3294 | |
| 3295 | template<class _Tp> |
| 3296 | template<class _A0, class _A1> |
| 3297 | shared_ptr<_Tp> |
| 3298 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) |
| 3299 | { |
| 3300 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3301 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3302 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3303 | _Alloc2 __alloc2; |
| 3304 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3305 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); |
| 3306 | shared_ptr<_Tp> __r; |
| 3307 | __r.__ptr_ = __hold2.get()->get(); |
| 3308 | __r.__cntrl_ = __hold2.release(); |
| 3309 | __r.__enable_weak_this(__r.__ptr_); |
| 3310 | return __r; |
| 3311 | } |
| 3312 | |
| 3313 | template<class _Tp> |
| 3314 | template<class _A0, class _A1, class _A2> |
| 3315 | shared_ptr<_Tp> |
| 3316 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 3317 | { |
| 3318 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3319 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3320 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3321 | _Alloc2 __alloc2; |
| 3322 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3323 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); |
| 3324 | shared_ptr<_Tp> __r; |
| 3325 | __r.__ptr_ = __hold2.get()->get(); |
| 3326 | __r.__cntrl_ = __hold2.release(); |
| 3327 | __r.__enable_weak_this(__r.__ptr_); |
| 3328 | return __r; |
| 3329 | } |
| 3330 | |
| 3331 | template<class _Tp> |
| 3332 | template<class _Alloc> |
| 3333 | shared_ptr<_Tp> |
| 3334 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) |
| 3335 | { |
| 3336 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3337 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3338 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3339 | _Alloc2 __alloc2(__a); |
| 3340 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3341 | ::new(__hold2.get()) _CntrlBlk(__a); |
| 3342 | shared_ptr<_Tp> __r; |
| 3343 | __r.__ptr_ = __hold2.get()->get(); |
| 3344 | __r.__cntrl_ = __hold2.release(); |
| 3345 | __r.__enable_weak_this(__r.__ptr_); |
| 3346 | return __r; |
| 3347 | } |
| 3348 | |
| 3349 | template<class _Tp> |
| 3350 | template<class _Alloc, class _A0> |
| 3351 | shared_ptr<_Tp> |
| 3352 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) |
| 3353 | { |
| 3354 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3355 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3356 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3357 | _Alloc2 __alloc2(__a); |
| 3358 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3359 | ::new(__hold2.get()) _CntrlBlk(__a, __a0); |
| 3360 | shared_ptr<_Tp> __r; |
| 3361 | __r.__ptr_ = __hold2.get()->get(); |
| 3362 | __r.__cntrl_ = __hold2.release(); |
| 3363 | __r.__enable_weak_this(__r.__ptr_); |
| 3364 | return __r; |
| 3365 | } |
| 3366 | |
| 3367 | template<class _Tp> |
| 3368 | template<class _Alloc, class _A0, class _A1> |
| 3369 | shared_ptr<_Tp> |
| 3370 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 3371 | { |
| 3372 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3373 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3374 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3375 | _Alloc2 __alloc2(__a); |
| 3376 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3377 | ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1); |
| 3378 | shared_ptr<_Tp> __r; |
| 3379 | __r.__ptr_ = __hold2.get()->get(); |
| 3380 | __r.__cntrl_ = __hold2.release(); |
| 3381 | __r.__enable_weak_this(__r.__ptr_); |
| 3382 | return __r; |
| 3383 | } |
| 3384 | |
| 3385 | template<class _Tp> |
| 3386 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 3387 | shared_ptr<_Tp> |
| 3388 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3389 | { |
| 3390 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3391 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3392 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3393 | _Alloc2 __alloc2(__a); |
| 3394 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3395 | ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2); |
| 3396 | shared_ptr<_Tp> __r; |
| 3397 | __r.__ptr_ = __hold2.get()->get(); |
| 3398 | __r.__cntrl_ = __hold2.release(); |
| 3399 | __r.__enable_weak_this(__r.__ptr_); |
| 3400 | return __r; |
| 3401 | } |
| 3402 | |
| 3403 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3404 | |
| 3405 | template<class _Tp> |
| 3406 | shared_ptr<_Tp>::~shared_ptr() |
| 3407 | { |
| 3408 | if (__cntrl_) |
| 3409 | __cntrl_->__release_shared(); |
| 3410 | } |
| 3411 | |
| 3412 | template<class _Tp> |
| 3413 | inline _LIBCPP_INLINE_VISIBILITY |
| 3414 | shared_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3415 | shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3416 | { |
| 3417 | shared_ptr(__r).swap(*this); |
| 3418 | return *this; |
| 3419 | } |
| 3420 | |
| 3421 | template<class _Tp> |
| 3422 | template<class _Yp> |
| 3423 | inline _LIBCPP_INLINE_VISIBILITY |
| 3424 | shared_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3425 | shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3426 | { |
| 3427 | shared_ptr(__r).swap(*this); |
| 3428 | return *this; |
| 3429 | } |
| 3430 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3431 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3432 | |
| 3433 | template<class _Tp> |
| 3434 | inline _LIBCPP_INLINE_VISIBILITY |
| 3435 | shared_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3436 | shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3437 | { |
| 3438 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3439 | return *this; |
| 3440 | } |
| 3441 | |
| 3442 | template<class _Tp> |
| 3443 | template<class _Yp> |
| 3444 | inline _LIBCPP_INLINE_VISIBILITY |
| 3445 | shared_ptr<_Tp>& |
| 3446 | shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) |
| 3447 | { |
| 3448 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3449 | return *this; |
| 3450 | } |
| 3451 | |
| 3452 | template<class _Tp> |
| 3453 | template<class _Yp> |
| 3454 | inline _LIBCPP_INLINE_VISIBILITY |
| 3455 | shared_ptr<_Tp>& |
| 3456 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) |
| 3457 | { |
Howard Hinnant | 6b41c60 | 2011-05-11 20:21:19 +0000 | [diff] [blame] | 3458 | shared_ptr(_STD::move(__r)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3459 | return *this; |
| 3460 | } |
| 3461 | |
| 3462 | template<class _Tp> |
| 3463 | template <class _Yp, class _Dp> |
| 3464 | inline _LIBCPP_INLINE_VISIBILITY |
| 3465 | shared_ptr<_Tp>& |
| 3466 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) |
| 3467 | { |
| 3468 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3469 | return *this; |
| 3470 | } |
| 3471 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3472 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3473 | |
| 3474 | template<class _Tp> |
| 3475 | template<class _Yp> |
| 3476 | inline _LIBCPP_INLINE_VISIBILITY |
| 3477 | shared_ptr<_Tp>& |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3478 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3479 | { |
| 3480 | shared_ptr(__r).swap(*this); |
| 3481 | return *this; |
| 3482 | } |
| 3483 | |
| 3484 | template<class _Tp> |
| 3485 | template <class _Yp, class _Dp> |
| 3486 | inline _LIBCPP_INLINE_VISIBILITY |
| 3487 | shared_ptr<_Tp>& |
| 3488 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) |
| 3489 | { |
| 3490 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3491 | return *this; |
| 3492 | } |
| 3493 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3494 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3495 | |
| 3496 | template<class _Tp> |
| 3497 | inline _LIBCPP_INLINE_VISIBILITY |
| 3498 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3499 | shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3500 | { |
| 3501 | _STD::swap(__ptr_, __r.__ptr_); |
| 3502 | _STD::swap(__cntrl_, __r.__cntrl_); |
| 3503 | } |
| 3504 | |
| 3505 | template<class _Tp> |
| 3506 | inline _LIBCPP_INLINE_VISIBILITY |
| 3507 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3508 | shared_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3509 | { |
| 3510 | shared_ptr().swap(*this); |
| 3511 | } |
| 3512 | |
| 3513 | template<class _Tp> |
| 3514 | template<class _Yp> |
| 3515 | inline _LIBCPP_INLINE_VISIBILITY |
| 3516 | void |
| 3517 | shared_ptr<_Tp>::reset(_Yp* __p) |
| 3518 | { |
| 3519 | shared_ptr(__p).swap(*this); |
| 3520 | } |
| 3521 | |
| 3522 | template<class _Tp> |
| 3523 | template<class _Yp, class _Dp> |
| 3524 | inline _LIBCPP_INLINE_VISIBILITY |
| 3525 | void |
| 3526 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) |
| 3527 | { |
| 3528 | shared_ptr(__p, __d).swap(*this); |
| 3529 | } |
| 3530 | |
| 3531 | template<class _Tp> |
| 3532 | template<class _Yp, class _Dp, class _Alloc> |
| 3533 | inline _LIBCPP_INLINE_VISIBILITY |
| 3534 | void |
| 3535 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) |
| 3536 | { |
| 3537 | shared_ptr(__p, __d, __a).swap(*this); |
| 3538 | } |
| 3539 | |
| 3540 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3541 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3542 | template<class _Tp, class ..._Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3543 | inline _LIBCPP_INLINE_VISIBILITY |
| 3544 | shared_ptr<_Tp> |
| 3545 | make_shared(_Args&& ...__args) |
| 3546 | { |
| 3547 | return shared_ptr<_Tp>::make_shared(_STD::forward<_Args>(__args)...); |
| 3548 | } |
| 3549 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3550 | template<class _Tp, class _Alloc, class ..._Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3551 | inline _LIBCPP_INLINE_VISIBILITY |
| 3552 | shared_ptr<_Tp> |
| 3553 | allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 3554 | { |
| 3555 | return shared_ptr<_Tp>::allocate_shared(__a, _STD::forward<_Args>(__args)...); |
| 3556 | } |
| 3557 | |
| 3558 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3559 | |
| 3560 | template<class _Tp> |
| 3561 | inline _LIBCPP_INLINE_VISIBILITY |
| 3562 | shared_ptr<_Tp> |
| 3563 | make_shared() |
| 3564 | { |
| 3565 | return shared_ptr<_Tp>::make_shared(); |
| 3566 | } |
| 3567 | |
| 3568 | template<class _Tp, class _A0> |
| 3569 | inline _LIBCPP_INLINE_VISIBILITY |
| 3570 | shared_ptr<_Tp> |
| 3571 | make_shared(_A0& __a0) |
| 3572 | { |
| 3573 | return shared_ptr<_Tp>::make_shared(__a0); |
| 3574 | } |
| 3575 | |
| 3576 | template<class _Tp, class _A0, class _A1> |
| 3577 | inline _LIBCPP_INLINE_VISIBILITY |
| 3578 | shared_ptr<_Tp> |
| 3579 | make_shared(_A0& __a0, _A1& __a1) |
| 3580 | { |
| 3581 | return shared_ptr<_Tp>::make_shared(__a0, __a1); |
| 3582 | } |
| 3583 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3584 | template<class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3585 | inline _LIBCPP_INLINE_VISIBILITY |
| 3586 | shared_ptr<_Tp> |
| 3587 | make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 3588 | { |
| 3589 | return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); |
| 3590 | } |
| 3591 | |
| 3592 | template<class _Tp, class _Alloc> |
| 3593 | inline _LIBCPP_INLINE_VISIBILITY |
| 3594 | shared_ptr<_Tp> |
| 3595 | allocate_shared(const _Alloc& __a) |
| 3596 | { |
| 3597 | return shared_ptr<_Tp>::allocate_shared(__a); |
| 3598 | } |
| 3599 | |
| 3600 | template<class _Tp, class _Alloc, class _A0> |
| 3601 | inline _LIBCPP_INLINE_VISIBILITY |
| 3602 | shared_ptr<_Tp> |
| 3603 | allocate_shared(const _Alloc& __a, _A0& __a0) |
| 3604 | { |
| 3605 | return shared_ptr<_Tp>::allocate_shared(__a, __a0); |
| 3606 | } |
| 3607 | |
| 3608 | template<class _Tp, class _Alloc, class _A0, class _A1> |
| 3609 | inline _LIBCPP_INLINE_VISIBILITY |
| 3610 | shared_ptr<_Tp> |
| 3611 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 3612 | { |
| 3613 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); |
| 3614 | } |
| 3615 | |
| 3616 | template<class _Tp, class _Alloc, class _A0, class _A1, class _A2> |
| 3617 | inline _LIBCPP_INLINE_VISIBILITY |
| 3618 | shared_ptr<_Tp> |
| 3619 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3620 | { |
| 3621 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); |
| 3622 | } |
| 3623 | |
| 3624 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3625 | |
| 3626 | template<class _Tp, class _Up> |
| 3627 | inline _LIBCPP_INLINE_VISIBILITY |
| 3628 | bool |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3629 | operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3630 | { |
| 3631 | return __x.get() == __y.get(); |
| 3632 | } |
| 3633 | |
| 3634 | template<class _Tp, class _Up> |
| 3635 | inline _LIBCPP_INLINE_VISIBILITY |
| 3636 | bool |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3637 | operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3638 | { |
| 3639 | return !(__x == __y); |
| 3640 | } |
| 3641 | |
| 3642 | template<class _Tp, class _Up> |
| 3643 | inline _LIBCPP_INLINE_VISIBILITY |
| 3644 | bool |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3645 | operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3646 | { |
| 3647 | return __x.get() < __y.get(); |
| 3648 | } |
| 3649 | |
| 3650 | template<class _Tp> |
| 3651 | inline _LIBCPP_INLINE_VISIBILITY |
| 3652 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3653 | swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3654 | { |
| 3655 | __x.swap(__y); |
| 3656 | } |
| 3657 | |
| 3658 | template<class _Tp, class _Up> |
| 3659 | inline _LIBCPP_INLINE_VISIBILITY |
| 3660 | shared_ptr<_Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3661 | static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3662 | { |
| 3663 | return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); |
| 3664 | } |
| 3665 | |
| 3666 | template<class _Tp, class _Up> |
| 3667 | inline _LIBCPP_INLINE_VISIBILITY |
| 3668 | shared_ptr<_Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3669 | dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3670 | { |
| 3671 | _Tp* __p = dynamic_cast<_Tp*>(__r.get()); |
| 3672 | return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); |
| 3673 | } |
| 3674 | |
| 3675 | template<class _Tp, class _Up> |
| 3676 | shared_ptr<_Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3677 | const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3678 | { |
| 3679 | return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get())); |
| 3680 | } |
| 3681 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3682 | #ifndef _LIBCPP_NO_RTTI |
| 3683 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3684 | template<class _Dp, class _Tp> |
| 3685 | inline _LIBCPP_INLINE_VISIBILITY |
| 3686 | _Dp* |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3687 | get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3688 | { |
| 3689 | return __p.template __get_deleter<_Dp>(); |
| 3690 | } |
| 3691 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3692 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3693 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3694 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3695 | class _LIBCPP_VISIBLE weak_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3696 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3697 | public: |
| 3698 | typedef _Tp element_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3699 | private: |
| 3700 | element_type* __ptr_; |
| 3701 | __shared_weak_count* __cntrl_; |
| 3702 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3703 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3704 | weak_ptr() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3705 | template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3706 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 3707 | _NOEXCEPT; |
| 3708 | weak_ptr(weak_ptr const& __r) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3709 | template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3710 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 3711 | _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3712 | |
| 3713 | ~weak_ptr(); |
| 3714 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3715 | weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; |
| 3716 | template<class _Yp> weak_ptr& operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; |
| 3717 | template<class _Yp> weak_ptr& operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3718 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3719 | void swap(weak_ptr& __r) _NOEXCEPT; |
| 3720 | void reset() _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3721 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3722 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3723 | long use_count() const _NOEXCEPT |
| 3724 | {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3726 | bool expired() const _NOEXCEPT |
| 3727 | {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} |
| 3728 | shared_ptr<_Tp> lock() const _NOEXCEPT; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3729 | template<class _Up> |
| 3730 | _LIBCPP_INLINE_VISIBILITY |
| 3731 | bool owner_before(const shared_ptr<_Up>& __r) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3732 | {return __cntrl_ < __r.__cntrl_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3733 | template<class _Up> |
| 3734 | _LIBCPP_INLINE_VISIBILITY |
| 3735 | bool owner_before(const weak_ptr<_Up>& __r) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3736 | {return __cntrl_ < __r.__cntrl_;} |
| 3737 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3738 | template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr; |
| 3739 | template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3740 | }; |
| 3741 | |
| 3742 | template<class _Tp> |
| 3743 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3744 | weak_ptr<_Tp>::weak_ptr() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3745 | : __ptr_(0), |
| 3746 | __cntrl_(0) |
| 3747 | { |
| 3748 | } |
| 3749 | |
| 3750 | template<class _Tp> |
| 3751 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3752 | weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3753 | : __ptr_(__r.__ptr_), |
| 3754 | __cntrl_(__r.__cntrl_) |
| 3755 | { |
| 3756 | if (__cntrl_) |
| 3757 | __cntrl_->__add_weak(); |
| 3758 | } |
| 3759 | |
| 3760 | template<class _Tp> |
| 3761 | template<class _Yp> |
| 3762 | inline _LIBCPP_INLINE_VISIBILITY |
| 3763 | weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | e003ce4 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 3764 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3765 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3766 | : __ptr_(__r.__ptr_), |
| 3767 | __cntrl_(__r.__cntrl_) |
| 3768 | { |
| 3769 | if (__cntrl_) |
| 3770 | __cntrl_->__add_weak(); |
| 3771 | } |
| 3772 | |
| 3773 | template<class _Tp> |
| 3774 | template<class _Yp> |
| 3775 | inline _LIBCPP_INLINE_VISIBILITY |
| 3776 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | e003ce4 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 3777 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3778 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3779 | : __ptr_(__r.__ptr_), |
| 3780 | __cntrl_(__r.__cntrl_) |
| 3781 | { |
| 3782 | if (__cntrl_) |
| 3783 | __cntrl_->__add_weak(); |
| 3784 | } |
| 3785 | |
| 3786 | template<class _Tp> |
| 3787 | weak_ptr<_Tp>::~weak_ptr() |
| 3788 | { |
| 3789 | if (__cntrl_) |
| 3790 | __cntrl_->__release_weak(); |
| 3791 | } |
| 3792 | |
| 3793 | template<class _Tp> |
| 3794 | inline _LIBCPP_INLINE_VISIBILITY |
| 3795 | weak_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3796 | weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3797 | { |
| 3798 | weak_ptr(__r).swap(*this); |
| 3799 | return *this; |
| 3800 | } |
| 3801 | |
| 3802 | template<class _Tp> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3803 | template<class _Yp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3804 | inline _LIBCPP_INLINE_VISIBILITY |
| 3805 | weak_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3806 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3807 | { |
| 3808 | weak_ptr(__r).swap(*this); |
| 3809 | return *this; |
| 3810 | } |
| 3811 | |
| 3812 | template<class _Tp> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3813 | template<class _Yp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3814 | inline _LIBCPP_INLINE_VISIBILITY |
| 3815 | weak_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3816 | weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3817 | { |
| 3818 | weak_ptr(__r).swap(*this); |
| 3819 | return *this; |
| 3820 | } |
| 3821 | |
| 3822 | template<class _Tp> |
| 3823 | inline _LIBCPP_INLINE_VISIBILITY |
| 3824 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3825 | weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3826 | { |
| 3827 | _STD::swap(__ptr_, __r.__ptr_); |
| 3828 | _STD::swap(__cntrl_, __r.__cntrl_); |
| 3829 | } |
| 3830 | |
| 3831 | template<class _Tp> |
| 3832 | inline _LIBCPP_INLINE_VISIBILITY |
| 3833 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3834 | swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3835 | { |
| 3836 | __x.swap(__y); |
| 3837 | } |
| 3838 | |
| 3839 | template<class _Tp> |
| 3840 | inline _LIBCPP_INLINE_VISIBILITY |
| 3841 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3842 | weak_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3843 | { |
| 3844 | weak_ptr().swap(*this); |
| 3845 | } |
| 3846 | |
| 3847 | template<class _Tp> |
| 3848 | template<class _Yp> |
| 3849 | shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, |
| 3850 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
| 3851 | : __ptr_(__r.__ptr_), |
| 3852 | __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) |
| 3853 | { |
| 3854 | if (__cntrl_ == 0) |
| 3855 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3856 | throw bad_weak_ptr(); |
| 3857 | #else |
| 3858 | assert(!"bad_weak_ptr"); |
| 3859 | #endif |
| 3860 | } |
| 3861 | |
| 3862 | template<class _Tp> |
| 3863 | shared_ptr<_Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3864 | weak_ptr<_Tp>::lock() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3865 | { |
| 3866 | shared_ptr<_Tp> __r; |
| 3867 | __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; |
| 3868 | if (__r.__cntrl_) |
| 3869 | __r.__ptr_ = __ptr_; |
| 3870 | return __r; |
| 3871 | } |
| 3872 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3873 | template <class _Tp> struct owner_less; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3874 | |
| 3875 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3876 | struct _LIBCPP_VISIBLE owner_less<shared_ptr<_Tp> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3877 | : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3878 | { |
| 3879 | typedef bool result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3880 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3881 | bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3882 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3884 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3885 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3886 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3887 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3888 | {return __x.owner_before(__y);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3889 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3890 | |
| 3891 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3892 | struct _LIBCPP_VISIBLE owner_less<weak_ptr<_Tp> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3893 | : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> |
| 3894 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3895 | typedef bool result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3896 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3897 | bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3898 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3899 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3900 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3901 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3902 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3903 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3904 | {return __x.owner_before(__y);} |
| 3905 | }; |
| 3906 | |
| 3907 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3908 | class _LIBCPP_VISIBLE enable_shared_from_this |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3909 | { |
| 3910 | mutable weak_ptr<_Tp> __weak_this_; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3911 | protected: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3912 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3913 | enable_shared_from_this() _NOEXCEPT {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3914 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3915 | enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3916 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3917 | enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT |
| 3918 | {return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3919 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3920 | ~enable_shared_from_this() {} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3921 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3922 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3923 | shared_ptr<_Tp> shared_from_this() |
| 3924 | {return shared_ptr<_Tp>(__weak_this_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3925 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3926 | shared_ptr<_Tp const> shared_from_this() const |
| 3927 | {return shared_ptr<const _Tp>(__weak_this_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3928 | |
| 3929 | template <class _Up> friend class shared_ptr; |
| 3930 | }; |
| 3931 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3932 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3933 | struct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> > |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3934 | { |
| 3935 | typedef shared_ptr<_Tp> argument_type; |
| 3936 | typedef size_t result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3937 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3938 | result_type operator()(const argument_type& __ptr) const _NOEXCEPT |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3939 | { |
| 3940 | return hash<_Tp*>()(__ptr.get()); |
| 3941 | } |
| 3942 | }; |
| 3943 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3944 | //enum class |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3945 | struct _LIBCPP_VISIBLE pointer_safety |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3946 | { |
| 3947 | enum _ |
| 3948 | { |
| 3949 | relaxed, |
| 3950 | preferred, |
| 3951 | strict |
| 3952 | }; |
| 3953 | |
| 3954 | _ __v_; |
| 3955 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3956 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3957 | pointer_safety(_ __v) : __v_(__v) {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3958 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3959 | operator int() const {return __v_;} |
| 3960 | }; |
| 3961 | |
| 3962 | void declare_reachable(void* __p); |
| 3963 | void declare_no_pointers(char* __p, size_t __n); |
| 3964 | void undeclare_no_pointers(char* __p, size_t __n); |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame^] | 3965 | pointer_safety get_pointer_safety() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3966 | void* __undeclare_reachable(void*); |
| 3967 | |
| 3968 | template <class _Tp> |
| 3969 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3970 | _Tp* |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3971 | undeclare_reachable(_Tp* __p) |
| 3972 | { |
| 3973 | return static_cast<_Tp*>(__undeclare_reachable(__p)); |
| 3974 | } |
| 3975 | |
| 3976 | void* align(size_t, size_t, void*&, size_t&); |
| 3977 | |
| 3978 | _LIBCPP_END_NAMESPACE_STD |
| 3979 | |
| 3980 | #endif // _LIBCPP_MEMORY |