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