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