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