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