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