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