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