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