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