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