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