Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- memory ------------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_MEMORY |
| 11 | #define _LIBCPP_MEMORY |
| 12 | |
| 13 | /* |
| 14 | memory synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | struct allocator_arg_t { }; |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 20 | inline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
| 22 | template <class T, class Alloc> struct uses_allocator; |
| 23 | |
| 24 | template <class Ptr> |
| 25 | struct pointer_traits |
| 26 | { |
| 27 | typedef Ptr pointer; |
| 28 | typedef <details> element_type; |
| 29 | typedef <details> difference_type; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 30 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | template <class U> using rebind = <details>; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 32 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | static pointer pointer_to(<details>); |
| 34 | }; |
| 35 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 36 | template <class T> |
| 37 | struct pointer_traits<T*> |
| 38 | { |
| 39 | typedef T* pointer; |
| 40 | typedef T element_type; |
| 41 | typedef ptrdiff_t difference_type; |
| 42 | |
| 43 | template <class U> using rebind = U*; |
| 44 | |
Louis Dionne | 44e1ea8 | 2018-11-13 17:04:05 +0000 | [diff] [blame] | 45 | static pointer pointer_to(<details>) noexcept; // constexpr in C++20 |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
Eric Fiselier | 45c9aac | 2017-11-22 19:49:21 +0000 | [diff] [blame] | 48 | template <class T> constexpr T* to_address(T* p) noexcept; // C++20 |
| 49 | template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20 |
| 50 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | template <class Alloc> |
| 52 | struct allocator_traits |
| 53 | { |
| 54 | typedef Alloc allocator_type; |
| 55 | typedef typename allocator_type::value_type |
| 56 | value_type; |
| 57 | |
| 58 | typedef Alloc::pointer | value_type* pointer; |
| 59 | typedef Alloc::const_pointer |
| 60 | | pointer_traits<pointer>::rebind<const value_type> |
| 61 | const_pointer; |
| 62 | typedef Alloc::void_pointer |
| 63 | | pointer_traits<pointer>::rebind<void> |
| 64 | void_pointer; |
| 65 | typedef Alloc::const_void_pointer |
| 66 | | pointer_traits<pointer>::rebind<const void> |
| 67 | const_void_pointer; |
| 68 | typedef Alloc::difference_type |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 69 | | pointer_traits<pointer>::difference_type |
| 70 | difference_type; |
| 71 | typedef Alloc::size_type |
| 72 | | make_unsigned<difference_type>::type |
| 73 | size_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 74 | typedef Alloc::propagate_on_container_copy_assignment |
| 75 | | false_type propagate_on_container_copy_assignment; |
| 76 | typedef Alloc::propagate_on_container_move_assignment |
| 77 | | false_type propagate_on_container_move_assignment; |
| 78 | typedef Alloc::propagate_on_container_swap |
| 79 | | false_type propagate_on_container_swap; |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 80 | typedef Alloc::is_always_equal |
| 81 | | is_empty is_always_equal; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 83 | template <class T> using rebind_alloc = Alloc::rebind<T>::other | Alloc<T, Args...>; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; |
| 85 | |
Marshall Clow | 0e58cae | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 86 | static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20 |
| 87 | static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 88 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 89 | static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | |
| 91 | template <class T, class... Args> |
| 92 | static void construct(allocator_type& a, T* p, Args&&... args); |
| 93 | |
| 94 | template <class T> |
| 95 | static void destroy(allocator_type& a, T* p); |
| 96 | |
Marshall Clow | 4f834b5 | 2013-08-27 20:22:15 +0000 | [diff] [blame] | 97 | static size_type max_size(const allocator_type& a); // noexcept in C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 98 | |
| 99 | static allocator_type |
| 100 | select_on_container_copy_construction(const allocator_type& a); |
| 101 | }; |
| 102 | |
| 103 | template <> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 104 | class allocator<void> // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 105 | { |
| 106 | public: |
| 107 | typedef void* pointer; |
| 108 | typedef const void* const_pointer; |
| 109 | typedef void value_type; |
| 110 | |
| 111 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 112 | }; |
| 113 | |
| 114 | template <class T> |
| 115 | class allocator |
| 116 | { |
| 117 | public: |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 118 | typedef size_t size_type; // deprecated in C++17, removed in C++20 |
| 119 | typedef ptrdiff_t difference_type; // deprecated in C++17, removed in C++20 |
| 120 | typedef T* pointer; // deprecated in C++17, removed in C++20 |
| 121 | typedef const T* const_pointer; // deprecated in C++17, removed in C++20 |
| 122 | typedef typename add_lvalue_reference<T>::type |
| 123 | reference; // deprecated in C++17, removed in C++20 |
| 124 | typedef typename add_lvalue_reference<const T>::type |
| 125 | const_reference; // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 127 | typedef T value_type; |
| 128 | |
| 129 | template <class U> struct rebind {typedef allocator<U> other;}; // deprecated in C++17, removed in C++20 |
| 130 | |
| 131 | typedef true_type propagate_on_container_move_assignment; |
| 132 | typedef true_type is_always_equal; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 133 | |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 134 | constexpr allocator() noexcept; // constexpr in C++20 |
| 135 | constexpr allocator(const allocator&) noexcept; // constexpr in C++20 |
| 136 | template <class U> |
| 137 | constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20 |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 138 | ~allocator(); |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 139 | pointer address(reference x) const noexcept; // deprecated in C++17, removed in C++20 |
| 140 | const_pointer address(const_reference x) const noexcept; // deprecated in C++17, removed in C++20 |
| 141 | T* allocate(size_t n, const void* hint); // deprecated in C++17, removed in C++20 |
| 142 | T* allocate(size_t n); |
| 143 | void deallocate(T* p, size_t n) noexcept; |
| 144 | size_type max_size() const noexcept; // deprecated in C++17, removed in C++20 |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 145 | template<class U, class... Args> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 146 | void construct(U* p, Args&&... args); // deprecated in C++17, removed in C++20 |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 147 | template <class U> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 148 | void destroy(U* p); // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | template <class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 152 | bool operator==(const allocator<T>&, const allocator<U>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 153 | |
| 154 | template <class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 155 | bool operator!=(const allocator<T>&, const allocator<U>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | |
| 157 | template <class OutputIterator, class T> |
| 158 | class raw_storage_iterator |
| 159 | : public iterator<output_iterator_tag, |
| 160 | T, // purposefully not C++03 |
| 161 | ptrdiff_t, // purposefully not C++03 |
| 162 | T*, // purposefully not C++03 |
| 163 | raw_storage_iterator&> // purposefully not C++03 |
| 164 | { |
| 165 | public: |
| 166 | explicit raw_storage_iterator(OutputIterator x); |
| 167 | raw_storage_iterator& operator*(); |
| 168 | raw_storage_iterator& operator=(const T& element); |
| 169 | raw_storage_iterator& operator++(); |
| 170 | raw_storage_iterator operator++(int); |
| 171 | }; |
| 172 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 173 | template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; |
| 174 | template <class T> void return_temporary_buffer(T* p) noexcept; |
| 175 | |
| 176 | template <class T> T* addressof(T& r) noexcept; |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 177 | template <class T> T* addressof(const T&& r) noexcept = delete; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 178 | |
| 179 | template <class InputIterator, class ForwardIterator> |
| 180 | ForwardIterator |
| 181 | uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); |
| 182 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 183 | template <class InputIterator, class Size, class ForwardIterator> |
| 184 | ForwardIterator |
| 185 | uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); |
| 186 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 187 | template <class ForwardIterator, class T> |
| 188 | void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); |
| 189 | |
| 190 | template <class ForwardIterator, class Size, class T> |
Howard Hinnant | 3c81109 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 191 | ForwardIterator |
| 192 | uninitialized_fill_n(ForwardIterator first, Size n, const T& x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 194 | template <class T> |
| 195 | void destroy_at(T* location); |
| 196 | |
| 197 | template <class ForwardIterator> |
| 198 | void destroy(ForwardIterator first, ForwardIterator last); |
| 199 | |
| 200 | template <class ForwardIterator, class Size> |
| 201 | ForwardIterator destroy_n(ForwardIterator first, Size n); |
| 202 | |
| 203 | template <class InputIterator, class ForwardIterator> |
| 204 | ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result); |
| 205 | |
| 206 | template <class InputIterator, class Size, class ForwardIterator> |
| 207 | pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result); |
| 208 | |
| 209 | template <class ForwardIterator> |
| 210 | void uninitialized_value_construct(ForwardIterator first, ForwardIterator last); |
| 211 | |
| 212 | template <class ForwardIterator, class Size> |
| 213 | ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n); |
| 214 | |
| 215 | template <class ForwardIterator> |
| 216 | void uninitialized_default_construct(ForwardIterator first, ForwardIterator last); |
| 217 | |
| 218 | template <class ForwardIterator, class Size> |
| 219 | ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n); |
| 220 | |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 221 | template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 222 | |
| 223 | template<class X> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 224 | class auto_ptr // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 225 | { |
| 226 | public: |
| 227 | typedef X element_type; |
| 228 | |
| 229 | explicit auto_ptr(X* p =0) throw(); |
| 230 | auto_ptr(auto_ptr&) throw(); |
| 231 | template<class Y> auto_ptr(auto_ptr<Y>&) throw(); |
| 232 | auto_ptr& operator=(auto_ptr&) throw(); |
| 233 | template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw(); |
| 234 | auto_ptr& operator=(auto_ptr_ref<X> r) throw(); |
| 235 | ~auto_ptr() throw(); |
| 236 | |
| 237 | typename add_lvalue_reference<X>::type operator*() const throw(); |
| 238 | X* operator->() const throw(); |
| 239 | X* get() const throw(); |
| 240 | X* release() throw(); |
| 241 | void reset(X* p =0) throw(); |
| 242 | |
| 243 | auto_ptr(auto_ptr_ref<X>) throw(); |
| 244 | template<class Y> operator auto_ptr_ref<Y>() throw(); |
| 245 | template<class Y> operator auto_ptr<Y>() throw(); |
| 246 | }; |
| 247 | |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 248 | template <class T> |
| 249 | struct default_delete |
| 250 | { |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 251 | constexpr default_delete() noexcept = default; |
| 252 | template <class U> default_delete(const default_delete<U>&) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 253 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 254 | void operator()(T*) const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | template <class T> |
| 258 | struct default_delete<T[]> |
| 259 | { |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 260 | constexpr default_delete() noexcept = default; |
| 261 | void operator()(T*) const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 262 | template <class U> void operator()(U*) const = delete; |
| 263 | }; |
| 264 | |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 265 | template <class T, class D = default_delete<T>> |
| 266 | class unique_ptr |
| 267 | { |
| 268 | public: |
| 269 | typedef see below pointer; |
| 270 | typedef T element_type; |
| 271 | typedef D deleter_type; |
| 272 | |
| 273 | // constructors |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 274 | constexpr unique_ptr() noexcept; |
| 275 | explicit unique_ptr(pointer p) noexcept; |
| 276 | unique_ptr(pointer p, see below d1) noexcept; |
| 277 | unique_ptr(pointer p, see below d2) noexcept; |
| 278 | unique_ptr(unique_ptr&& u) noexcept; |
| 279 | unique_ptr(nullptr_t) noexcept : unique_ptr() { } |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 280 | template <class U, class E> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 281 | unique_ptr(unique_ptr<U, E>&& u) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 282 | template <class U> |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 283 | unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17 |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 284 | |
| 285 | // destructor |
| 286 | ~unique_ptr(); |
| 287 | |
| 288 | // assignment |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 289 | unique_ptr& operator=(unique_ptr&& u) noexcept; |
| 290 | template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; |
| 291 | unique_ptr& operator=(nullptr_t) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 292 | |
| 293 | // observers |
| 294 | typename add_lvalue_reference<T>::type operator*() const; |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 295 | pointer operator->() const noexcept; |
| 296 | pointer get() const noexcept; |
| 297 | deleter_type& get_deleter() noexcept; |
| 298 | const deleter_type& get_deleter() const noexcept; |
| 299 | explicit operator bool() const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 300 | |
| 301 | // modifiers |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 302 | pointer release() noexcept; |
| 303 | void reset(pointer p = pointer()) noexcept; |
| 304 | void swap(unique_ptr& u) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 305 | }; |
| 306 | |
| 307 | template <class T, class D> |
| 308 | class unique_ptr<T[], D> |
| 309 | { |
| 310 | public: |
| 311 | typedef implementation-defined pointer; |
| 312 | typedef T element_type; |
| 313 | typedef D deleter_type; |
| 314 | |
| 315 | // constructors |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 316 | constexpr unique_ptr() noexcept; |
| 317 | explicit unique_ptr(pointer p) noexcept; |
| 318 | unique_ptr(pointer p, see below d) noexcept; |
| 319 | unique_ptr(pointer p, see below d) noexcept; |
| 320 | unique_ptr(unique_ptr&& u) noexcept; |
| 321 | unique_ptr(nullptr_t) noexcept : unique_ptr() { } |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 322 | |
| 323 | // destructor |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 324 | ~unique_ptr(); |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 325 | |
| 326 | // assignment |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 327 | unique_ptr& operator=(unique_ptr&& u) noexcept; |
| 328 | unique_ptr& operator=(nullptr_t) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 329 | |
| 330 | // observers |
| 331 | T& operator[](size_t i) const; |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 332 | pointer get() const noexcept; |
| 333 | deleter_type& get_deleter() noexcept; |
| 334 | const deleter_type& get_deleter() const noexcept; |
| 335 | explicit operator bool() const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 336 | |
| 337 | // modifiers |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 338 | pointer release() noexcept; |
| 339 | void reset(pointer p = pointer()) noexcept; |
| 340 | void reset(nullptr_t) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 341 | template <class U> void reset(U) = delete; |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 342 | void swap(unique_ptr& u) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | template <class T, class D> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 346 | void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 347 | |
| 348 | template <class T1, class D1, class T2, class D2> |
| 349 | bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 350 | template <class T1, class D1, class T2, class D2> |
| 351 | bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 352 | template <class T1, class D1, class T2, class D2> |
| 353 | bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 354 | template <class T1, class D1, class T2, class D2> |
| 355 | bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 356 | template <class T1, class D1, class T2, class D2> |
| 357 | bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 358 | template <class T1, class D1, class T2, class D2> |
| 359 | bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 360 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 361 | template <class T, class D> |
| 362 | bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; |
| 363 | template <class T, class D> |
| 364 | bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; |
| 365 | template <class T, class D> |
| 366 | bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; |
| 367 | template <class T, class D> |
| 368 | bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; |
| 369 | |
| 370 | template <class T, class D> |
| 371 | bool operator<(const unique_ptr<T, D>& x, nullptr_t); |
| 372 | template <class T, class D> |
| 373 | bool operator<(nullptr_t, const unique_ptr<T, D>& y); |
| 374 | template <class T, class D> |
| 375 | bool operator<=(const unique_ptr<T, D>& x, nullptr_t); |
| 376 | template <class T, class D> |
| 377 | bool operator<=(nullptr_t, const unique_ptr<T, D>& y); |
| 378 | template <class T, class D> |
| 379 | bool operator>(const unique_ptr<T, D>& x, nullptr_t); |
| 380 | template <class T, class D> |
| 381 | bool operator>(nullptr_t, const unique_ptr<T, D>& y); |
| 382 | template <class T, class D> |
| 383 | bool operator>=(const unique_ptr<T, D>& x, nullptr_t); |
| 384 | template <class T, class D> |
| 385 | bool operator>=(nullptr_t, const unique_ptr<T, D>& y); |
| 386 | |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 387 | class bad_weak_ptr |
| 388 | : public std::exception |
| 389 | { |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 390 | bad_weak_ptr() noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 391 | }; |
| 392 | |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 393 | template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14 |
| 394 | template<class T> unique_ptr<T> make_unique(size_t n); // C++14 |
| 395 | template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] |
| 396 | |
Marshall Clow | e52a324 | 2017-11-27 15:51:36 +0000 | [diff] [blame] | 397 | template<class E, class T, class Y, class D> |
| 398 | basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p); |
| 399 | |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 400 | template<class T> |
| 401 | class shared_ptr |
| 402 | { |
| 403 | public: |
| 404 | typedef T element_type; |
Eric Fiselier | ae5b667 | 2016-06-27 01:02:43 +0000 | [diff] [blame] | 405 | typedef weak_ptr<T> weak_type; // C++17 |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 406 | |
| 407 | // constructors: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 408 | constexpr shared_ptr() noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 409 | template<class Y> explicit shared_ptr(Y* p); |
| 410 | template<class Y, class D> shared_ptr(Y* p, D d); |
| 411 | template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); |
| 412 | template <class D> shared_ptr(nullptr_t p, D d); |
| 413 | template <class D, class A> shared_ptr(nullptr_t p, D d, A a); |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 414 | template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept; |
| 415 | shared_ptr(const shared_ptr& r) noexcept; |
| 416 | template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept; |
| 417 | shared_ptr(shared_ptr&& r) noexcept; |
| 418 | template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 419 | template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 420 | template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17 |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 421 | template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); |
| 422 | shared_ptr(nullptr_t) : shared_ptr() { } |
| 423 | |
| 424 | // destructor: |
| 425 | ~shared_ptr(); |
| 426 | |
| 427 | // assignment: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 428 | shared_ptr& operator=(const shared_ptr& r) noexcept; |
| 429 | template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept; |
| 430 | shared_ptr& operator=(shared_ptr&& r) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 431 | template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 432 | template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17 |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 433 | template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); |
| 434 | |
| 435 | // modifiers: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 436 | void swap(shared_ptr& r) noexcept; |
| 437 | void reset() noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 438 | template<class Y> void reset(Y* p); |
| 439 | template<class Y, class D> void reset(Y* p, D d); |
| 440 | template<class Y, class D, class A> void reset(Y* p, D d, A a); |
| 441 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 442 | // observers: |
| 443 | T* get() const noexcept; |
| 444 | T& operator*() const noexcept; |
| 445 | T* operator->() const noexcept; |
| 446 | long use_count() const noexcept; |
| 447 | bool unique() const noexcept; |
| 448 | explicit operator bool() const noexcept; |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 449 | template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; |
| 450 | template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 451 | }; |
| 452 | |
| 453 | // shared_ptr comparisons: |
| 454 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 455 | bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 456 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 457 | bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 458 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 459 | bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 460 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 461 | bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 462 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 463 | bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 464 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 465 | bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
| 466 | |
| 467 | template <class T> |
| 468 | bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 469 | template <class T> |
| 470 | bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 471 | template <class T> |
| 472 | bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 473 | template <class T> |
| 474 | bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 475 | template <class T> |
| 476 | bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 477 | template <class T> |
| 478 | bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 479 | template <class T> |
| 480 | bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 481 | template <class T> |
| 482 | bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 483 | template <class T> |
| 484 | bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 485 | template <class T> |
| 486 | bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; |
| 487 | template <class T> |
| 488 | bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; |
| 489 | template <class T> |
| 490 | bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 491 | |
| 492 | // shared_ptr specialized algorithms: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 493 | template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 494 | |
| 495 | // shared_ptr casts: |
| 496 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 497 | shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 498 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 499 | shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 500 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 501 | shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 502 | |
| 503 | // shared_ptr I/O: |
| 504 | template<class E, class T, class Y> |
| 505 | basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p); |
| 506 | |
| 507 | // shared_ptr get_deleter: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 508 | template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 509 | |
| 510 | template<class T, class... Args> |
| 511 | shared_ptr<T> make_shared(Args&&... args); |
| 512 | template<class T, class A, class... Args> |
| 513 | shared_ptr<T> allocate_shared(const A& a, Args&&... args); |
| 514 | |
| 515 | template<class T> |
| 516 | class weak_ptr |
| 517 | { |
| 518 | public: |
| 519 | typedef T element_type; |
| 520 | |
| 521 | // constructors |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 522 | constexpr weak_ptr() noexcept; |
| 523 | template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; |
| 524 | weak_ptr(weak_ptr const& r) noexcept; |
| 525 | template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; |
Marshall Clow | e9b0a5c | 2014-03-05 03:12:04 +0000 | [diff] [blame] | 526 | weak_ptr(weak_ptr&& r) noexcept; // C++14 |
| 527 | template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14 |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 528 | |
| 529 | // destructor |
| 530 | ~weak_ptr(); |
| 531 | |
| 532 | // assignment |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 533 | weak_ptr& operator=(weak_ptr const& r) noexcept; |
| 534 | template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; |
| 535 | template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; |
Marshall Clow | e9b0a5c | 2014-03-05 03:12:04 +0000 | [diff] [blame] | 536 | weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 |
| 537 | template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14 |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 538 | |
| 539 | // modifiers |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 540 | void swap(weak_ptr& r) noexcept; |
| 541 | void reset() noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 542 | |
| 543 | // observers |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 544 | long use_count() const noexcept; |
| 545 | bool expired() const noexcept; |
| 546 | shared_ptr<T> lock() const noexcept; |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 547 | template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; |
| 548 | template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 549 | }; |
| 550 | |
| 551 | // weak_ptr specialized algorithms: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 552 | template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 553 | |
| 554 | // class owner_less: |
| 555 | template<class T> struct owner_less; |
| 556 | |
| 557 | template<class T> |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 558 | struct owner_less<shared_ptr<T> > |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 559 | : binary_function<shared_ptr<T>, shared_ptr<T>, bool> |
| 560 | { |
| 561 | typedef bool result_type; |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 562 | bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept; |
| 563 | bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; |
| 564 | bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 565 | }; |
| 566 | |
| 567 | template<class T> |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 568 | struct owner_less<weak_ptr<T> > |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 569 | : binary_function<weak_ptr<T>, weak_ptr<T>, bool> |
| 570 | { |
| 571 | typedef bool result_type; |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 572 | bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept; |
| 573 | bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; |
| 574 | bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; |
| 575 | }; |
| 576 | |
| 577 | template <> // Added in C++14 |
| 578 | struct owner_less<void> |
| 579 | { |
| 580 | template <class _Tp, class _Up> |
| 581 | bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; |
| 582 | template <class _Tp, class _Up> |
| 583 | bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; |
| 584 | template <class _Tp, class _Up> |
| 585 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; |
| 586 | template <class _Tp, class _Up> |
| 587 | bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; |
| 588 | |
| 589 | typedef void is_transparent; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 590 | }; |
| 591 | |
| 592 | template<class T> |
| 593 | class enable_shared_from_this |
| 594 | { |
| 595 | protected: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 596 | constexpr enable_shared_from_this() noexcept; |
| 597 | enable_shared_from_this(enable_shared_from_this const&) noexcept; |
| 598 | enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 599 | ~enable_shared_from_this(); |
| 600 | public: |
| 601 | shared_ptr<T> shared_from_this(); |
| 602 | shared_ptr<T const> shared_from_this() const; |
| 603 | }; |
| 604 | |
| 605 | template<class T> |
| 606 | bool atomic_is_lock_free(const shared_ptr<T>* p); |
| 607 | template<class T> |
| 608 | shared_ptr<T> atomic_load(const shared_ptr<T>* p); |
| 609 | template<class T> |
| 610 | shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo); |
| 611 | template<class T> |
| 612 | void atomic_store(shared_ptr<T>* p, shared_ptr<T> r); |
| 613 | template<class T> |
| 614 | void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); |
| 615 | template<class T> |
| 616 | shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r); |
| 617 | template<class T> |
| 618 | shared_ptr<T> |
| 619 | atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); |
| 620 | template<class T> |
| 621 | bool |
| 622 | atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); |
| 623 | template<class T> |
| 624 | bool |
| 625 | atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); |
| 626 | template<class T> |
| 627 | bool |
| 628 | atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, |
| 629 | shared_ptr<T> w, memory_order success, |
| 630 | memory_order failure); |
| 631 | template<class T> |
| 632 | bool |
| 633 | atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, |
| 634 | shared_ptr<T> w, memory_order success, |
| 635 | memory_order failure); |
| 636 | // Hash support |
| 637 | template <class T> struct hash; |
| 638 | template <class T, class D> struct hash<unique_ptr<T, D> >; |
| 639 | template <class T> struct hash<shared_ptr<T> >; |
| 640 | |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 641 | template <class T, class Alloc> |
| 642 | inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; |
| 643 | |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 644 | // Pointer safety |
| 645 | enum class pointer_safety { relaxed, preferred, strict }; |
| 646 | void declare_reachable(void *p); |
| 647 | template <class T> T *undeclare_reachable(T *p); |
| 648 | void declare_no_pointers(char *p, size_t n); |
| 649 | void undeclare_no_pointers(char *p, size_t n); |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 650 | pointer_safety get_pointer_safety() noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 651 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 652 | void* align(size_t alignment, size_t size, void*& ptr, size_t& space); |
| 653 | |
| 654 | } // std |
| 655 | |
| 656 | */ |
| 657 | |
| 658 | #include <__config> |
| 659 | #include <type_traits> |
| 660 | #include <typeinfo> |
| 661 | #include <cstddef> |
| 662 | #include <cstdint> |
| 663 | #include <new> |
| 664 | #include <utility> |
| 665 | #include <limits> |
| 666 | #include <iterator> |
| 667 | #include <__functional_base> |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 668 | #include <iosfwd> |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 669 | #include <tuple> |
Eric Fiselier | 2db2bd5 | 2016-05-07 03:12:24 +0000 | [diff] [blame] | 670 | #include <stdexcept> |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 671 | #include <cstring> |
Eric Fiselier | 8020b6c | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 672 | #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 673 | # include <atomic> |
| 674 | #endif |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 675 | #include <version> |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 676 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 677 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 678 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 679 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 680 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 681 | _LIBCPP_PUSH_MACROS |
| 682 | #include <__undef_macros> |
| 683 | |
| 684 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 685 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 686 | |
Eric Fiselier | 89659d1 | 2015-07-07 00:27:16 +0000 | [diff] [blame] | 687 | template <class _ValueType> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 688 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 89659d1 | 2015-07-07 00:27:16 +0000 | [diff] [blame] | 689 | _ValueType __libcpp_relaxed_load(_ValueType const* __value) { |
| 690 | #if !defined(_LIBCPP_HAS_NO_THREADS) && \ |
| 691 | defined(__ATOMIC_RELAXED) && \ |
Richard Smith | ca47d0f | 2019-04-25 20:02:10 +0000 | [diff] [blame] | 692 | (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) |
Eric Fiselier | 89659d1 | 2015-07-07 00:27:16 +0000 | [diff] [blame] | 693 | return __atomic_load_n(__value, __ATOMIC_RELAXED); |
| 694 | #else |
| 695 | return *__value; |
| 696 | #endif |
| 697 | } |
| 698 | |
Kuba Brecka | de9d679 | 2016-09-04 09:55:12 +0000 | [diff] [blame] | 699 | template <class _ValueType> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 700 | inline _LIBCPP_INLINE_VISIBILITY |
Kuba Brecka | de9d679 | 2016-09-04 09:55:12 +0000 | [diff] [blame] | 701 | _ValueType __libcpp_acquire_load(_ValueType const* __value) { |
| 702 | #if !defined(_LIBCPP_HAS_NO_THREADS) && \ |
| 703 | defined(__ATOMIC_ACQUIRE) && \ |
Richard Smith | ca47d0f | 2019-04-25 20:02:10 +0000 | [diff] [blame] | 704 | (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) |
Kuba Brecka | de9d679 | 2016-09-04 09:55:12 +0000 | [diff] [blame] | 705 | return __atomic_load_n(__value, __ATOMIC_ACQUIRE); |
| 706 | #else |
| 707 | return *__value; |
| 708 | #endif |
| 709 | } |
| 710 | |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 711 | // addressof moved to <type_traits> |
Douglas Gregor | 1303444 | 2011-06-22 22:17:44 +0000 | [diff] [blame] | 712 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 713 | template <class _Tp> class allocator; |
| 714 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 715 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 716 | template <> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 717 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator<void> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 718 | { |
| 719 | public: |
| 720 | typedef void* pointer; |
| 721 | typedef const void* const_pointer; |
| 722 | typedef void value_type; |
| 723 | |
| 724 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 725 | }; |
| 726 | |
Howard Hinnant | 9f77105 | 2012-01-19 23:15:22 +0000 | [diff] [blame] | 727 | template <> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 728 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 allocator<const void> |
Howard Hinnant | 9f77105 | 2012-01-19 23:15:22 +0000 | [diff] [blame] | 729 | { |
| 730 | public: |
| 731 | typedef const void* pointer; |
| 732 | typedef const void* const_pointer; |
| 733 | typedef const void value_type; |
| 734 | |
| 735 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 736 | }; |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 737 | #endif |
Howard Hinnant | 9f77105 | 2012-01-19 23:15:22 +0000 | [diff] [blame] | 738 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 739 | // pointer_traits |
| 740 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 741 | template <class _Tp, class = void> |
| 742 | struct __has_element_type : false_type {}; |
| 743 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 744 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 745 | struct __has_element_type<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 746 | typename __void_t<typename _Tp::element_type>::type> : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 747 | |
| 748 | template <class _Ptr, bool = __has_element_type<_Ptr>::value> |
| 749 | struct __pointer_traits_element_type; |
| 750 | |
| 751 | template <class _Ptr> |
| 752 | struct __pointer_traits_element_type<_Ptr, true> |
| 753 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 754 | typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 755 | }; |
| 756 | |
| 757 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 758 | |
| 759 | template <template <class, class...> class _Sp, class _Tp, class ..._Args> |
| 760 | struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> |
| 761 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 762 | typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 763 | }; |
| 764 | |
| 765 | template <template <class, class...> class _Sp, class _Tp, class ..._Args> |
| 766 | struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> |
| 767 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 768 | typedef _LIBCPP_NODEBUG_TYPE _Tp type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 769 | }; |
| 770 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 771 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 772 | |
| 773 | template <template <class> class _Sp, class _Tp> |
| 774 | struct __pointer_traits_element_type<_Sp<_Tp>, true> |
| 775 | { |
| 776 | typedef typename _Sp<_Tp>::element_type type; |
| 777 | }; |
| 778 | |
| 779 | template <template <class> class _Sp, class _Tp> |
| 780 | struct __pointer_traits_element_type<_Sp<_Tp>, false> |
| 781 | { |
| 782 | typedef _Tp type; |
| 783 | }; |
| 784 | |
| 785 | template <template <class, class> class _Sp, class _Tp, class _A0> |
| 786 | struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true> |
| 787 | { |
| 788 | typedef typename _Sp<_Tp, _A0>::element_type type; |
| 789 | }; |
| 790 | |
| 791 | template <template <class, class> class _Sp, class _Tp, class _A0> |
| 792 | struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false> |
| 793 | { |
| 794 | typedef _Tp type; |
| 795 | }; |
| 796 | |
| 797 | template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> |
| 798 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true> |
| 799 | { |
| 800 | typedef typename _Sp<_Tp, _A0, _A1>::element_type type; |
| 801 | }; |
| 802 | |
| 803 | template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1> |
| 804 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false> |
| 805 | { |
| 806 | typedef _Tp type; |
| 807 | }; |
| 808 | |
| 809 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 810 | class _A1, class _A2> |
| 811 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true> |
| 812 | { |
| 813 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type; |
| 814 | }; |
| 815 | |
| 816 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 817 | class _A1, class _A2> |
| 818 | struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false> |
| 819 | { |
| 820 | typedef _Tp type; |
| 821 | }; |
| 822 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 823 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 824 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 825 | template <class _Tp, class = void> |
| 826 | struct __has_difference_type : false_type {}; |
| 827 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 828 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 829 | struct __has_difference_type<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 830 | typename __void_t<typename _Tp::difference_type>::type> : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | |
| 832 | template <class _Ptr, bool = __has_difference_type<_Ptr>::value> |
| 833 | struct __pointer_traits_difference_type |
| 834 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 835 | typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 836 | }; |
| 837 | |
| 838 | template <class _Ptr> |
| 839 | struct __pointer_traits_difference_type<_Ptr, true> |
| 840 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 841 | typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 842 | }; |
| 843 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 844 | template <class _Tp, class _Up, class = void> |
| 845 | struct __has_rebind : false_type {}; |
| 846 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 847 | template <class _Tp, class _Up> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 848 | struct __has_rebind<_Tp, _Up, |
| 849 | typename __void_t<typename _Tp::template rebind<_Up> >::type> : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 850 | |
| 851 | template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> |
| 852 | struct __pointer_traits_rebind |
| 853 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 854 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 855 | typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 856 | #else |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 857 | typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 858 | #endif |
| 859 | }; |
| 860 | |
| 861 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 862 | |
| 863 | template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> |
| 864 | struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> |
| 865 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 866 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 867 | typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | #else |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 869 | typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 870 | #endif |
| 871 | }; |
| 872 | |
| 873 | template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> |
| 874 | struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> |
| 875 | { |
| 876 | typedef _Sp<_Up, _Args...> type; |
| 877 | }; |
| 878 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 879 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 880 | |
| 881 | template <template <class> class _Sp, class _Tp, class _Up> |
| 882 | struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true> |
| 883 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 884 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 885 | typedef typename _Sp<_Tp>::template rebind<_Up> type; |
| 886 | #else |
| 887 | typedef typename _Sp<_Tp>::template rebind<_Up>::other type; |
| 888 | #endif |
| 889 | }; |
| 890 | |
| 891 | template <template <class> class _Sp, class _Tp, class _Up> |
| 892 | struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false> |
| 893 | { |
| 894 | typedef _Sp<_Up> type; |
| 895 | }; |
| 896 | |
| 897 | template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> |
| 898 | struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true> |
| 899 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 900 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 901 | typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type; |
| 902 | #else |
| 903 | typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type; |
| 904 | #endif |
| 905 | }; |
| 906 | |
| 907 | template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> |
| 908 | struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false> |
| 909 | { |
| 910 | typedef _Sp<_Up, _A0> type; |
| 911 | }; |
| 912 | |
| 913 | template <template <class, class, class> class _Sp, class _Tp, class _A0, |
| 914 | class _A1, class _Up> |
| 915 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true> |
| 916 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 917 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 918 | typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type; |
| 919 | #else |
| 920 | typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type; |
| 921 | #endif |
| 922 | }; |
| 923 | |
| 924 | template <template <class, class, class> class _Sp, class _Tp, class _A0, |
| 925 | class _A1, class _Up> |
| 926 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false> |
| 927 | { |
| 928 | typedef _Sp<_Up, _A0, _A1> type; |
| 929 | }; |
| 930 | |
| 931 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 932 | class _A1, class _A2, class _Up> |
| 933 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true> |
| 934 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 935 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 936 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type; |
| 937 | #else |
| 938 | typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; |
| 939 | #endif |
| 940 | }; |
| 941 | |
| 942 | template <template <class, class, class, class> class _Sp, class _Tp, class _A0, |
| 943 | class _A1, class _A2, class _Up> |
| 944 | struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false> |
| 945 | { |
| 946 | typedef _Sp<_Up, _A0, _A1, _A2> type; |
| 947 | }; |
| 948 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 949 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 950 | |
| 951 | template <class _Ptr> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 952 | struct _LIBCPP_TEMPLATE_VIS pointer_traits |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 953 | { |
| 954 | typedef _Ptr pointer; |
| 955 | typedef typename __pointer_traits_element_type<pointer>::type element_type; |
| 956 | typedef typename __pointer_traits_difference_type<pointer>::type difference_type; |
| 957 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 958 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f09283d | 2011-05-11 20:21:19 +0000 | [diff] [blame] | 959 | template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 960 | #else |
| 961 | template <class _Up> struct rebind |
| 962 | {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;}; |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 963 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 964 | |
| 965 | private: |
| 966 | struct __nat {}; |
| 967 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 968 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 969 | static pointer pointer_to(typename conditional<is_void<element_type>::value, |
| 970 | __nat, element_type>::type& __r) |
| 971 | {return pointer::pointer_to(__r);} |
| 972 | }; |
| 973 | |
| 974 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 975 | struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 976 | { |
| 977 | typedef _Tp* pointer; |
| 978 | typedef _Tp element_type; |
| 979 | typedef ptrdiff_t difference_type; |
| 980 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 981 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 982 | template <class _Up> using rebind = _Up*; |
| 983 | #else |
| 984 | template <class _Up> struct rebind {typedef _Up* other;}; |
| 985 | #endif |
| 986 | |
| 987 | private: |
| 988 | struct __nat {}; |
| 989 | public: |
Louis Dionne | 44e1ea8 | 2018-11-13 17:04:05 +0000 | [diff] [blame] | 990 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 991 | static pointer pointer_to(typename conditional<is_void<element_type>::value, |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 992 | __nat, element_type>::type& __r) _NOEXCEPT |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 993 | {return _VSTD::addressof(__r);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | }; |
| 995 | |
Eric Fiselier | ae3ab84 | 2015-08-23 02:56:05 +0000 | [diff] [blame] | 996 | template <class _From, class _To> |
| 997 | struct __rebind_pointer { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 998 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | ae3ab84 | 2015-08-23 02:56:05 +0000 | [diff] [blame] | 999 | typedef typename pointer_traits<_From>::template rebind<_To> type; |
| 1000 | #else |
| 1001 | typedef typename pointer_traits<_From>::template rebind<_To>::other type; |
| 1002 | #endif |
| 1003 | }; |
| 1004 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1005 | // allocator_traits |
| 1006 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1007 | template <class _Tp, class = void> |
| 1008 | struct __has_pointer_type : false_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1009 | |
| 1010 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1011 | struct __has_pointer_type<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1012 | typename __void_t<typename _Tp::pointer>::type> : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1013 | |
| 1014 | namespace __pointer_type_imp |
| 1015 | { |
| 1016 | |
| 1017 | template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value> |
| 1018 | struct __pointer_type |
| 1019 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1020 | typedef _LIBCPP_NODEBUG_TYPE typename _Dp::pointer type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1021 | }; |
| 1022 | |
| 1023 | template <class _Tp, class _Dp> |
| 1024 | struct __pointer_type<_Tp, _Dp, false> |
| 1025 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1026 | typedef _LIBCPP_NODEBUG_TYPE _Tp* type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1027 | }; |
| 1028 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1029 | } // __pointer_type_imp |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1030 | |
| 1031 | template <class _Tp, class _Dp> |
| 1032 | struct __pointer_type |
| 1033 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1034 | typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1035 | }; |
| 1036 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1037 | template <class _Tp, class = void> |
| 1038 | struct __has_const_pointer : false_type {}; |
| 1039 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1040 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1041 | struct __has_const_pointer<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1042 | typename __void_t<typename _Tp::const_pointer>::type> : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1043 | |
| 1044 | template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> |
| 1045 | struct __const_pointer |
| 1046 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1047 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_pointer type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1048 | }; |
| 1049 | |
| 1050 | template <class _Tp, class _Ptr, class _Alloc> |
| 1051 | struct __const_pointer<_Tp, _Ptr, _Alloc, false> |
| 1052 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1053 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1054 | typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1055 | #else |
| 1056 | typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type; |
| 1057 | #endif |
| 1058 | }; |
| 1059 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1060 | template <class _Tp, class = void> |
| 1061 | struct __has_void_pointer : false_type {}; |
| 1062 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1063 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1064 | struct __has_void_pointer<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1065 | typename __void_t<typename _Tp::void_pointer>::type> : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | |
| 1067 | template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> |
| 1068 | struct __void_pointer |
| 1069 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1070 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::void_pointer type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1071 | }; |
| 1072 | |
| 1073 | template <class _Ptr, class _Alloc> |
| 1074 | struct __void_pointer<_Ptr, _Alloc, false> |
| 1075 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1076 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1077 | typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1078 | #else |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1079 | typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void>::other type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1080 | #endif |
| 1081 | }; |
| 1082 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1083 | template <class _Tp, class = void> |
| 1084 | struct __has_const_void_pointer : false_type {}; |
| 1085 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1086 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1087 | struct __has_const_void_pointer<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1088 | typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1089 | |
| 1090 | template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> |
| 1091 | struct __const_void_pointer |
| 1092 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1093 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_void_pointer type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1094 | }; |
| 1095 | |
| 1096 | template <class _Ptr, class _Alloc> |
| 1097 | struct __const_void_pointer<_Ptr, _Alloc, false> |
| 1098 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1099 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1100 | typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | #else |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1102 | typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void>::other type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1103 | #endif |
| 1104 | }; |
| 1105 | |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1106 | |
| 1107 | template <bool _UsePointerTraits> struct __to_address_helper; |
| 1108 | |
| 1109 | template <> struct __to_address_helper<true> { |
| 1110 | template <class _Pointer> |
| 1111 | using __return_type = decltype(pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>())); |
| 1112 | |
| 1113 | template <class _Pointer> |
| 1114 | _LIBCPP_CONSTEXPR |
| 1115 | static __return_type<_Pointer> |
| 1116 | __do_it(const _Pointer &__p) _NOEXCEPT { return pointer_traits<_Pointer>::to_address(__p); } |
| 1117 | }; |
| 1118 | |
| 1119 | template <class _Pointer, bool _Dummy = true> |
| 1120 | using __choose_to_address = __to_address_helper<_IsValidExpansion<__to_address_helper<_Dummy>::template __return_type, _Pointer>::value>; |
| 1121 | |
| 1122 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1123 | template <class _Tp> |
Eric Fiselier | 45c9aac | 2017-11-22 19:49:21 +0000 | [diff] [blame] | 1124 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1125 | _Tp* |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1126 | __to_address(_Tp* __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1127 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1128 | static_assert(!is_function<_Tp>::value, "_Tp is a function type"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1129 | return __p; |
| 1130 | } |
| 1131 | |
| 1132 | template <class _Pointer> |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1133 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 1134 | typename __choose_to_address<_Pointer>::template __return_type<_Pointer> |
| 1135 | __to_address(const _Pointer& __p) _NOEXCEPT { |
| 1136 | return __choose_to_address<_Pointer>::__do_it(__p); |
Eric Fiselier | 45c9aac | 2017-11-22 19:49:21 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1139 | template <> struct __to_address_helper<false> { |
| 1140 | template <class _Pointer> |
| 1141 | using __return_type = typename pointer_traits<_Pointer>::element_type*; |
Eric Fiselier | 45c9aac | 2017-11-22 19:49:21 +0000 | [diff] [blame] | 1142 | |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1143 | template <class _Pointer> |
| 1144 | _LIBCPP_CONSTEXPR |
| 1145 | static __return_type<_Pointer> |
| 1146 | __do_it(const _Pointer &__p) _NOEXCEPT { return std::__to_address(__p.operator->()); } |
| 1147 | }; |
| 1148 | |
| 1149 | |
| 1150 | #if _LIBCPP_STD_VER > 17 |
Eric Fiselier | 45c9aac | 2017-11-22 19:49:21 +0000 | [diff] [blame] | 1151 | template <class _Tp> |
| 1152 | inline _LIBCPP_INLINE_VISIBILITY constexpr |
| 1153 | _Tp* |
| 1154 | to_address(_Tp* __p) _NOEXCEPT |
| 1155 | { |
| 1156 | static_assert(!is_function_v<_Tp>, "_Tp is a function type"); |
| 1157 | return __p; |
| 1158 | } |
| 1159 | |
| 1160 | template <class _Pointer> |
| 1161 | inline _LIBCPP_INLINE_VISIBILITY |
| 1162 | auto |
| 1163 | to_address(const _Pointer& __p) _NOEXCEPT |
| 1164 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1165 | return _VSTD::__to_address(__p); |
Eric Fiselier | 45c9aac | 2017-11-22 19:49:21 +0000 | [diff] [blame] | 1166 | } |
| 1167 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1168 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1169 | template <class _Tp, class = void> |
| 1170 | struct __has_size_type : false_type {}; |
| 1171 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1172 | template <class _Tp> |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1173 | struct __has_size_type<_Tp, |
| 1174 | typename __void_t<typename _Tp::size_type>::type> : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1175 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1176 | template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1177 | struct __size_type |
| 1178 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1179 | typedef _LIBCPP_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1180 | }; |
| 1181 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1182 | template <class _Alloc, class _DiffType> |
| 1183 | struct __size_type<_Alloc, _DiffType, true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1184 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1185 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::size_type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1186 | }; |
| 1187 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1188 | template <class _Tp, class = void> |
| 1189 | struct __has_propagate_on_container_copy_assignment : false_type {}; |
| 1190 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1191 | template <class _Tp> |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1192 | struct __has_propagate_on_container_copy_assignment<_Tp, |
| 1193 | typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type> |
| 1194 | : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | |
| 1196 | template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> |
| 1197 | struct __propagate_on_container_copy_assignment |
| 1198 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1199 | typedef _LIBCPP_NODEBUG_TYPE false_type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1200 | }; |
| 1201 | |
| 1202 | template <class _Alloc> |
| 1203 | struct __propagate_on_container_copy_assignment<_Alloc, true> |
| 1204 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1205 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1206 | }; |
| 1207 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1208 | template <class _Tp, class = void> |
| 1209 | struct __has_propagate_on_container_move_assignment : false_type {}; |
| 1210 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1211 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1212 | struct __has_propagate_on_container_move_assignment<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1213 | typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type> |
| 1214 | : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1215 | |
| 1216 | template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value> |
| 1217 | struct __propagate_on_container_move_assignment |
| 1218 | { |
| 1219 | typedef false_type type; |
| 1220 | }; |
| 1221 | |
| 1222 | template <class _Alloc> |
| 1223 | struct __propagate_on_container_move_assignment<_Alloc, true> |
| 1224 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1225 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1226 | }; |
| 1227 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1228 | template <class _Tp, class = void> |
| 1229 | struct __has_propagate_on_container_swap : false_type {}; |
| 1230 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1231 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1232 | struct __has_propagate_on_container_swap<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1233 | typename __void_t<typename _Tp::propagate_on_container_swap>::type> |
| 1234 | : true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1235 | |
| 1236 | template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value> |
| 1237 | struct __propagate_on_container_swap |
| 1238 | { |
| 1239 | typedef false_type type; |
| 1240 | }; |
| 1241 | |
| 1242 | template <class _Alloc> |
| 1243 | struct __propagate_on_container_swap<_Alloc, true> |
| 1244 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1245 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | }; |
| 1247 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1248 | template <class _Tp, class = void> |
| 1249 | struct __has_is_always_equal : false_type {}; |
| 1250 | |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1251 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1252 | struct __has_is_always_equal<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1253 | typename __void_t<typename _Tp::is_always_equal>::type> |
| 1254 | : true_type {}; |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1255 | |
| 1256 | template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value> |
| 1257 | struct __is_always_equal |
| 1258 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1259 | typedef _LIBCPP_NODEBUG_TYPE typename _VSTD::is_empty<_Alloc>::type type; |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1260 | }; |
| 1261 | |
| 1262 | template <class _Alloc> |
| 1263 | struct __is_always_equal<_Alloc, true> |
| 1264 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1265 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::is_always_equal type; |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1266 | }; |
| 1267 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1268 | template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> |
| 1269 | struct __has_rebind_other |
| 1270 | { |
| 1271 | private: |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 1272 | struct __two {char __lx; char __lxx;}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1273 | template <class _Xp> static __two __test(...); |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1274 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1275 | template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0); |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1276 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | public: |
| 1278 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 1279 | }; |
| 1280 | |
| 1281 | template <class _Tp, class _Up> |
| 1282 | struct __has_rebind_other<_Tp, _Up, false> |
| 1283 | { |
| 1284 | static const bool value = false; |
| 1285 | }; |
| 1286 | |
| 1287 | template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> |
| 1288 | struct __allocator_traits_rebind |
| 1289 | { |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1290 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1291 | typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type; |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1292 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1293 | }; |
| 1294 | |
| 1295 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1296 | |
| 1297 | template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> |
| 1298 | struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> |
| 1299 | { |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1300 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1301 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type; |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1302 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1303 | }; |
| 1304 | |
| 1305 | template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> |
| 1306 | struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> |
| 1307 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1308 | typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1309 | }; |
| 1310 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1311 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1312 | |
| 1313 | template <template <class> class _Alloc, class _Tp, class _Up> |
| 1314 | struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true> |
| 1315 | { |
| 1316 | typedef typename _Alloc<_Tp>::template rebind<_Up>::other type; |
| 1317 | }; |
| 1318 | |
| 1319 | template <template <class> class _Alloc, class _Tp, class _Up> |
| 1320 | struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false> |
| 1321 | { |
| 1322 | typedef _Alloc<_Up> type; |
| 1323 | }; |
| 1324 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> |
| 1326 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true> |
| 1327 | { |
| 1328 | typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type; |
| 1329 | }; |
| 1330 | |
| 1331 | template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up> |
| 1332 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false> |
| 1333 | { |
| 1334 | typedef _Alloc<_Up, _A0> type; |
| 1335 | }; |
| 1336 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1337 | template <template <class, class, class> class _Alloc, class _Tp, class _A0, |
| 1338 | class _A1, class _Up> |
| 1339 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true> |
| 1340 | { |
| 1341 | typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type; |
| 1342 | }; |
| 1343 | |
| 1344 | template <template <class, class, class> class _Alloc, class _Tp, class _A0, |
| 1345 | class _A1, class _Up> |
| 1346 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false> |
| 1347 | { |
| 1348 | typedef _Alloc<_Up, _A0, _A1> type; |
| 1349 | }; |
| 1350 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1351 | template <template <class, class, class, class> class _Alloc, class _Tp, class _A0, |
| 1352 | class _A1, class _A2, class _Up> |
| 1353 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true> |
| 1354 | { |
| 1355 | typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; |
| 1356 | }; |
| 1357 | |
| 1358 | template <template <class, class, class, class> class _Alloc, class _Tp, class _A0, |
| 1359 | class _A1, class _A2, class _Up> |
| 1360 | struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false> |
| 1361 | { |
| 1362 | typedef _Alloc<_Up, _A0, _A1, _A2> type; |
| 1363 | }; |
| 1364 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1365 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1366 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1367 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1368 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1369 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1370 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1371 | auto |
| 1372 | __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) |
Eric Fiselier | be4cb61 | 2017-09-15 00:31:38 +0000 | [diff] [blame] | 1373 | -> decltype((void)__a.allocate(__sz, __p), true_type()); |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1374 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1375 | |
| 1376 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1377 | auto |
| 1378 | __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) |
| 1379 | -> false_type; |
| 1380 | |
| 1381 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1382 | struct __has_allocate_hint |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1383 | : decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(), |
| 1384 | declval<_SizeType>(), |
| 1385 | declval<_ConstVoidPtr>())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1386 | { |
| 1387 | }; |
| 1388 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1389 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1390 | |
| 1391 | template <class _Alloc, class _SizeType, class _ConstVoidPtr> |
| 1392 | struct __has_allocate_hint |
| 1393 | : true_type |
| 1394 | { |
| 1395 | }; |
| 1396 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1397 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1398 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1399 | #if !defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1400 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1401 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 1402 | template <class _Alloc, class _Tp, class... _Args> |
| 1403 | auto |
| 1404 | __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&&... __args) |
| 1405 | -> decltype(__a.construct(__p, _VSTD::forward<_Args>(__args)...), true_type()); |
| 1406 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1407 | |
| 1408 | template <class _Alloc, class _Pointer, class ..._Args> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1409 | auto |
| 1410 | __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args) |
| 1411 | -> false_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1412 | |
| 1413 | template <class _Alloc, class _Pointer, class ..._Args> |
| 1414 | struct __has_construct |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1415 | : decltype(_VSTD::__has_construct_test(declval<_Alloc>(), |
| 1416 | declval<_Pointer>(), |
| 1417 | declval<_Args>()...)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1418 | { |
| 1419 | }; |
| 1420 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1421 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | template <class _Alloc, class _Pointer> |
| 1423 | auto |
| 1424 | __has_destroy_test(_Alloc&& __a, _Pointer&& __p) |
| 1425 | -> decltype(__a.destroy(__p), true_type()); |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1426 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1427 | |
| 1428 | template <class _Alloc, class _Pointer> |
| 1429 | auto |
| 1430 | __has_destroy_test(const _Alloc& __a, _Pointer&& __p) |
| 1431 | -> false_type; |
| 1432 | |
| 1433 | template <class _Alloc, class _Pointer> |
| 1434 | struct __has_destroy |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1435 | : decltype(_VSTD::__has_destroy_test(declval<_Alloc>(), |
| 1436 | declval<_Pointer>())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1437 | { |
| 1438 | }; |
| 1439 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1440 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1441 | template <class _Alloc> |
| 1442 | auto |
| 1443 | __has_max_size_test(_Alloc&& __a) |
| 1444 | -> decltype(__a.max_size(), true_type()); |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1445 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1446 | |
| 1447 | template <class _Alloc> |
| 1448 | auto |
| 1449 | __has_max_size_test(const volatile _Alloc& __a) |
| 1450 | -> false_type; |
| 1451 | |
| 1452 | template <class _Alloc> |
| 1453 | struct __has_max_size |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1454 | : decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | { |
| 1456 | }; |
| 1457 | |
| 1458 | template <class _Alloc> |
| 1459 | auto |
| 1460 | __has_select_on_container_copy_construction_test(_Alloc&& __a) |
| 1461 | -> decltype(__a.select_on_container_copy_construction(), true_type()); |
| 1462 | |
| 1463 | template <class _Alloc> |
| 1464 | auto |
| 1465 | __has_select_on_container_copy_construction_test(const volatile _Alloc& __a) |
| 1466 | -> false_type; |
| 1467 | |
| 1468 | template <class _Alloc> |
| 1469 | struct __has_select_on_container_copy_construction |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1470 | : decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1471 | { |
| 1472 | }; |
| 1473 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1474 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | |
Volodymyr Sapsai | 2b1eb84 | 2018-12-19 20:08:43 +0000 | [diff] [blame] | 1476 | template <class _Alloc, class _Pointer, class _Tp, class = void> |
| 1477 | struct __has_construct : std::false_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1478 | |
Volodymyr Sapsai | 2b1eb84 | 2018-12-19 20:08:43 +0000 | [diff] [blame] | 1479 | template <class _Alloc, class _Pointer, class _Tp> |
| 1480 | struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t< |
| 1481 | decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>())) |
| 1482 | >::type> : std::true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1483 | |
Volodymyr Sapsai | 2b1eb84 | 2018-12-19 20:08:43 +0000 | [diff] [blame] | 1484 | template <class _Alloc, class _Pointer, class = void> |
| 1485 | struct __has_destroy : false_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | |
| 1487 | template <class _Alloc, class _Pointer> |
Volodymyr Sapsai | 2b1eb84 | 2018-12-19 20:08:43 +0000 | [diff] [blame] | 1488 | struct __has_destroy<_Alloc, _Pointer, typename __void_t< |
| 1489 | decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>())) |
| 1490 | >::type> : std::true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1491 | |
| 1492 | template <class _Alloc> |
| 1493 | struct __has_max_size |
| 1494 | : true_type |
| 1495 | { |
| 1496 | }; |
| 1497 | |
| 1498 | template <class _Alloc> |
| 1499 | struct __has_select_on_container_copy_construction |
| 1500 | : false_type |
| 1501 | { |
| 1502 | }; |
| 1503 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1504 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1505 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1506 | template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> |
| 1507 | struct __alloc_traits_difference_type |
| 1508 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1509 | typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type; |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1510 | }; |
| 1511 | |
| 1512 | template <class _Alloc, class _Ptr> |
| 1513 | struct __alloc_traits_difference_type<_Alloc, _Ptr, true> |
| 1514 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1515 | typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::difference_type type; |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1516 | }; |
| 1517 | |
Volodymyr Sapsai | 5c16302 | 2019-01-08 00:03:16 +0000 | [diff] [blame] | 1518 | template <class _Tp> |
| 1519 | struct __is_default_allocator : false_type {}; |
| 1520 | |
| 1521 | template <class _Tp> |
| 1522 | struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {}; |
| 1523 | |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1524 | |
| 1525 | |
| 1526 | template <class _Alloc, |
| 1527 | bool = __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value && !__is_default_allocator<_Alloc>::value |
| 1528 | > |
| 1529 | struct __is_cpp17_move_insertable; |
| 1530 | template <class _Alloc> |
| 1531 | struct __is_cpp17_move_insertable<_Alloc, true> : std::true_type {}; |
| 1532 | template <class _Alloc> |
| 1533 | struct __is_cpp17_move_insertable<_Alloc, false> : std::is_move_constructible<typename _Alloc::value_type> {}; |
| 1534 | |
| 1535 | template <class _Alloc, |
| 1536 | bool = __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value && !__is_default_allocator<_Alloc>::value |
| 1537 | > |
| 1538 | struct __is_cpp17_copy_insertable; |
| 1539 | template <class _Alloc> |
| 1540 | struct __is_cpp17_copy_insertable<_Alloc, true> : __is_cpp17_move_insertable<_Alloc> {}; |
| 1541 | template <class _Alloc> |
| 1542 | struct __is_cpp17_copy_insertable<_Alloc, false> : integral_constant<bool, |
| 1543 | std::is_copy_constructible<typename _Alloc::value_type>::value && |
| 1544 | __is_cpp17_move_insertable<_Alloc>::value> |
| 1545 | {}; |
| 1546 | |
| 1547 | |
| 1548 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1549 | template <class _Alloc> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1550 | struct _LIBCPP_TEMPLATE_VIS allocator_traits |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1551 | { |
| 1552 | typedef _Alloc allocator_type; |
| 1553 | typedef typename allocator_type::value_type value_type; |
| 1554 | |
| 1555 | typedef typename __pointer_type<value_type, allocator_type>::type pointer; |
| 1556 | typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer; |
| 1557 | typedef typename __void_pointer<pointer, allocator_type>::type void_pointer; |
| 1558 | typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer; |
| 1559 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1560 | typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type; |
| 1561 | typedef typename __size_type<allocator_type, difference_type>::type size_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1562 | |
| 1563 | typedef typename __propagate_on_container_copy_assignment<allocator_type>::type |
| 1564 | propagate_on_container_copy_assignment; |
| 1565 | typedef typename __propagate_on_container_move_assignment<allocator_type>::type |
| 1566 | propagate_on_container_move_assignment; |
| 1567 | typedef typename __propagate_on_container_swap<allocator_type>::type |
| 1568 | propagate_on_container_swap; |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1569 | typedef typename __is_always_equal<allocator_type>::type |
| 1570 | is_always_equal; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1571 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1572 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1573 | template <class _Tp> using rebind_alloc = |
Howard Hinnant | f09283d | 2011-05-11 20:21:19 +0000 | [diff] [blame] | 1574 | typename __allocator_traits_rebind<allocator_type, _Tp>::type; |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 1575 | template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp> >; |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1576 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1577 | template <class _Tp> struct rebind_alloc |
| 1578 | {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; |
| 1579 | template <class _Tp> struct rebind_traits |
| 1580 | {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;}; |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1581 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1582 | |
Marshall Clow | 0e58cae | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 1583 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1584 | static pointer allocate(allocator_type& __a, size_type __n) |
| 1585 | {return __a.allocate(__n);} |
Marshall Clow | 0e58cae | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 1586 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1587 | static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1588 | {return __allocate(__a, __n, __hint, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1589 | __has_allocate_hint<allocator_type, size_type, const_void_pointer>());} |
| 1590 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1592 | static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1593 | {__a.deallocate(__p, __n);} |
| 1594 | |
| 1595 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1596 | template <class _Tp, class... _Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1597 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1598 | static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) |
Marshall Clow | 3996b8b | 2014-11-11 19:22:33 +0000 | [diff] [blame] | 1599 | {__construct(__has_construct<allocator_type, _Tp*, _Args...>(), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1600 | __a, __p, _VSTD::forward<_Args>(__args)...);} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1601 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1602 | template <class _Tp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1603 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2b2ec3e | 2017-01-14 01:33:53 +0000 | [diff] [blame] | 1604 | static void construct(allocator_type&, _Tp* __p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1605 | { |
| 1606 | ::new ((void*)__p) _Tp(); |
| 1607 | } |
| 1608 | template <class _Tp, class _A0> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1609 | _LIBCPP_INLINE_VISIBILITY |
Volodymyr Sapsai | 2b1eb84 | 2018-12-19 20:08:43 +0000 | [diff] [blame] | 1610 | static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1611 | { |
Volodymyr Sapsai | 2b1eb84 | 2018-12-19 20:08:43 +0000 | [diff] [blame] | 1612 | __construct(__has_construct<allocator_type, _Tp*, const _A0&>(), |
| 1613 | __a, __p, __a0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1614 | } |
| 1615 | template <class _Tp, class _A0, class _A1> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1616 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2b2ec3e | 2017-01-14 01:33:53 +0000 | [diff] [blame] | 1617 | static void construct(allocator_type&, _Tp* __p, const _A0& __a0, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1618 | const _A1& __a1) |
| 1619 | { |
| 1620 | ::new ((void*)__p) _Tp(__a0, __a1); |
| 1621 | } |
| 1622 | template <class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1623 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2b2ec3e | 2017-01-14 01:33:53 +0000 | [diff] [blame] | 1624 | static void construct(allocator_type&, _Tp* __p, const _A0& __a0, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1625 | const _A1& __a1, const _A2& __a2) |
| 1626 | { |
| 1627 | ::new ((void*)__p) _Tp(__a0, __a1, __a2); |
| 1628 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1629 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1630 | |
| 1631 | template <class _Tp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1632 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1633 | static void destroy(allocator_type& __a, _Tp* __p) |
| 1634 | {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);} |
| 1635 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1636 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4f834b5 | 2013-08-27 20:22:15 +0000 | [diff] [blame] | 1637 | static size_type max_size(const allocator_type& __a) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1638 | {return __max_size(__has_max_size<const allocator_type>(), __a);} |
| 1639 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1640 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1641 | static allocator_type |
| 1642 | select_on_container_copy_construction(const allocator_type& __a) |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1643 | {return __select_on_container_copy_construction( |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1644 | __has_select_on_container_copy_construction<const allocator_type>(), |
| 1645 | __a);} |
| 1646 | |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1647 | template <class _Ptr> |
| 1648 | _LIBCPP_INLINE_VISIBILITY |
| 1649 | static |
| 1650 | void |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1651 | __construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1652 | { |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1653 | static_assert(__is_cpp17_move_insertable<allocator_type>::value, |
| 1654 | "The specified type does not meet the requirements of Cpp17MoveInsertible"); |
Louis Dionne | 301a677 | 2018-12-07 16:42:28 +0000 | [diff] [blame] | 1655 | for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1656 | construct(__a, _VSTD::__to_address(__begin2), |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1657 | #ifdef _LIBCPP_NO_EXCEPTIONS |
| 1658 | _VSTD::move(*__begin1) |
| 1659 | #else |
| 1660 | _VSTD::move_if_noexcept(*__begin1) |
| 1661 | #endif |
| 1662 | ); |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | template <class _Tp> |
| 1666 | _LIBCPP_INLINE_VISIBILITY |
| 1667 | static |
| 1668 | typename enable_if |
| 1669 | < |
Volodymyr Sapsai | 5c16302 | 2019-01-08 00:03:16 +0000 | [diff] [blame] | 1670 | (__is_default_allocator<allocator_type>::value |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1671 | || !__has_construct<allocator_type, _Tp*, _Tp>::value) && |
| 1672 | is_trivially_move_constructible<_Tp>::value, |
| 1673 | void |
| 1674 | >::type |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1675 | __construct_forward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1676 | { |
| 1677 | ptrdiff_t _Np = __end1 - __begin1; |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1678 | if (_Np > 0) |
Marshall Clow | 426d6d2 | 2015-06-02 13:04:18 +0000 | [diff] [blame] | 1679 | { |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1680 | _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); |
Marshall Clow | 426d6d2 | 2015-06-02 13:04:18 +0000 | [diff] [blame] | 1681 | __begin2 += _Np; |
| 1682 | } |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1685 | template <class _Iter, class _Ptr> |
| 1686 | _LIBCPP_INLINE_VISIBILITY |
| 1687 | static |
| 1688 | void |
| 1689 | __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) |
| 1690 | { |
| 1691 | for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1692 | construct(__a, _VSTD::__to_address(__begin2), *__begin1); |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
Volodymyr Sapsai | 5c16302 | 2019-01-08 00:03:16 +0000 | [diff] [blame] | 1695 | template <class _SourceTp, class _DestTp, |
| 1696 | class _RawSourceTp = typename remove_const<_SourceTp>::type, |
| 1697 | class _RawDestTp = typename remove_const<_DestTp>::type> |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1698 | _LIBCPP_INLINE_VISIBILITY |
| 1699 | static |
| 1700 | typename enable_if |
| 1701 | < |
Louis Dionne | 358c6cb | 2020-02-11 17:11:00 +0100 | [diff] [blame] | 1702 | is_trivially_copy_constructible<_DestTp>::value && |
Volodymyr Sapsai | 5c16302 | 2019-01-08 00:03:16 +0000 | [diff] [blame] | 1703 | is_same<_RawSourceTp, _RawDestTp>::value && |
| 1704 | (__is_default_allocator<allocator_type>::value || |
| 1705 | !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value), |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1706 | void |
| 1707 | >::type |
Volodymyr Sapsai | 5c16302 | 2019-01-08 00:03:16 +0000 | [diff] [blame] | 1708 | __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2) |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1709 | { |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1710 | ptrdiff_t _Np = __end1 - __begin1; |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1711 | if (_Np > 0) |
Marshall Clow | 426d6d2 | 2015-06-02 13:04:18 +0000 | [diff] [blame] | 1712 | { |
Volodymyr Sapsai | 5c16302 | 2019-01-08 00:03:16 +0000 | [diff] [blame] | 1713 | _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp)); |
Marshall Clow | 426d6d2 | 2015-06-02 13:04:18 +0000 | [diff] [blame] | 1714 | __begin2 += _Np; |
| 1715 | } |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1718 | template <class _Ptr> |
| 1719 | _LIBCPP_INLINE_VISIBILITY |
| 1720 | static |
| 1721 | void |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1722 | __construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1723 | { |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1724 | static_assert(__is_cpp17_move_insertable<allocator_type>::value, |
| 1725 | "The specified type does not meet the requirements of Cpp17MoveInsertable"); |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1726 | while (__end1 != __begin1) |
Howard Hinnant | 5adee4c | 2013-01-11 20:36:59 +0000 | [diff] [blame] | 1727 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1728 | construct(__a, _VSTD::__to_address(__end2 - 1), |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1729 | #ifdef _LIBCPP_NO_EXCEPTIONS |
| 1730 | _VSTD::move(*--__end1) |
| 1731 | #else |
| 1732 | _VSTD::move_if_noexcept(*--__end1) |
| 1733 | #endif |
| 1734 | ); |
| 1735 | --__end2; |
Howard Hinnant | 5adee4c | 2013-01-11 20:36:59 +0000 | [diff] [blame] | 1736 | } |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | template <class _Tp> |
| 1740 | _LIBCPP_INLINE_VISIBILITY |
| 1741 | static |
| 1742 | typename enable_if |
| 1743 | < |
Volodymyr Sapsai | 5c16302 | 2019-01-08 00:03:16 +0000 | [diff] [blame] | 1744 | (__is_default_allocator<allocator_type>::value |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1745 | || !__has_construct<allocator_type, _Tp*, _Tp>::value) && |
| 1746 | is_trivially_move_constructible<_Tp>::value, |
| 1747 | void |
| 1748 | >::type |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 1749 | __construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1750 | { |
| 1751 | ptrdiff_t _Np = __end1 - __begin1; |
| 1752 | __end2 -= _Np; |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1753 | if (_Np > 0) |
| 1754 | _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1757 | private: |
| 1758 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1759 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1760 | static pointer __allocate(allocator_type& __a, size_type __n, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1761 | const_void_pointer __hint, true_type) |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1762 | { |
| 1763 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 1764 | return __a.allocate(__n, __hint); |
| 1765 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 1766 | } |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1767 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1768 | static pointer __allocate(allocator_type& __a, size_type __n, |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1769 | const_void_pointer, false_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1770 | {return __a.allocate(__n);} |
| 1771 | |
| 1772 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1773 | template <class _Tp, class... _Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1774 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1775 | static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args) |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1776 | { |
| 1777 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 1778 | __a.construct(__p, _VSTD::forward<_Args>(__args)...); |
| 1779 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 1780 | } |
| 1781 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | template <class _Tp, class... _Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1784 | static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args) |
| 1785 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1786 | ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1787 | } |
Volodymyr Sapsai | 2b1eb84 | 2018-12-19 20:08:43 +0000 | [diff] [blame] | 1788 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 1789 | template <class _Tp, class _A0> |
| 1790 | _LIBCPP_INLINE_VISIBILITY |
| 1791 | static void __construct(true_type, allocator_type& __a, _Tp* __p, |
| 1792 | const _A0& __a0) |
| 1793 | {__a.construct(__p, __a0);} |
| 1794 | template <class _Tp, class _A0> |
| 1795 | _LIBCPP_INLINE_VISIBILITY |
| 1796 | static void __construct(false_type, allocator_type&, _Tp* __p, |
| 1797 | const _A0& __a0) |
| 1798 | { |
| 1799 | ::new ((void*)__p) _Tp(__a0); |
| 1800 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1801 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1802 | |
| 1803 | template <class _Tp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1804 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1805 | static void __destroy(true_type, allocator_type& __a, _Tp* __p) |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1806 | { |
| 1807 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 1808 | __a.destroy(__p); |
| 1809 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 1810 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1811 | template <class _Tp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1812 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1813 | static void __destroy(false_type, allocator_type&, _Tp* __p) |
| 1814 | { |
| 1815 | __p->~_Tp(); |
| 1816 | } |
| 1817 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1818 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f817a35 | 2017-12-05 15:56:26 +0000 | [diff] [blame] | 1819 | static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1820 | { |
| 1821 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 1822 | return __a.max_size(); |
| 1823 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 1824 | } |
| 1825 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1826 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f817a35 | 2017-12-05 15:56:26 +0000 | [diff] [blame] | 1827 | static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT |
Marshall Clow | 33daa16 | 2015-10-25 19:34:04 +0000 | [diff] [blame] | 1828 | {return numeric_limits<size_type>::max() / sizeof(value_type);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1829 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1830 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1831 | static allocator_type |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1832 | __select_on_container_copy_construction(true_type, const allocator_type& __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1833 | {return __a.select_on_container_copy_construction();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1834 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1835 | static allocator_type |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1836 | __select_on_container_copy_construction(false_type, const allocator_type& __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | {return __a;} |
| 1838 | }; |
| 1839 | |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1840 | template <class _Traits, class _Tp> |
| 1841 | struct __rebind_alloc_helper |
| 1842 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1843 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1844 | typedef _LIBCPP_NODEBUG_TYPE typename _Traits::template rebind_alloc<_Tp> type; |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1845 | #else |
| 1846 | typedef typename _Traits::template rebind_alloc<_Tp>::other type; |
| 1847 | #endif |
| 1848 | }; |
| 1849 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 | // allocator |
| 1851 | |
| 1852 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1853 | class _LIBCPP_TEMPLATE_VIS allocator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1854 | { |
| 1855 | public: |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1856 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
| 1857 | _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t size_type; |
| 1858 | _LIBCPP_DEPRECATED_IN_CXX17 typedef ptrdiff_t difference_type; |
| 1859 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp* pointer; |
| 1860 | _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; |
| 1861 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp& reference; |
| 1862 | _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; |
| 1863 | |
| 1864 | template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;}; |
| 1865 | #endif |
| 1866 | |
| 1867 | typedef _Tp value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1868 | |
Howard Hinnant | 4931e09 | 2011-06-02 21:38:57 +0000 | [diff] [blame] | 1869 | typedef true_type propagate_on_container_move_assignment; |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1870 | typedef true_type is_always_equal; |
Howard Hinnant | 4931e09 | 2011-06-02 21:38:57 +0000 | [diff] [blame] | 1871 | |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 1872 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1873 | allocator() _NOEXCEPT {} |
| 1874 | |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1875 | template <class _Up> |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 1876 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1877 | allocator(const allocator<_Up>&) _NOEXCEPT {} |
| 1878 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1879 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
| 1880 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 1881 | pointer address(reference __x) const _NOEXCEPT |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1882 | {return _VSTD::addressof(__x);} |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1883 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 1884 | const_pointer address(const_reference __x) const _NOEXCEPT |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1885 | {return _VSTD::addressof(__x);} |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1886 | #endif |
| 1887 | |
| 1888 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _Tp* allocate(size_t __n) |
Marshall Clow | 813ffb3 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 1889 | { |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1890 | // TODO(mpark): Replace with `allocator_traits<allocator>::max_size(*this)`. |
| 1891 | if (__n > (size_t(~0) / sizeof(_Tp))) |
Marshall Clow | ed3e229 | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 1892 | __throw_length_error("allocator<T>::allocate(size_t n)" |
| 1893 | " 'n' exceeds maximum supported size"); |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1894 | return static_cast<_Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); |
Marshall Clow | 813ffb3 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 1895 | } |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1896 | |
| 1897 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
| 1898 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 |
| 1899 | _Tp* allocate(size_t __n, const void*) { return allocate(__n); } |
| 1900 | #endif |
| 1901 | |
| 1902 | _LIBCPP_INLINE_VISIBILITY void deallocate(_Tp* __p, size_t __n) _NOEXCEPT |
Eric Fiselier | 0f0ed9d | 2019-01-16 01:51:12 +0000 | [diff] [blame] | 1903 | {_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));} |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1904 | |
| 1905 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
| 1906 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1907 | {return size_type(~0) / sizeof(_Tp);} |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1908 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1909 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1910 | template <class _Up, class... _Args> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1911 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1912 | void |
| 1913 | construct(_Up* __p, _Args&&... __args) |
| 1914 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1915 | ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1916 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1917 | #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1918 | _LIBCPP_INLINE_VISIBILITY |
| 1919 | void |
| 1920 | construct(pointer __p) |
| 1921 | { |
| 1922 | ::new((void*)__p) _Tp(); |
| 1923 | } |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1924 | # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1925 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1926 | template <class _A0> |
| 1927 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1928 | void |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1929 | construct(pointer __p, _A0& __a0) |
| 1930 | { |
| 1931 | ::new((void*)__p) _Tp(__a0); |
| 1932 | } |
| 1933 | template <class _A0> |
| 1934 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1935 | void |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1936 | construct(pointer __p, const _A0& __a0) |
| 1937 | { |
| 1938 | ::new((void*)__p) _Tp(__a0); |
| 1939 | } |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1940 | # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1941 | template <class _A0, class _A1> |
| 1942 | _LIBCPP_INLINE_VISIBILITY |
| 1943 | void |
| 1944 | construct(pointer __p, _A0& __a0, _A1& __a1) |
| 1945 | { |
| 1946 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1947 | } |
| 1948 | template <class _A0, class _A1> |
| 1949 | _LIBCPP_INLINE_VISIBILITY |
| 1950 | void |
| 1951 | construct(pointer __p, const _A0& __a0, _A1& __a1) |
| 1952 | { |
| 1953 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1954 | } |
| 1955 | template <class _A0, class _A1> |
| 1956 | _LIBCPP_INLINE_VISIBILITY |
| 1957 | void |
| 1958 | construct(pointer __p, _A0& __a0, const _A1& __a1) |
| 1959 | { |
| 1960 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1961 | } |
| 1962 | template <class _A0, class _A1> |
| 1963 | _LIBCPP_INLINE_VISIBILITY |
| 1964 | void |
| 1965 | construct(pointer __p, const _A0& __a0, const _A1& __a1) |
| 1966 | { |
| 1967 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1968 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1969 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1970 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} |
| 1971 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1972 | }; |
| 1973 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1974 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1975 | class _LIBCPP_TEMPLATE_VIS allocator<const _Tp> |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1976 | { |
| 1977 | public: |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 1978 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
| 1979 | _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t size_type; |
| 1980 | _LIBCPP_DEPRECATED_IN_CXX17 typedef ptrdiff_t difference_type; |
| 1981 | _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer; |
| 1982 | _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; |
| 1983 | _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference; |
| 1984 | _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; |
| 1985 | |
| 1986 | template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;}; |
| 1987 | #endif |
| 1988 | |
| 1989 | typedef const _Tp value_type; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1990 | |
| 1991 | typedef true_type propagate_on_container_move_assignment; |
Marshall Clow | ac12fcc | 2015-07-01 21:23:40 +0000 | [diff] [blame] | 1992 | typedef true_type is_always_equal; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1993 | |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 1994 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1995 | allocator() _NOEXCEPT {} |
| 1996 | |
| 1997 | template <class _Up> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1998 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 1999 | allocator(const allocator<_Up>&) _NOEXCEPT {} |
| 2000 | |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2001 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
| 2002 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 2003 | const_pointer address(const_reference __x) const _NOEXCEPT |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2004 | {return _VSTD::addressof(__x);} |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2005 | #endif |
| 2006 | |
| 2007 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const _Tp* allocate(size_t __n) |
Marshall Clow | 813ffb3 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 2008 | { |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2009 | // TODO(mpark): Replace with `allocator_traits<allocator>::max_size(*this)`. |
| 2010 | if (__n > (size_t(~0) / sizeof(_Tp))) |
Marshall Clow | ed3e229 | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 2011 | __throw_length_error("allocator<const T>::allocate(size_t n)" |
| 2012 | " 'n' exceeds maximum supported size"); |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2013 | return static_cast<const _Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); |
Eric Fiselier | 2db2bd5 | 2016-05-07 03:12:24 +0000 | [diff] [blame] | 2014 | } |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2015 | |
| 2016 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
| 2017 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17 |
| 2018 | const _Tp* allocate(size_t __n, const void*) { return allocate(__n); } |
| 2019 | #endif |
| 2020 | |
| 2021 | _LIBCPP_INLINE_VISIBILITY void deallocate(const _Tp* __p, size_t __n) |
Eric Fiselier | 0f0ed9d | 2019-01-16 01:51:12 +0000 | [diff] [blame] | 2022 | {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));} |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2023 | |
| 2024 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS) |
| 2025 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2026 | {return size_type(~0) / sizeof(_Tp);} |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2027 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2028 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
| 2029 | template <class _Up, class... _Args> |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2030 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2031 | void |
| 2032 | construct(_Up* __p, _Args&&... __args) |
| 2033 | { |
| 2034 | ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); |
| 2035 | } |
| 2036 | #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
| 2037 | _LIBCPP_INLINE_VISIBILITY |
| 2038 | void |
| 2039 | construct(pointer __p) |
| 2040 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 2041 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2042 | } |
| 2043 | # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 2044 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2045 | template <class _A0> |
| 2046 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 2047 | void |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2048 | construct(pointer __p, _A0& __a0) |
| 2049 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 2050 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2051 | } |
| 2052 | template <class _A0> |
| 2053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 2054 | void |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2055 | construct(pointer __p, const _A0& __a0) |
| 2056 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 2057 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2058 | } |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2059 | # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
| 2060 | template <class _A0, class _A1> |
| 2061 | _LIBCPP_INLINE_VISIBILITY |
| 2062 | void |
| 2063 | construct(pointer __p, _A0& __a0, _A1& __a1) |
| 2064 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 2065 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2066 | } |
| 2067 | template <class _A0, class _A1> |
| 2068 | _LIBCPP_INLINE_VISIBILITY |
| 2069 | void |
| 2070 | construct(pointer __p, const _A0& __a0, _A1& __a1) |
| 2071 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 2072 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2073 | } |
| 2074 | template <class _A0, class _A1> |
| 2075 | _LIBCPP_INLINE_VISIBILITY |
| 2076 | void |
| 2077 | construct(pointer __p, _A0& __a0, const _A1& __a1) |
| 2078 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 2079 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2080 | } |
| 2081 | template <class _A0, class _A1> |
| 2082 | _LIBCPP_INLINE_VISIBILITY |
| 2083 | void |
| 2084 | construct(pointer __p, const _A0& __a0, const _A1& __a1) |
| 2085 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 2086 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2087 | } |
| 2088 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Michael Park | 99f9e91 | 2020-03-04 11:27:14 -0500 | [diff] [blame^] | 2089 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} |
| 2090 | #endif |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2091 | }; |
| 2092 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2093 | template <class _Tp, class _Up> |
| 2094 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2095 | bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2096 | |
| 2097 | template <class _Tp, class _Up> |
| 2098 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2099 | bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2100 | |
| 2101 | template <class _OutputIterator, class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2102 | class _LIBCPP_TEMPLATE_VIS raw_storage_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2103 | : public iterator<output_iterator_tag, |
| 2104 | _Tp, // purposefully not C++03 |
| 2105 | ptrdiff_t, // purposefully not C++03 |
| 2106 | _Tp*, // purposefully not C++03 |
| 2107 | raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 |
| 2108 | { |
| 2109 | private: |
| 2110 | _OutputIterator __x_; |
| 2111 | public: |
| 2112 | _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} |
| 2113 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} |
| 2114 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) |
Marshall Clow | bdfdea8 | 2018-08-28 13:29:30 +0000 | [diff] [blame] | 2115 | {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;} |
Marshall Clow | 5c3f09e | 2015-10-25 18:58:07 +0000 | [diff] [blame] | 2116 | #if _LIBCPP_STD_VER >= 14 |
| 2117 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) |
Marshall Clow | bdfdea8 | 2018-08-28 13:29:30 +0000 | [diff] [blame] | 2118 | {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} |
Marshall Clow | 5c3f09e | 2015-10-25 18:58:07 +0000 | [diff] [blame] | 2119 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2120 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} |
| 2121 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) |
| 2122 | {raw_storage_iterator __t(*this); ++__x_; return __t;} |
Marshall Clow | b949f1b | 2015-05-10 13:14:08 +0000 | [diff] [blame] | 2123 | #if _LIBCPP_STD_VER >= 14 |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 2124 | _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } |
Marshall Clow | b949f1b | 2015-05-10 13:14:08 +0000 | [diff] [blame] | 2125 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2126 | }; |
| 2127 | |
| 2128 | template <class _Tp> |
Roman Lebedev | b5959fa | 2018-09-22 17:54:48 +0000 | [diff] [blame] | 2129 | _LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2130 | pair<_Tp*, ptrdiff_t> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2131 | get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2132 | { |
| 2133 | pair<_Tp*, ptrdiff_t> __r(0, 0); |
| 2134 | const ptrdiff_t __m = (~ptrdiff_t(0) ^ |
| 2135 | ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) |
| 2136 | / sizeof(_Tp); |
| 2137 | if (__n > __m) |
| 2138 | __n = __m; |
| 2139 | while (__n > 0) |
| 2140 | { |
Eric Fiselier | 6a07b34 | 2018-10-26 17:12:32 +0000 | [diff] [blame] | 2141 | #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) |
Eric Fiselier | 0f0ed9d | 2019-01-16 01:51:12 +0000 | [diff] [blame] | 2142 | if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2143 | { |
| 2144 | std::align_val_t __al = |
| 2145 | std::align_val_t(std::alignment_of<_Tp>::value); |
| 2146 | __r.first = static_cast<_Tp*>(::operator new( |
| 2147 | __n * sizeof(_Tp), __al, nothrow)); |
| 2148 | } else { |
| 2149 | __r.first = static_cast<_Tp*>(::operator new( |
| 2150 | __n * sizeof(_Tp), nothrow)); |
| 2151 | } |
| 2152 | #else |
Eric Fiselier | 0f0ed9d | 2019-01-16 01:51:12 +0000 | [diff] [blame] | 2153 | if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2154 | { |
| 2155 | // Since aligned operator new is unavailable, return an empty |
| 2156 | // buffer rather than one with invalid alignment. |
| 2157 | return __r; |
| 2158 | } |
| 2159 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2160 | __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2161 | #endif |
| 2162 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2163 | if (__r.first) |
| 2164 | { |
| 2165 | __r.second = __n; |
| 2166 | break; |
| 2167 | } |
| 2168 | __n /= 2; |
| 2169 | } |
| 2170 | return __r; |
| 2171 | } |
| 2172 | |
| 2173 | template <class _Tp> |
| 2174 | inline _LIBCPP_INLINE_VISIBILITY |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2175 | void return_temporary_buffer(_Tp* __p) _NOEXCEPT |
| 2176 | { |
Eric Fiselier | 0f0ed9d | 2019-01-16 01:51:12 +0000 | [diff] [blame] | 2177 | _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2178 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2179 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 2180 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2181 | template <class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 2182 | struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2183 | { |
| 2184 | _Tp* __ptr_; |
| 2185 | }; |
| 2186 | |
| 2187 | template<class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 2188 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2189 | { |
| 2190 | private: |
| 2191 | _Tp* __ptr_; |
| 2192 | public: |
| 2193 | typedef _Tp element_type; |
| 2194 | |
| 2195 | _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {} |
| 2196 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {} |
| 2197 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw() |
| 2198 | : __ptr_(__p.release()) {} |
| 2199 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw() |
| 2200 | {reset(__p.release()); return *this;} |
| 2201 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw() |
| 2202 | {reset(__p.release()); return *this;} |
| 2203 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw() |
| 2204 | {reset(__p.__ptr_); return *this;} |
| 2205 | _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;} |
| 2206 | |
| 2207 | _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw() |
| 2208 | {return *__ptr_;} |
| 2209 | _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;} |
| 2210 | _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;} |
| 2211 | _LIBCPP_INLINE_VISIBILITY _Tp* release() throw() |
| 2212 | { |
| 2213 | _Tp* __t = __ptr_; |
| 2214 | __ptr_ = 0; |
| 2215 | return __t; |
| 2216 | } |
| 2217 | _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw() |
| 2218 | { |
| 2219 | if (__ptr_ != __p) |
| 2220 | delete __ptr_; |
| 2221 | __ptr_ = __p; |
| 2222 | } |
| 2223 | |
| 2224 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {} |
| 2225 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw() |
| 2226 | {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} |
| 2227 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw() |
| 2228 | {return auto_ptr<_Up>(release());} |
| 2229 | }; |
| 2230 | |
| 2231 | template <> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 2232 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2233 | { |
| 2234 | public: |
| 2235 | typedef void element_type; |
| 2236 | }; |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 2237 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2238 | |
Eric Fiselier | 15eae3b | 2019-12-16 17:00:10 -0500 | [diff] [blame] | 2239 | // Tag used to default initialize one or both of the pair's elements. |
| 2240 | struct __default_init_tag {}; |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2241 | struct __value_init_tag {}; |
Eric Fiselier | 15eae3b | 2019-12-16 17:00:10 -0500 | [diff] [blame] | 2242 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2243 | template <class _Tp, int _Idx, |
| 2244 | bool _CanBeEmptyBase = |
| 2245 | is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value> |
| 2246 | struct __compressed_pair_elem { |
| 2247 | typedef _Tp _ParamT; |
| 2248 | typedef _Tp& reference; |
| 2249 | typedef const _Tp& const_reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2250 | |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2251 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Eric Fiselier | 15eae3b | 2019-12-16 17:00:10 -0500 | [diff] [blame] | 2252 | __compressed_pair_elem(__default_init_tag) {} |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2253 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 2254 | __compressed_pair_elem(__value_init_tag) : __value_() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2255 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2256 | template <class _Up, class = typename enable_if< |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2257 | !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value |
| 2258 | >::type> |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2259 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2260 | _LIBCPP_CONSTEXPR explicit |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2261 | __compressed_pair_elem(_Up&& __u) |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 2262 | : __value_(_VSTD::forward<_Up>(__u)) |
| 2263 | { |
| 2264 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2265 | |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2266 | |
| 2267 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2268 | template <class... _Args, size_t... _Indexes> |
| 2269 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2270 | __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, |
| 2271 | __tuple_indices<_Indexes...>) |
| 2272 | : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2273 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2274 | |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2275 | |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2276 | _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } |
| 2277 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2278 | const_reference __get() const _NOEXCEPT { return __value_; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2279 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2280 | private: |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2281 | _Tp __value_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2282 | }; |
| 2283 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2284 | template <class _Tp, int _Idx> |
| 2285 | struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { |
| 2286 | typedef _Tp _ParamT; |
| 2287 | typedef _Tp& reference; |
| 2288 | typedef const _Tp& const_reference; |
| 2289 | typedef _Tp __value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2290 | |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2291 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __compressed_pair_elem() = default; |
| 2292 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 2293 | __compressed_pair_elem(__default_init_tag) {} |
| 2294 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 2295 | __compressed_pair_elem(__value_init_tag) : __value_type() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2296 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2297 | template <class _Up, class = typename enable_if< |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2298 | !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value |
| 2299 | >::type> |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2300 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2301 | _LIBCPP_CONSTEXPR explicit |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2302 | __compressed_pair_elem(_Up&& __u) |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 2303 | : __value_type(_VSTD::forward<_Up>(__u)) |
| 2304 | {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2305 | |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2306 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2307 | template <class... _Args, size_t... _Indexes> |
| 2308 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2309 | __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, |
| 2310 | __tuple_indices<_Indexes...>) |
| 2311 | : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2312 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2313 | |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2314 | _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } |
| 2315 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2316 | const_reference __get() const _NOEXCEPT { return *this; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2317 | }; |
| 2318 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2319 | template <class _T1, class _T2> |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2320 | class __compressed_pair : private __compressed_pair_elem<_T1, 0>, |
| 2321 | private __compressed_pair_elem<_T2, 1> { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2322 | typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1; |
| 2323 | typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2; |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2324 | |
| 2325 | // NOTE: This static assert should never fire because __compressed_pair |
| 2326 | // is *almost never* used in a scenario where it's possible for T1 == T2. |
| 2327 | // (The exception is std::function where it is possible that the function |
| 2328 | // object and the allocator have the same type). |
Eric Fiselier | c5adf47 | 2017-04-13 01:13:58 +0000 | [diff] [blame] | 2329 | static_assert((!is_same<_T1, _T2>::value), |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2330 | "__compressed_pair cannot be instantated when T1 and T2 are the same type; " |
| 2331 | "The current implementation is NOT ABI-compatible with the previous " |
| 2332 | "implementation for this configuration"); |
| 2333 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2334 | public: |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2335 | template <bool _Dummy = true, |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2336 | class = typename enable_if< |
| 2337 | __dependent_type<is_default_constructible<_T1>, _Dummy>::value && |
| 2338 | __dependent_type<is_default_constructible<_T2>, _Dummy>::value |
| 2339 | >::type |
| 2340 | > |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2341 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2342 | _LIBCPP_CONSTEXPR __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2344 | template <class _U1, class _U2> |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2345 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2346 | __compressed_pair(_U1&& __t1, _U2&& __t2) |
| 2347 | : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2348 | |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2349 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2350 | template <class... _Args1, class... _Args2> |
| 2351 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2352 | __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, |
| 2353 | tuple<_Args2...> __second_args) |
| 2354 | : _Base1(__pc, _VSTD::move(__first_args), |
| 2355 | typename __make_tuple_indices<sizeof...(_Args1)>::type()), |
| 2356 | _Base2(__pc, _VSTD::move(__second_args), |
| 2357 | typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2358 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2359 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2360 | _LIBCPP_INLINE_VISIBILITY |
| 2361 | typename _Base1::reference first() _NOEXCEPT { |
| 2362 | return static_cast<_Base1&>(*this).__get(); |
| 2363 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2364 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2365 | _LIBCPP_INLINE_VISIBILITY |
| 2366 | typename _Base1::const_reference first() const _NOEXCEPT { |
| 2367 | return static_cast<_Base1 const&>(*this).__get(); |
| 2368 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2369 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2370 | _LIBCPP_INLINE_VISIBILITY |
| 2371 | typename _Base2::reference second() _NOEXCEPT { |
| 2372 | return static_cast<_Base2&>(*this).__get(); |
| 2373 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2374 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2375 | _LIBCPP_INLINE_VISIBILITY |
| 2376 | typename _Base2::const_reference second() const _NOEXCEPT { |
| 2377 | return static_cast<_Base2 const&>(*this).__get(); |
| 2378 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2379 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2380 | _LIBCPP_INLINE_VISIBILITY |
| 2381 | void swap(__compressed_pair& __x) |
| 2382 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2383 | __is_nothrow_swappable<_T2>::value) |
| 2384 | { |
| 2385 | using std::swap; |
| 2386 | swap(first(), __x.first()); |
| 2387 | swap(second(), __x.second()); |
| 2388 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2389 | }; |
| 2390 | |
| 2391 | template <class _T1, class _T2> |
| 2392 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2393 | void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) |
| 2394 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2395 | __is_nothrow_swappable<_T2>::value) { |
| 2396 | __x.swap(__y); |
| 2397 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2398 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2399 | // default_delete |
| 2400 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2401 | template <class _Tp> |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2402 | struct _LIBCPP_TEMPLATE_VIS default_delete { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 2403 | static_assert(!is_function<_Tp>::value, |
| 2404 | "default_delete cannot be instantiated for function types"); |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2405 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2406 | _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2407 | #else |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2408 | _LIBCPP_INLINE_VISIBILITY default_delete() {} |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2409 | #endif |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2410 | template <class _Up> |
| 2411 | _LIBCPP_INLINE_VISIBILITY |
| 2412 | default_delete(const default_delete<_Up>&, |
| 2413 | typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = |
| 2414 | 0) _NOEXCEPT {} |
| 2415 | |
| 2416 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT { |
| 2417 | static_assert(sizeof(_Tp) > 0, |
| 2418 | "default_delete can not delete incomplete type"); |
| 2419 | static_assert(!is_void<_Tp>::value, |
| 2420 | "default_delete can not delete incomplete type"); |
| 2421 | delete __ptr; |
| 2422 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2423 | }; |
| 2424 | |
| 2425 | template <class _Tp> |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2426 | struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { |
| 2427 | private: |
| 2428 | template <class _Up> |
| 2429 | struct _EnableIfConvertible |
| 2430 | : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; |
| 2431 | |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2432 | public: |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2433 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2434 | _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2435 | #else |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2436 | _LIBCPP_INLINE_VISIBILITY default_delete() {} |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2437 | #endif |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2438 | |
| 2439 | template <class _Up> |
| 2440 | _LIBCPP_INLINE_VISIBILITY |
| 2441 | default_delete(const default_delete<_Up[]>&, |
| 2442 | typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} |
| 2443 | |
| 2444 | template <class _Up> |
| 2445 | _LIBCPP_INLINE_VISIBILITY |
| 2446 | typename _EnableIfConvertible<_Up>::type |
| 2447 | operator()(_Up* __ptr) const _NOEXCEPT { |
| 2448 | static_assert(sizeof(_Tp) > 0, |
| 2449 | "default_delete can not delete incomplete type"); |
| 2450 | static_assert(!is_void<_Tp>::value, |
| 2451 | "default_delete can not delete void type"); |
| 2452 | delete[] __ptr; |
| 2453 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2454 | }; |
| 2455 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2456 | template <class _Deleter> |
| 2457 | struct __unique_ptr_deleter_sfinae { |
| 2458 | static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); |
| 2459 | typedef const _Deleter& __lval_ref_type; |
| 2460 | typedef _Deleter&& __good_rval_ref_type; |
| 2461 | typedef true_type __enable_rval_overload; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2462 | }; |
| 2463 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2464 | template <class _Deleter> |
| 2465 | struct __unique_ptr_deleter_sfinae<_Deleter const&> { |
| 2466 | typedef const _Deleter& __lval_ref_type; |
| 2467 | typedef const _Deleter&& __bad_rval_ref_type; |
| 2468 | typedef false_type __enable_rval_overload; |
| 2469 | }; |
| 2470 | |
| 2471 | template <class _Deleter> |
| 2472 | struct __unique_ptr_deleter_sfinae<_Deleter&> { |
| 2473 | typedef _Deleter& __lval_ref_type; |
| 2474 | typedef _Deleter&& __bad_rval_ref_type; |
| 2475 | typedef false_type __enable_rval_overload; |
| 2476 | }; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2477 | |
| 2478 | template <class _Tp, class _Dp = default_delete<_Tp> > |
| 2479 | class _LIBCPP_TEMPLATE_VIS unique_ptr { |
| 2480 | public: |
| 2481 | typedef _Tp element_type; |
| 2482 | typedef _Dp deleter_type; |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2483 | typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type<_Tp, deleter_type>::type pointer; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2484 | |
| 2485 | static_assert(!is_rvalue_reference<deleter_type>::value, |
| 2486 | "the specified deleter type cannot be an rvalue reference"); |
| 2487 | |
| 2488 | private: |
| 2489 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 2490 | |
| 2491 | struct __nat { int __for_bool_; }; |
| 2492 | |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2493 | typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2494 | |
| 2495 | template <bool _Dummy> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2496 | using _LValRefType _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2497 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2498 | |
| 2499 | template <bool _Dummy> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2500 | using _GoodRValRefType _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2501 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2502 | |
| 2503 | template <bool _Dummy> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2504 | using _BadRValRefType _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2505 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2506 | |
| 2507 | template <bool _Dummy, class _Deleter = typename __dependent_type< |
| 2508 | __identity<deleter_type>, _Dummy>::type> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2509 | using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2510 | typename enable_if<is_default_constructible<_Deleter>::value && |
| 2511 | !is_pointer<_Deleter>::value>::type; |
| 2512 | |
| 2513 | template <class _ArgType> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2514 | using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2515 | typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; |
| 2516 | |
| 2517 | template <class _UPtr, class _Up> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2518 | using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2519 | is_convertible<typename _UPtr::pointer, pointer>::value && |
| 2520 | !is_array<_Up>::value |
| 2521 | >::type; |
| 2522 | |
| 2523 | template <class _UDel> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2524 | using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2525 | (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || |
| 2526 | (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) |
| 2527 | >::type; |
| 2528 | |
| 2529 | template <class _UDel> |
| 2530 | using _EnableIfDeleterAssignable = typename enable_if< |
| 2531 | is_assignable<_Dp&, _UDel&&>::value |
| 2532 | >::type; |
| 2533 | |
| 2534 | public: |
| 2535 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2536 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2537 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2538 | _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2539 | |
| 2540 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2541 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2542 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2543 | _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2544 | |
| 2545 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2546 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2547 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2548 | explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {} |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2549 | |
| 2550 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2551 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2552 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2553 | unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2554 | : __ptr_(__p, __d) {} |
| 2555 | |
| 2556 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2557 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2558 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2559 | unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2560 | : __ptr_(__p, _VSTD::move(__d)) { |
| 2561 | static_assert(!is_reference<deleter_type>::value, |
| 2562 | "rvalue deleter bound to reference"); |
| 2563 | } |
| 2564 | |
| 2565 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2566 | class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2567 | _LIBCPP_INLINE_VISIBILITY |
| 2568 | unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; |
| 2569 | |
| 2570 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2571 | unique_ptr(unique_ptr&& __u) _NOEXCEPT |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2572 | : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { |
| 2573 | } |
| 2574 | |
| 2575 | template <class _Up, class _Ep, |
| 2576 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2577 | class = _EnableIfDeleterConvertible<_Ep> |
| 2578 | > |
| 2579 | _LIBCPP_INLINE_VISIBILITY |
| 2580 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT |
| 2581 | : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} |
| 2582 | |
| 2583 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 2584 | template <class _Up> |
| 2585 | _LIBCPP_INLINE_VISIBILITY |
| 2586 | unique_ptr(auto_ptr<_Up>&& __p, |
| 2587 | typename enable_if<is_convertible<_Up*, _Tp*>::value && |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2588 | is_same<_Dp, default_delete<_Tp> >::value, |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2589 | __nat>::type = __nat()) _NOEXCEPT |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2590 | : __ptr_(__p.release(), __default_init_tag()) {} |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2591 | #endif |
| 2592 | |
| 2593 | _LIBCPP_INLINE_VISIBILITY |
| 2594 | unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { |
| 2595 | reset(__u.release()); |
| 2596 | __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); |
| 2597 | return *this; |
| 2598 | } |
| 2599 | |
| 2600 | template <class _Up, class _Ep, |
| 2601 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2602 | class = _EnableIfDeleterAssignable<_Ep> |
| 2603 | > |
| 2604 | _LIBCPP_INLINE_VISIBILITY |
| 2605 | unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { |
| 2606 | reset(__u.release()); |
| 2607 | __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); |
| 2608 | return *this; |
| 2609 | } |
| 2610 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2611 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 2612 | template <class _Up> |
| 2613 | _LIBCPP_INLINE_VISIBILITY |
| 2614 | typename enable_if<is_convertible<_Up*, _Tp*>::value && |
| 2615 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2616 | unique_ptr&>::type |
| 2617 | operator=(auto_ptr<_Up> __p) { |
| 2618 | reset(__p.release()); |
| 2619 | return *this; |
| 2620 | } |
| 2621 | #endif |
| 2622 | |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2623 | #ifdef _LIBCPP_CXX03_LANG |
| 2624 | unique_ptr(unique_ptr const&) = delete; |
| 2625 | unique_ptr& operator=(unique_ptr const&) = delete; |
| 2626 | #endif |
| 2627 | |
| 2628 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2629 | _LIBCPP_INLINE_VISIBILITY |
| 2630 | ~unique_ptr() { reset(); } |
| 2631 | |
| 2632 | _LIBCPP_INLINE_VISIBILITY |
| 2633 | unique_ptr& operator=(nullptr_t) _NOEXCEPT { |
| 2634 | reset(); |
| 2635 | return *this; |
| 2636 | } |
| 2637 | |
| 2638 | _LIBCPP_INLINE_VISIBILITY |
| 2639 | typename add_lvalue_reference<_Tp>::type |
| 2640 | operator*() const { |
| 2641 | return *__ptr_.first(); |
| 2642 | } |
| 2643 | _LIBCPP_INLINE_VISIBILITY |
| 2644 | pointer operator->() const _NOEXCEPT { |
| 2645 | return __ptr_.first(); |
| 2646 | } |
| 2647 | _LIBCPP_INLINE_VISIBILITY |
| 2648 | pointer get() const _NOEXCEPT { |
| 2649 | return __ptr_.first(); |
| 2650 | } |
| 2651 | _LIBCPP_INLINE_VISIBILITY |
| 2652 | deleter_type& get_deleter() _NOEXCEPT { |
| 2653 | return __ptr_.second(); |
| 2654 | } |
| 2655 | _LIBCPP_INLINE_VISIBILITY |
| 2656 | const deleter_type& get_deleter() const _NOEXCEPT { |
| 2657 | return __ptr_.second(); |
| 2658 | } |
| 2659 | _LIBCPP_INLINE_VISIBILITY |
| 2660 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { |
| 2661 | return __ptr_.first() != nullptr; |
| 2662 | } |
| 2663 | |
| 2664 | _LIBCPP_INLINE_VISIBILITY |
| 2665 | pointer release() _NOEXCEPT { |
| 2666 | pointer __t = __ptr_.first(); |
| 2667 | __ptr_.first() = pointer(); |
| 2668 | return __t; |
| 2669 | } |
| 2670 | |
| 2671 | _LIBCPP_INLINE_VISIBILITY |
| 2672 | void reset(pointer __p = pointer()) _NOEXCEPT { |
| 2673 | pointer __tmp = __ptr_.first(); |
| 2674 | __ptr_.first() = __p; |
| 2675 | if (__tmp) |
| 2676 | __ptr_.second()(__tmp); |
| 2677 | } |
| 2678 | |
| 2679 | _LIBCPP_INLINE_VISIBILITY |
| 2680 | void swap(unique_ptr& __u) _NOEXCEPT { |
| 2681 | __ptr_.swap(__u.__ptr_); |
| 2682 | } |
| 2683 | }; |
| 2684 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2685 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2686 | template <class _Tp, class _Dp> |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2687 | class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2688 | public: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2689 | typedef _Tp element_type; |
| 2690 | typedef _Dp deleter_type; |
| 2691 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2692 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2693 | private: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2694 | __compressed_pair<pointer, deleter_type> __ptr_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2695 | |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2696 | template <class _From> |
| 2697 | struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2698 | |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2699 | template <class _FromElem> |
| 2700 | struct _CheckArrayPointerConversion<_FromElem*> |
| 2701 | : integral_constant<bool, |
| 2702 | is_same<_FromElem*, pointer>::value || |
| 2703 | (is_same<pointer, element_type*>::value && |
| 2704 | is_convertible<_FromElem(*)[], element_type(*)[]>::value) |
| 2705 | > |
| 2706 | {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2707 | |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2708 | typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2709 | |
| 2710 | template <bool _Dummy> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2711 | using _LValRefType _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2712 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2713 | |
| 2714 | template <bool _Dummy> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2715 | using _GoodRValRefType _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2716 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2717 | |
| 2718 | template <bool _Dummy> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2719 | using _BadRValRefType _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2720 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2721 | |
| 2722 | template <bool _Dummy, class _Deleter = typename __dependent_type< |
| 2723 | __identity<deleter_type>, _Dummy>::type> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2724 | using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2725 | typename enable_if<is_default_constructible<_Deleter>::value && |
| 2726 | !is_pointer<_Deleter>::value>::type; |
| 2727 | |
| 2728 | template <class _ArgType> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2729 | using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE = |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2730 | typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; |
| 2731 | |
| 2732 | template <class _Pp> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2733 | using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2734 | _CheckArrayPointerConversion<_Pp>::value |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2735 | >::type; |
| 2736 | |
| 2737 | template <class _UPtr, class _Up, |
| 2738 | class _ElemT = typename _UPtr::element_type> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2739 | using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2740 | is_array<_Up>::value && |
| 2741 | is_same<pointer, element_type*>::value && |
| 2742 | is_same<typename _UPtr::pointer, _ElemT*>::value && |
| 2743 | is_convertible<_ElemT(*)[], element_type(*)[]>::value |
| 2744 | >::type; |
| 2745 | |
| 2746 | template <class _UDel> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2747 | using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2748 | (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || |
| 2749 | (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) |
| 2750 | >::type; |
| 2751 | |
| 2752 | template <class _UDel> |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 2753 | using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if< |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2754 | is_assignable<_Dp&, _UDel&&>::value |
| 2755 | >::type; |
| 2756 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2757 | public: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2758 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2759 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2760 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2761 | _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2762 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2763 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2764 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2765 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2766 | _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2767 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2768 | template <class _Pp, bool _Dummy = true, |
| 2769 | class = _EnableIfDeleterDefaultConstructible<_Dummy>, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2770 | class = _EnableIfPointerConvertible<_Pp> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2771 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2772 | explicit unique_ptr(_Pp __p) _NOEXCEPT |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2773 | : __ptr_(__p, __default_init_tag()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2774 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2775 | template <class _Pp, bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2776 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >, |
| 2777 | class = _EnableIfPointerConvertible<_Pp> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2778 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2779 | unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2780 | : __ptr_(__p, __d) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2781 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2782 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2783 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2784 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2785 | unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2786 | : __ptr_(nullptr, __d) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2787 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2788 | template <class _Pp, bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2789 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >, |
| 2790 | class = _EnableIfPointerConvertible<_Pp> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2791 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2792 | unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2793 | : __ptr_(__p, _VSTD::move(__d)) { |
| 2794 | static_assert(!is_reference<deleter_type>::value, |
| 2795 | "rvalue deleter bound to reference"); |
| 2796 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2797 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2798 | template <bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2799 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2800 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2801 | unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2802 | : __ptr_(nullptr, _VSTD::move(__d)) { |
| 2803 | static_assert(!is_reference<deleter_type>::value, |
| 2804 | "rvalue deleter bound to reference"); |
| 2805 | } |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2806 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2807 | template <class _Pp, bool _Dummy = true, |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2808 | class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >, |
| 2809 | class = _EnableIfPointerConvertible<_Pp> > |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2810 | _LIBCPP_INLINE_VISIBILITY |
| 2811 | unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2812 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2813 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2814 | unique_ptr(unique_ptr&& __u) _NOEXCEPT |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2815 | : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { |
| 2816 | } |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2817 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2818 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2819 | unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2820 | reset(__u.release()); |
| 2821 | __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); |
| 2822 | return *this; |
| 2823 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2824 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2825 | template <class _Up, class _Ep, |
| 2826 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2827 | class = _EnableIfDeleterConvertible<_Ep> |
| 2828 | > |
| 2829 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2830 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT |
Eric Fiselier | 3827e6a | 2017-04-17 20:20:27 +0000 | [diff] [blame] | 2831 | : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2832 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2833 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2834 | template <class _Up, class _Ep, |
| 2835 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2836 | class = _EnableIfDeleterAssignable<_Ep> |
| 2837 | > |
| 2838 | _LIBCPP_INLINE_VISIBILITY |
| 2839 | unique_ptr& |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2840 | operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2841 | reset(__u.release()); |
| 2842 | __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); |
| 2843 | return *this; |
| 2844 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2845 | |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 2846 | #ifdef _LIBCPP_CXX03_LANG |
| 2847 | unique_ptr(unique_ptr const&) = delete; |
| 2848 | unique_ptr& operator=(unique_ptr const&) = delete; |
| 2849 | #endif |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2850 | |
| 2851 | public: |
| 2852 | _LIBCPP_INLINE_VISIBILITY |
| 2853 | ~unique_ptr() { reset(); } |
| 2854 | |
| 2855 | _LIBCPP_INLINE_VISIBILITY |
| 2856 | unique_ptr& operator=(nullptr_t) _NOEXCEPT { |
| 2857 | reset(); |
| 2858 | return *this; |
| 2859 | } |
| 2860 | |
| 2861 | _LIBCPP_INLINE_VISIBILITY |
| 2862 | typename add_lvalue_reference<_Tp>::type |
| 2863 | operator[](size_t __i) const { |
| 2864 | return __ptr_.first()[__i]; |
| 2865 | } |
| 2866 | _LIBCPP_INLINE_VISIBILITY |
| 2867 | pointer get() const _NOEXCEPT { |
| 2868 | return __ptr_.first(); |
| 2869 | } |
| 2870 | |
| 2871 | _LIBCPP_INLINE_VISIBILITY |
| 2872 | deleter_type& get_deleter() _NOEXCEPT { |
| 2873 | return __ptr_.second(); |
| 2874 | } |
| 2875 | |
| 2876 | _LIBCPP_INLINE_VISIBILITY |
| 2877 | const deleter_type& get_deleter() const _NOEXCEPT { |
| 2878 | return __ptr_.second(); |
| 2879 | } |
| 2880 | _LIBCPP_INLINE_VISIBILITY |
| 2881 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { |
| 2882 | return __ptr_.first() != nullptr; |
| 2883 | } |
| 2884 | |
| 2885 | _LIBCPP_INLINE_VISIBILITY |
| 2886 | pointer release() _NOEXCEPT { |
| 2887 | pointer __t = __ptr_.first(); |
| 2888 | __ptr_.first() = pointer(); |
| 2889 | return __t; |
| 2890 | } |
| 2891 | |
| 2892 | template <class _Pp> |
| 2893 | _LIBCPP_INLINE_VISIBILITY |
| 2894 | typename enable_if< |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2895 | _CheckArrayPointerConversion<_Pp>::value |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2896 | >::type |
| 2897 | reset(_Pp __p) _NOEXCEPT { |
| 2898 | pointer __tmp = __ptr_.first(); |
| 2899 | __ptr_.first() = __p; |
| 2900 | if (__tmp) |
| 2901 | __ptr_.second()(__tmp); |
| 2902 | } |
| 2903 | |
| 2904 | _LIBCPP_INLINE_VISIBILITY |
| 2905 | void reset(nullptr_t = nullptr) _NOEXCEPT { |
| 2906 | pointer __tmp = __ptr_.first(); |
| 2907 | __ptr_.first() = nullptr; |
| 2908 | if (__tmp) |
| 2909 | __ptr_.second()(__tmp); |
| 2910 | } |
| 2911 | |
| 2912 | _LIBCPP_INLINE_VISIBILITY |
| 2913 | void swap(unique_ptr& __u) _NOEXCEPT { |
| 2914 | __ptr_.swap(__u.__ptr_); |
| 2915 | } |
| 2916 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2917 | }; |
| 2918 | |
| 2919 | template <class _Tp, class _Dp> |
| 2920 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6bfed25 | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 2921 | typename enable_if< |
| 2922 | __is_swappable<_Dp>::value, |
| 2923 | void |
| 2924 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2925 | swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2926 | |
| 2927 | template <class _T1, class _D1, class _T2, class _D2> |
| 2928 | inline _LIBCPP_INLINE_VISIBILITY |
| 2929 | bool |
| 2930 | operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} |
| 2931 | |
| 2932 | template <class _T1, class _D1, class _T2, class _D2> |
| 2933 | inline _LIBCPP_INLINE_VISIBILITY |
| 2934 | bool |
| 2935 | operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} |
| 2936 | |
| 2937 | template <class _T1, class _D1, class _T2, class _D2> |
| 2938 | inline _LIBCPP_INLINE_VISIBILITY |
| 2939 | bool |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2940 | operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) |
| 2941 | { |
| 2942 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 2943 | typedef typename unique_ptr<_T2, _D2>::pointer _P2; |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 2944 | typedef typename common_type<_P1, _P2>::type _Vp; |
| 2945 | return less<_Vp>()(__x.get(), __y.get()); |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2946 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2947 | |
| 2948 | template <class _T1, class _D1, class _T2, class _D2> |
| 2949 | inline _LIBCPP_INLINE_VISIBILITY |
| 2950 | bool |
| 2951 | operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} |
| 2952 | |
| 2953 | template <class _T1, class _D1, class _T2, class _D2> |
| 2954 | inline _LIBCPP_INLINE_VISIBILITY |
| 2955 | bool |
| 2956 | operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} |
| 2957 | |
| 2958 | template <class _T1, class _D1, class _T2, class _D2> |
| 2959 | inline _LIBCPP_INLINE_VISIBILITY |
| 2960 | bool |
| 2961 | operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} |
| 2962 | |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2963 | template <class _T1, class _D1> |
| 2964 | inline _LIBCPP_INLINE_VISIBILITY |
| 2965 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2966 | operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2967 | { |
| 2968 | return !__x; |
| 2969 | } |
| 2970 | |
| 2971 | template <class _T1, class _D1> |
| 2972 | inline _LIBCPP_INLINE_VISIBILITY |
| 2973 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2974 | operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2975 | { |
| 2976 | return !__x; |
| 2977 | } |
| 2978 | |
| 2979 | template <class _T1, class _D1> |
| 2980 | inline _LIBCPP_INLINE_VISIBILITY |
| 2981 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2982 | operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2983 | { |
| 2984 | return static_cast<bool>(__x); |
| 2985 | } |
| 2986 | |
| 2987 | template <class _T1, class _D1> |
| 2988 | inline _LIBCPP_INLINE_VISIBILITY |
| 2989 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2990 | operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2991 | { |
| 2992 | return static_cast<bool>(__x); |
| 2993 | } |
| 2994 | |
| 2995 | template <class _T1, class _D1> |
| 2996 | inline _LIBCPP_INLINE_VISIBILITY |
| 2997 | bool |
| 2998 | operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 2999 | { |
| 3000 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 3001 | return less<_P1>()(__x.get(), nullptr); |
| 3002 | } |
| 3003 | |
| 3004 | template <class _T1, class _D1> |
| 3005 | inline _LIBCPP_INLINE_VISIBILITY |
| 3006 | bool |
| 3007 | operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3008 | { |
| 3009 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 3010 | return less<_P1>()(nullptr, __x.get()); |
| 3011 | } |
| 3012 | |
| 3013 | template <class _T1, class _D1> |
| 3014 | inline _LIBCPP_INLINE_VISIBILITY |
| 3015 | bool |
| 3016 | operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3017 | { |
| 3018 | return nullptr < __x; |
| 3019 | } |
| 3020 | |
| 3021 | template <class _T1, class _D1> |
| 3022 | inline _LIBCPP_INLINE_VISIBILITY |
| 3023 | bool |
| 3024 | operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3025 | { |
| 3026 | return __x < nullptr; |
| 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 | return !(nullptr < __x); |
| 3035 | } |
| 3036 | |
| 3037 | template <class _T1, class _D1> |
| 3038 | inline _LIBCPP_INLINE_VISIBILITY |
| 3039 | bool |
| 3040 | operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3041 | { |
| 3042 | return !(__x < nullptr); |
| 3043 | } |
| 3044 | |
| 3045 | template <class _T1, class _D1> |
| 3046 | inline _LIBCPP_INLINE_VISIBILITY |
| 3047 | bool |
| 3048 | operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3049 | { |
| 3050 | return !(__x < nullptr); |
| 3051 | } |
| 3052 | |
| 3053 | template <class _T1, class _D1> |
| 3054 | inline _LIBCPP_INLINE_VISIBILITY |
| 3055 | bool |
| 3056 | operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3057 | { |
| 3058 | return !(nullptr < __x); |
| 3059 | } |
| 3060 | |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3061 | #if _LIBCPP_STD_VER > 11 |
| 3062 | |
| 3063 | template<class _Tp> |
| 3064 | struct __unique_if |
| 3065 | { |
| 3066 | typedef unique_ptr<_Tp> __unique_single; |
| 3067 | }; |
| 3068 | |
| 3069 | template<class _Tp> |
| 3070 | struct __unique_if<_Tp[]> |
| 3071 | { |
| 3072 | typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; |
| 3073 | }; |
| 3074 | |
| 3075 | template<class _Tp, size_t _Np> |
| 3076 | struct __unique_if<_Tp[_Np]> |
| 3077 | { |
| 3078 | typedef void __unique_array_known_bound; |
| 3079 | }; |
| 3080 | |
| 3081 | template<class _Tp, class... _Args> |
Marshall Clow | 724e3df | 2013-07-02 20:06:09 +0000 | [diff] [blame] | 3082 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3083 | typename __unique_if<_Tp>::__unique_single |
| 3084 | make_unique(_Args&&... __args) |
| 3085 | { |
| 3086 | return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); |
| 3087 | } |
| 3088 | |
| 3089 | template<class _Tp> |
Marshall Clow | 724e3df | 2013-07-02 20:06:09 +0000 | [diff] [blame] | 3090 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3091 | typename __unique_if<_Tp>::__unique_array_unknown_bound |
| 3092 | make_unique(size_t __n) |
| 3093 | { |
| 3094 | typedef typename remove_extent<_Tp>::type _Up; |
| 3095 | return unique_ptr<_Tp>(new _Up[__n]()); |
| 3096 | } |
| 3097 | |
| 3098 | template<class _Tp, class... _Args> |
| 3099 | typename __unique_if<_Tp>::__unique_array_known_bound |
| 3100 | make_unique(_Args&&...) = delete; |
| 3101 | |
| 3102 | #endif // _LIBCPP_STD_VER > 11 |
| 3103 | |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3104 | template <class _Tp, class _Dp> |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 3105 | #ifdef _LIBCPP_CXX03_LANG |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3106 | struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> > |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 3107 | #else |
| 3108 | struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< |
Eric Fiselier | ea6fdf6 | 2019-06-23 20:47:21 +0000 | [diff] [blame] | 3109 | unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> > |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 3110 | #endif |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3111 | { |
| 3112 | typedef unique_ptr<_Tp, _Dp> argument_type; |
| 3113 | typedef size_t result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3114 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4903689 | 2017-03-23 02:40:28 +0000 | [diff] [blame] | 3115 | result_type operator()(const argument_type& __ptr) const |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3116 | { |
| 3117 | typedef typename argument_type::pointer pointer; |
| 3118 | return hash<pointer>()(__ptr.get()); |
| 3119 | } |
| 3120 | }; |
| 3121 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3122 | struct __destruct_n |
| 3123 | { |
| 3124 | private: |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3125 | size_t __size_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3126 | |
| 3127 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3128 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3129 | {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3130 | |
| 3131 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3132 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3133 | {} |
| 3134 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3135 | _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3136 | {++__size_;} |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3137 | _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3138 | {} |
| 3139 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3140 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3141 | {__size_ = __s;} |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3142 | _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3143 | {} |
| 3144 | public: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3145 | _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3146 | : __size_(__s) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3147 | |
| 3148 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3149 | _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3150 | {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3151 | |
| 3152 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3153 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3154 | {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3155 | |
| 3156 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3157 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3158 | {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3159 | }; |
| 3160 | |
| 3161 | template <class _Alloc> |
| 3162 | class __allocator_destructor |
| 3163 | { |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 3164 | typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3165 | public: |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 3166 | typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer; |
| 3167 | typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3168 | private: |
| 3169 | _Alloc& __alloc_; |
| 3170 | size_type __s_; |
| 3171 | public: |
| 3172 | _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3173 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3174 | : __alloc_(__a), __s_(__s) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3175 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3176 | void operator()(pointer __p) _NOEXCEPT |
| 3177 | {__alloc_traits::deallocate(__alloc_, __p, __s_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3178 | }; |
| 3179 | |
| 3180 | template <class _InputIterator, class _ForwardIterator> |
| 3181 | _ForwardIterator |
| 3182 | uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) |
| 3183 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3184 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3185 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3186 | _ForwardIterator __s = __r; |
| 3187 | try |
| 3188 | { |
| 3189 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3190 | for (; __f != __l; ++__f, (void) ++__r) |
| 3191 | ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3192 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3193 | } |
| 3194 | catch (...) |
| 3195 | { |
| 3196 | for (; __s != __r; ++__s) |
| 3197 | __s->~value_type(); |
| 3198 | throw; |
| 3199 | } |
| 3200 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3201 | return __r; |
| 3202 | } |
| 3203 | |
| 3204 | template <class _InputIterator, class _Size, class _ForwardIterator> |
| 3205 | _ForwardIterator |
| 3206 | uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) |
| 3207 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3208 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3209 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3210 | _ForwardIterator __s = __r; |
| 3211 | try |
| 3212 | { |
| 3213 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3214 | for (; __n > 0; ++__f, (void) ++__r, (void) --__n) |
| 3215 | ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3216 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3217 | } |
| 3218 | catch (...) |
| 3219 | { |
| 3220 | for (; __s != __r; ++__s) |
| 3221 | __s->~value_type(); |
| 3222 | throw; |
| 3223 | } |
| 3224 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3225 | return __r; |
| 3226 | } |
| 3227 | |
| 3228 | template <class _ForwardIterator, class _Tp> |
| 3229 | void |
| 3230 | uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) |
| 3231 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3232 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3233 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3234 | _ForwardIterator __s = __f; |
| 3235 | try |
| 3236 | { |
| 3237 | #endif |
| 3238 | for (; __f != __l; ++__f) |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3239 | ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3240 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3241 | } |
| 3242 | catch (...) |
| 3243 | { |
| 3244 | for (; __s != __f; ++__s) |
| 3245 | __s->~value_type(); |
| 3246 | throw; |
| 3247 | } |
| 3248 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | template <class _ForwardIterator, class _Size, class _Tp> |
Howard Hinnant | 3c81109 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 3252 | _ForwardIterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3253 | uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) |
| 3254 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3255 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3256 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3257 | _ForwardIterator __s = __f; |
| 3258 | try |
| 3259 | { |
| 3260 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3261 | for (; __n > 0; ++__f, (void) --__n) |
| 3262 | ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3263 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3264 | } |
| 3265 | catch (...) |
| 3266 | { |
| 3267 | for (; __s != __f; ++__s) |
| 3268 | __s->~value_type(); |
| 3269 | throw; |
| 3270 | } |
| 3271 | #endif |
Howard Hinnant | 3c81109 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 3272 | return __f; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3273 | } |
| 3274 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3275 | #if _LIBCPP_STD_VER > 14 |
| 3276 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3277 | template <class _Tp> |
| 3278 | inline _LIBCPP_INLINE_VISIBILITY |
| 3279 | void destroy_at(_Tp* __loc) { |
| 3280 | _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); |
| 3281 | __loc->~_Tp(); |
| 3282 | } |
| 3283 | |
| 3284 | template <class _ForwardIterator> |
| 3285 | inline _LIBCPP_INLINE_VISIBILITY |
| 3286 | void destroy(_ForwardIterator __first, _ForwardIterator __last) { |
| 3287 | for (; __first != __last; ++__first) |
| 3288 | _VSTD::destroy_at(_VSTD::addressof(*__first)); |
| 3289 | } |
| 3290 | |
| 3291 | template <class _ForwardIterator, class _Size> |
| 3292 | inline _LIBCPP_INLINE_VISIBILITY |
| 3293 | _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { |
| 3294 | for (; __n > 0; (void)++__first, --__n) |
| 3295 | _VSTD::destroy_at(_VSTD::addressof(*__first)); |
| 3296 | return __first; |
| 3297 | } |
| 3298 | |
Eric Fiselier | 290c07c | 2016-10-11 21:13:44 +0000 | [diff] [blame] | 3299 | template <class _ForwardIterator> |
| 3300 | inline _LIBCPP_INLINE_VISIBILITY |
| 3301 | void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { |
| 3302 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3303 | auto __idx = __first; |
| 3304 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3305 | try { |
| 3306 | #endif |
| 3307 | for (; __idx != __last; ++__idx) |
| 3308 | ::new((void*)_VSTD::addressof(*__idx)) _Vt; |
| 3309 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3310 | } catch (...) { |
| 3311 | _VSTD::destroy(__first, __idx); |
| 3312 | throw; |
| 3313 | } |
| 3314 | #endif |
| 3315 | } |
| 3316 | |
| 3317 | template <class _ForwardIterator, class _Size> |
| 3318 | inline _LIBCPP_INLINE_VISIBILITY |
| 3319 | _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { |
| 3320 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3321 | auto __idx = __first; |
| 3322 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3323 | try { |
| 3324 | #endif |
| 3325 | for (; __n > 0; (void)++__idx, --__n) |
| 3326 | ::new((void*)_VSTD::addressof(*__idx)) _Vt; |
| 3327 | return __idx; |
| 3328 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3329 | } catch (...) { |
| 3330 | _VSTD::destroy(__first, __idx); |
| 3331 | throw; |
| 3332 | } |
| 3333 | #endif |
| 3334 | } |
| 3335 | |
| 3336 | |
| 3337 | template <class _ForwardIterator> |
| 3338 | inline _LIBCPP_INLINE_VISIBILITY |
| 3339 | void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { |
| 3340 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3341 | auto __idx = __first; |
| 3342 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3343 | try { |
| 3344 | #endif |
| 3345 | for (; __idx != __last; ++__idx) |
| 3346 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(); |
| 3347 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3348 | } catch (...) { |
| 3349 | _VSTD::destroy(__first, __idx); |
| 3350 | throw; |
| 3351 | } |
| 3352 | #endif |
| 3353 | } |
| 3354 | |
| 3355 | template <class _ForwardIterator, class _Size> |
| 3356 | inline _LIBCPP_INLINE_VISIBILITY |
| 3357 | _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { |
| 3358 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3359 | auto __idx = __first; |
| 3360 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3361 | try { |
| 3362 | #endif |
| 3363 | for (; __n > 0; (void)++__idx, --__n) |
| 3364 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(); |
| 3365 | return __idx; |
| 3366 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3367 | } catch (...) { |
| 3368 | _VSTD::destroy(__first, __idx); |
| 3369 | throw; |
| 3370 | } |
| 3371 | #endif |
| 3372 | } |
| 3373 | |
| 3374 | |
| 3375 | template <class _InputIt, class _ForwardIt> |
| 3376 | inline _LIBCPP_INLINE_VISIBILITY |
| 3377 | _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) { |
| 3378 | using _Vt = typename iterator_traits<_ForwardIt>::value_type; |
| 3379 | auto __idx = __first_res; |
| 3380 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3381 | try { |
| 3382 | #endif |
| 3383 | for (; __first != __last; (void)++__idx, ++__first) |
| 3384 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); |
| 3385 | return __idx; |
| 3386 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3387 | } catch (...) { |
| 3388 | _VSTD::destroy(__first_res, __idx); |
| 3389 | throw; |
| 3390 | } |
| 3391 | #endif |
| 3392 | } |
| 3393 | |
| 3394 | template <class _InputIt, class _Size, class _ForwardIt> |
| 3395 | inline _LIBCPP_INLINE_VISIBILITY |
| 3396 | pair<_InputIt, _ForwardIt> |
| 3397 | uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { |
| 3398 | using _Vt = typename iterator_traits<_ForwardIt>::value_type; |
| 3399 | auto __idx = __first_res; |
| 3400 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3401 | try { |
| 3402 | #endif |
| 3403 | for (; __n > 0; ++__idx, (void)++__first, --__n) |
| 3404 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); |
| 3405 | return {__first, __idx}; |
| 3406 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3407 | } catch (...) { |
| 3408 | _VSTD::destroy(__first_res, __idx); |
| 3409 | throw; |
| 3410 | } |
| 3411 | #endif |
| 3412 | } |
| 3413 | |
| 3414 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3415 | #endif // _LIBCPP_STD_VER > 14 |
| 3416 | |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3417 | // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) |
| 3418 | // should be sufficient for thread safety. |
Eric Fiselier | 5d60401 | 2017-02-17 08:37:03 +0000 | [diff] [blame] | 3419 | // See https://bugs.llvm.org/show_bug.cgi?id=22803 |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3420 | #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \ |
| 3421 | && defined(__ATOMIC_RELAXED) \ |
| 3422 | && defined(__ATOMIC_ACQ_REL) |
| 3423 | # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT |
Richard Smith | ca47d0f | 2019-04-25 20:02:10 +0000 | [diff] [blame] | 3424 | #elif defined(_LIBCPP_COMPILER_GCC) |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3425 | # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT |
| 3426 | #endif |
| 3427 | |
| 3428 | template <class _Tp> |
| 3429 | inline _LIBCPP_INLINE_VISIBILITY _Tp |
| 3430 | __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT |
| 3431 | { |
| 3432 | #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) |
| 3433 | return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED); |
| 3434 | #else |
| 3435 | return __t += 1; |
| 3436 | #endif |
| 3437 | } |
| 3438 | |
| 3439 | template <class _Tp> |
| 3440 | inline _LIBCPP_INLINE_VISIBILITY _Tp |
| 3441 | __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT |
| 3442 | { |
| 3443 | #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) |
| 3444 | return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); |
| 3445 | #else |
| 3446 | return __t -= 1; |
| 3447 | #endif |
| 3448 | } |
| 3449 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3450 | class _LIBCPP_EXCEPTION_ABI bad_weak_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3451 | : public std::exception |
| 3452 | { |
| 3453 | public: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3454 | virtual ~bad_weak_ptr() _NOEXCEPT; |
| 3455 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3456 | }; |
| 3457 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 3458 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 3459 | void __throw_bad_weak_ptr() |
| 3460 | { |
| 3461 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3462 | throw bad_weak_ptr(); |
| 3463 | #else |
| 3464 | _VSTD::abort(); |
| 3465 | #endif |
| 3466 | } |
| 3467 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3468 | template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3469 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3470 | class _LIBCPP_TYPE_VIS __shared_count |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3471 | { |
| 3472 | __shared_count(const __shared_count&); |
| 3473 | __shared_count& operator=(const __shared_count&); |
| 3474 | |
| 3475 | protected: |
| 3476 | long __shared_owners_; |
| 3477 | virtual ~__shared_count(); |
| 3478 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3479 | virtual void __on_zero_shared() _NOEXCEPT = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3480 | |
| 3481 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3483 | explicit __shared_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3484 | : __shared_owners_(__refs) {} |
| 3485 | |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 3486 | #if defined(_LIBCPP_BUILDING_LIBRARY) && \ |
Eric Fiselier | 9884857 | 2017-01-17 03:16:26 +0000 | [diff] [blame] | 3487 | defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) |
Eric Fiselier | e0700ff | 2017-01-17 03:05:31 +0000 | [diff] [blame] | 3488 | void __add_shared() _NOEXCEPT; |
| 3489 | bool __release_shared() _NOEXCEPT; |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3490 | #else |
| 3491 | _LIBCPP_INLINE_VISIBILITY |
| 3492 | void __add_shared() _NOEXCEPT { |
| 3493 | __libcpp_atomic_refcount_increment(__shared_owners_); |
| 3494 | } |
| 3495 | _LIBCPP_INLINE_VISIBILITY |
| 3496 | bool __release_shared() _NOEXCEPT { |
| 3497 | if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { |
| 3498 | __on_zero_shared(); |
| 3499 | return true; |
| 3500 | } |
| 3501 | return false; |
| 3502 | } |
| 3503 | #endif |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3504 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 89659d1 | 2015-07-07 00:27:16 +0000 | [diff] [blame] | 3505 | long use_count() const _NOEXCEPT { |
| 3506 | return __libcpp_relaxed_load(&__shared_owners_) + 1; |
| 3507 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3508 | }; |
| 3509 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3510 | class _LIBCPP_TYPE_VIS __shared_weak_count |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3511 | : private __shared_count |
| 3512 | { |
| 3513 | long __shared_weak_owners_; |
| 3514 | |
| 3515 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3517 | explicit __shared_weak_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3518 | : __shared_count(__refs), |
| 3519 | __shared_weak_owners_(__refs) {} |
| 3520 | protected: |
| 3521 | virtual ~__shared_weak_count(); |
| 3522 | |
| 3523 | public: |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 3524 | #if defined(_LIBCPP_BUILDING_LIBRARY) && \ |
Eric Fiselier | 9884857 | 2017-01-17 03:16:26 +0000 | [diff] [blame] | 3525 | defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) |
Eric Fiselier | e0700ff | 2017-01-17 03:05:31 +0000 | [diff] [blame] | 3526 | void __add_shared() _NOEXCEPT; |
| 3527 | void __add_weak() _NOEXCEPT; |
| 3528 | void __release_shared() _NOEXCEPT; |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3529 | #else |
| 3530 | _LIBCPP_INLINE_VISIBILITY |
| 3531 | void __add_shared() _NOEXCEPT { |
| 3532 | __shared_count::__add_shared(); |
| 3533 | } |
| 3534 | _LIBCPP_INLINE_VISIBILITY |
| 3535 | void __add_weak() _NOEXCEPT { |
| 3536 | __libcpp_atomic_refcount_increment(__shared_weak_owners_); |
| 3537 | } |
| 3538 | _LIBCPP_INLINE_VISIBILITY |
| 3539 | void __release_shared() _NOEXCEPT { |
| 3540 | if (__shared_count::__release_shared()) |
| 3541 | __release_weak(); |
| 3542 | } |
| 3543 | #endif |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3544 | void __release_weak() _NOEXCEPT; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3545 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3546 | long use_count() const _NOEXCEPT {return __shared_count::use_count();} |
| 3547 | __shared_weak_count* lock() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3548 | |
Howard Hinnant | 807d633 | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 3549 | // Define the function out only if we build static libc++ without RTTI. |
| 3550 | // Otherwise we may break clients who need to compile their projects with |
| 3551 | // -fno-rtti and yet link against a libc++.dylib compiled |
| 3552 | // without -fno-rtti. |
| 3553 | #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3554 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | 807d633 | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 3555 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3556 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3557 | virtual void __on_zero_shared_weak() _NOEXCEPT = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3558 | }; |
| 3559 | |
| 3560 | template <class _Tp, class _Dp, class _Alloc> |
| 3561 | class __shared_ptr_pointer |
| 3562 | : public __shared_weak_count |
| 3563 | { |
| 3564 | __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; |
| 3565 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3566 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3567 | __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3568 | : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3569 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3570 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3571 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3572 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3573 | |
| 3574 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3575 | virtual void __on_zero_shared() _NOEXCEPT; |
| 3576 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3577 | }; |
| 3578 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3579 | #ifndef _LIBCPP_NO_RTTI |
| 3580 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3581 | template <class _Tp, class _Dp, class _Alloc> |
| 3582 | const void* |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3583 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3584 | { |
Eric Fiselier | c7490d0 | 2017-05-04 01:06:56 +0000 | [diff] [blame] | 3585 | return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3586 | } |
| 3587 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3588 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3589 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3590 | template <class _Tp, class _Dp, class _Alloc> |
| 3591 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3592 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3593 | { |
| 3594 | __data_.first().second()(__data_.first().first()); |
| 3595 | __data_.first().second().~_Dp(); |
| 3596 | } |
| 3597 | |
| 3598 | template <class _Tp, class _Dp, class _Alloc> |
| 3599 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3600 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3601 | { |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3602 | typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; |
| 3603 | typedef allocator_traits<_Al> _ATraits; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3604 | typedef pointer_traits<typename _ATraits::pointer> _PTraits; |
| 3605 | |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3606 | _Al __a(__data_.second()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3607 | __data_.second().~_Alloc(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3608 | __a.deallocate(_PTraits::pointer_to(*this), 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | template <class _Tp, class _Alloc> |
| 3612 | class __shared_ptr_emplace |
| 3613 | : public __shared_weak_count |
| 3614 | { |
| 3615 | __compressed_pair<_Alloc, _Tp> __data_; |
| 3616 | public: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3617 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3618 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3619 | __shared_ptr_emplace(_Alloc __a) |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 3620 | : __data_(_VSTD::move(__a), __value_init_tag()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3621 | |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 3622 | |
| 3623 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3624 | template <class ..._Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3625 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3626 | __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 3627 | : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), |
| 3628 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3629 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3630 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3631 | template <class _A0> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3632 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3633 | __shared_ptr_emplace(_Alloc __a, _A0& __a0) |
| 3634 | : __data_(__a, _Tp(__a0)) {} |
| 3635 | |
| 3636 | template <class _A0, class _A1> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3637 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3638 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) |
| 3639 | : __data_(__a, _Tp(__a0, __a1)) {} |
| 3640 | |
| 3641 | template <class _A0, class _A1, class _A2> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3642 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3643 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3644 | : __data_(__a, _Tp(__a0, __a1, __a2)) {} |
| 3645 | |
| 3646 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3647 | |
| 3648 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3649 | virtual void __on_zero_shared() _NOEXCEPT; |
| 3650 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3651 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3652 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | bdfdea8 | 2018-08-28 13:29:30 +0000 | [diff] [blame] | 3653 | _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3654 | }; |
| 3655 | |
| 3656 | template <class _Tp, class _Alloc> |
| 3657 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3658 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3659 | { |
| 3660 | __data_.second().~_Tp(); |
| 3661 | } |
| 3662 | |
| 3663 | template <class _Tp, class _Alloc> |
| 3664 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3665 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3666 | { |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3667 | typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; |
| 3668 | typedef allocator_traits<_Al> _ATraits; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3669 | typedef pointer_traits<typename _ATraits::pointer> _PTraits; |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3670 | _Al __a(__data_.first()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3671 | __data_.first().~_Alloc(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3672 | __a.deallocate(_PTraits::pointer_to(*this), 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 3675 | struct __shared_ptr_dummy_rebind_allocator_type; |
| 3676 | template <> |
| 3677 | class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> |
| 3678 | { |
| 3679 | public: |
| 3680 | template <class _Other> |
| 3681 | struct rebind |
| 3682 | { |
| 3683 | typedef allocator<_Other> other; |
| 3684 | }; |
| 3685 | }; |
| 3686 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3687 | template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3688 | |
| 3689 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3690 | class _LIBCPP_TEMPLATE_VIS shared_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3691 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3692 | public: |
| 3693 | typedef _Tp element_type; |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3694 | |
Eric Fiselier | ae5b667 | 2016-06-27 01:02:43 +0000 | [diff] [blame] | 3695 | #if _LIBCPP_STD_VER > 14 |
| 3696 | typedef weak_ptr<_Tp> weak_type; |
| 3697 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3698 | private: |
| 3699 | element_type* __ptr_; |
| 3700 | __shared_weak_count* __cntrl_; |
| 3701 | |
| 3702 | struct __nat {int __for_bool_;}; |
| 3703 | public: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3704 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3705 | _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3706 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3707 | _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3708 | template<class _Yp> |
| 3709 | explicit shared_ptr(_Yp* __p, |
| 3710 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
| 3711 | template<class _Yp, class _Dp> |
| 3712 | shared_ptr(_Yp* __p, _Dp __d, |
| 3713 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
| 3714 | template<class _Yp, class _Dp, class _Alloc> |
| 3715 | shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, |
| 3716 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3717 | template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); |
| 3718 | template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3719 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; |
| 3720 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3721 | shared_ptr(const shared_ptr& __r) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3722 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3723 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3724 | shared_ptr(const shared_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3725 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3726 | _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3727 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3728 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3729 | shared_ptr(shared_ptr&& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3730 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3731 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3732 | _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3733 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3734 | template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3735 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3736 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3737 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3738 | template<class _Yp> |
| 3739 | shared_ptr(auto_ptr<_Yp>&& __r, |
| 3740 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3741 | #else |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3742 | template<class _Yp> |
| 3743 | shared_ptr(auto_ptr<_Yp> __r, |
| 3744 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3745 | #endif |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3746 | #endif |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3747 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3748 | template <class _Yp, class _Dp> |
| 3749 | shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 3750 | typename enable_if |
| 3751 | < |
| 3752 | !is_lvalue_reference<_Dp>::value && |
| 3753 | !is_array<_Yp>::value && |
| 3754 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3755 | __nat |
| 3756 | >::type = __nat()); |
| 3757 | template <class _Yp, class _Dp> |
| 3758 | shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 3759 | typename enable_if |
| 3760 | < |
| 3761 | is_lvalue_reference<_Dp>::value && |
| 3762 | !is_array<_Yp>::value && |
| 3763 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3764 | __nat |
| 3765 | >::type = __nat()); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3766 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3767 | template <class _Yp, class _Dp> |
| 3768 | shared_ptr(unique_ptr<_Yp, _Dp>, |
| 3769 | typename enable_if |
| 3770 | < |
| 3771 | !is_lvalue_reference<_Dp>::value && |
| 3772 | !is_array<_Yp>::value && |
| 3773 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3774 | __nat |
| 3775 | >::type = __nat()); |
| 3776 | template <class _Yp, class _Dp> |
| 3777 | shared_ptr(unique_ptr<_Yp, _Dp>, |
| 3778 | typename enable_if |
| 3779 | < |
| 3780 | is_lvalue_reference<_Dp>::value && |
| 3781 | !is_array<_Yp>::value && |
| 3782 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3783 | __nat |
| 3784 | >::type = __nat()); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3785 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3786 | |
| 3787 | ~shared_ptr(); |
| 3788 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3789 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3790 | shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3791 | template<class _Yp> |
| 3792 | typename enable_if |
| 3793 | < |
| 3794 | is_convertible<_Yp*, element_type*>::value, |
| 3795 | shared_ptr& |
| 3796 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3797 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3798 | operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3799 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3800 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3801 | shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3802 | template<class _Yp> |
| 3803 | typename enable_if |
| 3804 | < |
| 3805 | is_convertible<_Yp*, element_type*>::value, |
| 3806 | shared_ptr<_Tp>& |
| 3807 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3808 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3809 | operator=(shared_ptr<_Yp>&& __r); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3810 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3811 | template<class _Yp> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 3812 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3813 | typename enable_if |
| 3814 | < |
| 3815 | !is_array<_Yp>::value && |
| 3816 | is_convertible<_Yp*, element_type*>::value, |
Howard Hinnant | 25bcaf6 | 2013-09-13 23:56:00 +0000 | [diff] [blame] | 3817 | shared_ptr |
| 3818 | >::type& |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3819 | operator=(auto_ptr<_Yp>&& __r); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3820 | #endif |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3821 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3822 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3823 | template<class _Yp> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 3824 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3825 | typename enable_if |
| 3826 | < |
| 3827 | !is_array<_Yp>::value && |
| 3828 | is_convertible<_Yp*, element_type*>::value, |
| 3829 | shared_ptr& |
| 3830 | >::type |
| 3831 | operator=(auto_ptr<_Yp> __r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3832 | #endif |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3833 | #endif |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3834 | template <class _Yp, class _Dp> |
| 3835 | typename enable_if |
| 3836 | < |
| 3837 | !is_array<_Yp>::value && |
| 3838 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3839 | shared_ptr& |
| 3840 | >::type |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3841 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3842 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3843 | operator=(unique_ptr<_Yp, _Dp>&& __r); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3844 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 0319287 | 2015-12-09 22:32:36 +0000 | [diff] [blame] | 3845 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3846 | operator=(unique_ptr<_Yp, _Dp> __r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3847 | #endif |
| 3848 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3849 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3850 | void swap(shared_ptr& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3851 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3852 | void reset() _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3853 | template<class _Yp> |
| 3854 | typename enable_if |
| 3855 | < |
| 3856 | is_convertible<_Yp*, element_type*>::value, |
| 3857 | void |
| 3858 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3859 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3860 | reset(_Yp* __p); |
| 3861 | template<class _Yp, class _Dp> |
| 3862 | typename enable_if |
| 3863 | < |
| 3864 | is_convertible<_Yp*, element_type*>::value, |
| 3865 | void |
| 3866 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3867 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3868 | reset(_Yp* __p, _Dp __d); |
| 3869 | template<class _Yp, class _Dp, class _Alloc> |
| 3870 | typename enable_if |
| 3871 | < |
| 3872 | is_convertible<_Yp*, element_type*>::value, |
| 3873 | void |
| 3874 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3875 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3876 | reset(_Yp* __p, _Dp __d, _Alloc __a); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3877 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3878 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3879 | element_type* get() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3880 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3881 | typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT |
| 3882 | {return *__ptr_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3884 | element_type* operator->() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3885 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3886 | long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3887 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3888 | bool unique() const _NOEXCEPT {return use_count() == 1;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3889 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 86a291f | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 3890 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3891 | template <class _Up> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3892 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 3893 | bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3894 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3895 | template <class _Up> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3896 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 3897 | bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3898 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 3899 | _LIBCPP_INLINE_VISIBILITY |
| 3900 | bool |
| 3901 | __owner_equivalent(const shared_ptr& __p) const |
| 3902 | {return __cntrl_ == __p.__cntrl_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3903 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3904 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3905 | template <class _Dp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3906 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3907 | _Dp* __get_deleter() const _NOEXCEPT |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 3908 | {return static_cast<_Dp*>(__cntrl_ |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 3909 | ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 3910 | : nullptr);} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3911 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3912 | |
Zoe Carver | d9040c7 | 2019-10-22 15:16:49 +0000 | [diff] [blame] | 3913 | template<class _Yp, class _CntrlBlk> |
| 3914 | static shared_ptr<_Tp> |
| 3915 | __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) |
| 3916 | { |
| 3917 | shared_ptr<_Tp> __r; |
| 3918 | __r.__ptr_ = __p; |
| 3919 | __r.__cntrl_ = __cntrl; |
| 3920 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
| 3921 | return __r; |
| 3922 | } |
Zoe Carver | 6cd05c3 | 2019-08-19 15:47:16 +0000 | [diff] [blame] | 3923 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3924 | private: |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 3925 | template <class _Yp, bool = is_function<_Yp>::value> |
| 3926 | struct __shared_ptr_default_allocator |
| 3927 | { |
| 3928 | typedef allocator<_Yp> type; |
| 3929 | }; |
| 3930 | |
| 3931 | template <class _Yp> |
| 3932 | struct __shared_ptr_default_allocator<_Yp, true> |
| 3933 | { |
| 3934 | typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; |
| 3935 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3936 | |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 3937 | template <class _Yp, class _OrigPtr> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3938 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 30d5ac6 | 2017-05-10 19:35:49 +0000 | [diff] [blame] | 3939 | typename enable_if<is_convertible<_OrigPtr*, |
| 3940 | const enable_shared_from_this<_Yp>* |
| 3941 | >::value, |
| 3942 | void>::type |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 3943 | __enable_weak_this(const enable_shared_from_this<_Yp>* __e, |
| 3944 | _OrigPtr* __ptr) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3945 | { |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 3946 | typedef typename remove_cv<_Yp>::type _RawYp; |
Eric Fiselier | 8400686 | 2016-06-02 00:15:35 +0000 | [diff] [blame] | 3947 | if (__e && __e->__weak_this_.expired()) |
Marshall Clow | 99442fc | 2015-06-19 15:54:13 +0000 | [diff] [blame] | 3948 | { |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 3949 | __e->__weak_this_ = shared_ptr<_RawYp>(*this, |
| 3950 | const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); |
Marshall Clow | 99442fc | 2015-06-19 15:54:13 +0000 | [diff] [blame] | 3951 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 3954 | _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3955 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3956 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
| 3957 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3958 | }; |
| 3959 | |
Eric Fiselier | 30d5ac6 | 2017-05-10 19:35:49 +0000 | [diff] [blame] | 3960 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3961 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3962 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3963 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3964 | shared_ptr<_Tp>::shared_ptr() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3965 | : __ptr_(0), |
| 3966 | __cntrl_(0) |
| 3967 | { |
| 3968 | } |
| 3969 | |
| 3970 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3971 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3972 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3973 | shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3974 | : __ptr_(0), |
| 3975 | __cntrl_(0) |
| 3976 | { |
| 3977 | } |
| 3978 | |
| 3979 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3980 | template<class _Yp> |
| 3981 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, |
| 3982 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3983 | : __ptr_(__p) |
| 3984 | { |
| 3985 | unique_ptr<_Yp> __hold(__p); |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 3986 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 3987 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk; |
| 3988 | __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3989 | __hold.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 3990 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3994 | template<class _Yp, class _Dp> |
| 3995 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, |
| 3996 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3997 | : __ptr_(__p) |
| 3998 | { |
| 3999 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4000 | try |
| 4001 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4002 | #endif // _LIBCPP_NO_EXCEPTIONS |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4003 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 4004 | typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; |
| 4005 | __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4006 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4007 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4008 | } |
| 4009 | catch (...) |
| 4010 | { |
| 4011 | __d(__p); |
| 4012 | throw; |
| 4013 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4014 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | template<class _Tp> |
| 4018 | template<class _Dp> |
| 4019 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) |
| 4020 | : __ptr_(0) |
| 4021 | { |
| 4022 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4023 | try |
| 4024 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4025 | #endif // _LIBCPP_NO_EXCEPTIONS |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4026 | typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; |
| 4027 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk; |
| 4028 | __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4029 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4030 | } |
| 4031 | catch (...) |
| 4032 | { |
| 4033 | __d(__p); |
| 4034 | throw; |
| 4035 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4036 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4040 | template<class _Yp, class _Dp, class _Alloc> |
| 4041 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, |
| 4042 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4043 | : __ptr_(__p) |
| 4044 | { |
| 4045 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4046 | try |
| 4047 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4048 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4049 | typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4050 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4051 | typedef __allocator_destructor<_A2> _D2; |
| 4052 | _A2 __a2(__a); |
| 4053 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4054 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4055 | _CntrlBlk(__p, __d, __a); |
| 4056 | __cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4057 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4058 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4059 | } |
| 4060 | catch (...) |
| 4061 | { |
| 4062 | __d(__p); |
| 4063 | throw; |
| 4064 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4065 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | template<class _Tp> |
| 4069 | template<class _Dp, class _Alloc> |
| 4070 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) |
| 4071 | : __ptr_(0) |
| 4072 | { |
| 4073 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4074 | try |
| 4075 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4076 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4077 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4078 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4079 | typedef __allocator_destructor<_A2> _D2; |
| 4080 | _A2 __a2(__a); |
| 4081 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4082 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4083 | _CntrlBlk(__p, __d, __a); |
| 4084 | __cntrl_ = _VSTD::addressof(*__hold2.release()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4085 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4086 | } |
| 4087 | catch (...) |
| 4088 | { |
| 4089 | __d(__p); |
| 4090 | throw; |
| 4091 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4092 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | template<class _Tp> |
| 4096 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4097 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4098 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4099 | : __ptr_(__p), |
| 4100 | __cntrl_(__r.__cntrl_) |
| 4101 | { |
| 4102 | if (__cntrl_) |
| 4103 | __cntrl_->__add_shared(); |
| 4104 | } |
| 4105 | |
| 4106 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4107 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4108 | shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4109 | : __ptr_(__r.__ptr_), |
| 4110 | __cntrl_(__r.__cntrl_) |
| 4111 | { |
| 4112 | if (__cntrl_) |
| 4113 | __cntrl_->__add_shared(); |
| 4114 | } |
| 4115 | |
| 4116 | template<class _Tp> |
| 4117 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4118 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4119 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4120 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4121 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4122 | : __ptr_(__r.__ptr_), |
| 4123 | __cntrl_(__r.__cntrl_) |
| 4124 | { |
| 4125 | if (__cntrl_) |
| 4126 | __cntrl_->__add_shared(); |
| 4127 | } |
| 4128 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4129 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4130 | |
| 4131 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4132 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4133 | shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4134 | : __ptr_(__r.__ptr_), |
| 4135 | __cntrl_(__r.__cntrl_) |
| 4136 | { |
| 4137 | __r.__ptr_ = 0; |
| 4138 | __r.__cntrl_ = 0; |
| 4139 | } |
| 4140 | |
| 4141 | template<class _Tp> |
| 4142 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4143 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4144 | shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4145 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4146 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4147 | : __ptr_(__r.__ptr_), |
| 4148 | __cntrl_(__r.__cntrl_) |
| 4149 | { |
| 4150 | __r.__ptr_ = 0; |
| 4151 | __r.__cntrl_ = 0; |
| 4152 | } |
| 4153 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4154 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4155 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4156 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4157 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4158 | template<class _Yp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4159 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4160 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4161 | #else |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4162 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4163 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4164 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4165 | : __ptr_(__r.get()) |
| 4166 | { |
| 4167 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 4168 | __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4169 | __enable_weak_this(__r.get(), __r.get()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4170 | __r.release(); |
| 4171 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4172 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4173 | |
| 4174 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4175 | template <class _Yp, class _Dp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4176 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4177 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 4178 | #else |
| 4179 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 4180 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4181 | typename enable_if |
| 4182 | < |
| 4183 | !is_lvalue_reference<_Dp>::value && |
| 4184 | !is_array<_Yp>::value && |
| 4185 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 4186 | __nat |
| 4187 | >::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4188 | : __ptr_(__r.get()) |
| 4189 | { |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4190 | #if _LIBCPP_STD_VER > 11 |
| 4191 | if (__ptr_ == nullptr) |
| 4192 | __cntrl_ = nullptr; |
| 4193 | else |
| 4194 | #endif |
| 4195 | { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4196 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 4197 | typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; |
| 4198 | __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4199 | __enable_weak_this(__r.get(), __r.get()); |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4200 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4201 | __r.release(); |
| 4202 | } |
| 4203 | |
| 4204 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4205 | template <class _Yp, class _Dp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4206 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4207 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 4208 | #else |
| 4209 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 4210 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4211 | typename enable_if |
| 4212 | < |
| 4213 | is_lvalue_reference<_Dp>::value && |
| 4214 | !is_array<_Yp>::value && |
| 4215 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 4216 | __nat |
| 4217 | >::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4218 | : __ptr_(__r.get()) |
| 4219 | { |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4220 | #if _LIBCPP_STD_VER > 11 |
| 4221 | if (__ptr_ == nullptr) |
| 4222 | __cntrl_ = nullptr; |
| 4223 | else |
| 4224 | #endif |
| 4225 | { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4226 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4227 | typedef __shared_ptr_pointer<_Yp*, |
| 4228 | reference_wrapper<typename remove_reference<_Dp>::type>, |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4229 | _AllocT > _CntrlBlk; |
Logan Smith | 85cb081 | 2020-02-20 12:23:36 -0500 | [diff] [blame] | 4230 | __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4231 | __enable_weak_this(__r.get(), __r.get()); |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4232 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4233 | __r.release(); |
| 4234 | } |
| 4235 | |
Zoe Carver | 6cd05c3 | 2019-08-19 15:47:16 +0000 | [diff] [blame] | 4236 | template<class _Tp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4237 | shared_ptr<_Tp>::~shared_ptr() |
| 4238 | { |
| 4239 | if (__cntrl_) |
| 4240 | __cntrl_->__release_shared(); |
| 4241 | } |
| 4242 | |
| 4243 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4244 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4245 | shared_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4246 | shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4247 | { |
| 4248 | shared_ptr(__r).swap(*this); |
| 4249 | return *this; |
| 4250 | } |
| 4251 | |
| 4252 | template<class _Tp> |
| 4253 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4254 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4255 | typename enable_if |
| 4256 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4257 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4258 | shared_ptr<_Tp>& |
| 4259 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4260 | shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4261 | { |
| 4262 | shared_ptr(__r).swap(*this); |
| 4263 | return *this; |
| 4264 | } |
| 4265 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4266 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4267 | |
| 4268 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4269 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4270 | shared_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4271 | shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4272 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4273 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4274 | return *this; |
| 4275 | } |
| 4276 | |
| 4277 | template<class _Tp> |
| 4278 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4279 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4280 | typename enable_if |
| 4281 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4282 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4283 | shared_ptr<_Tp>& |
| 4284 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4285 | shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) |
| 4286 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4287 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4288 | return *this; |
| 4289 | } |
| 4290 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4291 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4292 | template<class _Tp> |
| 4293 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4294 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4295 | typename enable_if |
| 4296 | < |
| 4297 | !is_array<_Yp>::value && |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4298 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 25bcaf6 | 2013-09-13 23:56:00 +0000 | [diff] [blame] | 4299 | shared_ptr<_Tp> |
| 4300 | >::type& |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4301 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) |
| 4302 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4303 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4304 | return *this; |
| 4305 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4306 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4307 | |
| 4308 | template<class _Tp> |
| 4309 | template <class _Yp, class _Dp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4310 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4311 | typename enable_if |
| 4312 | < |
| 4313 | !is_array<_Yp>::value && |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 4314 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4315 | typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4316 | shared_ptr<_Tp>& |
| 4317 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4318 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) |
| 4319 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4320 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4321 | return *this; |
| 4322 | } |
| 4323 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4324 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4325 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4326 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4327 | template<class _Tp> |
| 4328 | template<class _Yp> |
| 4329 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4330 | typename enable_if |
| 4331 | < |
| 4332 | !is_array<_Yp>::value && |
Marshall Clow | b89a86e | 2017-01-10 18:40:01 +0000 | [diff] [blame] | 4333 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4334 | shared_ptr<_Tp>& |
| 4335 | >::type |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4336 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4337 | { |
| 4338 | shared_ptr(__r).swap(*this); |
| 4339 | return *this; |
| 4340 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4341 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4342 | |
| 4343 | template<class _Tp> |
| 4344 | template <class _Yp, class _Dp> |
| 4345 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4346 | typename enable_if |
| 4347 | < |
| 4348 | !is_array<_Yp>::value && |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 4349 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, |
Marshall Clow | b89a86e | 2017-01-10 18:40:01 +0000 | [diff] [blame] | 4350 | typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4351 | shared_ptr<_Tp>& |
| 4352 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4353 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) |
| 4354 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4355 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4356 | return *this; |
| 4357 | } |
| 4358 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4359 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4360 | |
| 4361 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4362 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4363 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4364 | shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4365 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4366 | _VSTD::swap(__ptr_, __r.__ptr_); |
| 4367 | _VSTD::swap(__cntrl_, __r.__cntrl_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4371 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4372 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4373 | shared_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4374 | { |
| 4375 | shared_ptr().swap(*this); |
| 4376 | } |
| 4377 | |
| 4378 | template<class _Tp> |
| 4379 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4380 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4381 | typename enable_if |
| 4382 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4383 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4384 | void |
| 4385 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4386 | shared_ptr<_Tp>::reset(_Yp* __p) |
| 4387 | { |
| 4388 | shared_ptr(__p).swap(*this); |
| 4389 | } |
| 4390 | |
| 4391 | template<class _Tp> |
| 4392 | template<class _Yp, class _Dp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4393 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4394 | typename enable_if |
| 4395 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4396 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4397 | void |
| 4398 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4399 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) |
| 4400 | { |
| 4401 | shared_ptr(__p, __d).swap(*this); |
| 4402 | } |
| 4403 | |
| 4404 | template<class _Tp> |
| 4405 | template<class _Yp, class _Dp, class _Alloc> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4406 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4407 | typename enable_if |
| 4408 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4409 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4410 | void |
| 4411 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4412 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) |
| 4413 | { |
| 4414 | shared_ptr(__p, __d, __a).swap(*this); |
| 4415 | } |
| 4416 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4417 | template<class _Tp, class ..._Args> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4418 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4419 | typename enable_if |
| 4420 | < |
| 4421 | !is_array<_Tp>::value, |
| 4422 | shared_ptr<_Tp> |
| 4423 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4424 | make_shared(_Args&& ...__args) |
| 4425 | { |
Zoe Carver | d9040c7 | 2019-10-22 15:16:49 +0000 | [diff] [blame] | 4426 | static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared"); |
| 4427 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4428 | typedef allocator<_CntrlBlk> _A2; |
| 4429 | typedef __allocator_destructor<_A2> _D2; |
| 4430 | |
| 4431 | _A2 __a2; |
| 4432 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 4433 | ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); |
| 4434 | |
| 4435 | _Tp *__ptr = __hold2.get()->get(); |
| 4436 | return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4437 | } |
| 4438 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4439 | template<class _Tp, class _Alloc, class ..._Args> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4440 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4441 | typename enable_if |
| 4442 | < |
| 4443 | !is_array<_Tp>::value, |
| 4444 | shared_ptr<_Tp> |
| 4445 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4446 | allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 4447 | { |
zoecarver | 505730a | 2020-02-25 16:50:57 -0800 | [diff] [blame] | 4448 | static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared"); |
| 4449 | |
| 4450 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
| 4451 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
| 4452 | typedef __allocator_destructor<_A2> _D2; |
| 4453 | |
| 4454 | _A2 __a2(__a); |
| 4455 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
| 4456 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4457 | _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); |
| 4458 | |
| 4459 | typename shared_ptr<_Tp>::element_type *__p = __hold2.get()->get(); |
| 4460 | return shared_ptr<_Tp>::__create_with_control_block(__p, _VSTD::addressof(*__hold2.release())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4461 | } |
| 4462 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4463 | template<class _Tp, class _Up> |
| 4464 | inline _LIBCPP_INLINE_VISIBILITY |
| 4465 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4466 | operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4467 | { |
| 4468 | return __x.get() == __y.get(); |
| 4469 | } |
| 4470 | |
| 4471 | template<class _Tp, class _Up> |
| 4472 | inline _LIBCPP_INLINE_VISIBILITY |
| 4473 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4474 | operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4475 | { |
| 4476 | return !(__x == __y); |
| 4477 | } |
| 4478 | |
| 4479 | template<class _Tp, class _Up> |
| 4480 | inline _LIBCPP_INLINE_VISIBILITY |
| 4481 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4482 | operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4483 | { |
Marshall Clow | 8afdf7a | 2018-02-12 17:26:40 +0000 | [diff] [blame] | 4484 | #if _LIBCPP_STD_VER <= 11 |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 4485 | typedef typename common_type<_Tp*, _Up*>::type _Vp; |
| 4486 | return less<_Vp>()(__x.get(), __y.get()); |
Marshall Clow | 8afdf7a | 2018-02-12 17:26:40 +0000 | [diff] [blame] | 4487 | #else |
| 4488 | return less<>()(__x.get(), __y.get()); |
| 4489 | #endif |
| 4490 | |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | template<class _Tp, class _Up> |
| 4494 | inline _LIBCPP_INLINE_VISIBILITY |
| 4495 | bool |
| 4496 | operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4497 | { |
| 4498 | return __y < __x; |
| 4499 | } |
| 4500 | |
| 4501 | template<class _Tp, class _Up> |
| 4502 | inline _LIBCPP_INLINE_VISIBILITY |
| 4503 | bool |
| 4504 | operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4505 | { |
| 4506 | return !(__y < __x); |
| 4507 | } |
| 4508 | |
| 4509 | template<class _Tp, class _Up> |
| 4510 | inline _LIBCPP_INLINE_VISIBILITY |
| 4511 | bool |
| 4512 | operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4513 | { |
| 4514 | return !(__x < __y); |
| 4515 | } |
| 4516 | |
| 4517 | template<class _Tp> |
| 4518 | inline _LIBCPP_INLINE_VISIBILITY |
| 4519 | bool |
| 4520 | operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4521 | { |
| 4522 | return !__x; |
| 4523 | } |
| 4524 | |
| 4525 | template<class _Tp> |
| 4526 | inline _LIBCPP_INLINE_VISIBILITY |
| 4527 | bool |
| 4528 | operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4529 | { |
| 4530 | return !__x; |
| 4531 | } |
| 4532 | |
| 4533 | template<class _Tp> |
| 4534 | inline _LIBCPP_INLINE_VISIBILITY |
| 4535 | bool |
| 4536 | operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4537 | { |
| 4538 | return static_cast<bool>(__x); |
| 4539 | } |
| 4540 | |
| 4541 | template<class _Tp> |
| 4542 | inline _LIBCPP_INLINE_VISIBILITY |
| 4543 | bool |
| 4544 | operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4545 | { |
| 4546 | return static_cast<bool>(__x); |
| 4547 | } |
| 4548 | |
| 4549 | template<class _Tp> |
| 4550 | inline _LIBCPP_INLINE_VISIBILITY |
| 4551 | bool |
| 4552 | operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4553 | { |
| 4554 | return less<_Tp*>()(__x.get(), nullptr); |
| 4555 | } |
| 4556 | |
| 4557 | template<class _Tp> |
| 4558 | inline _LIBCPP_INLINE_VISIBILITY |
| 4559 | bool |
| 4560 | operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4561 | { |
| 4562 | return less<_Tp*>()(nullptr, __x.get()); |
| 4563 | } |
| 4564 | |
| 4565 | template<class _Tp> |
| 4566 | inline _LIBCPP_INLINE_VISIBILITY |
| 4567 | bool |
| 4568 | operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4569 | { |
| 4570 | return nullptr < __x; |
| 4571 | } |
| 4572 | |
| 4573 | template<class _Tp> |
| 4574 | inline _LIBCPP_INLINE_VISIBILITY |
| 4575 | bool |
| 4576 | operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4577 | { |
| 4578 | return __x < nullptr; |
| 4579 | } |
| 4580 | |
| 4581 | template<class _Tp> |
| 4582 | inline _LIBCPP_INLINE_VISIBILITY |
| 4583 | bool |
| 4584 | operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4585 | { |
| 4586 | return !(nullptr < __x); |
| 4587 | } |
| 4588 | |
| 4589 | template<class _Tp> |
| 4590 | inline _LIBCPP_INLINE_VISIBILITY |
| 4591 | bool |
| 4592 | operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4593 | { |
| 4594 | return !(__x < nullptr); |
| 4595 | } |
| 4596 | |
| 4597 | template<class _Tp> |
| 4598 | inline _LIBCPP_INLINE_VISIBILITY |
| 4599 | bool |
| 4600 | operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4601 | { |
| 4602 | return !(__x < nullptr); |
| 4603 | } |
| 4604 | |
| 4605 | template<class _Tp> |
| 4606 | inline _LIBCPP_INLINE_VISIBILITY |
| 4607 | bool |
| 4608 | operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4609 | { |
| 4610 | return !(nullptr < __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | template<class _Tp> |
| 4614 | inline _LIBCPP_INLINE_VISIBILITY |
| 4615 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4616 | swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4617 | { |
| 4618 | __x.swap(__y); |
| 4619 | } |
| 4620 | |
| 4621 | template<class _Tp, class _Up> |
| 4622 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4623 | typename enable_if |
| 4624 | < |
| 4625 | !is_array<_Tp>::value && !is_array<_Up>::value, |
| 4626 | shared_ptr<_Tp> |
| 4627 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4628 | static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4629 | { |
| 4630 | return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); |
| 4631 | } |
| 4632 | |
| 4633 | template<class _Tp, class _Up> |
| 4634 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4635 | typename enable_if |
| 4636 | < |
| 4637 | !is_array<_Tp>::value && !is_array<_Up>::value, |
| 4638 | shared_ptr<_Tp> |
| 4639 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4640 | dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4641 | { |
| 4642 | _Tp* __p = dynamic_cast<_Tp*>(__r.get()); |
| 4643 | return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); |
| 4644 | } |
| 4645 | |
| 4646 | template<class _Tp, class _Up> |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4647 | typename enable_if |
| 4648 | < |
| 4649 | is_array<_Tp>::value == is_array<_Up>::value, |
| 4650 | shared_ptr<_Tp> |
| 4651 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4652 | const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4653 | { |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4654 | typedef typename remove_extent<_Tp>::type _RTp; |
| 4655 | return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4656 | } |
| 4657 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4658 | #ifndef _LIBCPP_NO_RTTI |
| 4659 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4660 | template<class _Dp, class _Tp> |
| 4661 | inline _LIBCPP_INLINE_VISIBILITY |
| 4662 | _Dp* |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4663 | get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4664 | { |
| 4665 | return __p.template __get_deleter<_Dp>(); |
| 4666 | } |
| 4667 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4668 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4669 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4670 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4671 | class _LIBCPP_TEMPLATE_VIS weak_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4672 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4673 | public: |
| 4674 | typedef _Tp element_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4675 | private: |
| 4676 | element_type* __ptr_; |
| 4677 | __shared_weak_count* __cntrl_; |
| 4678 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4679 | public: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4680 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 4681 | _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4682 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4683 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 4684 | _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4685 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4686 | weak_ptr(weak_ptr const& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4687 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4688 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 4689 | _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4690 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4691 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4692 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4693 | weak_ptr(weak_ptr&& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4694 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4695 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 4696 | _NOEXCEPT; |
| 4697 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4698 | ~weak_ptr(); |
| 4699 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4700 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4701 | weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4702 | template<class _Yp> |
| 4703 | typename enable_if |
| 4704 | < |
| 4705 | is_convertible<_Yp*, element_type*>::value, |
| 4706 | weak_ptr& |
| 4707 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4708 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4709 | operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; |
| 4710 | |
| 4711 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 4712 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4713 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4714 | weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; |
| 4715 | template<class _Yp> |
| 4716 | typename enable_if |
| 4717 | < |
| 4718 | is_convertible<_Yp*, element_type*>::value, |
| 4719 | weak_ptr& |
| 4720 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4721 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4722 | operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; |
| 4723 | |
| 4724 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 4725 | |
| 4726 | template<class _Yp> |
| 4727 | typename enable_if |
| 4728 | < |
| 4729 | is_convertible<_Yp*, element_type*>::value, |
| 4730 | weak_ptr& |
| 4731 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4732 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4733 | operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4734 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4735 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4736 | void swap(weak_ptr& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4737 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4738 | void reset() _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4739 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4740 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4741 | long use_count() const _NOEXCEPT |
| 4742 | {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4743 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4744 | bool expired() const _NOEXCEPT |
| 4745 | {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} |
| 4746 | shared_ptr<_Tp> lock() const _NOEXCEPT; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4747 | template<class _Up> |
| 4748 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4749 | bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4750 | {return __cntrl_ < __r.__cntrl_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4751 | template<class _Up> |
| 4752 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4753 | bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4754 | {return __cntrl_ < __r.__cntrl_;} |
| 4755 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4756 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
| 4757 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4758 | }; |
| 4759 | |
| 4760 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4761 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 4762 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4763 | weak_ptr<_Tp>::weak_ptr() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4764 | : __ptr_(0), |
| 4765 | __cntrl_(0) |
| 4766 | { |
| 4767 | } |
| 4768 | |
| 4769 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4770 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4771 | weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4772 | : __ptr_(__r.__ptr_), |
| 4773 | __cntrl_(__r.__cntrl_) |
| 4774 | { |
| 4775 | if (__cntrl_) |
| 4776 | __cntrl_->__add_weak(); |
| 4777 | } |
| 4778 | |
| 4779 | template<class _Tp> |
| 4780 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4781 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4782 | weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | 3a085e8 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 4783 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4784 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4785 | : __ptr_(__r.__ptr_), |
| 4786 | __cntrl_(__r.__cntrl_) |
| 4787 | { |
| 4788 | if (__cntrl_) |
| 4789 | __cntrl_->__add_weak(); |
| 4790 | } |
| 4791 | |
| 4792 | template<class _Tp> |
| 4793 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4794 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4795 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | 3a085e8 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 4796 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4797 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4798 | : __ptr_(__r.__ptr_), |
| 4799 | __cntrl_(__r.__cntrl_) |
| 4800 | { |
| 4801 | if (__cntrl_) |
| 4802 | __cntrl_->__add_weak(); |
| 4803 | } |
| 4804 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4805 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 4806 | |
| 4807 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4808 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4809 | weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT |
| 4810 | : __ptr_(__r.__ptr_), |
| 4811 | __cntrl_(__r.__cntrl_) |
| 4812 | { |
| 4813 | __r.__ptr_ = 0; |
| 4814 | __r.__cntrl_ = 0; |
| 4815 | } |
| 4816 | |
| 4817 | template<class _Tp> |
| 4818 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4819 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4820 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, |
| 4821 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
| 4822 | _NOEXCEPT |
| 4823 | : __ptr_(__r.__ptr_), |
| 4824 | __cntrl_(__r.__cntrl_) |
| 4825 | { |
| 4826 | __r.__ptr_ = 0; |
| 4827 | __r.__cntrl_ = 0; |
| 4828 | } |
| 4829 | |
| 4830 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 4831 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4832 | template<class _Tp> |
| 4833 | weak_ptr<_Tp>::~weak_ptr() |
| 4834 | { |
| 4835 | if (__cntrl_) |
| 4836 | __cntrl_->__release_weak(); |
| 4837 | } |
| 4838 | |
| 4839 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4840 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4841 | weak_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4842 | weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4843 | { |
| 4844 | weak_ptr(__r).swap(*this); |
| 4845 | return *this; |
| 4846 | } |
| 4847 | |
| 4848 | template<class _Tp> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4849 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4850 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4851 | typename enable_if |
| 4852 | < |
| 4853 | is_convertible<_Yp*, _Tp*>::value, |
| 4854 | weak_ptr<_Tp>& |
| 4855 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4856 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4857 | { |
| 4858 | weak_ptr(__r).swap(*this); |
| 4859 | return *this; |
| 4860 | } |
| 4861 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4862 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 4863 | |
| 4864 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4865 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4866 | weak_ptr<_Tp>& |
| 4867 | weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT |
| 4868 | { |
| 4869 | weak_ptr(_VSTD::move(__r)).swap(*this); |
| 4870 | return *this; |
| 4871 | } |
| 4872 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4873 | template<class _Tp> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4874 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4875 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4876 | typename enable_if |
| 4877 | < |
| 4878 | is_convertible<_Yp*, _Tp*>::value, |
| 4879 | weak_ptr<_Tp>& |
| 4880 | >::type |
| 4881 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT |
| 4882 | { |
| 4883 | weak_ptr(_VSTD::move(__r)).swap(*this); |
| 4884 | return *this; |
| 4885 | } |
| 4886 | |
| 4887 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 4888 | |
| 4889 | template<class _Tp> |
| 4890 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4891 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4892 | typename enable_if |
| 4893 | < |
| 4894 | is_convertible<_Yp*, _Tp*>::value, |
| 4895 | weak_ptr<_Tp>& |
| 4896 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4897 | weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4898 | { |
| 4899 | weak_ptr(__r).swap(*this); |
| 4900 | return *this; |
| 4901 | } |
| 4902 | |
| 4903 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4904 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4905 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4906 | weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4907 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4908 | _VSTD::swap(__ptr_, __r.__ptr_); |
| 4909 | _VSTD::swap(__cntrl_, __r.__cntrl_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | template<class _Tp> |
| 4913 | inline _LIBCPP_INLINE_VISIBILITY |
| 4914 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4915 | swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4916 | { |
| 4917 | __x.swap(__y); |
| 4918 | } |
| 4919 | |
| 4920 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4921 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4922 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4923 | weak_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4924 | { |
| 4925 | weak_ptr().swap(*this); |
| 4926 | } |
| 4927 | |
| 4928 | template<class _Tp> |
| 4929 | template<class _Yp> |
| 4930 | shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4931 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4932 | : __ptr_(__r.__ptr_), |
| 4933 | __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) |
| 4934 | { |
| 4935 | if (__cntrl_ == 0) |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 4936 | __throw_bad_weak_ptr(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | template<class _Tp> |
| 4940 | shared_ptr<_Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4941 | weak_ptr<_Tp>::lock() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4942 | { |
| 4943 | shared_ptr<_Tp> __r; |
| 4944 | __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; |
| 4945 | if (__r.__cntrl_) |
| 4946 | __r.__ptr_ = __ptr_; |
| 4947 | return __r; |
| 4948 | } |
| 4949 | |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 4950 | #if _LIBCPP_STD_VER > 14 |
| 4951 | template <class _Tp = void> struct owner_less; |
| 4952 | #else |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4953 | template <class _Tp> struct owner_less; |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 4954 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4955 | |
| 4956 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4957 | struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4958 | : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4959 | { |
| 4960 | typedef bool result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4961 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4962 | bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4963 | {return __x.owner_before(__y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4964 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4965 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4966 | {return __x.owner_before(__y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4967 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4968 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4969 | {return __x.owner_before(__y);} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4970 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4971 | |
| 4972 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4973 | struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4974 | : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> |
| 4975 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4976 | typedef bool result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4977 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4978 | bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4979 | {return __x.owner_before(__y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4980 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4981 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4982 | {return __x.owner_before(__y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4983 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4984 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4985 | {return __x.owner_before(__y);} |
| 4986 | }; |
| 4987 | |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 4988 | #if _LIBCPP_STD_VER > 14 |
| 4989 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4990 | struct _LIBCPP_TEMPLATE_VIS owner_less<void> |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 4991 | { |
| 4992 | template <class _Tp, class _Up> |
| 4993 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4994 | bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 4995 | {return __x.owner_before(__y);} |
| 4996 | template <class _Tp, class _Up> |
| 4997 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 4998 | bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 4999 | {return __x.owner_before(__y);} |
| 5000 | template <class _Tp, class _Up> |
| 5001 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5002 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5003 | {return __x.owner_before(__y);} |
| 5004 | template <class _Tp, class _Up> |
| 5005 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5006 | bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5007 | {return __x.owner_before(__y);} |
| 5008 | typedef void is_transparent; |
| 5009 | }; |
| 5010 | #endif |
| 5011 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5012 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5013 | class _LIBCPP_TEMPLATE_VIS enable_shared_from_this |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5014 | { |
| 5015 | mutable weak_ptr<_Tp> __weak_this_; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5016 | protected: |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 5017 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5018 | enable_shared_from_this() _NOEXCEPT {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5019 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5020 | enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5021 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5022 | enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT |
| 5023 | {return *this;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5024 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5025 | ~enable_shared_from_this() {} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5026 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5027 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5028 | shared_ptr<_Tp> shared_from_this() |
| 5029 | {return shared_ptr<_Tp>(__weak_this_);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5030 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5031 | shared_ptr<_Tp const> shared_from_this() const |
| 5032 | {return shared_ptr<const _Tp>(__weak_this_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5033 | |
Eric Fiselier | 8400686 | 2016-06-02 00:15:35 +0000 | [diff] [blame] | 5034 | #if _LIBCPP_STD_VER > 14 |
| 5035 | _LIBCPP_INLINE_VISIBILITY |
| 5036 | weak_ptr<_Tp> weak_from_this() _NOEXCEPT |
| 5037 | { return __weak_this_; } |
| 5038 | |
| 5039 | _LIBCPP_INLINE_VISIBILITY |
| 5040 | weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT |
| 5041 | { return __weak_this_; } |
| 5042 | #endif // _LIBCPP_STD_VER > 14 |
| 5043 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5044 | template <class _Up> friend class shared_ptr; |
| 5045 | }; |
| 5046 | |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5047 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5048 | struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5049 | { |
| 5050 | typedef shared_ptr<_Tp> argument_type; |
| 5051 | typedef size_t result_type; |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 5052 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5054 | result_type operator()(const argument_type& __ptr) const _NOEXCEPT |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5055 | { |
| 5056 | return hash<_Tp*>()(__ptr.get()); |
| 5057 | } |
| 5058 | }; |
| 5059 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5060 | template<class _CharT, class _Traits, class _Yp> |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 5061 | inline _LIBCPP_INLINE_VISIBILITY |
| 5062 | basic_ostream<_CharT, _Traits>& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5063 | operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 5064 | |
Eric Fiselier | 9b49267 | 2016-06-18 02:12:53 +0000 | [diff] [blame] | 5065 | |
| 5066 | #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5067 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5068 | class _LIBCPP_TYPE_VIS __sp_mut |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5069 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5070 | void* __lx; |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5071 | public: |
| 5072 | void lock() _NOEXCEPT; |
| 5073 | void unlock() _NOEXCEPT; |
| 5074 | |
| 5075 | private: |
| 5076 | _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; |
| 5077 | __sp_mut(const __sp_mut&); |
| 5078 | __sp_mut& operator=(const __sp_mut&); |
| 5079 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 5080 | friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5081 | }; |
| 5082 | |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5083 | _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
| 5084 | __sp_mut& __get_sp_mut(const void*); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5085 | |
| 5086 | template <class _Tp> |
| 5087 | inline _LIBCPP_INLINE_VISIBILITY |
| 5088 | bool |
| 5089 | atomic_is_lock_free(const shared_ptr<_Tp>*) |
| 5090 | { |
| 5091 | return false; |
| 5092 | } |
| 5093 | |
| 5094 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5095 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5096 | shared_ptr<_Tp> |
| 5097 | atomic_load(const shared_ptr<_Tp>* __p) |
| 5098 | { |
| 5099 | __sp_mut& __m = __get_sp_mut(__p); |
| 5100 | __m.lock(); |
| 5101 | shared_ptr<_Tp> __q = *__p; |
| 5102 | __m.unlock(); |
| 5103 | return __q; |
| 5104 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5105 | |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5106 | template <class _Tp> |
| 5107 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5108 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5109 | shared_ptr<_Tp> |
| 5110 | atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) |
| 5111 | { |
| 5112 | return atomic_load(__p); |
| 5113 | } |
| 5114 | |
| 5115 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5116 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5117 | void |
| 5118 | atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) |
| 5119 | { |
| 5120 | __sp_mut& __m = __get_sp_mut(__p); |
| 5121 | __m.lock(); |
| 5122 | __p->swap(__r); |
| 5123 | __m.unlock(); |
| 5124 | } |
| 5125 | |
| 5126 | template <class _Tp> |
| 5127 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5128 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5129 | void |
| 5130 | atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) |
| 5131 | { |
| 5132 | atomic_store(__p, __r); |
| 5133 | } |
| 5134 | |
| 5135 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5136 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5137 | shared_ptr<_Tp> |
| 5138 | atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) |
| 5139 | { |
| 5140 | __sp_mut& __m = __get_sp_mut(__p); |
| 5141 | __m.lock(); |
| 5142 | __p->swap(__r); |
| 5143 | __m.unlock(); |
| 5144 | return __r; |
| 5145 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5146 | |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5147 | template <class _Tp> |
| 5148 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5149 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5150 | shared_ptr<_Tp> |
| 5151 | atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) |
| 5152 | { |
| 5153 | return atomic_exchange(__p, __r); |
| 5154 | } |
| 5155 | |
| 5156 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5157 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5158 | bool |
| 5159 | atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) |
| 5160 | { |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5161 | shared_ptr<_Tp> __temp; |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5162 | __sp_mut& __m = __get_sp_mut(__p); |
| 5163 | __m.lock(); |
| 5164 | if (__p->__owner_equivalent(*__v)) |
| 5165 | { |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5166 | _VSTD::swap(__temp, *__p); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5167 | *__p = __w; |
| 5168 | __m.unlock(); |
| 5169 | return true; |
| 5170 | } |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5171 | _VSTD::swap(__temp, *__v); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5172 | *__v = *__p; |
| 5173 | __m.unlock(); |
| 5174 | return false; |
| 5175 | } |
| 5176 | |
| 5177 | template <class _Tp> |
| 5178 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5179 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5180 | bool |
| 5181 | atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) |
| 5182 | { |
| 5183 | return atomic_compare_exchange_strong(__p, __v, __w); |
| 5184 | } |
| 5185 | |
| 5186 | template <class _Tp> |
| 5187 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5188 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5189 | bool |
| 5190 | atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, |
| 5191 | shared_ptr<_Tp> __w, memory_order, memory_order) |
| 5192 | { |
| 5193 | return atomic_compare_exchange_strong(__p, __v, __w); |
| 5194 | } |
| 5195 | |
| 5196 | template <class _Tp> |
| 5197 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5198 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5199 | bool |
| 5200 | atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, |
| 5201 | shared_ptr<_Tp> __w, memory_order, memory_order) |
| 5202 | { |
| 5203 | return atomic_compare_exchange_weak(__p, __v, __w); |
| 5204 | } |
| 5205 | |
Eric Fiselier | 9b49267 | 2016-06-18 02:12:53 +0000 | [diff] [blame] | 5206 | #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5207 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5208 | //enum class |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5209 | #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) |
| 5210 | # ifndef _LIBCPP_CXX03_LANG |
| 5211 | enum class pointer_safety : unsigned char { |
| 5212 | relaxed, |
| 5213 | preferred, |
| 5214 | strict |
| 5215 | }; |
| 5216 | # endif |
| 5217 | #else |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 5218 | struct _LIBCPP_TYPE_VIS pointer_safety |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5219 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5220 | enum __lx |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5221 | { |
| 5222 | relaxed, |
| 5223 | preferred, |
| 5224 | strict |
| 5225 | }; |
| 5226 | |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5227 | __lx __v_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5228 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5229 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2fdd22b | 2017-01-05 01:28:40 +0000 | [diff] [blame] | 5230 | pointer_safety() : __v_() {} |
| 5231 | |
| 5232 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5233 | pointer_safety(__lx __v) : __v_(__v) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5235 | operator int() const {return __v_;} |
| 5236 | }; |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5237 | #endif |
| 5238 | |
| 5239 | #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \ |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 5240 | defined(_LIBCPP_BUILDING_LIBRARY) |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5241 | _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; |
| 5242 | #else |
| 5243 | // This function is only offered in C++03 under ABI v1. |
| 5244 | # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG) |
| 5245 | inline _LIBCPP_INLINE_VISIBILITY |
| 5246 | pointer_safety get_pointer_safety() _NOEXCEPT { |
| 5247 | return pointer_safety::relaxed; |
| 5248 | } |
| 5249 | # endif |
| 5250 | #endif |
| 5251 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5252 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5253 | _LIBCPP_FUNC_VIS void declare_reachable(void* __p); |
| 5254 | _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); |
| 5255 | _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5256 | _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5257 | |
| 5258 | template <class _Tp> |
| 5259 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5260 | _Tp* |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5261 | undeclare_reachable(_Tp* __p) |
| 5262 | { |
| 5263 | return static_cast<_Tp*>(__undeclare_reachable(__p)); |
| 5264 | } |
| 5265 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5266 | _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5267 | |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5268 | // --- Helper for container swap -- |
| 5269 | template <typename _Alloc> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 5270 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5271 | void __swap_allocator(_Alloc & __a1, _Alloc & __a2) |
| 5272 | #if _LIBCPP_STD_VER >= 14 |
| 5273 | _NOEXCEPT |
| 5274 | #else |
| 5275 | _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) |
| 5276 | #endif |
| 5277 | { |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5278 | __swap_allocator(__a1, __a2, |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5279 | integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); |
| 5280 | } |
| 5281 | |
| 5282 | template <typename _Alloc> |
| 5283 | _LIBCPP_INLINE_VISIBILITY |
| 5284 | void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) |
| 5285 | #if _LIBCPP_STD_VER >= 14 |
| 5286 | _NOEXCEPT |
| 5287 | #else |
| 5288 | _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) |
| 5289 | #endif |
| 5290 | { |
| 5291 | using _VSTD::swap; |
| 5292 | swap(__a1, __a2); |
| 5293 | } |
| 5294 | |
| 5295 | template <typename _Alloc> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 5296 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5297 | void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} |
| 5298 | |
Marshall Clow | ff91de8 | 2015-08-18 19:51:37 +0000 | [diff] [blame] | 5299 | template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5300 | struct __noexcept_move_assign_container : public integral_constant<bool, |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 5301 | _Traits::propagate_on_container_move_assignment::value |
| 5302 | #if _LIBCPP_STD_VER > 14 |
| 5303 | || _Traits::is_always_equal::value |
| 5304 | #else |
| 5305 | && is_nothrow_move_assignable<_Alloc>::value |
| 5306 | #endif |
| 5307 | > {}; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5308 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5309 | |
| 5310 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 5311 | template <class _Tp, class _Alloc> |
| 5312 | struct __temp_value { |
| 5313 | typedef allocator_traits<_Alloc> _Traits; |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5314 | |
Eric Fiselier | 0f0ed9d | 2019-01-16 01:51:12 +0000 | [diff] [blame] | 5315 | typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v; |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5316 | _Alloc &__a; |
| 5317 | |
| 5318 | _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } |
| 5319 | _Tp & get() { return *__addr(); } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5320 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5321 | template<class... _Args> |
Peter Collingbourne | cb12615 | 2018-08-15 17:49:30 +0000 | [diff] [blame] | 5322 | _LIBCPP_NO_CFI |
| 5323 | __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { |
| 5324 | _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)), |
| 5325 | _VSTD::forward<_Args>(__args)...); |
| 5326 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5327 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5328 | ~__temp_value() { _Traits::destroy(__a, __addr()); } |
| 5329 | }; |
| 5330 | #endif |
| 5331 | |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 5332 | template<typename _Alloc, typename = void, typename = void> |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5333 | struct __is_allocator : false_type {}; |
| 5334 | |
| 5335 | template<typename _Alloc> |
| 5336 | struct __is_allocator<_Alloc, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 5337 | typename __void_t<typename _Alloc::value_type>::type, |
| 5338 | typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type |
| 5339 | > |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5340 | : true_type {}; |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5341 | |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 5342 | // __builtin_new_allocator -- A non-templated helper for allocating and |
| 5343 | // deallocating memory using __builtin_operator_new and |
| 5344 | // __builtin_operator_delete. It should be used in preference to |
| 5345 | // `std::allocator<T>` to avoid additional instantiations. |
| 5346 | struct __builtin_new_allocator { |
| 5347 | struct __builtin_new_deleter { |
| 5348 | typedef void* pointer_type; |
| 5349 | |
| 5350 | _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align) |
| 5351 | : __size_(__size), __align_(__align) {} |
| 5352 | |
| 5353 | void operator()(void* p) const _NOEXCEPT { |
| 5354 | std::__libcpp_deallocate(p, __size_, __align_); |
| 5355 | } |
| 5356 | |
| 5357 | private: |
| 5358 | size_t __size_; |
| 5359 | size_t __align_; |
| 5360 | }; |
| 5361 | |
| 5362 | typedef unique_ptr<void, __builtin_new_deleter> __holder_t; |
| 5363 | |
| 5364 | static __holder_t __allocate_bytes(size_t __s, size_t __align) { |
| 5365 | return __holder_t(std::__libcpp_allocate(__s, __align), |
| 5366 | __builtin_new_deleter(__s, __align)); |
| 5367 | } |
| 5368 | |
| 5369 | static void __deallocate_bytes(void* __p, size_t __s, |
| 5370 | size_t __align) _NOEXCEPT { |
| 5371 | std::__libcpp_deallocate(__p, __s, __align); |
| 5372 | } |
| 5373 | |
| 5374 | template <class _Tp> |
| 5375 | _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE |
| 5376 | static __holder_t __allocate_type(size_t __n) { |
| 5377 | return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); |
| 5378 | } |
| 5379 | |
| 5380 | template <class _Tp> |
| 5381 | _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE |
| 5382 | static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { |
| 5383 | __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); |
| 5384 | } |
| 5385 | }; |
| 5386 | |
| 5387 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5388 | _LIBCPP_END_NAMESPACE_STD |
| 5389 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 5390 | _LIBCPP_POP_MACROS |
| 5391 | |
Louis Dionne | 59d0b3c | 2019-08-05 18:29:14 +0000 | [diff] [blame] | 5392 | #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 |
Louis Dionne | d53d8c0 | 2019-08-06 21:11:24 +0000 | [diff] [blame] | 5393 | # include <__pstl_memory> |
Louis Dionne | 59d0b3c | 2019-08-05 18:29:14 +0000 | [diff] [blame] | 5394 | #endif |
| 5395 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5396 | #endif // _LIBCPP_MEMORY |