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