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