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