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 | |
Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 +0000 | [diff] [blame] | 1594 | typedef true_type propagate_on_container_move_assignment; |
| 1595 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1596 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 1597 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1598 | _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {} |
| 1599 | template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {} |
| 1600 | _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT |
| 1601 | {return _STD::addressof(__x);} |
| 1602 | _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT |
| 1603 | {return _STD::addressof(__x);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1604 | _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) |
| 1605 | {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1606 | _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT |
| 1607 | {::operator delete((void*)__p);} |
| 1608 | _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT |
| 1609 | {return size_type(~0) / sizeof(_Tp);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1610 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1611 | template <class _Up, class... _Args> |
| 1612 | _LIBCPP_INLINE_VISIBILITY |
| 1613 | void |
| 1614 | construct(_Up* __p, _Args&&... __args) |
| 1615 | { |
| 1616 | ::new((void*)__p) _Up(_STD::forward<_Args>(__args)...); |
| 1617 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1618 | #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1619 | _LIBCPP_INLINE_VISIBILITY |
| 1620 | void |
| 1621 | construct(pointer __p) |
| 1622 | { |
| 1623 | ::new((void*)__p) _Tp(); |
| 1624 | } |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1625 | # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1626 | template <class _A0> |
| 1627 | _LIBCPP_INLINE_VISIBILITY |
| 1628 | typename enable_if |
| 1629 | < |
| 1630 | !is_convertible<_A0, __rv<_A0> >::value, |
| 1631 | void |
| 1632 | >::type |
| 1633 | construct(pointer __p, _A0& __a0) |
| 1634 | { |
| 1635 | ::new((void*)__p) _Tp(__a0); |
| 1636 | } |
| 1637 | template <class _A0> |
| 1638 | _LIBCPP_INLINE_VISIBILITY |
| 1639 | typename enable_if |
| 1640 | < |
| 1641 | !is_convertible<_A0, __rv<_A0> >::value, |
| 1642 | void |
| 1643 | >::type |
| 1644 | construct(pointer __p, const _A0& __a0) |
| 1645 | { |
| 1646 | ::new((void*)__p) _Tp(__a0); |
| 1647 | } |
| 1648 | template <class _A0> |
| 1649 | _LIBCPP_INLINE_VISIBILITY |
| 1650 | typename enable_if |
| 1651 | < |
| 1652 | is_convertible<_A0, __rv<_A0> >::value, |
| 1653 | void |
| 1654 | >::type |
| 1655 | construct(pointer __p, _A0 __a0) |
| 1656 | { |
| 1657 | ::new((void*)__p) _Tp(_STD::move(__a0)); |
| 1658 | } |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1659 | # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1660 | template <class _A0, class _A1> |
| 1661 | _LIBCPP_INLINE_VISIBILITY |
| 1662 | void |
| 1663 | construct(pointer __p, _A0& __a0, _A1& __a1) |
| 1664 | { |
| 1665 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1666 | } |
| 1667 | template <class _A0, class _A1> |
| 1668 | _LIBCPP_INLINE_VISIBILITY |
| 1669 | void |
| 1670 | construct(pointer __p, const _A0& __a0, _A1& __a1) |
| 1671 | { |
| 1672 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1673 | } |
| 1674 | template <class _A0, class _A1> |
| 1675 | _LIBCPP_INLINE_VISIBILITY |
| 1676 | void |
| 1677 | construct(pointer __p, _A0& __a0, const _A1& __a1) |
| 1678 | { |
| 1679 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1680 | } |
| 1681 | template <class _A0, class _A1> |
| 1682 | _LIBCPP_INLINE_VISIBILITY |
| 1683 | void |
| 1684 | construct(pointer __p, const _A0& __a0, const _A1& __a1) |
| 1685 | { |
| 1686 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1687 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1688 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1689 | _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} |
| 1690 | }; |
| 1691 | |
| 1692 | template <class _Tp, class _Up> |
| 1693 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1694 | bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1695 | |
| 1696 | template <class _Tp, class _Up> |
| 1697 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1698 | bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1699 | |
| 1700 | template <class _OutputIterator, class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1701 | class _LIBCPP_VISIBLE raw_storage_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1702 | : public iterator<output_iterator_tag, |
| 1703 | _Tp, // purposefully not C++03 |
| 1704 | ptrdiff_t, // purposefully not C++03 |
| 1705 | _Tp*, // purposefully not C++03 |
| 1706 | raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 |
| 1707 | { |
| 1708 | private: |
| 1709 | _OutputIterator __x_; |
| 1710 | public: |
| 1711 | _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} |
| 1712 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} |
| 1713 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) |
| 1714 | {::new(&*__x_) _Tp(__element); return *this;} |
| 1715 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} |
| 1716 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) |
| 1717 | {raw_storage_iterator __t(*this); ++__x_; return __t;} |
| 1718 | }; |
| 1719 | |
| 1720 | template <class _Tp> |
| 1721 | pair<_Tp*, ptrdiff_t> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1722 | get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1723 | { |
| 1724 | pair<_Tp*, ptrdiff_t> __r(0, 0); |
| 1725 | const ptrdiff_t __m = (~ptrdiff_t(0) ^ |
| 1726 | ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) |
| 1727 | / sizeof(_Tp); |
| 1728 | if (__n > __m) |
| 1729 | __n = __m; |
| 1730 | while (__n > 0) |
| 1731 | { |
| 1732 | __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); |
| 1733 | if (__r.first) |
| 1734 | { |
| 1735 | __r.second = __n; |
| 1736 | break; |
| 1737 | } |
| 1738 | __n /= 2; |
| 1739 | } |
| 1740 | return __r; |
| 1741 | } |
| 1742 | |
| 1743 | template <class _Tp> |
| 1744 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1745 | void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1746 | |
| 1747 | template <class _Tp> |
| 1748 | struct auto_ptr_ref |
| 1749 | { |
| 1750 | _Tp* __ptr_; |
| 1751 | }; |
| 1752 | |
| 1753 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1754 | class _LIBCPP_VISIBLE auto_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1755 | { |
| 1756 | private: |
| 1757 | _Tp* __ptr_; |
| 1758 | public: |
| 1759 | typedef _Tp element_type; |
| 1760 | |
| 1761 | _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {} |
| 1762 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {} |
| 1763 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw() |
| 1764 | : __ptr_(__p.release()) {} |
| 1765 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw() |
| 1766 | {reset(__p.release()); return *this;} |
| 1767 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw() |
| 1768 | {reset(__p.release()); return *this;} |
| 1769 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw() |
| 1770 | {reset(__p.__ptr_); return *this;} |
| 1771 | _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;} |
| 1772 | |
| 1773 | _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw() |
| 1774 | {return *__ptr_;} |
| 1775 | _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;} |
| 1776 | _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;} |
| 1777 | _LIBCPP_INLINE_VISIBILITY _Tp* release() throw() |
| 1778 | { |
| 1779 | _Tp* __t = __ptr_; |
| 1780 | __ptr_ = 0; |
| 1781 | return __t; |
| 1782 | } |
| 1783 | _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw() |
| 1784 | { |
| 1785 | if (__ptr_ != __p) |
| 1786 | delete __ptr_; |
| 1787 | __ptr_ = __p; |
| 1788 | } |
| 1789 | |
| 1790 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {} |
| 1791 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw() |
| 1792 | {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} |
| 1793 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw() |
| 1794 | {return auto_ptr<_Up>(release());} |
| 1795 | }; |
| 1796 | |
| 1797 | template <> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1798 | class _LIBCPP_VISIBLE auto_ptr<void> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1799 | { |
| 1800 | public: |
| 1801 | typedef void element_type; |
| 1802 | }; |
| 1803 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1804 | template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type, |
| 1805 | typename remove_cv<_T2>::type>::value, |
| 1806 | bool = is_empty<_T1>::value, |
| 1807 | bool = is_empty<_T2>::value> |
| 1808 | struct __libcpp_compressed_pair_switch; |
| 1809 | |
| 1810 | template <class _T1, class _T2, bool IsSame> |
| 1811 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};}; |
| 1812 | |
| 1813 | template <class _T1, class _T2, bool IsSame> |
| 1814 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};}; |
| 1815 | |
| 1816 | template <class _T1, class _T2, bool IsSame> |
| 1817 | struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};}; |
| 1818 | |
| 1819 | template <class _T1, class _T2> |
| 1820 | struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};}; |
| 1821 | |
| 1822 | template <class _T1, class _T2> |
| 1823 | struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};}; |
| 1824 | |
| 1825 | template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value> |
| 1826 | class __libcpp_compressed_pair_imp; |
| 1827 | |
| 1828 | template <class _T1, class _T2> |
| 1829 | class __libcpp_compressed_pair_imp<_T1, _T2, 0> |
| 1830 | { |
| 1831 | private: |
| 1832 | _T1 __first_; |
| 1833 | _T2 __second_; |
| 1834 | public: |
| 1835 | typedef _T1 _T1_param; |
| 1836 | typedef _T2 _T2_param; |
| 1837 | |
| 1838 | typedef typename remove_reference<_T1>::type& _T1_reference; |
| 1839 | typedef typename remove_reference<_T2>::type& _T2_reference; |
| 1840 | |
| 1841 | typedef const typename remove_reference<_T1>::type& _T1_const_reference; |
| 1842 | typedef const typename remove_reference<_T2>::type& _T2_const_reference; |
| 1843 | |
| 1844 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1845 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0) |
| 1846 | : __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1847 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0) |
| 1848 | : __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1849 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1850 | : __first_(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1851 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1852 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1853 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1854 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 1855 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1856 | : __first_(_STD::forward<_T1>(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1857 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1858 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1859 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} |
| 1860 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1861 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1862 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} |
| 1863 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1864 | |
| 1865 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1866 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 1867 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1868 | { |
| 1869 | using _STD::swap; |
| 1870 | swap(__first_, __x.__first_); |
| 1871 | swap(__second_, __x.__second_); |
| 1872 | } |
| 1873 | }; |
| 1874 | |
| 1875 | template <class _T1, class _T2> |
| 1876 | class __libcpp_compressed_pair_imp<_T1, _T2, 1> |
| 1877 | : private _T1 |
| 1878 | { |
| 1879 | private: |
| 1880 | _T2 __second_; |
| 1881 | public: |
| 1882 | typedef _T1 _T1_param; |
| 1883 | typedef _T2 _T2_param; |
| 1884 | |
| 1885 | typedef _T1& _T1_reference; |
| 1886 | typedef typename remove_reference<_T2>::type& _T2_reference; |
| 1887 | |
| 1888 | typedef const _T1& _T1_const_reference; |
| 1889 | typedef const typename remove_reference<_T2>::type& _T2_const_reference; |
| 1890 | |
| 1891 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1892 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0) |
| 1893 | : _T1(_STD::forward<_T1_param>(__t1)) {} |
| 1894 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0) |
| 1895 | : __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1896 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1897 | : _T1(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {} |
| 1898 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1899 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1900 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1901 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 1902 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1903 | : _T1(_STD::move(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1904 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1905 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1906 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} |
| 1907 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1908 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1909 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} |
| 1910 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1911 | |
| 1912 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1913 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 1914 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1915 | { |
| 1916 | using _STD::swap; |
| 1917 | swap(__second_, __x.__second_); |
| 1918 | } |
| 1919 | }; |
| 1920 | |
| 1921 | template <class _T1, class _T2> |
| 1922 | class __libcpp_compressed_pair_imp<_T1, _T2, 2> |
| 1923 | : private _T2 |
| 1924 | { |
| 1925 | private: |
| 1926 | _T1 __first_; |
| 1927 | public: |
| 1928 | typedef _T1 _T1_param; |
| 1929 | typedef _T2 _T2_param; |
| 1930 | |
| 1931 | typedef typename remove_reference<_T1>::type& _T1_reference; |
| 1932 | typedef _T2& _T2_reference; |
| 1933 | |
| 1934 | typedef const typename remove_reference<_T1>::type& _T1_const_reference; |
| 1935 | typedef const _T2& _T2_const_reference; |
| 1936 | |
| 1937 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1938 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) |
| 1939 | : __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1940 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) |
| 1941 | : _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1942 | _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] | 1943 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 1944 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1945 | : _T2(_STD::forward<_T2_param>(__t2)), __first_(_STD::forward<_T1_param>(__t1)) {} |
| 1946 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1947 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1948 | __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
| 1949 | : _T2(_STD::forward<_T2>(__p.second())), __first_(_STD::move(__p.first())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1950 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1951 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1952 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} |
| 1953 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1954 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1955 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} |
| 1956 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1957 | |
| 1958 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1959 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 1960 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1961 | { |
| 1962 | using _STD::swap; |
| 1963 | swap(__first_, __x.__first_); |
| 1964 | } |
| 1965 | }; |
| 1966 | |
| 1967 | template <class _T1, class _T2> |
| 1968 | class __libcpp_compressed_pair_imp<_T1, _T2, 3> |
| 1969 | : private _T1, |
| 1970 | private _T2 |
| 1971 | { |
| 1972 | public: |
| 1973 | typedef _T1 _T1_param; |
| 1974 | typedef _T2 _T2_param; |
| 1975 | |
| 1976 | typedef _T1& _T1_reference; |
| 1977 | typedef _T2& _T2_reference; |
| 1978 | |
| 1979 | typedef const _T1& _T1_const_reference; |
| 1980 | typedef const _T2& _T2_const_reference; |
| 1981 | |
| 1982 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} |
| 1983 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) |
| 1984 | : _T1(_STD::forward<_T1_param>(__t1)) {} |
| 1985 | _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) |
| 1986 | : _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1987 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) |
| 1988 | : _T1(_STD::forward<_T1_param>(__t1)), _T2(_STD::forward<_T2_param>(__t2)) {} |
| 1989 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1990 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1991 | _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1992 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 1993 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1994 | : _T1(_STD::move(__p.first())), _T2(_STD::move(__p.second())) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1995 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1996 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1997 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} |
| 1998 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1999 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2000 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} |
| 2001 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2002 | |
| 2003 | _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2004 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2005 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2006 | { |
| 2007 | } |
| 2008 | }; |
| 2009 | |
| 2010 | template <class _T1, class _T2> |
| 2011 | class __compressed_pair |
| 2012 | : private __libcpp_compressed_pair_imp<_T1, _T2> |
| 2013 | { |
| 2014 | typedef __libcpp_compressed_pair_imp<_T1, _T2> base; |
| 2015 | public: |
| 2016 | typedef typename base::_T1_param _T1_param; |
| 2017 | typedef typename base::_T2_param _T2_param; |
| 2018 | |
| 2019 | typedef typename base::_T1_reference _T1_reference; |
| 2020 | typedef typename base::_T2_reference _T2_reference; |
| 2021 | |
| 2022 | typedef typename base::_T1_const_reference _T1_const_reference; |
| 2023 | typedef typename base::_T2_const_reference _T2_const_reference; |
| 2024 | |
| 2025 | _LIBCPP_INLINE_VISIBILITY __compressed_pair() {} |
| 2026 | _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1, int = 0) |
| 2027 | : base(_STD::forward<_T1_param>(__t1)) {} |
| 2028 | _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2, int* = 0) |
| 2029 | : base(_STD::forward<_T2_param>(__t2)) {} |
| 2030 | _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2) |
| 2031 | : base(_STD::forward<_T1_param>(__t1), _STD::forward<_T2_param>(__t2)) {} |
| 2032 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2033 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2034 | __compressed_pair(__compressed_pair&& __p) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2035 | _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && |
| 2036 | is_nothrow_move_constructible<_T2>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2037 | : base(_STD::move(__p)) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2038 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2039 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2040 | _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();} |
| 2041 | _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2042 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2043 | _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();} |
| 2044 | _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2045 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2046 | _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) |
| 2047 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2048 | __is_nothrow_swappable<_T1>::value) |
| 2049 | {base::swap(__x);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2050 | }; |
| 2051 | |
| 2052 | template <class _T1, class _T2> |
| 2053 | inline _LIBCPP_INLINE_VISIBILITY |
| 2054 | void |
| 2055 | swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2056 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2057 | __is_nothrow_swappable<_T1>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2058 | {__x.swap(__y);} |
| 2059 | |
| 2060 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2061 | struct _LIBCPP_VISIBLE default_delete |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2062 | { |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2063 | _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2064 | template <class _Up> |
| 2065 | _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2066 | typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} |
| 2067 | _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2068 | { |
| 2069 | static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); |
| 2070 | delete __ptr; |
| 2071 | } |
| 2072 | }; |
| 2073 | |
| 2074 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2075 | struct _LIBCPP_VISIBLE default_delete<_Tp[]> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | { |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2077 | _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2078 | { |
| 2079 | static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); |
| 2080 | delete [] __ptr; |
| 2081 | } |
| 2082 | private: |
| 2083 | template <class _Up> void operator() (_Up*) const; |
| 2084 | }; |
| 2085 | |
| 2086 | template <class _Tp, class _Dp = default_delete<_Tp> > |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2087 | class _LIBCPP_VISIBLE unique_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2088 | { |
| 2089 | public: |
| 2090 | typedef _Tp element_type; |
| 2091 | typedef _Dp deleter_type; |
| 2092 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2093 | private: |
| 2094 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 2095 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2096 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2097 | unique_ptr(const unique_ptr&); |
| 2098 | unique_ptr& operator=(const unique_ptr&); |
| 2099 | template <class _Up, class _Ep> |
| 2100 | unique_ptr(const unique_ptr<_Up, _Ep>&); |
| 2101 | template <class _Up, class _Ep> |
| 2102 | unique_ptr& operator=(const unique_ptr<_Up, _Ep>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2103 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2104 | unique_ptr(unique_ptr&); |
| 2105 | template <class _Up, class _Ep> |
| 2106 | unique_ptr(unique_ptr<_Up, _Ep>&); |
| 2107 | unique_ptr& operator=(unique_ptr&); |
| 2108 | template <class _Up, class _Ep> |
| 2109 | unique_ptr& operator=(unique_ptr<_Up, _Ep>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2110 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2111 | |
| 2112 | struct __nat {int __for_bool_;}; |
| 2113 | |
| 2114 | typedef typename remove_reference<deleter_type>::type& _Dp_reference; |
| 2115 | typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; |
| 2116 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2117 | _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2118 | : __ptr_(pointer()) |
| 2119 | { |
| 2120 | static_assert(!is_pointer<deleter_type>::value, |
| 2121 | "unique_ptr constructed with null function pointer deleter"); |
| 2122 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2123 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2124 | : __ptr_(pointer()) |
| 2125 | { |
| 2126 | static_assert(!is_pointer<deleter_type>::value, |
| 2127 | "unique_ptr constructed with null function pointer deleter"); |
| 2128 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2129 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2130 | : __ptr_(_STD::move(__p)) |
| 2131 | { |
| 2132 | static_assert(!is_pointer<deleter_type>::value, |
| 2133 | "unique_ptr constructed with null function pointer deleter"); |
| 2134 | } |
| 2135 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2136 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2137 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional< |
| 2138 | is_reference<deleter_type>::value, |
| 2139 | deleter_type, |
| 2140 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2141 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2142 | : __ptr_(__p, __d) {} |
| 2143 | |
| 2144 | _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] | 2145 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2146 | : __ptr_(__p, _STD::move(__d)) |
| 2147 | { |
| 2148 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2149 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2150 | _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2151 | : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {} |
| 2152 | template <class _Up, class _Ep> |
| 2153 | _LIBCPP_INLINE_VISIBILITY |
| 2154 | unique_ptr(unique_ptr<_Up, _Ep>&& __u, |
| 2155 | typename enable_if |
| 2156 | < |
| 2157 | !is_array<_Up>::value && |
| 2158 | is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && |
| 2159 | is_convertible<_Ep, deleter_type>::value && |
| 2160 | ( |
| 2161 | !is_reference<deleter_type>::value || |
| 2162 | is_same<deleter_type, _Ep>::value |
| 2163 | ), |
| 2164 | __nat |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2165 | >::type = __nat()) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2166 | : __ptr_(__u.release(), _STD::forward<_Ep>(__u.get_deleter())) {} |
| 2167 | |
| 2168 | template <class _Up> |
| 2169 | _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p, |
| 2170 | typename enable_if< |
| 2171 | is_convertible<_Up*, _Tp*>::value && |
| 2172 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2173 | __nat |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2174 | >::type = __nat()) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2175 | : __ptr_(__p.release()) |
| 2176 | { |
| 2177 | } |
| 2178 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2179 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2180 | { |
| 2181 | reset(__u.release()); |
| 2182 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2183 | return *this; |
| 2184 | } |
| 2185 | |
| 2186 | template <class _Up, class _Ep> |
| 2187 | _LIBCPP_INLINE_VISIBILITY |
| 2188 | typename enable_if |
| 2189 | < |
| 2190 | !is_array<_Up>::value, |
| 2191 | unique_ptr& |
| 2192 | >::type |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2193 | operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2194 | { |
| 2195 | reset(__u.release()); |
| 2196 | __ptr_.second() = _STD::forward<_Ep>(__u.get_deleter()); |
| 2197 | return *this; |
| 2198 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2199 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2200 | |
| 2201 | _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() |
| 2202 | { |
| 2203 | return __rv<unique_ptr>(*this); |
| 2204 | } |
| 2205 | |
| 2206 | _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) |
| 2207 | : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {} |
| 2208 | |
| 2209 | template <class _Up, class _Ep> |
| 2210 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u) |
| 2211 | { |
| 2212 | reset(__u.release()); |
| 2213 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2214 | return *this; |
| 2215 | } |
| 2216 | |
| 2217 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) |
| 2218 | : __ptr_(_STD::move(__p), _STD::move(__d)) {} |
| 2219 | |
| 2220 | template <class _Up> |
| 2221 | _LIBCPP_INLINE_VISIBILITY |
| 2222 | typename enable_if< |
| 2223 | is_convertible<_Up*, _Tp*>::value && |
| 2224 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2225 | unique_ptr& |
| 2226 | >::type |
| 2227 | operator=(auto_ptr<_Up> __p) |
| 2228 | {reset(__p.release()); return *this;} |
| 2229 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2230 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2231 | _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} |
| 2232 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2233 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2234 | { |
| 2235 | reset(); |
| 2236 | return *this; |
| 2237 | } |
| 2238 | |
| 2239 | _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const |
| 2240 | {return *__ptr_.first();} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2241 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();} |
| 2242 | _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} |
| 2243 | _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT |
| 2244 | {return __ptr_.second();} |
| 2245 | _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT |
| 2246 | {return __ptr_.second();} |
| 2247 | _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const |
| 2248 | _NOEXCEPT |
| 2249 | {return __ptr_.first() ? &__nat::__for_bool_ : 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2250 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2251 | _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2252 | { |
| 2253 | pointer __t = __ptr_.first(); |
| 2254 | __ptr_.first() = pointer(); |
| 2255 | return __t; |
| 2256 | } |
| 2257 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2258 | _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2259 | { |
| 2260 | pointer __tmp = __ptr_.first(); |
| 2261 | __ptr_.first() = __p; |
| 2262 | if (__tmp) |
| 2263 | __ptr_.second()(__tmp); |
| 2264 | } |
| 2265 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2266 | _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT |
| 2267 | {__ptr_.swap(__u.__ptr_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2268 | }; |
| 2269 | |
| 2270 | template <class _Tp, class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2271 | class _LIBCPP_VISIBLE unique_ptr<_Tp[], _Dp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2272 | { |
| 2273 | public: |
| 2274 | typedef _Tp element_type; |
| 2275 | typedef _Dp deleter_type; |
| 2276 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2277 | private: |
| 2278 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 2279 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2280 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2281 | unique_ptr(const unique_ptr&); |
| 2282 | unique_ptr& operator=(const unique_ptr&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2283 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2284 | unique_ptr(unique_ptr&); |
| 2285 | template <class _Up> |
| 2286 | unique_ptr(unique_ptr<_Up>&); |
| 2287 | unique_ptr& operator=(unique_ptr&); |
| 2288 | template <class _Up> |
| 2289 | unique_ptr& operator=(unique_ptr<_Up>&); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2290 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2291 | |
| 2292 | struct __nat {int __for_bool_;}; |
| 2293 | |
| 2294 | typedef typename remove_reference<deleter_type>::type& _Dp_reference; |
| 2295 | typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; |
| 2296 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2297 | _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2298 | : __ptr_(pointer()) |
| 2299 | { |
| 2300 | static_assert(!is_pointer<deleter_type>::value, |
| 2301 | "unique_ptr constructed with null function pointer deleter"); |
| 2302 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2303 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2304 | : __ptr_(pointer()) |
| 2305 | { |
| 2306 | static_assert(!is_pointer<deleter_type>::value, |
| 2307 | "unique_ptr constructed with null function pointer deleter"); |
| 2308 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2309 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2310 | template <class _P, |
| 2311 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2312 | > |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2313 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_P __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2314 | : __ptr_(__p) |
| 2315 | { |
| 2316 | static_assert(!is_pointer<deleter_type>::value, |
| 2317 | "unique_ptr constructed with null function pointer deleter"); |
| 2318 | } |
| 2319 | |
| 2320 | template <class _P, |
| 2321 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2322 | > |
| 2323 | _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename conditional< |
| 2324 | is_reference<deleter_type>::value, |
| 2325 | deleter_type, |
| 2326 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2327 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2328 | : __ptr_(__p, __d) {} |
| 2329 | |
| 2330 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional< |
| 2331 | is_reference<deleter_type>::value, |
| 2332 | deleter_type, |
| 2333 | typename add_lvalue_reference<const deleter_type>::type>::type __d) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2334 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2335 | : __ptr_(pointer(), __d) {} |
| 2336 | |
| 2337 | template <class _P, |
| 2338 | class = typename enable_if<is_same<_P, pointer>::value || |
| 2339 | is_same<_P, nullptr_t>::value>::type |
| 2340 | > |
| 2341 | _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] | 2342 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | : __ptr_(__p, _STD::move(__d)) |
| 2344 | { |
| 2345 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2346 | } |
| 2347 | |
| 2348 | _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] | 2349 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2350 | : __ptr_(pointer(), _STD::move(__d)) |
| 2351 | { |
| 2352 | static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); |
| 2353 | } |
| 2354 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2355 | _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2356 | : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {} |
| 2357 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2358 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2359 | { |
| 2360 | reset(__u.release()); |
| 2361 | __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter()); |
| 2362 | return *this; |
| 2363 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2364 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2365 | |
| 2366 | _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) |
| 2367 | : __ptr_(__p) |
| 2368 | { |
| 2369 | static_assert(!is_pointer<deleter_type>::value, |
| 2370 | "unique_ptr constructed with null function pointer deleter"); |
| 2371 | } |
| 2372 | |
| 2373 | _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) |
| 2374 | : __ptr_(__p, _STD::forward<deleter_type>(__d)) {} |
| 2375 | |
| 2376 | _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d) |
| 2377 | : __ptr_(pointer(), _STD::forward<deleter_type>(__d)) {} |
| 2378 | |
| 2379 | _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() |
| 2380 | { |
| 2381 | return __rv<unique_ptr>(*this); |
| 2382 | } |
| 2383 | |
| 2384 | _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) |
| 2385 | : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {} |
| 2386 | |
| 2387 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u) |
| 2388 | { |
| 2389 | reset(__u->release()); |
| 2390 | __ptr_.second() = _STD::forward<deleter_type>(__u->get_deleter()); |
| 2391 | return *this; |
| 2392 | } |
| 2393 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2394 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2395 | _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} |
| 2396 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2397 | _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2398 | { |
| 2399 | reset(); |
| 2400 | return *this; |
| 2401 | } |
| 2402 | |
| 2403 | _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const |
| 2404 | {return __ptr_.first()[__i];} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2405 | _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} |
| 2406 | _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT |
| 2407 | {return __ptr_.second();} |
| 2408 | _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT |
| 2409 | {return __ptr_.second();} |
| 2410 | _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const _NOEXCEPT |
| 2411 | {return __ptr_.first() ? &__nat::__for_bool_ : 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2412 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2413 | _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2414 | { |
| 2415 | pointer __t = __ptr_.first(); |
| 2416 | __ptr_.first() = pointer(); |
| 2417 | return __t; |
| 2418 | } |
| 2419 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2420 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2421 | template <class _P, |
| 2422 | class = typename enable_if<is_same<_P, pointer>::value>::type |
| 2423 | > |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2424 | _LIBCPP_INLINE_VISIBILITY void reset(_P __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2425 | { |
| 2426 | pointer __tmp = __ptr_.first(); |
| 2427 | __ptr_.first() = __p; |
| 2428 | if (__tmp) |
| 2429 | __ptr_.second()(__tmp); |
| 2430 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2431 | _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2432 | { |
| 2433 | pointer __tmp = __ptr_.first(); |
| 2434 | __ptr_.first() = nullptr; |
| 2435 | if (__tmp) |
| 2436 | __ptr_.second()(__tmp); |
| 2437 | } |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2438 | _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2439 | { |
| 2440 | pointer __tmp = __ptr_.first(); |
| 2441 | __ptr_.first() = nullptr; |
| 2442 | if (__tmp) |
| 2443 | __ptr_.second()(__tmp); |
| 2444 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2445 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2446 | _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) |
| 2447 | { |
| 2448 | pointer __tmp = __ptr_.first(); |
| 2449 | __ptr_.first() = __p; |
| 2450 | if (__tmp) |
| 2451 | __ptr_.second()(__tmp); |
| 2452 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2453 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2454 | |
| 2455 | _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);} |
| 2456 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2457 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2458 | #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2459 | template <class _Up> |
| 2460 | explicit unique_ptr(_Up); |
| 2461 | template <class _Up> |
| 2462 | unique_ptr(_Up __u, |
| 2463 | typename conditional< |
| 2464 | is_reference<deleter_type>::value, |
| 2465 | deleter_type, |
| 2466 | typename add_lvalue_reference<const deleter_type>::type>::type, |
| 2467 | typename enable_if |
| 2468 | < |
| 2469 | is_convertible<_Up, pointer>::value, |
| 2470 | __nat |
| 2471 | >::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2472 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2473 | }; |
| 2474 | |
| 2475 | template <class _Tp, class _Dp> |
| 2476 | inline _LIBCPP_INLINE_VISIBILITY |
| 2477 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2478 | 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] | 2479 | |
| 2480 | template <class _T1, class _D1, class _T2, class _D2> |
| 2481 | inline _LIBCPP_INLINE_VISIBILITY |
| 2482 | bool |
| 2483 | operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} |
| 2484 | |
| 2485 | template <class _T1, class _D1, class _T2, class _D2> |
| 2486 | inline _LIBCPP_INLINE_VISIBILITY |
| 2487 | bool |
| 2488 | operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} |
| 2489 | |
| 2490 | template <class _T1, class _D1, class _T2, class _D2> |
| 2491 | inline _LIBCPP_INLINE_VISIBILITY |
| 2492 | bool |
| 2493 | operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() < __y.get();} |
| 2494 | |
| 2495 | template <class _T1, class _D1, class _T2, class _D2> |
| 2496 | inline _LIBCPP_INLINE_VISIBILITY |
| 2497 | bool |
| 2498 | operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} |
| 2499 | |
| 2500 | template <class _T1, class _D1, class _T2, class _D2> |
| 2501 | inline _LIBCPP_INLINE_VISIBILITY |
| 2502 | bool |
| 2503 | operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} |
| 2504 | |
| 2505 | template <class _T1, class _D1, class _T2, class _D2> |
| 2506 | inline _LIBCPP_INLINE_VISIBILITY |
| 2507 | bool |
| 2508 | operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} |
| 2509 | |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2510 | template <class _Tp> struct hash; |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2511 | |
| 2512 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2513 | struct _LIBCPP_VISIBLE hash<_Tp*> |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2514 | : public unary_function<_Tp*, size_t> |
| 2515 | { |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2517 | size_t operator()(_Tp* __v) const _NOEXCEPT |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2518 | { |
| 2519 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 2520 | return *__p; |
| 2521 | } |
| 2522 | }; |
| 2523 | |
| 2524 | template <class _Tp, class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2525 | struct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> > |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2526 | { |
| 2527 | typedef unique_ptr<_Tp, _Dp> argument_type; |
| 2528 | typedef size_t result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2529 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2530 | result_type operator()(const argument_type& __ptr) const _NOEXCEPT |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2531 | { |
| 2532 | typedef typename argument_type::pointer pointer; |
| 2533 | return hash<pointer>()(__ptr.get()); |
| 2534 | } |
| 2535 | }; |
| 2536 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2537 | struct __destruct_n |
| 2538 | { |
| 2539 | private: |
| 2540 | size_t size; |
| 2541 | |
| 2542 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2543 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2544 | {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();} |
| 2545 | |
| 2546 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2547 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2548 | {} |
| 2549 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2550 | _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2551 | {++size;} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2552 | _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2553 | {} |
| 2554 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2555 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2556 | {size = __s;} |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2557 | _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2558 | {} |
| 2559 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2560 | _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT |
| 2561 | : size(__s) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2562 | |
| 2563 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2564 | _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2565 | {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2566 | |
| 2567 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2568 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2569 | {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2570 | |
| 2571 | template <class _Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2572 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 2573 | {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2574 | }; |
| 2575 | |
| 2576 | template <class _Alloc> |
| 2577 | class __allocator_destructor |
| 2578 | { |
| 2579 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 2580 | public: |
| 2581 | typedef typename __alloc_traits::pointer pointer; |
| 2582 | typedef typename __alloc_traits::size_type size_type; |
| 2583 | private: |
| 2584 | _Alloc& __alloc_; |
| 2585 | size_type __s_; |
| 2586 | public: |
| 2587 | _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2588 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2589 | : __alloc_(__a), __s_(__s) {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2590 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2591 | void operator()(pointer __p) _NOEXCEPT |
| 2592 | {__alloc_traits::deallocate(__alloc_, __p, __s_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2593 | }; |
| 2594 | |
| 2595 | template <class _InputIterator, class _ForwardIterator> |
| 2596 | _ForwardIterator |
| 2597 | uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) |
| 2598 | { |
| 2599 | __destruct_n __d(0); |
| 2600 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2601 | unique_ptr<value_type, __destruct_n&> __h(&*__r, __d); |
| 2602 | for (; __f != __l; ++__f, ++__r, __d.__incr((value_type*)0)) |
| 2603 | ::new(&*__r) value_type(*__f); |
| 2604 | __h.release(); |
| 2605 | return __r; |
| 2606 | } |
| 2607 | |
| 2608 | template <class _InputIterator, class _Size, class _ForwardIterator> |
| 2609 | _ForwardIterator |
| 2610 | uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) |
| 2611 | { |
| 2612 | __destruct_n __d(0); |
| 2613 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2614 | unique_ptr<value_type, __destruct_n&> __h(&*__r, __d); |
| 2615 | for (; __n > 0; ++__f, ++__r, __d.__incr((value_type*)0), --__n) |
| 2616 | ::new(&*__r) value_type(*__f); |
| 2617 | __h.release(); |
| 2618 | return __r; |
| 2619 | } |
| 2620 | |
| 2621 | template <class _ForwardIterator, class _Tp> |
| 2622 | void |
| 2623 | uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) |
| 2624 | { |
| 2625 | __destruct_n __d(0); |
| 2626 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2627 | unique_ptr<value_type, __destruct_n&> __h(&*__f, __d); |
| 2628 | for (; __f != __l; ++__f, __d.__incr((value_type*)0)) |
| 2629 | ::new(&*__f) value_type(__x); |
| 2630 | __h.release(); |
| 2631 | } |
| 2632 | |
| 2633 | template <class _ForwardIterator, class _Size, class _Tp> |
Howard Hinnant | 2f6a627 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 2634 | _ForwardIterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2635 | uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) |
| 2636 | { |
| 2637 | __destruct_n __d(0); |
| 2638 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
| 2639 | unique_ptr<value_type, __destruct_n&> __h(&*__f, __d); |
| 2640 | for (; __n > 0; ++__f, --__n, __d.__incr((value_type*)0)) |
| 2641 | ::new(&*__f) value_type(__x); |
| 2642 | __h.release(); |
Howard Hinnant | 2f6a627 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 2643 | return __f; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2646 | class _LIBCPP_EXCEPTION_ABI bad_weak_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2647 | : public std::exception |
| 2648 | { |
| 2649 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2650 | virtual ~bad_weak_ptr() _NOEXCEPT; |
| 2651 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2652 | }; |
| 2653 | |
| 2654 | template<class _Tp> class weak_ptr; |
| 2655 | |
| 2656 | class __shared_count |
| 2657 | { |
| 2658 | __shared_count(const __shared_count&); |
| 2659 | __shared_count& operator=(const __shared_count&); |
| 2660 | |
| 2661 | protected: |
| 2662 | long __shared_owners_; |
| 2663 | virtual ~__shared_count(); |
| 2664 | private: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2665 | virtual void __on_zero_shared() _NOEXCEPT = 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2666 | |
| 2667 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2668 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2669 | explicit __shared_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2670 | : __shared_owners_(__refs) {} |
| 2671 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2672 | void __add_shared() _NOEXCEPT; |
| 2673 | bool __release_shared() _NOEXCEPT; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2674 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2675 | long use_count() const _NOEXCEPT {return __shared_owners_ + 1;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2676 | }; |
| 2677 | |
| 2678 | class __shared_weak_count |
| 2679 | : private __shared_count |
| 2680 | { |
| 2681 | long __shared_weak_owners_; |
| 2682 | |
| 2683 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2684 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2685 | explicit __shared_weak_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2686 | : __shared_count(__refs), |
| 2687 | __shared_weak_owners_(__refs) {} |
| 2688 | protected: |
| 2689 | virtual ~__shared_weak_count(); |
| 2690 | |
| 2691 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2692 | void __add_shared() _NOEXCEPT; |
| 2693 | void __add_weak() _NOEXCEPT; |
| 2694 | void __release_shared() _NOEXCEPT; |
| 2695 | void __release_weak() _NOEXCEPT; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2696 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2697 | long use_count() const _NOEXCEPT {return __shared_count::use_count();} |
| 2698 | __shared_weak_count* lock() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2699 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2700 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2701 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2702 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2703 | private: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2704 | virtual void __on_zero_shared_weak() _NOEXCEPT = 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2705 | }; |
| 2706 | |
| 2707 | template <class _Tp, class _Dp, class _Alloc> |
| 2708 | class __shared_ptr_pointer |
| 2709 | : public __shared_weak_count |
| 2710 | { |
| 2711 | __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; |
| 2712 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2713 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2714 | __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) |
| 2715 | : __data_(__compressed_pair<_Tp, _Dp>(__p, _STD::move(__d)), _STD::move(__a)) {} |
| 2716 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2717 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2718 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2719 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2720 | |
| 2721 | private: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2722 | virtual void __on_zero_shared() _NOEXCEPT; |
| 2723 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2724 | }; |
| 2725 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2726 | #ifndef _LIBCPP_NO_RTTI |
| 2727 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2728 | template <class _Tp, class _Dp, class _Alloc> |
| 2729 | const void* |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2730 | __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] | 2731 | { |
| 2732 | return __t == typeid(_Dp) ? &__data_.first().second() : 0; |
| 2733 | } |
| 2734 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2735 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2736 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2737 | template <class _Tp, class _Dp, class _Alloc> |
| 2738 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2739 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2740 | { |
| 2741 | __data_.first().second()(__data_.first().first()); |
| 2742 | __data_.first().second().~_Dp(); |
| 2743 | } |
| 2744 | |
| 2745 | template <class _Tp, class _Dp, class _Alloc> |
| 2746 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2747 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2748 | { |
| 2749 | typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second()); |
| 2750 | __data_.second().~_Alloc(); |
| 2751 | __a.deallocate(this, 1); |
| 2752 | } |
| 2753 | |
| 2754 | template <class _Tp, class _Alloc> |
| 2755 | class __shared_ptr_emplace |
| 2756 | : public __shared_weak_count |
| 2757 | { |
| 2758 | __compressed_pair<_Alloc, _Tp> __data_; |
| 2759 | public: |
| 2760 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 2761 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2762 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2763 | __shared_ptr_emplace(_Alloc __a) |
| 2764 | : __data_(_STD::move(__a)) {} |
| 2765 | |
| 2766 | template <class ..._Args> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2767 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2768 | __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) |
| 2769 | : __data_(_STD::move(__a), _Tp(_STD::forward<_Args>(__args)...)) {} |
| 2770 | |
| 2771 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 2772 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2773 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2774 | __shared_ptr_emplace(_Alloc __a) |
| 2775 | : __data_(__a) {} |
| 2776 | |
| 2777 | template <class _A0> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2778 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2779 | __shared_ptr_emplace(_Alloc __a, _A0& __a0) |
| 2780 | : __data_(__a, _Tp(__a0)) {} |
| 2781 | |
| 2782 | template <class _A0, class _A1> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2784 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) |
| 2785 | : __data_(__a, _Tp(__a0, __a1)) {} |
| 2786 | |
| 2787 | template <class _A0, class _A1, class _A2> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2788 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2789 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 2790 | : __data_(__a, _Tp(__a0, __a1, __a2)) {} |
| 2791 | |
| 2792 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2793 | |
| 2794 | private: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2795 | virtual void __on_zero_shared() _NOEXCEPT; |
| 2796 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2797 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2799 | _Tp* get() _NOEXCEPT {return &__data_.second();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2800 | }; |
| 2801 | |
| 2802 | template <class _Tp, class _Alloc> |
| 2803 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2804 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2805 | { |
| 2806 | __data_.second().~_Tp(); |
| 2807 | } |
| 2808 | |
| 2809 | template <class _Tp, class _Alloc> |
| 2810 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2811 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2812 | { |
| 2813 | typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first()); |
| 2814 | __data_.first().~_Alloc(); |
| 2815 | __a.deallocate(this, 1); |
| 2816 | } |
| 2817 | |
| 2818 | template<class _Tp> class enable_shared_from_this; |
| 2819 | |
| 2820 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2821 | class _LIBCPP_VISIBLE shared_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2822 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2823 | public: |
| 2824 | typedef _Tp element_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2825 | private: |
| 2826 | element_type* __ptr_; |
| 2827 | __shared_weak_count* __cntrl_; |
| 2828 | |
| 2829 | struct __nat {int __for_bool_;}; |
| 2830 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2831 | shared_ptr() _NOEXCEPT; |
| 2832 | shared_ptr(nullptr_t) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2833 | template<class _Yp> explicit shared_ptr(_Yp* __p); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2834 | template<class _Yp, class _Dp> shared_ptr(_Yp* __p, _Dp __d); |
| 2835 | 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] | 2836 | template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); |
| 2837 | 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] | 2838 | template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; |
| 2839 | shared_ptr(const shared_ptr& __r) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2840 | template<class _Yp> |
| 2841 | shared_ptr(const shared_ptr<_Yp>& __r, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2842 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) |
| 2843 | _NOEXCEPT; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2844 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2845 | shared_ptr(shared_ptr&& __r) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2846 | template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2847 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) |
| 2848 | _NOEXCEPT; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2849 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2850 | template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2851 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2852 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2853 | template<class _Yp> shared_ptr(auto_ptr<_Yp>&& __r); |
| 2854 | #else |
| 2855 | template<class _Yp> shared_ptr(auto_ptr<_Yp> __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2856 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2857 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2858 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2859 | 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] | 2860 | public: |
| 2861 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 2862 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
| 2863 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 2864 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2865 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2866 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>, |
| 2867 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
| 2868 | template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>, |
| 2869 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat()); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2870 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2871 | |
| 2872 | ~shared_ptr(); |
| 2873 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2874 | shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; |
| 2875 | template<class _Yp> shared_ptr& operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2876 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2877 | shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2878 | template<class _Yp> shared_ptr& operator=(shared_ptr<_Yp>&& __r); |
| 2879 | template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp>&& __r); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2880 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2881 | template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp> __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2882 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2883 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2884 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2885 | 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] | 2886 | public: |
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 | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2888 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2889 | 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] | 2890 | #endif |
| 2891 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2892 | void swap(shared_ptr& __r) _NOEXCEPT; |
| 2893 | void reset() _NOEXCEPT; |
| 2894 | template<class _Yp> void reset(_Yp* __p) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2895 | template<class _Yp, class _Dp> void reset(_Yp* __p, _Dp __d); |
| 2896 | template<class _Yp, class _Dp, class _Alloc> void reset(_Yp* __p, _Dp __d, _Alloc __a); |
| 2897 | |
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 | element_type* get() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2900 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2901 | typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT |
| 2902 | {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 | element_type* operator->() const _NOEXCEPT {return __ptr_;} |
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 | long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} |
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 | bool unique() const _NOEXCEPT {return use_count() == 1;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2909 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2910 | /*explicit*/ operator bool() const _NOEXCEPT {return get() != 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2911 | template <class _U> |
| 2912 | _LIBCPP_INLINE_VISIBILITY |
| 2913 | bool owner_before(shared_ptr<_U> const& __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2914 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2915 | template <class _U> |
| 2916 | _LIBCPP_INLINE_VISIBILITY |
| 2917 | bool owner_before(weak_ptr<_U> const& __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2918 | {return __cntrl_ < __p.__cntrl_;} |
| 2919 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2920 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2921 | template <class _Dp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2922 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2923 | _Dp* __get_deleter() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2924 | {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2925 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2926 | |
| 2927 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 2928 | |
| 2929 | template<class ..._Args> |
| 2930 | static |
| 2931 | shared_ptr<_Tp> |
| 2932 | make_shared(_Args&& ...__args); |
| 2933 | |
| 2934 | template<class _Alloc, class ..._Args> |
| 2935 | static |
| 2936 | shared_ptr<_Tp> |
| 2937 | allocate_shared(const _Alloc& __a, _Args&& ...__args); |
| 2938 | |
| 2939 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 2940 | |
| 2941 | static shared_ptr<_Tp> make_shared(); |
| 2942 | |
| 2943 | template<class _A0> |
| 2944 | static shared_ptr<_Tp> make_shared(_A0&); |
| 2945 | |
| 2946 | template<class _A0, class _A1> |
| 2947 | static shared_ptr<_Tp> make_shared(_A0&, _A1&); |
| 2948 | |
| 2949 | template<class _A0, class _A1, class _A2> |
| 2950 | static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); |
| 2951 | |
| 2952 | template<class _Alloc> |
| 2953 | static shared_ptr<_Tp> |
| 2954 | allocate_shared(const _Alloc& __a); |
| 2955 | |
| 2956 | template<class _Alloc, class _A0> |
| 2957 | static shared_ptr<_Tp> |
| 2958 | allocate_shared(const _Alloc& __a, _A0& __a0); |
| 2959 | |
| 2960 | template<class _Alloc, class _A0, class _A1> |
| 2961 | static shared_ptr<_Tp> |
| 2962 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); |
| 2963 | |
| 2964 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 2965 | static shared_ptr<_Tp> |
| 2966 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); |
| 2967 | |
| 2968 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2969 | |
| 2970 | private: |
| 2971 | |
| 2972 | template <class _Yp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2973 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2974 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2975 | __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2976 | { |
| 2977 | if (__e) |
| 2978 | __e->__weak_this_ = *this; |
| 2979 | } |
| 2980 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2981 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2982 | void __enable_weak_this(const void*) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2983 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2984 | template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr; |
| 2985 | template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2986 | }; |
| 2987 | |
| 2988 | template<class _Tp> |
| 2989 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2990 | shared_ptr<_Tp>::shared_ptr() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | : __ptr_(0), |
| 2992 | __cntrl_(0) |
| 2993 | { |
| 2994 | } |
| 2995 | |
| 2996 | template<class _Tp> |
| 2997 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2998 | shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2999 | : __ptr_(0), |
| 3000 | __cntrl_(0) |
| 3001 | { |
| 3002 | } |
| 3003 | |
| 3004 | template<class _Tp> |
| 3005 | template<class _Yp> |
| 3006 | shared_ptr<_Tp>::shared_ptr(_Yp* __p) |
| 3007 | : __ptr_(__p) |
| 3008 | { |
| 3009 | unique_ptr<_Yp> __hold(__p); |
| 3010 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 3011 | __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>()); |
| 3012 | __hold.release(); |
| 3013 | __enable_weak_this(__p); |
| 3014 | } |
| 3015 | |
| 3016 | template<class _Tp> |
| 3017 | template<class _Yp, class _Dp> |
| 3018 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d) |
| 3019 | : __ptr_(__p) |
| 3020 | { |
| 3021 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3022 | try |
| 3023 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3024 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3025 | typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; |
| 3026 | __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>()); |
| 3027 | __enable_weak_this(__p); |
| 3028 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3029 | } |
| 3030 | catch (...) |
| 3031 | { |
| 3032 | __d(__p); |
| 3033 | throw; |
| 3034 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3035 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | template<class _Tp> |
| 3039 | template<class _Dp> |
| 3040 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) |
| 3041 | : __ptr_(0) |
| 3042 | { |
| 3043 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3044 | try |
| 3045 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3046 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3047 | typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk; |
| 3048 | __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>()); |
| 3049 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3050 | } |
| 3051 | catch (...) |
| 3052 | { |
| 3053 | __d(__p); |
| 3054 | throw; |
| 3055 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3056 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | template<class _Tp> |
| 3060 | template<class _Yp, class _Dp, class _Alloc> |
| 3061 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) |
| 3062 | : __ptr_(__p) |
| 3063 | { |
| 3064 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3065 | try |
| 3066 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3067 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3068 | typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; |
| 3069 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 3070 | typedef __allocator_destructor<_A2> _D2; |
| 3071 | _A2 __a2(__a); |
| 3072 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3073 | ::new(__hold2.get()) _CntrlBlk(__p, __d, __a); |
| 3074 | __cntrl_ = __hold2.release(); |
| 3075 | __enable_weak_this(__p); |
| 3076 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3077 | } |
| 3078 | catch (...) |
| 3079 | { |
| 3080 | __d(__p); |
| 3081 | throw; |
| 3082 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3083 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | template<class _Tp> |
| 3087 | template<class _Dp, class _Alloc> |
| 3088 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) |
| 3089 | : __ptr_(0) |
| 3090 | { |
| 3091 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3092 | try |
| 3093 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3094 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3095 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; |
| 3096 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 3097 | typedef __allocator_destructor<_A2> _D2; |
| 3098 | _A2 __a2(__a); |
| 3099 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3100 | ::new(__hold2.get()) _CntrlBlk(__p, __d, __a); |
| 3101 | __cntrl_ = __hold2.release(); |
| 3102 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3103 | } |
| 3104 | catch (...) |
| 3105 | { |
| 3106 | __d(__p); |
| 3107 | throw; |
| 3108 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3109 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | template<class _Tp> |
| 3113 | template<class _Yp> |
| 3114 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3115 | 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] | 3116 | : __ptr_(__p), |
| 3117 | __cntrl_(__r.__cntrl_) |
| 3118 | { |
| 3119 | if (__cntrl_) |
| 3120 | __cntrl_->__add_shared(); |
| 3121 | } |
| 3122 | |
| 3123 | template<class _Tp> |
| 3124 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3125 | shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3126 | : __ptr_(__r.__ptr_), |
| 3127 | __cntrl_(__r.__cntrl_) |
| 3128 | { |
| 3129 | if (__cntrl_) |
| 3130 | __cntrl_->__add_shared(); |
| 3131 | } |
| 3132 | |
| 3133 | template<class _Tp> |
| 3134 | template<class _Yp> |
| 3135 | inline _LIBCPP_INLINE_VISIBILITY |
| 3136 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, |
| 3137 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3138 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3139 | : __ptr_(__r.__ptr_), |
| 3140 | __cntrl_(__r.__cntrl_) |
| 3141 | { |
| 3142 | if (__cntrl_) |
| 3143 | __cntrl_->__add_shared(); |
| 3144 | } |
| 3145 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3146 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3147 | |
| 3148 | template<class _Tp> |
| 3149 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3150 | shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3151 | : __ptr_(__r.__ptr_), |
| 3152 | __cntrl_(__r.__cntrl_) |
| 3153 | { |
| 3154 | __r.__ptr_ = 0; |
| 3155 | __r.__cntrl_ = 0; |
| 3156 | } |
| 3157 | |
| 3158 | template<class _Tp> |
| 3159 | template<class _Yp> |
| 3160 | inline _LIBCPP_INLINE_VISIBILITY |
| 3161 | shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, |
| 3162 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3163 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3164 | : __ptr_(__r.__ptr_), |
| 3165 | __cntrl_(__r.__cntrl_) |
| 3166 | { |
| 3167 | __r.__ptr_ = 0; |
| 3168 | __r.__cntrl_ = 0; |
| 3169 | } |
| 3170 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3171 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3172 | |
| 3173 | template<class _Tp> |
| 3174 | template<class _Yp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3175 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3176 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r) |
| 3177 | #else |
Howard Hinnant | 92172b8 | 2010-08-21 21:14:53 +0000 | [diff] [blame] | 3178 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3179 | #endif |
| 3180 | : __ptr_(__r.get()) |
| 3181 | { |
| 3182 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 3183 | __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); |
| 3184 | __enable_weak_this(__r.get()); |
| 3185 | __r.release(); |
| 3186 | } |
| 3187 | |
| 3188 | template<class _Tp> |
| 3189 | template <class _Yp, class _Dp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3190 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3191 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 3192 | #else |
| 3193 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 3194 | #endif |
| 3195 | typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type) |
| 3196 | : __ptr_(__r.get()) |
| 3197 | { |
| 3198 | typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; |
| 3199 | __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); |
| 3200 | __enable_weak_this(__r.get()); |
| 3201 | __r.release(); |
| 3202 | } |
| 3203 | |
| 3204 | template<class _Tp> |
| 3205 | template <class _Yp, class _Dp> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3206 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3207 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 3208 | #else |
| 3209 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 3210 | #endif |
| 3211 | typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type) |
| 3212 | : __ptr_(__r.get()) |
| 3213 | { |
| 3214 | typedef __shared_ptr_pointer<_Yp*, |
| 3215 | reference_wrapper<typename remove_reference<_Dp>::type>, |
| 3216 | allocator<_Yp> > _CntrlBlk; |
| 3217 | __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); |
| 3218 | __enable_weak_this(__r.get()); |
| 3219 | __r.release(); |
| 3220 | } |
| 3221 | |
| 3222 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3223 | |
| 3224 | template<class _Tp> |
| 3225 | template<class ..._Args> |
| 3226 | shared_ptr<_Tp> |
| 3227 | shared_ptr<_Tp>::make_shared(_Args&& ...__args) |
| 3228 | { |
| 3229 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3230 | typedef allocator<_CntrlBlk> _A2; |
| 3231 | typedef __allocator_destructor<_A2> _D2; |
| 3232 | _A2 __a2; |
| 3233 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3234 | ::new(__hold2.get()) _CntrlBlk(__a2, _STD::forward<_Args>(__args)...); |
| 3235 | shared_ptr<_Tp> __r; |
| 3236 | __r.__ptr_ = __hold2.get()->get(); |
| 3237 | __r.__cntrl_ = __hold2.release(); |
| 3238 | __r.__enable_weak_this(__r.__ptr_); |
| 3239 | return __r; |
| 3240 | } |
| 3241 | |
| 3242 | template<class _Tp> |
| 3243 | template<class _Alloc, class ..._Args> |
| 3244 | shared_ptr<_Tp> |
| 3245 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 3246 | { |
| 3247 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3248 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2; |
| 3249 | typedef __allocator_destructor<_A2> _D2; |
| 3250 | _A2 __a2(__a); |
| 3251 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 3252 | ::new(__hold2.get()) _CntrlBlk(__a, _STD::forward<_Args>(__args)...); |
| 3253 | shared_ptr<_Tp> __r; |
| 3254 | __r.__ptr_ = __hold2.get()->get(); |
| 3255 | __r.__cntrl_ = __hold2.release(); |
| 3256 | __r.__enable_weak_this(__r.__ptr_); |
| 3257 | return __r; |
| 3258 | } |
| 3259 | |
| 3260 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3261 | |
| 3262 | template<class _Tp> |
| 3263 | shared_ptr<_Tp> |
| 3264 | shared_ptr<_Tp>::make_shared() |
| 3265 | { |
| 3266 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3267 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3268 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3269 | _Alloc2 __alloc2; |
| 3270 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3271 | ::new(__hold2.get()) _CntrlBlk(__alloc2); |
| 3272 | shared_ptr<_Tp> __r; |
| 3273 | __r.__ptr_ = __hold2.get()->get(); |
| 3274 | __r.__cntrl_ = __hold2.release(); |
| 3275 | __r.__enable_weak_this(__r.__ptr_); |
| 3276 | return __r; |
| 3277 | } |
| 3278 | |
| 3279 | template<class _Tp> |
| 3280 | template<class _A0> |
| 3281 | shared_ptr<_Tp> |
| 3282 | shared_ptr<_Tp>::make_shared(_A0& __a0) |
| 3283 | { |
| 3284 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3285 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3286 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3287 | _Alloc2 __alloc2; |
| 3288 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3289 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); |
| 3290 | shared_ptr<_Tp> __r; |
| 3291 | __r.__ptr_ = __hold2.get()->get(); |
| 3292 | __r.__cntrl_ = __hold2.release(); |
| 3293 | __r.__enable_weak_this(__r.__ptr_); |
| 3294 | return __r; |
| 3295 | } |
| 3296 | |
| 3297 | template<class _Tp> |
| 3298 | template<class _A0, class _A1> |
| 3299 | shared_ptr<_Tp> |
| 3300 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) |
| 3301 | { |
| 3302 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3303 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3304 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3305 | _Alloc2 __alloc2; |
| 3306 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3307 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); |
| 3308 | shared_ptr<_Tp> __r; |
| 3309 | __r.__ptr_ = __hold2.get()->get(); |
| 3310 | __r.__cntrl_ = __hold2.release(); |
| 3311 | __r.__enable_weak_this(__r.__ptr_); |
| 3312 | return __r; |
| 3313 | } |
| 3314 | |
| 3315 | template<class _Tp> |
| 3316 | template<class _A0, class _A1, class _A2> |
| 3317 | shared_ptr<_Tp> |
| 3318 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 3319 | { |
| 3320 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 3321 | typedef allocator<_CntrlBlk> _Alloc2; |
| 3322 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3323 | _Alloc2 __alloc2; |
| 3324 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3325 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); |
| 3326 | shared_ptr<_Tp> __r; |
| 3327 | __r.__ptr_ = __hold2.get()->get(); |
| 3328 | __r.__cntrl_ = __hold2.release(); |
| 3329 | __r.__enable_weak_this(__r.__ptr_); |
| 3330 | return __r; |
| 3331 | } |
| 3332 | |
| 3333 | template<class _Tp> |
| 3334 | template<class _Alloc> |
| 3335 | shared_ptr<_Tp> |
| 3336 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) |
| 3337 | { |
| 3338 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3339 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3340 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3341 | _Alloc2 __alloc2(__a); |
| 3342 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3343 | ::new(__hold2.get()) _CntrlBlk(__a); |
| 3344 | shared_ptr<_Tp> __r; |
| 3345 | __r.__ptr_ = __hold2.get()->get(); |
| 3346 | __r.__cntrl_ = __hold2.release(); |
| 3347 | __r.__enable_weak_this(__r.__ptr_); |
| 3348 | return __r; |
| 3349 | } |
| 3350 | |
| 3351 | template<class _Tp> |
| 3352 | template<class _Alloc, class _A0> |
| 3353 | shared_ptr<_Tp> |
| 3354 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) |
| 3355 | { |
| 3356 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3357 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3358 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3359 | _Alloc2 __alloc2(__a); |
| 3360 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3361 | ::new(__hold2.get()) _CntrlBlk(__a, __a0); |
| 3362 | shared_ptr<_Tp> __r; |
| 3363 | __r.__ptr_ = __hold2.get()->get(); |
| 3364 | __r.__cntrl_ = __hold2.release(); |
| 3365 | __r.__enable_weak_this(__r.__ptr_); |
| 3366 | return __r; |
| 3367 | } |
| 3368 | |
| 3369 | template<class _Tp> |
| 3370 | template<class _Alloc, class _A0, class _A1> |
| 3371 | shared_ptr<_Tp> |
| 3372 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 3373 | { |
| 3374 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3375 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3376 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3377 | _Alloc2 __alloc2(__a); |
| 3378 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3379 | ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1); |
| 3380 | shared_ptr<_Tp> __r; |
| 3381 | __r.__ptr_ = __hold2.get()->get(); |
| 3382 | __r.__cntrl_ = __hold2.release(); |
| 3383 | __r.__enable_weak_this(__r.__ptr_); |
| 3384 | return __r; |
| 3385 | } |
| 3386 | |
| 3387 | template<class _Tp> |
| 3388 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 3389 | shared_ptr<_Tp> |
| 3390 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3391 | { |
| 3392 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 3393 | typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2; |
| 3394 | typedef __allocator_destructor<_Alloc2> _D2; |
| 3395 | _Alloc2 __alloc2(__a); |
| 3396 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 3397 | ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2); |
| 3398 | shared_ptr<_Tp> __r; |
| 3399 | __r.__ptr_ = __hold2.get()->get(); |
| 3400 | __r.__cntrl_ = __hold2.release(); |
| 3401 | __r.__enable_weak_this(__r.__ptr_); |
| 3402 | return __r; |
| 3403 | } |
| 3404 | |
| 3405 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3406 | |
| 3407 | template<class _Tp> |
| 3408 | shared_ptr<_Tp>::~shared_ptr() |
| 3409 | { |
| 3410 | if (__cntrl_) |
| 3411 | __cntrl_->__release_shared(); |
| 3412 | } |
| 3413 | |
| 3414 | template<class _Tp> |
| 3415 | inline _LIBCPP_INLINE_VISIBILITY |
| 3416 | shared_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3417 | shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3418 | { |
| 3419 | shared_ptr(__r).swap(*this); |
| 3420 | return *this; |
| 3421 | } |
| 3422 | |
| 3423 | template<class _Tp> |
| 3424 | template<class _Yp> |
| 3425 | inline _LIBCPP_INLINE_VISIBILITY |
| 3426 | shared_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3427 | shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3428 | { |
| 3429 | shared_ptr(__r).swap(*this); |
| 3430 | return *this; |
| 3431 | } |
| 3432 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3433 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3434 | |
| 3435 | template<class _Tp> |
| 3436 | inline _LIBCPP_INLINE_VISIBILITY |
| 3437 | shared_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3438 | shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3439 | { |
| 3440 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3441 | return *this; |
| 3442 | } |
| 3443 | |
| 3444 | template<class _Tp> |
| 3445 | template<class _Yp> |
| 3446 | inline _LIBCPP_INLINE_VISIBILITY |
| 3447 | shared_ptr<_Tp>& |
| 3448 | shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) |
| 3449 | { |
| 3450 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3451 | return *this; |
| 3452 | } |
| 3453 | |
| 3454 | template<class _Tp> |
| 3455 | template<class _Yp> |
| 3456 | inline _LIBCPP_INLINE_VISIBILITY |
| 3457 | shared_ptr<_Tp>& |
| 3458 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) |
| 3459 | { |
Howard Hinnant | 6b41c60 | 2011-05-11 20:21:19 +0000 | [diff] [blame] | 3460 | shared_ptr(_STD::move(__r)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3461 | return *this; |
| 3462 | } |
| 3463 | |
| 3464 | template<class _Tp> |
| 3465 | template <class _Yp, class _Dp> |
| 3466 | inline _LIBCPP_INLINE_VISIBILITY |
| 3467 | shared_ptr<_Tp>& |
| 3468 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) |
| 3469 | { |
| 3470 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3471 | return *this; |
| 3472 | } |
| 3473 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3474 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3475 | |
| 3476 | template<class _Tp> |
| 3477 | template<class _Yp> |
| 3478 | inline _LIBCPP_INLINE_VISIBILITY |
| 3479 | shared_ptr<_Tp>& |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3480 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3481 | { |
| 3482 | shared_ptr(__r).swap(*this); |
| 3483 | return *this; |
| 3484 | } |
| 3485 | |
| 3486 | template<class _Tp> |
| 3487 | template <class _Yp, class _Dp> |
| 3488 | inline _LIBCPP_INLINE_VISIBILITY |
| 3489 | shared_ptr<_Tp>& |
| 3490 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) |
| 3491 | { |
| 3492 | shared_ptr(_STD::move(__r)).swap(*this); |
| 3493 | return *this; |
| 3494 | } |
| 3495 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3496 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3497 | |
| 3498 | template<class _Tp> |
| 3499 | inline _LIBCPP_INLINE_VISIBILITY |
| 3500 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3501 | shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3502 | { |
| 3503 | _STD::swap(__ptr_, __r.__ptr_); |
| 3504 | _STD::swap(__cntrl_, __r.__cntrl_); |
| 3505 | } |
| 3506 | |
| 3507 | template<class _Tp> |
| 3508 | inline _LIBCPP_INLINE_VISIBILITY |
| 3509 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3510 | shared_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3511 | { |
| 3512 | shared_ptr().swap(*this); |
| 3513 | } |
| 3514 | |
| 3515 | template<class _Tp> |
| 3516 | template<class _Yp> |
| 3517 | inline _LIBCPP_INLINE_VISIBILITY |
| 3518 | void |
| 3519 | shared_ptr<_Tp>::reset(_Yp* __p) |
| 3520 | { |
| 3521 | shared_ptr(__p).swap(*this); |
| 3522 | } |
| 3523 | |
| 3524 | template<class _Tp> |
| 3525 | template<class _Yp, class _Dp> |
| 3526 | inline _LIBCPP_INLINE_VISIBILITY |
| 3527 | void |
| 3528 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) |
| 3529 | { |
| 3530 | shared_ptr(__p, __d).swap(*this); |
| 3531 | } |
| 3532 | |
| 3533 | template<class _Tp> |
| 3534 | template<class _Yp, class _Dp, class _Alloc> |
| 3535 | inline _LIBCPP_INLINE_VISIBILITY |
| 3536 | void |
| 3537 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) |
| 3538 | { |
| 3539 | shared_ptr(__p, __d, __a).swap(*this); |
| 3540 | } |
| 3541 | |
| 3542 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3543 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3544 | template<class _Tp, class ..._Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3545 | inline _LIBCPP_INLINE_VISIBILITY |
| 3546 | shared_ptr<_Tp> |
| 3547 | make_shared(_Args&& ...__args) |
| 3548 | { |
| 3549 | return shared_ptr<_Tp>::make_shared(_STD::forward<_Args>(__args)...); |
| 3550 | } |
| 3551 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3552 | template<class _Tp, class _Alloc, class ..._Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3553 | inline _LIBCPP_INLINE_VISIBILITY |
| 3554 | shared_ptr<_Tp> |
| 3555 | allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 3556 | { |
| 3557 | return shared_ptr<_Tp>::allocate_shared(__a, _STD::forward<_Args>(__args)...); |
| 3558 | } |
| 3559 | |
| 3560 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3561 | |
| 3562 | template<class _Tp> |
| 3563 | inline _LIBCPP_INLINE_VISIBILITY |
| 3564 | shared_ptr<_Tp> |
| 3565 | make_shared() |
| 3566 | { |
| 3567 | return shared_ptr<_Tp>::make_shared(); |
| 3568 | } |
| 3569 | |
| 3570 | template<class _Tp, class _A0> |
| 3571 | inline _LIBCPP_INLINE_VISIBILITY |
| 3572 | shared_ptr<_Tp> |
| 3573 | make_shared(_A0& __a0) |
| 3574 | { |
| 3575 | return shared_ptr<_Tp>::make_shared(__a0); |
| 3576 | } |
| 3577 | |
| 3578 | template<class _Tp, class _A0, class _A1> |
| 3579 | inline _LIBCPP_INLINE_VISIBILITY |
| 3580 | shared_ptr<_Tp> |
| 3581 | make_shared(_A0& __a0, _A1& __a1) |
| 3582 | { |
| 3583 | return shared_ptr<_Tp>::make_shared(__a0, __a1); |
| 3584 | } |
| 3585 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3586 | template<class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3587 | inline _LIBCPP_INLINE_VISIBILITY |
| 3588 | shared_ptr<_Tp> |
| 3589 | make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 3590 | { |
| 3591 | return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); |
| 3592 | } |
| 3593 | |
| 3594 | template<class _Tp, class _Alloc> |
| 3595 | inline _LIBCPP_INLINE_VISIBILITY |
| 3596 | shared_ptr<_Tp> |
| 3597 | allocate_shared(const _Alloc& __a) |
| 3598 | { |
| 3599 | return shared_ptr<_Tp>::allocate_shared(__a); |
| 3600 | } |
| 3601 | |
| 3602 | template<class _Tp, class _Alloc, class _A0> |
| 3603 | inline _LIBCPP_INLINE_VISIBILITY |
| 3604 | shared_ptr<_Tp> |
| 3605 | allocate_shared(const _Alloc& __a, _A0& __a0) |
| 3606 | { |
| 3607 | return shared_ptr<_Tp>::allocate_shared(__a, __a0); |
| 3608 | } |
| 3609 | |
| 3610 | template<class _Tp, class _Alloc, class _A0, class _A1> |
| 3611 | inline _LIBCPP_INLINE_VISIBILITY |
| 3612 | shared_ptr<_Tp> |
| 3613 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 3614 | { |
| 3615 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); |
| 3616 | } |
| 3617 | |
| 3618 | template<class _Tp, class _Alloc, class _A0, class _A1, class _A2> |
| 3619 | inline _LIBCPP_INLINE_VISIBILITY |
| 3620 | shared_ptr<_Tp> |
| 3621 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3622 | { |
| 3623 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); |
| 3624 | } |
| 3625 | |
| 3626 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3627 | |
| 3628 | template<class _Tp, class _Up> |
| 3629 | inline _LIBCPP_INLINE_VISIBILITY |
| 3630 | bool |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3631 | operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3632 | { |
| 3633 | return __x.get() == __y.get(); |
| 3634 | } |
| 3635 | |
| 3636 | template<class _Tp, class _Up> |
| 3637 | inline _LIBCPP_INLINE_VISIBILITY |
| 3638 | bool |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3639 | operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3640 | { |
| 3641 | return !(__x == __y); |
| 3642 | } |
| 3643 | |
| 3644 | template<class _Tp, class _Up> |
| 3645 | inline _LIBCPP_INLINE_VISIBILITY |
| 3646 | bool |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3647 | operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3648 | { |
| 3649 | return __x.get() < __y.get(); |
| 3650 | } |
| 3651 | |
| 3652 | template<class _Tp> |
| 3653 | inline _LIBCPP_INLINE_VISIBILITY |
| 3654 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3655 | swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3656 | { |
| 3657 | __x.swap(__y); |
| 3658 | } |
| 3659 | |
| 3660 | template<class _Tp, class _Up> |
| 3661 | inline _LIBCPP_INLINE_VISIBILITY |
| 3662 | shared_ptr<_Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3663 | static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3664 | { |
| 3665 | return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); |
| 3666 | } |
| 3667 | |
| 3668 | template<class _Tp, class _Up> |
| 3669 | inline _LIBCPP_INLINE_VISIBILITY |
| 3670 | shared_ptr<_Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3671 | dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3672 | { |
| 3673 | _Tp* __p = dynamic_cast<_Tp*>(__r.get()); |
| 3674 | return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); |
| 3675 | } |
| 3676 | |
| 3677 | template<class _Tp, class _Up> |
| 3678 | shared_ptr<_Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3679 | const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3680 | { |
| 3681 | return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get())); |
| 3682 | } |
| 3683 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3684 | #ifndef _LIBCPP_NO_RTTI |
| 3685 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3686 | template<class _Dp, class _Tp> |
| 3687 | inline _LIBCPP_INLINE_VISIBILITY |
| 3688 | _Dp* |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3689 | get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3690 | { |
| 3691 | return __p.template __get_deleter<_Dp>(); |
| 3692 | } |
| 3693 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3694 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3695 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3696 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3697 | class _LIBCPP_VISIBLE weak_ptr |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3698 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3699 | public: |
| 3700 | typedef _Tp element_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3701 | private: |
| 3702 | element_type* __ptr_; |
| 3703 | __shared_weak_count* __cntrl_; |
| 3704 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3705 | public: |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3706 | weak_ptr() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3707 | template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3708 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 3709 | _NOEXCEPT; |
| 3710 | weak_ptr(weak_ptr const& __r) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3711 | template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3712 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 3713 | _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3714 | |
| 3715 | ~weak_ptr(); |
| 3716 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3717 | weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; |
| 3718 | template<class _Yp> weak_ptr& operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; |
| 3719 | template<class _Yp> weak_ptr& operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3720 | |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3721 | void swap(weak_ptr& __r) _NOEXCEPT; |
| 3722 | void reset() _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3723 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3724 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3725 | long use_count() const _NOEXCEPT |
| 3726 | {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3728 | bool expired() const _NOEXCEPT |
| 3729 | {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} |
| 3730 | shared_ptr<_Tp> lock() const _NOEXCEPT; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3731 | template<class _Up> |
| 3732 | _LIBCPP_INLINE_VISIBILITY |
| 3733 | bool owner_before(const shared_ptr<_Up>& __r) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3734 | {return __cntrl_ < __r.__cntrl_;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3735 | template<class _Up> |
| 3736 | _LIBCPP_INLINE_VISIBILITY |
| 3737 | bool owner_before(const weak_ptr<_Up>& __r) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3738 | {return __cntrl_ < __r.__cntrl_;} |
| 3739 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3740 | template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr; |
| 3741 | template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3742 | }; |
| 3743 | |
| 3744 | template<class _Tp> |
| 3745 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3746 | weak_ptr<_Tp>::weak_ptr() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3747 | : __ptr_(0), |
| 3748 | __cntrl_(0) |
| 3749 | { |
| 3750 | } |
| 3751 | |
| 3752 | template<class _Tp> |
| 3753 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3754 | weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3755 | : __ptr_(__r.__ptr_), |
| 3756 | __cntrl_(__r.__cntrl_) |
| 3757 | { |
| 3758 | if (__cntrl_) |
| 3759 | __cntrl_->__add_weak(); |
| 3760 | } |
| 3761 | |
| 3762 | template<class _Tp> |
| 3763 | template<class _Yp> |
| 3764 | inline _LIBCPP_INLINE_VISIBILITY |
| 3765 | weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | e003ce4 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 3766 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3767 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3768 | : __ptr_(__r.__ptr_), |
| 3769 | __cntrl_(__r.__cntrl_) |
| 3770 | { |
| 3771 | if (__cntrl_) |
| 3772 | __cntrl_->__add_weak(); |
| 3773 | } |
| 3774 | |
| 3775 | template<class _Tp> |
| 3776 | template<class _Yp> |
| 3777 | inline _LIBCPP_INLINE_VISIBILITY |
| 3778 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | e003ce4 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 3779 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3780 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3781 | : __ptr_(__r.__ptr_), |
| 3782 | __cntrl_(__r.__cntrl_) |
| 3783 | { |
| 3784 | if (__cntrl_) |
| 3785 | __cntrl_->__add_weak(); |
| 3786 | } |
| 3787 | |
| 3788 | template<class _Tp> |
| 3789 | weak_ptr<_Tp>::~weak_ptr() |
| 3790 | { |
| 3791 | if (__cntrl_) |
| 3792 | __cntrl_->__release_weak(); |
| 3793 | } |
| 3794 | |
| 3795 | template<class _Tp> |
| 3796 | inline _LIBCPP_INLINE_VISIBILITY |
| 3797 | weak_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3798 | weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3799 | { |
| 3800 | weak_ptr(__r).swap(*this); |
| 3801 | return *this; |
| 3802 | } |
| 3803 | |
| 3804 | template<class _Tp> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3805 | template<class _Yp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3806 | inline _LIBCPP_INLINE_VISIBILITY |
| 3807 | weak_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3808 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3809 | { |
| 3810 | weak_ptr(__r).swap(*this); |
| 3811 | return *this; |
| 3812 | } |
| 3813 | |
| 3814 | template<class _Tp> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3815 | template<class _Yp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3816 | inline _LIBCPP_INLINE_VISIBILITY |
| 3817 | weak_ptr<_Tp>& |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3818 | weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3819 | { |
| 3820 | weak_ptr(__r).swap(*this); |
| 3821 | return *this; |
| 3822 | } |
| 3823 | |
| 3824 | template<class _Tp> |
| 3825 | inline _LIBCPP_INLINE_VISIBILITY |
| 3826 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3827 | weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3828 | { |
| 3829 | _STD::swap(__ptr_, __r.__ptr_); |
| 3830 | _STD::swap(__cntrl_, __r.__cntrl_); |
| 3831 | } |
| 3832 | |
| 3833 | template<class _Tp> |
| 3834 | inline _LIBCPP_INLINE_VISIBILITY |
| 3835 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3836 | swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3837 | { |
| 3838 | __x.swap(__y); |
| 3839 | } |
| 3840 | |
| 3841 | template<class _Tp> |
| 3842 | inline _LIBCPP_INLINE_VISIBILITY |
| 3843 | void |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3844 | weak_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3845 | { |
| 3846 | weak_ptr().swap(*this); |
| 3847 | } |
| 3848 | |
| 3849 | template<class _Tp> |
| 3850 | template<class _Yp> |
| 3851 | shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, |
| 3852 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) |
| 3853 | : __ptr_(__r.__ptr_), |
| 3854 | __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) |
| 3855 | { |
| 3856 | if (__cntrl_ == 0) |
| 3857 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3858 | throw bad_weak_ptr(); |
| 3859 | #else |
| 3860 | assert(!"bad_weak_ptr"); |
| 3861 | #endif |
| 3862 | } |
| 3863 | |
| 3864 | template<class _Tp> |
| 3865 | shared_ptr<_Tp> |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3866 | weak_ptr<_Tp>::lock() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3867 | { |
| 3868 | shared_ptr<_Tp> __r; |
| 3869 | __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; |
| 3870 | if (__r.__cntrl_) |
| 3871 | __r.__ptr_ = __ptr_; |
| 3872 | return __r; |
| 3873 | } |
| 3874 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3875 | template <class _Tp> struct owner_less; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3876 | |
| 3877 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3878 | struct _LIBCPP_VISIBLE owner_less<shared_ptr<_Tp> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3879 | : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3880 | { |
| 3881 | typedef bool result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3882 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3883 | bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3884 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3885 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3886 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3887 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3888 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3889 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3890 | {return __x.owner_before(__y);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3891 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3892 | |
| 3893 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3894 | struct _LIBCPP_VISIBLE owner_less<weak_ptr<_Tp> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3895 | : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> |
| 3896 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3897 | typedef bool result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3898 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3899 | bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3900 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3901 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3902 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const |
| 3903 | {return __x.owner_before(__y);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3904 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3905 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const |
| 3906 | {return __x.owner_before(__y);} |
| 3907 | }; |
| 3908 | |
| 3909 | template<class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3910 | class _LIBCPP_VISIBLE enable_shared_from_this |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3911 | { |
| 3912 | mutable weak_ptr<_Tp> __weak_this_; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3913 | protected: |
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() _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(enable_shared_from_this const&) _NOEXCEPT {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3918 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3919 | enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT |
| 3920 | {return *this;} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3921 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3922 | ~enable_shared_from_this() {} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3923 | public: |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3924 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3925 | shared_ptr<_Tp> shared_from_this() |
| 3926 | {return shared_ptr<_Tp>(__weak_this_);} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3927 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3928 | shared_ptr<_Tp const> shared_from_this() const |
| 3929 | {return shared_ptr<const _Tp>(__weak_this_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3930 | |
| 3931 | template <class _Up> friend class shared_ptr; |
| 3932 | }; |
| 3933 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3934 | template <class _Tp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3935 | struct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> > |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3936 | { |
| 3937 | typedef shared_ptr<_Tp> argument_type; |
| 3938 | typedef size_t result_type; |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3939 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3940 | result_type operator()(const argument_type& __ptr) const _NOEXCEPT |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3941 | { |
| 3942 | return hash<_Tp*>()(__ptr.get()); |
| 3943 | } |
| 3944 | }; |
| 3945 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3946 | //enum class |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3947 | struct _LIBCPP_VISIBLE pointer_safety |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3948 | { |
| 3949 | enum _ |
| 3950 | { |
| 3951 | relaxed, |
| 3952 | preferred, |
| 3953 | strict |
| 3954 | }; |
| 3955 | |
| 3956 | _ __v_; |
| 3957 | |
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 | pointer_safety(_ __v) : __v_(__v) {} |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3960 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3961 | operator int() const {return __v_;} |
| 3962 | }; |
| 3963 | |
| 3964 | void declare_reachable(void* __p); |
| 3965 | void declare_no_pointers(char* __p, size_t __n); |
| 3966 | void undeclare_no_pointers(char* __p, size_t __n); |
Howard Hinnant | 1694d23 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3967 | pointer_safety get_pointer_safety() _NOEXCEPT; |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 3968 | void* __undeclare_reachable(void* __p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3969 | |
| 3970 | template <class _Tp> |
| 3971 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3972 | _Tp* |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3973 | undeclare_reachable(_Tp* __p) |
| 3974 | { |
| 3975 | return static_cast<_Tp*>(__undeclare_reachable(__p)); |
| 3976 | } |
| 3977 | |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 3978 | void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3979 | |
| 3980 | _LIBCPP_END_NAMESPACE_STD |
| 3981 | |
| 3982 | #endif // _LIBCPP_MEMORY |