Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- memory ------------------------------------===// |
| 3 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | ee11c31 | 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 | c51e102 | 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 | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 21 | inline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); |
Howard Hinnant | c51e102 | 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 | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 31 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | template <class U> using rebind = <details>; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 33 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | static pointer pointer_to(<details>); |
| 35 | }; |
| 36 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 37 | template <class T> |
| 38 | struct pointer_traits<T*> |
| 39 | { |
| 40 | typedef T* pointer; |
| 41 | typedef T element_type; |
| 42 | typedef ptrdiff_t difference_type; |
| 43 | |
| 44 | template <class U> using rebind = U*; |
| 45 | |
| 46 | static pointer pointer_to(<details>) noexcept; |
| 47 | }; |
| 48 | |
Eric Fiselier | 45c9aac | 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 | c51e102 | 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 | 8e4e600 | 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 | c51e102 | 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 | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 81 | typedef Alloc::is_always_equal |
| 82 | | is_empty is_always_equal; |
Howard Hinnant | c51e102 | 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 | 0e58cae | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 89 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 90 | static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; |
Howard Hinnant | c51e102 | 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 | 4f834b5 | 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 | c51e102 | 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 | bc75976 | 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 | 719bda3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 136 | pointer allocate(size_type, allocator<void>::const_pointer hint = 0); |
Howard Hinnant | 719bda3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | template <class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 146 | bool operator==(const allocator<T>&, const allocator<U>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 147 | |
| 148 | template <class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 149 | bool operator!=(const allocator<T>&, const allocator<U>&) noexcept; |
Howard Hinnant | c51e102 | 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 | 719bda3 | 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 | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 171 | template <class T> T* addressof(const T&& r) noexcept = delete; |
Howard Hinnant | c51e102 | 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 | 719bda3 | 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 | c51e102 | 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 | 3c81109 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 185 | ForwardIterator |
| 186 | uninitialized_fill_n(ForwardIterator first, Size n, const T& x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 187 | |
Eric Fiselier | 383f6cf | 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 | 481a266 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | |
| 217 | template<class X> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 218 | class auto_ptr // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 242 | template <class T> |
| 243 | struct default_delete |
| 244 | { |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 247 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 248 | void operator()(T*) const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | template <class T> |
| 252 | struct default_delete<T[]> |
| 253 | { |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 254 | constexpr default_delete() noexcept = default; |
| 255 | void operator()(T*) const noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 256 | template <class U> void operator()(U*) const = delete; |
| 257 | }; |
| 258 | |
Howard Hinnant | d26c01d | 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 | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 274 | template <class U, class E> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 275 | unique_ptr(unique_ptr<U, E>&& u) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 276 | template <class U> |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 277 | unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17 |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 278 | |
| 279 | // destructor |
| 280 | ~unique_ptr(); |
| 281 | |
| 282 | // assignment |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 286 | |
| 287 | // observers |
| 288 | typename add_lvalue_reference<T>::type operator*() const; |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 294 | |
| 295 | // modifiers |
Howard Hinnant | 719bda3 | 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 | d26c01d | 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 | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 316 | |
| 317 | // destructor |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 318 | ~unique_ptr(); |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 319 | |
| 320 | // assignment |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 323 | |
| 324 | // observers |
| 325 | T& operator[](size_t i) const; |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 330 | |
| 331 | // modifiers |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 335 | template <class U> void reset(U) = delete; |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 336 | void swap(unique_ptr& u) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | template <class T, class D> |
Howard Hinnant | 719bda3 | 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 | d26c01d | 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 | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 381 | class bad_weak_ptr |
| 382 | : public std::exception |
| 383 | { |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 384 | bad_weak_ptr() noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 385 | }; |
| 386 | |
Marshall Clow | 9e8f4a9 | 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 | e52a324 | 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 | d26c01d | 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 | ae5b667 | 2016-06-27 01:02:43 +0000 | [diff] [blame] | 399 | typedef weak_ptr<T> weak_type; // C++17 |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 400 | |
| 401 | // constructors: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 402 | constexpr shared_ptr() noexcept; |
Howard Hinnant | d26c01d | 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 | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 413 | template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); |
Marshall Clow | b22274f | 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 | d26c01d | 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 | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 425 | template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); |
Marshall Clow | b22274f | 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 | d26c01d | 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 | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 430 | void swap(shared_ptr& r) noexcept; |
| 431 | void reset() noexcept; |
Howard Hinnant | d26c01d | 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 | 719bda3 | 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 | 18a7cd5 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | // shared_ptr comparisons: |
| 448 | template<class T, class U> |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 450 | template<class T, class U> |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 452 | template<class T, class U> |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 454 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 455 | bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 456 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 457 | bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 458 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 459 | bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; |
| 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 485 | |
| 486 | // shared_ptr specialized algorithms: |
Howard Hinnant | 719bda3 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 488 | |
| 489 | // shared_ptr casts: |
| 490 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 491 | shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 492 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 493 | shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 494 | template<class T, class U> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 495 | shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept; |
Howard Hinnant | d26c01d | 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 | 719bda3 | 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 | d26c01d | 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 | 719bda3 | 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 | e9b0a5c | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 522 | |
| 523 | // destructor |
| 524 | ~weak_ptr(); |
| 525 | |
| 526 | // assignment |
Howard Hinnant | 719bda3 | 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 | e9b0a5c | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 532 | |
| 533 | // modifiers |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 534 | void swap(weak_ptr& r) noexcept; |
| 535 | void reset() noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 536 | |
| 537 | // observers |
Howard Hinnant | 719bda3 | 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 | 18a7cd5 | 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 | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 543 | }; |
| 544 | |
| 545 | // weak_ptr specialized algorithms: |
Howard Hinnant | 719bda3 | 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 | d26c01d | 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 | 18a7cd5 | 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 | d26c01d | 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 | 18a7cd5 | 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 | d26c01d | 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 | 719bda3 | 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 | d26c01d | 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 | f1bf62f | 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 | d26c01d | 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 | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 644 | pointer_safety get_pointer_safety() noexcept; |
Howard Hinnant | d26c01d | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 645 | |
Howard Hinnant | c51e102 | 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 | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 662 | #include <iosfwd> |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 663 | #include <tuple> |
Eric Fiselier | 2db2bd5 | 2016-05-07 03:12:24 +0000 | [diff] [blame] | 664 | #include <stdexcept> |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 665 | #include <cstring> |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 666 | #include <cassert> |
Eric Fiselier | 8020b6c | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 667 | #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 668 | # include <atomic> |
| 669 | #endif |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 670 | #include <version> |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 671 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 672 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 673 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 674 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 675 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 676 | _LIBCPP_PUSH_MACROS |
| 677 | #include <__undef_macros> |
| 678 | |
| 679 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 680 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 681 | |
Eric Fiselier | 89659d1 | 2015-07-07 00:27:16 +0000 | [diff] [blame] | 682 | template <class _ValueType> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 683 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 89659d1 | 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 | de9d679 | 2016-09-04 09:55:12 +0000 | [diff] [blame] | 694 | template <class _ValueType> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 695 | inline _LIBCPP_INLINE_VISIBILITY |
Kuba Brecka | de9d679 | 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 | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 706 | // addressof moved to <type_traits> |
Douglas Gregor | 1303444 | 2011-06-22 22:17:44 +0000 | [diff] [blame] | 707 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | template <class _Tp> class allocator; |
| 709 | |
| 710 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 711 | class _LIBCPP_TEMPLATE_VIS allocator<void> |
Howard Hinnant | c51e102 | 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 | 9f77105 | 2012-01-19 23:15:22 +0000 | [diff] [blame] | 721 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 722 | class _LIBCPP_TEMPLATE_VIS allocator<const void> |
Howard Hinnant | 9f77105 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 732 | // pointer_traits |
| 733 | |
Marshall Clow | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 737 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 738 | struct __has_element_type<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 739 | typename __void_t<typename _Tp::element_type>::type> : true_type {}; |
Howard Hinnant | c51e102 | 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 | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 764 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 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 | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 816 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 817 | |
Marshall Clow | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 821 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 822 | struct __has_difference_type<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 823 | typename __void_t<typename _Tp::difference_type>::type> : true_type {}; |
Howard Hinnant | c51e102 | 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 | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 841 | struct __two {char __lx; char __lxx;}; |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 851 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 863 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 876 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 881 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 897 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 914 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 932 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 946 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 947 | |
| 948 | template <class _Ptr> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 949 | struct _LIBCPP_TEMPLATE_VIS pointer_traits |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 955 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f09283d | 2011-05-11 20:21:19 +0000 | [diff] [blame] | 956 | template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 960 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 961 | |
| 962 | private: |
| 963 | struct __nat {}; |
| 964 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 965 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 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 | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 972 | struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 978 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 987 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 988 | static pointer pointer_to(typename conditional<is_void<element_type>::value, |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 989 | __nat, element_type>::type& __r) _NOEXCEPT |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 990 | {return _VSTD::addressof(__r);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 991 | }; |
| 992 | |
Eric Fiselier | ae3ab84 | 2015-08-23 02:56:05 +0000 | [diff] [blame] | 993 | template <class _From, class _To> |
| 994 | struct __rebind_pointer { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 995 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | ae3ab84 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1002 | // allocator_traits |
| 1003 | |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1004 | template <class _Tp, class = void> |
| 1005 | struct __has_pointer_type : false_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1006 | |
| 1007 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1008 | struct __has_pointer_type<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1009 | typename __void_t<typename _Tp::pointer>::type> : true_type {}; |
Howard Hinnant | c51e102 | 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 | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1026 | } // __pointer_type_imp |
Howard Hinnant | c51e102 | 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 | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1037 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1038 | struct __has_const_pointer<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1039 | typename __void_t<typename _Tp::const_pointer>::type> : true_type {}; |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1050 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1061 | struct __has_void_pointer<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1062 | typename __void_t<typename _Tp::void_pointer>::type> : true_type {}; |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1073 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1083 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1084 | struct __has_const_void_pointer<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1085 | typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {}; |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1096 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1103 | template <class _Tp> |
Eric Fiselier | 45c9aac | 2017-11-22 19:49:21 +0000 | [diff] [blame] | 1104 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1105 | _Tp* |
| 1106 | __to_raw_pointer(_Tp* __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1107 | { |
| 1108 | return __p; |
| 1109 | } |
| 1110 | |
Eric Fiselier | 45c9aac | 2017-11-22 19:49:21 +0000 | [diff] [blame] | 1111 | #if _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 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 | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1115 | __to_raw_pointer(_Pointer __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1116 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1117 | return _VSTD::__to_raw_pointer(__p.operator->()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | } |
Eric Fiselier | 45c9aac | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | |
Marshall Clow | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1158 | template <class _Tp> |
Marshall Clow | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1161 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1162 | template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1163 | struct __size_type |
| 1164 | { |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1165 | typedef typename make_unsigned<_DiffType>::type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1166 | }; |
| 1167 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1168 | template <class _Alloc, class _DiffType> |
| 1169 | struct __size_type<_Alloc, _DiffType, true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1170 | { |
| 1171 | typedef typename _Alloc::size_type type; |
| 1172 | }; |
| 1173 | |
Marshall Clow | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1177 | template <class _Tp> |
Marshall Clow | 0be70c3 | 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 | c51e102 | 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 | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1197 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1198 | struct __has_propagate_on_container_move_assignment<_Tp, |
Marshall Clow | 0be70c3 | 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 | c51e102 | 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 | 0be70c3 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1217 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1218 | struct __has_propagate_on_container_swap<_Tp, |
Marshall Clow | 0be70c3 | 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 | c51e102 | 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 | 0be70c3 | 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 | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1237 | template <class _Tp> |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 1238 | struct __has_is_always_equal<_Tp, |
Marshall Clow | 0be70c3 | 2017-06-14 21:23:57 +0000 | [diff] [blame] | 1239 | typename __void_t<typename _Tp::is_always_equal>::type> |
| 1240 | : true_type {}; |
Marshall Clow | 0b58756 | 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 | c51e102 | 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 | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 1258 | struct __two {char __lx; char __lxx;}; |
Howard Hinnant | c51e102 | 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 | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1291 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 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 | c51e102 | 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 | c51e102 | 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 | c51e102 | 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 | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1345 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1346 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1347 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | be4cb61 | 2017-09-15 00:31:38 +0000 | [diff] [blame] | 1352 | -> decltype((void)__a.allocate(__sz, __p), true_type()); |
Howard Hinnant | c51e102 | 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 | be4cb61 | 2017-09-15 00:31:38 +0000 | [diff] [blame] | 1363 | decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1364 | declval<_SizeType>(), |
| 1365 | declval<_ConstVoidPtr>())), |
| 1366 | true_type>::value> |
| 1367 | { |
| 1368 | }; |
| 1369 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1370 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 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 | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1378 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1379 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1380 | #if !defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1381 | |
| 1382 | template <class _Alloc, class _Tp, class ..._Args> |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1383 | decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(), |
| 1384 | _VSTD::declval<_Args>()...), |
Howard Hinnant | c51e102 | 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 | be4cb61 | 2017-09-15 00:31:38 +0000 | [diff] [blame] | 1396 | decltype(_VSTD::__has_construct_test(declval<_Alloc>(), |
Howard Hinnant | c51e102 | 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 | be4cb61 | 2017-09-15 00:31:38 +0000 | [diff] [blame] | 1417 | decltype(_VSTD::__has_destroy_test(declval<_Alloc>(), |
Howard Hinnant | c51e102 | 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 | be4cb61 | 2017-09-15 00:31:38 +0000 | [diff] [blame] | 1437 | decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())), |
Howard Hinnant | c51e102 | 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 | be4cb61 | 2017-09-15 00:31:38 +0000 | [diff] [blame] | 1456 | decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1457 | true_type>::value> |
| 1458 | { |
| 1459 | }; |
| 1460 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1461 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | |
| 1463 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1464 | |
| 1465 | template <class _Alloc, class _Pointer, class ..._Args> |
| 1466 | struct __has_construct |
| 1467 | : false_type |
| 1468 | { |
| 1469 | }; |
| 1470 | |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1471 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 1472 | |
| 1473 | template <class _Alloc, class _Pointer, class _Args> |
| 1474 | struct __has_construct |
| 1475 | : false_type |
| 1476 | { |
| 1477 | }; |
| 1478 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1479 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1480 | |
| 1481 | template <class _Alloc, class _Pointer> |
| 1482 | struct __has_destroy |
| 1483 | : false_type |
| 1484 | { |
| 1485 | }; |
| 1486 | |
| 1487 | template <class _Alloc> |
| 1488 | struct __has_max_size |
| 1489 | : true_type |
| 1490 | { |
| 1491 | }; |
| 1492 | |
| 1493 | template <class _Alloc> |
| 1494 | struct __has_select_on_container_copy_construction |
| 1495 | : false_type |
| 1496 | { |
| 1497 | }; |
| 1498 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1499 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1500 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1501 | template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> |
| 1502 | struct __alloc_traits_difference_type |
| 1503 | { |
| 1504 | typedef typename pointer_traits<_Ptr>::difference_type type; |
| 1505 | }; |
| 1506 | |
| 1507 | template <class _Alloc, class _Ptr> |
| 1508 | struct __alloc_traits_difference_type<_Alloc, _Ptr, true> |
| 1509 | { |
| 1510 | typedef typename _Alloc::difference_type type; |
| 1511 | }; |
| 1512 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1513 | template <class _Alloc> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1514 | struct _LIBCPP_TEMPLATE_VIS allocator_traits |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1515 | { |
| 1516 | typedef _Alloc allocator_type; |
| 1517 | typedef typename allocator_type::value_type value_type; |
| 1518 | |
| 1519 | typedef typename __pointer_type<value_type, allocator_type>::type pointer; |
| 1520 | typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer; |
| 1521 | typedef typename __void_pointer<pointer, allocator_type>::type void_pointer; |
| 1522 | typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer; |
| 1523 | |
Howard Hinnant | 8e4e600 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 1524 | typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type; |
| 1525 | typedef typename __size_type<allocator_type, difference_type>::type size_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1526 | |
| 1527 | typedef typename __propagate_on_container_copy_assignment<allocator_type>::type |
| 1528 | propagate_on_container_copy_assignment; |
| 1529 | typedef typename __propagate_on_container_move_assignment<allocator_type>::type |
| 1530 | propagate_on_container_move_assignment; |
| 1531 | typedef typename __propagate_on_container_swap<allocator_type>::type |
| 1532 | propagate_on_container_swap; |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1533 | typedef typename __is_always_equal<allocator_type>::type |
| 1534 | is_always_equal; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1536 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1537 | template <class _Tp> using rebind_alloc = |
Howard Hinnant | f09283d | 2011-05-11 20:21:19 +0000 | [diff] [blame] | 1538 | typename __allocator_traits_rebind<allocator_type, _Tp>::type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1539 | template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1540 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1541 | template <class _Tp> struct rebind_alloc |
| 1542 | {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; |
| 1543 | template <class _Tp> struct rebind_traits |
| 1544 | {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;}; |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1545 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1546 | |
Marshall Clow | 0e58cae | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 1547 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1548 | static pointer allocate(allocator_type& __a, size_type __n) |
| 1549 | {return __a.allocate(__n);} |
Marshall Clow | 0e58cae | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 1550 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1551 | static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1552 | {return __allocate(__a, __n, __hint, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1553 | __has_allocate_hint<allocator_type, size_type, const_void_pointer>());} |
| 1554 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1555 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1556 | static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1557 | {__a.deallocate(__p, __n);} |
| 1558 | |
| 1559 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1560 | template <class _Tp, class... _Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1561 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1562 | static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) |
Marshall Clow | 3996b8b | 2014-11-11 19:22:33 +0000 | [diff] [blame] | 1563 | {__construct(__has_construct<allocator_type, _Tp*, _Args...>(), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1564 | __a, __p, _VSTD::forward<_Args>(__args)...);} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1565 | #else // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1566 | template <class _Tp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1567 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2b2ec3e | 2017-01-14 01:33:53 +0000 | [diff] [blame] | 1568 | static void construct(allocator_type&, _Tp* __p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1569 | { |
| 1570 | ::new ((void*)__p) _Tp(); |
| 1571 | } |
| 1572 | template <class _Tp, class _A0> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1573 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2b2ec3e | 2017-01-14 01:33:53 +0000 | [diff] [blame] | 1574 | static void construct(allocator_type&, _Tp* __p, const _A0& __a0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1575 | { |
| 1576 | ::new ((void*)__p) _Tp(__a0); |
| 1577 | } |
| 1578 | template <class _Tp, class _A0, class _A1> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1579 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2b2ec3e | 2017-01-14 01:33:53 +0000 | [diff] [blame] | 1580 | static void construct(allocator_type&, _Tp* __p, const _A0& __a0, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1581 | const _A1& __a1) |
| 1582 | { |
| 1583 | ::new ((void*)__p) _Tp(__a0, __a1); |
| 1584 | } |
| 1585 | template <class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1586 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2b2ec3e | 2017-01-14 01:33:53 +0000 | [diff] [blame] | 1587 | static void construct(allocator_type&, _Tp* __p, const _A0& __a0, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1588 | const _A1& __a1, const _A2& __a2) |
| 1589 | { |
| 1590 | ::new ((void*)__p) _Tp(__a0, __a1, __a2); |
| 1591 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1592 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1593 | |
| 1594 | template <class _Tp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1595 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1596 | static void destroy(allocator_type& __a, _Tp* __p) |
| 1597 | {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);} |
| 1598 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1599 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4f834b5 | 2013-08-27 20:22:15 +0000 | [diff] [blame] | 1600 | static size_type max_size(const allocator_type& __a) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1601 | {return __max_size(__has_max_size<const allocator_type>(), __a);} |
| 1602 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1603 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1604 | static allocator_type |
| 1605 | select_on_container_copy_construction(const allocator_type& __a) |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1606 | {return __select_on_container_copy_construction( |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1607 | __has_select_on_container_copy_construction<const allocator_type>(), |
| 1608 | __a);} |
| 1609 | |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1610 | template <class _Ptr> |
| 1611 | _LIBCPP_INLINE_VISIBILITY |
| 1612 | static |
| 1613 | void |
| 1614 | __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) |
| 1615 | { |
| 1616 | for (; __begin1 != __end1; ++__begin1, ++__begin2) |
| 1617 | construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1)); |
| 1618 | } |
| 1619 | |
| 1620 | template <class _Tp> |
| 1621 | _LIBCPP_INLINE_VISIBILITY |
| 1622 | static |
| 1623 | typename enable_if |
| 1624 | < |
| 1625 | (is_same<allocator_type, allocator<_Tp> >::value |
| 1626 | || !__has_construct<allocator_type, _Tp*, _Tp>::value) && |
| 1627 | is_trivially_move_constructible<_Tp>::value, |
| 1628 | void |
| 1629 | >::type |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 1630 | __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1631 | { |
| 1632 | ptrdiff_t _Np = __end1 - __begin1; |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1633 | if (_Np > 0) |
Marshall Clow | 426d6d2 | 2015-06-02 13:04:18 +0000 | [diff] [blame] | 1634 | { |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1635 | _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); |
Marshall Clow | 426d6d2 | 2015-06-02 13:04:18 +0000 | [diff] [blame] | 1636 | __begin2 += _Np; |
| 1637 | } |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1640 | template <class _Iter, class _Ptr> |
| 1641 | _LIBCPP_INLINE_VISIBILITY |
| 1642 | static |
| 1643 | void |
| 1644 | __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) |
| 1645 | { |
| 1646 | for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) |
| 1647 | construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1); |
| 1648 | } |
| 1649 | |
| 1650 | template <class _Tp> |
| 1651 | _LIBCPP_INLINE_VISIBILITY |
| 1652 | static |
| 1653 | typename enable_if |
| 1654 | < |
| 1655 | (is_same<allocator_type, allocator<_Tp> >::value |
| 1656 | || !__has_construct<allocator_type, _Tp*, _Tp>::value) && |
| 1657 | is_trivially_move_constructible<_Tp>::value, |
| 1658 | void |
| 1659 | >::type |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 1660 | __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1661 | { |
| 1662 | typedef typename remove_const<_Tp>::type _Vp; |
| 1663 | ptrdiff_t _Np = __end1 - __begin1; |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1664 | if (_Np > 0) |
Marshall Clow | 426d6d2 | 2015-06-02 13:04:18 +0000 | [diff] [blame] | 1665 | { |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1666 | _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp)); |
Marshall Clow | 426d6d2 | 2015-06-02 13:04:18 +0000 | [diff] [blame] | 1667 | __begin2 += _Np; |
| 1668 | } |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1671 | template <class _Ptr> |
| 1672 | _LIBCPP_INLINE_VISIBILITY |
| 1673 | static |
| 1674 | void |
| 1675 | __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) |
| 1676 | { |
| 1677 | while (__end1 != __begin1) |
Howard Hinnant | 5adee4c | 2013-01-11 20:36:59 +0000 | [diff] [blame] | 1678 | { |
| 1679 | construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1)); |
| 1680 | --__end2; |
| 1681 | } |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | template <class _Tp> |
| 1685 | _LIBCPP_INLINE_VISIBILITY |
| 1686 | static |
| 1687 | typename enable_if |
| 1688 | < |
| 1689 | (is_same<allocator_type, allocator<_Tp> >::value |
| 1690 | || !__has_construct<allocator_type, _Tp*, _Tp>::value) && |
| 1691 | is_trivially_move_constructible<_Tp>::value, |
| 1692 | void |
| 1693 | >::type |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 1694 | __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1695 | { |
| 1696 | ptrdiff_t _Np = __end1 - __begin1; |
| 1697 | __end2 -= _Np; |
Marshall Clow | 4907e8f | 2015-05-31 03:13:31 +0000 | [diff] [blame] | 1698 | if (_Np > 0) |
| 1699 | _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1702 | private: |
| 1703 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1704 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1705 | static pointer __allocate(allocator_type& __a, size_type __n, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1706 | const_void_pointer __hint, true_type) |
| 1707 | {return __a.allocate(__n, __hint);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1708 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1709 | static pointer __allocate(allocator_type& __a, size_type __n, |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1710 | const_void_pointer, false_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1711 | {return __a.allocate(__n);} |
| 1712 | |
| 1713 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1714 | template <class _Tp, class... _Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1715 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1716 | static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1717 | {__a.construct(__p, _VSTD::forward<_Args>(__args)...);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1718 | template <class _Tp, class... _Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1719 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1720 | static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args) |
| 1721 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1722 | ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1723 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1724 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1725 | |
| 1726 | template <class _Tp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1728 | static void __destroy(true_type, allocator_type& __a, _Tp* __p) |
| 1729 | {__a.destroy(__p);} |
| 1730 | template <class _Tp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1731 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1732 | static void __destroy(false_type, allocator_type&, _Tp* __p) |
| 1733 | { |
| 1734 | __p->~_Tp(); |
| 1735 | } |
| 1736 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1737 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f817a35 | 2017-12-05 15:56:26 +0000 | [diff] [blame] | 1738 | static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1739 | {return __a.max_size();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1740 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f817a35 | 2017-12-05 15:56:26 +0000 | [diff] [blame] | 1741 | static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT |
Marshall Clow | 33daa16 | 2015-10-25 19:34:04 +0000 | [diff] [blame] | 1742 | {return numeric_limits<size_type>::max() / sizeof(value_type);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1743 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1744 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | static allocator_type |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1746 | __select_on_container_copy_construction(true_type, const allocator_type& __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1747 | {return __a.select_on_container_copy_construction();} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1748 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1749 | static allocator_type |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1750 | __select_on_container_copy_construction(false_type, const allocator_type& __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1751 | {return __a;} |
| 1752 | }; |
| 1753 | |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1754 | template <class _Traits, class _Tp> |
| 1755 | struct __rebind_alloc_helper |
| 1756 | { |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1757 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 1758 | typedef typename _Traits::template rebind_alloc<_Tp> type; |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1759 | #else |
| 1760 | typedef typename _Traits::template rebind_alloc<_Tp>::other type; |
| 1761 | #endif |
| 1762 | }; |
| 1763 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1764 | // allocator |
| 1765 | |
| 1766 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1767 | class _LIBCPP_TEMPLATE_VIS allocator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1768 | { |
| 1769 | public: |
| 1770 | typedef size_t size_type; |
| 1771 | typedef ptrdiff_t difference_type; |
| 1772 | typedef _Tp* pointer; |
| 1773 | typedef const _Tp* const_pointer; |
| 1774 | typedef _Tp& reference; |
| 1775 | typedef const _Tp& const_reference; |
| 1776 | typedef _Tp value_type; |
| 1777 | |
Howard Hinnant | 4931e09 | 2011-06-02 21:38:57 +0000 | [diff] [blame] | 1778 | typedef true_type propagate_on_container_move_assignment; |
Marshall Clow | 0b58756 | 2015-06-02 16:34:03 +0000 | [diff] [blame] | 1779 | typedef true_type is_always_equal; |
Howard Hinnant | 4931e09 | 2011-06-02 21:38:57 +0000 | [diff] [blame] | 1780 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1781 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 1782 | |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 1783 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1784 | allocator() _NOEXCEPT {} |
| 1785 | |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1786 | template <class _Up> |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 1787 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1788 | allocator(const allocator<_Up>&) _NOEXCEPT {} |
| 1789 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1790 | _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1791 | {return _VSTD::addressof(__x);} |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1792 | _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1793 | {return _VSTD::addressof(__x);} |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1794 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 0e58cae | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 1795 | pointer allocate(size_type __n, allocator<void>::const_pointer = 0) |
Marshall Clow | 813ffb3 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 1796 | { |
| 1797 | if (__n > max_size()) |
Marshall Clow | ed3e229 | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 1798 | __throw_length_error("allocator<T>::allocate(size_t n)" |
| 1799 | " 'n' exceeds maximum supported size"); |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 1800 | return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), __alignof(_Tp))); |
Marshall Clow | 813ffb3 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 1801 | } |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1802 | _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 1803 | {_VSTD::__libcpp_deallocate((void*)__p, __alignof(_Tp));} |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1804 | _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT |
| 1805 | {return size_type(~0) / sizeof(_Tp);} |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1806 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1807 | template <class _Up, class... _Args> |
| 1808 | _LIBCPP_INLINE_VISIBILITY |
| 1809 | void |
| 1810 | construct(_Up* __p, _Args&&... __args) |
| 1811 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1812 | ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1813 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1814 | #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1815 | _LIBCPP_INLINE_VISIBILITY |
| 1816 | void |
| 1817 | construct(pointer __p) |
| 1818 | { |
| 1819 | ::new((void*)__p) _Tp(); |
| 1820 | } |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1821 | # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1822 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1823 | template <class _A0> |
| 1824 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1825 | void |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1826 | construct(pointer __p, _A0& __a0) |
| 1827 | { |
| 1828 | ::new((void*)__p) _Tp(__a0); |
| 1829 | } |
| 1830 | template <class _A0> |
| 1831 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1832 | void |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1833 | construct(pointer __p, const _A0& __a0) |
| 1834 | { |
| 1835 | ::new((void*)__p) _Tp(__a0); |
| 1836 | } |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1837 | # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1838 | template <class _A0, class _A1> |
| 1839 | _LIBCPP_INLINE_VISIBILITY |
| 1840 | void |
| 1841 | construct(pointer __p, _A0& __a0, _A1& __a1) |
| 1842 | { |
| 1843 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1844 | } |
| 1845 | template <class _A0, class _A1> |
| 1846 | _LIBCPP_INLINE_VISIBILITY |
| 1847 | void |
| 1848 | construct(pointer __p, const _A0& __a0, _A1& __a1) |
| 1849 | { |
| 1850 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1851 | } |
| 1852 | template <class _A0, class _A1> |
| 1853 | _LIBCPP_INLINE_VISIBILITY |
| 1854 | void |
| 1855 | construct(pointer __p, _A0& __a0, const _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, const _A1& __a1) |
| 1863 | { |
| 1864 | ::new((void*)__p) _Tp(__a0, __a1); |
| 1865 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1866 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1867 | _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} |
| 1868 | }; |
| 1869 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1870 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1871 | class _LIBCPP_TEMPLATE_VIS allocator<const _Tp> |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1872 | { |
| 1873 | public: |
| 1874 | typedef size_t size_type; |
| 1875 | typedef ptrdiff_t difference_type; |
| 1876 | typedef const _Tp* pointer; |
| 1877 | typedef const _Tp* const_pointer; |
| 1878 | typedef const _Tp& reference; |
| 1879 | typedef const _Tp& const_reference; |
Howard Hinnant | 9bc95e2 | 2013-06-07 01:56:37 +0000 | [diff] [blame] | 1880 | typedef const _Tp value_type; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1881 | |
| 1882 | typedef true_type propagate_on_container_move_assignment; |
Marshall Clow | ac12fcc | 2015-07-01 21:23:40 +0000 | [diff] [blame] | 1883 | typedef true_type is_always_equal; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1884 | |
| 1885 | template <class _Up> struct rebind {typedef allocator<_Up> other;}; |
| 1886 | |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 1887 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1888 | allocator() _NOEXCEPT {} |
| 1889 | |
| 1890 | template <class _Up> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1891 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | bc75976 | 2018-03-20 23:02:53 +0000 | [diff] [blame] | 1892 | allocator(const allocator<_Up>&) _NOEXCEPT {} |
| 1893 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1894 | _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT |
| 1895 | {return _VSTD::addressof(__x);} |
| 1896 | _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) |
Marshall Clow | 813ffb3 | 2016-03-03 12:04:39 +0000 | [diff] [blame] | 1897 | { |
| 1898 | if (__n > max_size()) |
Marshall Clow | ed3e229 | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 1899 | __throw_length_error("allocator<const T>::allocate(size_t n)" |
| 1900 | " 'n' exceeds maximum supported size"); |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 1901 | return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), __alignof(_Tp))); |
Eric Fiselier | 2db2bd5 | 2016-05-07 03:12:24 +0000 | [diff] [blame] | 1902 | } |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1903 | _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 1904 | {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __alignof(_Tp));} |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1905 | _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT |
| 1906 | {return size_type(~0) / sizeof(_Tp);} |
| 1907 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
| 1908 | template <class _Up, class... _Args> |
| 1909 | _LIBCPP_INLINE_VISIBILITY |
| 1910 | void |
| 1911 | construct(_Up* __p, _Args&&... __args) |
| 1912 | { |
| 1913 | ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); |
| 1914 | } |
| 1915 | #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
| 1916 | _LIBCPP_INLINE_VISIBILITY |
| 1917 | void |
| 1918 | construct(pointer __p) |
| 1919 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 1920 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1921 | } |
| 1922 | # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1923 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1924 | template <class _A0> |
| 1925 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1926 | void |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1927 | construct(pointer __p, _A0& __a0) |
| 1928 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 1929 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1930 | } |
| 1931 | template <class _A0> |
| 1932 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 1933 | void |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1934 | construct(pointer __p, const _A0& __a0) |
| 1935 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 1936 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1937 | } |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1938 | # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
| 1939 | template <class _A0, class _A1> |
| 1940 | _LIBCPP_INLINE_VISIBILITY |
| 1941 | void |
| 1942 | construct(pointer __p, _A0& __a0, _A1& __a1) |
| 1943 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 1944 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1945 | } |
| 1946 | template <class _A0, class _A1> |
| 1947 | _LIBCPP_INLINE_VISIBILITY |
| 1948 | void |
| 1949 | construct(pointer __p, const _A0& __a0, _A1& __a1) |
| 1950 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 1951 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1952 | } |
| 1953 | template <class _A0, class _A1> |
| 1954 | _LIBCPP_INLINE_VISIBILITY |
| 1955 | void |
| 1956 | construct(pointer __p, _A0& __a0, const _A1& __a1) |
| 1957 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 1958 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); |
Howard Hinnant | 741c8fa | 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, const _A1& __a1) |
| 1964 | { |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 1965 | ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 1966 | } |
| 1967 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
| 1968 | _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} |
| 1969 | }; |
| 1970 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1971 | template <class _Tp, class _Up> |
| 1972 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1973 | bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1974 | |
| 1975 | template <class _Tp, class _Up> |
| 1976 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 1977 | bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1978 | |
| 1979 | template <class _OutputIterator, class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1980 | class _LIBCPP_TEMPLATE_VIS raw_storage_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1981 | : public iterator<output_iterator_tag, |
| 1982 | _Tp, // purposefully not C++03 |
| 1983 | ptrdiff_t, // purposefully not C++03 |
| 1984 | _Tp*, // purposefully not C++03 |
| 1985 | raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03 |
| 1986 | { |
| 1987 | private: |
| 1988 | _OutputIterator __x_; |
| 1989 | public: |
| 1990 | _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} |
| 1991 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} |
| 1992 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) |
Marshall Clow | bdfdea8 | 2018-08-28 13:29:30 +0000 | [diff] [blame] | 1993 | {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;} |
Marshall Clow | 5c3f09e | 2015-10-25 18:58:07 +0000 | [diff] [blame] | 1994 | #if _LIBCPP_STD_VER >= 14 |
| 1995 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) |
Marshall Clow | bdfdea8 | 2018-08-28 13:29:30 +0000 | [diff] [blame] | 1996 | {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} |
Marshall Clow | 5c3f09e | 2015-10-25 18:58:07 +0000 | [diff] [blame] | 1997 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1998 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} |
| 1999 | _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) |
| 2000 | {raw_storage_iterator __t(*this); ++__x_; return __t;} |
Marshall Clow | b949f1b | 2015-05-10 13:14:08 +0000 | [diff] [blame] | 2001 | #if _LIBCPP_STD_VER >= 14 |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 2002 | _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } |
Marshall Clow | b949f1b | 2015-05-10 13:14:08 +0000 | [diff] [blame] | 2003 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2004 | }; |
| 2005 | |
| 2006 | template <class _Tp> |
Roman Lebedev | b5959fa | 2018-09-22 17:54:48 +0000 | [diff] [blame] | 2007 | _LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2008 | pair<_Tp*, ptrdiff_t> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2009 | get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2010 | { |
| 2011 | pair<_Tp*, ptrdiff_t> __r(0, 0); |
| 2012 | const ptrdiff_t __m = (~ptrdiff_t(0) ^ |
| 2013 | ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) |
| 2014 | / sizeof(_Tp); |
| 2015 | if (__n > __m) |
| 2016 | __n = __m; |
| 2017 | while (__n > 0) |
| 2018 | { |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2019 | #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 2020 | if (__is_overaligned_for_new(__alignof(_Tp))) |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2021 | { |
| 2022 | std::align_val_t __al = |
| 2023 | std::align_val_t(std::alignment_of<_Tp>::value); |
| 2024 | __r.first = static_cast<_Tp*>(::operator new( |
| 2025 | __n * sizeof(_Tp), __al, nothrow)); |
| 2026 | } else { |
| 2027 | __r.first = static_cast<_Tp*>(::operator new( |
| 2028 | __n * sizeof(_Tp), nothrow)); |
| 2029 | } |
| 2030 | #else |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 2031 | if (__is_overaligned_for_new(__alignof(_Tp))) |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2032 | { |
| 2033 | // Since aligned operator new is unavailable, return an empty |
| 2034 | // buffer rather than one with invalid alignment. |
| 2035 | return __r; |
| 2036 | } |
| 2037 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2038 | __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow)); |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2039 | #endif |
| 2040 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2041 | if (__r.first) |
| 2042 | { |
| 2043 | __r.second = __n; |
| 2044 | break; |
| 2045 | } |
| 2046 | __n /= 2; |
| 2047 | } |
| 2048 | return __r; |
| 2049 | } |
| 2050 | |
| 2051 | template <class _Tp> |
| 2052 | inline _LIBCPP_INLINE_VISIBILITY |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2053 | void return_temporary_buffer(_Tp* __p) _NOEXCEPT |
| 2054 | { |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 2055 | _VSTD::__libcpp_deallocate((void*)__p, __alignof(_Tp)); |
Richard Smith | 0657be1 | 2018-02-01 22:24:45 +0000 | [diff] [blame] | 2056 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2057 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 2058 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2059 | template <class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 2060 | struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2061 | { |
| 2062 | _Tp* __ptr_; |
| 2063 | }; |
| 2064 | |
| 2065 | template<class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 2066 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2067 | { |
| 2068 | private: |
| 2069 | _Tp* __ptr_; |
| 2070 | public: |
| 2071 | typedef _Tp element_type; |
| 2072 | |
| 2073 | _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {} |
| 2074 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {} |
| 2075 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw() |
| 2076 | : __ptr_(__p.release()) {} |
| 2077 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw() |
| 2078 | {reset(__p.release()); return *this;} |
| 2079 | template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw() |
| 2080 | {reset(__p.release()); return *this;} |
| 2081 | _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw() |
| 2082 | {reset(__p.__ptr_); return *this;} |
| 2083 | _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;} |
| 2084 | |
| 2085 | _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw() |
| 2086 | {return *__ptr_;} |
| 2087 | _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;} |
| 2088 | _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;} |
| 2089 | _LIBCPP_INLINE_VISIBILITY _Tp* release() throw() |
| 2090 | { |
| 2091 | _Tp* __t = __ptr_; |
| 2092 | __ptr_ = 0; |
| 2093 | return __t; |
| 2094 | } |
| 2095 | _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw() |
| 2096 | { |
| 2097 | if (__ptr_ != __p) |
| 2098 | delete __ptr_; |
| 2099 | __ptr_ = __p; |
| 2100 | } |
| 2101 | |
| 2102 | _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {} |
| 2103 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw() |
| 2104 | {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} |
| 2105 | template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw() |
| 2106 | {return auto_ptr<_Up>(release());} |
| 2107 | }; |
| 2108 | |
| 2109 | template <> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 2110 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2111 | { |
| 2112 | public: |
| 2113 | typedef void element_type; |
| 2114 | }; |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 2115 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2116 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2117 | template <class _Tp, int _Idx, |
| 2118 | bool _CanBeEmptyBase = |
| 2119 | is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value> |
| 2120 | struct __compressed_pair_elem { |
| 2121 | typedef _Tp _ParamT; |
| 2122 | typedef _Tp& reference; |
| 2123 | typedef const _Tp& const_reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2124 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2125 | #ifndef _LIBCPP_CXX03_LANG |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2126 | _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2127 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2128 | template <class _Up, class = typename enable_if< |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2129 | !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value |
| 2130 | >::type> |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2131 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2132 | constexpr explicit |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2133 | __compressed_pair_elem(_Up&& __u) |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame^] | 2134 | : __value_(_VSTD::forward<_Up>(__u)) |
| 2135 | { |
| 2136 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2137 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2138 | template <class... _Args, size_t... _Indexes> |
| 2139 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2140 | __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, |
| 2141 | __tuple_indices<_Indexes...>) |
| 2142 | : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} |
| 2143 | #else |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2144 | _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {} |
| 2145 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2146 | __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {} |
| 2147 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2148 | |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2149 | _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } |
| 2150 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2151 | const_reference __get() const _NOEXCEPT { return __value_; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2152 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2153 | private: |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2154 | _Tp __value_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2155 | }; |
| 2156 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2157 | template <class _Tp, int _Idx> |
| 2158 | struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { |
| 2159 | typedef _Tp _ParamT; |
| 2160 | typedef _Tp& reference; |
| 2161 | typedef const _Tp& const_reference; |
| 2162 | typedef _Tp __value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2163 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2164 | #ifndef _LIBCPP_CXX03_LANG |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2165 | _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2166 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2167 | template <class _Up, class = typename enable_if< |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2168 | !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value |
| 2169 | >::type> |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2170 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2171 | constexpr explicit |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2172 | __compressed_pair_elem(_Up&& __u) |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame^] | 2173 | : __value_type(_VSTD::forward<_Up>(__u)) |
| 2174 | {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2175 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2176 | template <class... _Args, size_t... _Indexes> |
| 2177 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2178 | __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, |
| 2179 | __tuple_indices<_Indexes...>) |
| 2180 | : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} |
| 2181 | #else |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2182 | _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {} |
| 2183 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2184 | __compressed_pair_elem(_ParamT __p) |
| 2185 | : __value_type(std::forward<_ParamT>(__p)) {} |
| 2186 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2187 | |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2188 | _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } |
| 2189 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2190 | const_reference __get() const _NOEXCEPT { return *this; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2191 | }; |
| 2192 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2193 | // Tag used to construct the second element of the compressed pair. |
| 2194 | struct __second_tag {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2195 | |
| 2196 | template <class _T1, class _T2> |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2197 | class __compressed_pair : private __compressed_pair_elem<_T1, 0>, |
| 2198 | private __compressed_pair_elem<_T2, 1> { |
| 2199 | typedef __compressed_pair_elem<_T1, 0> _Base1; |
| 2200 | typedef __compressed_pair_elem<_T2, 1> _Base2; |
| 2201 | |
| 2202 | // NOTE: This static assert should never fire because __compressed_pair |
| 2203 | // is *almost never* used in a scenario where it's possible for T1 == T2. |
| 2204 | // (The exception is std::function where it is possible that the function |
| 2205 | // object and the allocator have the same type). |
Eric Fiselier | c5adf47 | 2017-04-13 01:13:58 +0000 | [diff] [blame] | 2206 | static_assert((!is_same<_T1, _T2>::value), |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2207 | "__compressed_pair cannot be instantated when T1 and T2 are the same type; " |
| 2208 | "The current implementation is NOT ABI-compatible with the previous " |
| 2209 | "implementation for this configuration"); |
| 2210 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2211 | public: |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2212 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2213 | template <bool _Dummy = true, |
| 2214 | class = typename enable_if< |
| 2215 | __dependent_type<is_default_constructible<_T1>, _Dummy>::value && |
| 2216 | __dependent_type<is_default_constructible<_T2>, _Dummy>::value |
| 2217 | >::type |
| 2218 | > |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2219 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2220 | constexpr __compressed_pair() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2221 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2222 | template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type, |
| 2223 | __compressed_pair>::value, |
| 2224 | bool>::type = true> |
| 2225 | _LIBCPP_INLINE_VISIBILITY constexpr explicit |
| 2226 | __compressed_pair(_Tp&& __t) |
| 2227 | : _Base1(std::forward<_Tp>(__t)), _Base2() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2228 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2229 | template <class _Tp> |
| 2230 | _LIBCPP_INLINE_VISIBILITY constexpr |
| 2231 | __compressed_pair(__second_tag, _Tp&& __t) |
| 2232 | : _Base1(), _Base2(std::forward<_Tp>(__t)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2233 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2234 | template <class _U1, class _U2> |
| 2235 | _LIBCPP_INLINE_VISIBILITY constexpr |
| 2236 | __compressed_pair(_U1&& __t1, _U2&& __t2) |
| 2237 | : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2238 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2239 | template <class... _Args1, class... _Args2> |
| 2240 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2241 | __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, |
| 2242 | tuple<_Args2...> __second_args) |
| 2243 | : _Base1(__pc, _VSTD::move(__first_args), |
| 2244 | typename __make_tuple_indices<sizeof...(_Args1)>::type()), |
| 2245 | _Base2(__pc, _VSTD::move(__second_args), |
| 2246 | typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 2247 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2248 | #else |
| 2249 | _LIBCPP_INLINE_VISIBILITY |
| 2250 | __compressed_pair() {} |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 2251 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2252 | _LIBCPP_INLINE_VISIBILITY explicit |
| 2253 | __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {} |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 2254 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2255 | _LIBCPP_INLINE_VISIBILITY |
| 2256 | __compressed_pair(__second_tag, _T2 __t2) |
| 2257 | : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2258 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2259 | _LIBCPP_INLINE_VISIBILITY |
| 2260 | __compressed_pair(_T1 __t1, _T2 __t2) |
| 2261 | : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {} |
| 2262 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2263 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2264 | _LIBCPP_INLINE_VISIBILITY |
| 2265 | typename _Base1::reference first() _NOEXCEPT { |
| 2266 | return static_cast<_Base1&>(*this).__get(); |
| 2267 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2268 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2269 | _LIBCPP_INLINE_VISIBILITY |
| 2270 | typename _Base1::const_reference first() const _NOEXCEPT { |
| 2271 | return static_cast<_Base1 const&>(*this).__get(); |
| 2272 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2273 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2274 | _LIBCPP_INLINE_VISIBILITY |
| 2275 | typename _Base2::reference second() _NOEXCEPT { |
| 2276 | return static_cast<_Base2&>(*this).__get(); |
| 2277 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2278 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2279 | _LIBCPP_INLINE_VISIBILITY |
| 2280 | typename _Base2::const_reference second() const _NOEXCEPT { |
| 2281 | return static_cast<_Base2 const&>(*this).__get(); |
| 2282 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2283 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2284 | _LIBCPP_INLINE_VISIBILITY |
| 2285 | void swap(__compressed_pair& __x) |
| 2286 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2287 | __is_nothrow_swappable<_T2>::value) |
| 2288 | { |
| 2289 | using std::swap; |
| 2290 | swap(first(), __x.first()); |
| 2291 | swap(second(), __x.second()); |
| 2292 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2293 | }; |
| 2294 | |
| 2295 | template <class _T1, class _T2> |
| 2296 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2297 | void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) |
| 2298 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2299 | __is_nothrow_swappable<_T2>::value) { |
| 2300 | __x.swap(__y); |
| 2301 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2302 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2303 | // default_delete |
| 2304 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2305 | template <class _Tp> |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2306 | struct _LIBCPP_TEMPLATE_VIS default_delete { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 2307 | static_assert(!is_function<_Tp>::value, |
| 2308 | "default_delete cannot be instantiated for function types"); |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2309 | #ifndef _LIBCPP_CXX03_LANG |
| 2310 | _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2311 | #else |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2312 | _LIBCPP_INLINE_VISIBILITY default_delete() {} |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2313 | #endif |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2314 | template <class _Up> |
| 2315 | _LIBCPP_INLINE_VISIBILITY |
| 2316 | default_delete(const default_delete<_Up>&, |
| 2317 | typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = |
| 2318 | 0) _NOEXCEPT {} |
| 2319 | |
| 2320 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT { |
| 2321 | static_assert(sizeof(_Tp) > 0, |
| 2322 | "default_delete can not delete incomplete type"); |
| 2323 | static_assert(!is_void<_Tp>::value, |
| 2324 | "default_delete can not delete incomplete type"); |
| 2325 | delete __ptr; |
| 2326 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2327 | }; |
| 2328 | |
| 2329 | template <class _Tp> |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2330 | struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { |
| 2331 | private: |
| 2332 | template <class _Up> |
| 2333 | struct _EnableIfConvertible |
| 2334 | : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; |
| 2335 | |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2336 | public: |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2337 | #ifndef _LIBCPP_CXX03_LANG |
| 2338 | _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2339 | #else |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2340 | _LIBCPP_INLINE_VISIBILITY default_delete() {} |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2341 | #endif |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2342 | |
| 2343 | template <class _Up> |
| 2344 | _LIBCPP_INLINE_VISIBILITY |
| 2345 | default_delete(const default_delete<_Up[]>&, |
| 2346 | typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} |
| 2347 | |
| 2348 | template <class _Up> |
| 2349 | _LIBCPP_INLINE_VISIBILITY |
| 2350 | typename _EnableIfConvertible<_Up>::type |
| 2351 | operator()(_Up* __ptr) const _NOEXCEPT { |
| 2352 | static_assert(sizeof(_Tp) > 0, |
| 2353 | "default_delete can not delete incomplete type"); |
| 2354 | static_assert(!is_void<_Tp>::value, |
| 2355 | "default_delete can not delete void type"); |
| 2356 | delete[] __ptr; |
| 2357 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2358 | }; |
| 2359 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2360 | |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2361 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2362 | #ifndef _LIBCPP_CXX03_LANG |
| 2363 | template <class _Deleter> |
| 2364 | struct __unique_ptr_deleter_sfinae { |
| 2365 | static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); |
| 2366 | typedef const _Deleter& __lval_ref_type; |
| 2367 | typedef _Deleter&& __good_rval_ref_type; |
| 2368 | typedef true_type __enable_rval_overload; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2369 | }; |
| 2370 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2371 | template <class _Deleter> |
| 2372 | struct __unique_ptr_deleter_sfinae<_Deleter const&> { |
| 2373 | typedef const _Deleter& __lval_ref_type; |
| 2374 | typedef const _Deleter&& __bad_rval_ref_type; |
| 2375 | typedef false_type __enable_rval_overload; |
| 2376 | }; |
| 2377 | |
| 2378 | template <class _Deleter> |
| 2379 | struct __unique_ptr_deleter_sfinae<_Deleter&> { |
| 2380 | typedef _Deleter& __lval_ref_type; |
| 2381 | typedef _Deleter&& __bad_rval_ref_type; |
| 2382 | typedef false_type __enable_rval_overload; |
| 2383 | }; |
| 2384 | #endif // !defined(_LIBCPP_CXX03_LANG) |
| 2385 | |
| 2386 | template <class _Tp, class _Dp = default_delete<_Tp> > |
| 2387 | class _LIBCPP_TEMPLATE_VIS unique_ptr { |
| 2388 | public: |
| 2389 | typedef _Tp element_type; |
| 2390 | typedef _Dp deleter_type; |
| 2391 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2392 | |
| 2393 | static_assert(!is_rvalue_reference<deleter_type>::value, |
| 2394 | "the specified deleter type cannot be an rvalue reference"); |
| 2395 | |
| 2396 | private: |
| 2397 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 2398 | |
| 2399 | struct __nat { int __for_bool_; }; |
| 2400 | |
| 2401 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2402 | typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2403 | |
| 2404 | template <bool _Dummy> |
| 2405 | using _LValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2406 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2407 | |
| 2408 | template <bool _Dummy> |
| 2409 | using _GoodRValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2410 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2411 | |
| 2412 | template <bool _Dummy> |
| 2413 | using _BadRValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2414 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2415 | |
| 2416 | template <bool _Dummy, class _Deleter = typename __dependent_type< |
| 2417 | __identity<deleter_type>, _Dummy>::type> |
| 2418 | using _EnableIfDeleterDefaultConstructible = |
| 2419 | typename enable_if<is_default_constructible<_Deleter>::value && |
| 2420 | !is_pointer<_Deleter>::value>::type; |
| 2421 | |
| 2422 | template <class _ArgType> |
| 2423 | using _EnableIfDeleterConstructible = |
| 2424 | typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; |
| 2425 | |
| 2426 | template <class _UPtr, class _Up> |
| 2427 | using _EnableIfMoveConvertible = typename enable_if< |
| 2428 | is_convertible<typename _UPtr::pointer, pointer>::value && |
| 2429 | !is_array<_Up>::value |
| 2430 | >::type; |
| 2431 | |
| 2432 | template <class _UDel> |
| 2433 | using _EnableIfDeleterConvertible = typename enable_if< |
| 2434 | (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || |
| 2435 | (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) |
| 2436 | >::type; |
| 2437 | |
| 2438 | template <class _UDel> |
| 2439 | using _EnableIfDeleterAssignable = typename enable_if< |
| 2440 | is_assignable<_Dp&, _UDel&&>::value |
| 2441 | >::type; |
| 2442 | |
| 2443 | public: |
| 2444 | template <bool _Dummy = true, |
| 2445 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2446 | _LIBCPP_INLINE_VISIBILITY |
| 2447 | constexpr unique_ptr() noexcept : __ptr_(pointer()) {} |
| 2448 | |
| 2449 | template <bool _Dummy = true, |
| 2450 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2451 | _LIBCPP_INLINE_VISIBILITY |
| 2452 | constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} |
| 2453 | |
| 2454 | template <bool _Dummy = true, |
| 2455 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2456 | _LIBCPP_INLINE_VISIBILITY |
| 2457 | explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {} |
| 2458 | |
| 2459 | template <bool _Dummy = true, |
| 2460 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> |
| 2461 | _LIBCPP_INLINE_VISIBILITY |
| 2462 | unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept |
| 2463 | : __ptr_(__p, __d) {} |
| 2464 | |
| 2465 | template <bool _Dummy = true, |
| 2466 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> |
| 2467 | _LIBCPP_INLINE_VISIBILITY |
| 2468 | unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept |
| 2469 | : __ptr_(__p, _VSTD::move(__d)) { |
| 2470 | static_assert(!is_reference<deleter_type>::value, |
| 2471 | "rvalue deleter bound to reference"); |
| 2472 | } |
| 2473 | |
| 2474 | template <bool _Dummy = true, |
| 2475 | class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>> |
| 2476 | _LIBCPP_INLINE_VISIBILITY |
| 2477 | unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; |
| 2478 | |
| 2479 | _LIBCPP_INLINE_VISIBILITY |
| 2480 | unique_ptr(unique_ptr&& __u) noexcept |
| 2481 | : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { |
| 2482 | } |
| 2483 | |
| 2484 | template <class _Up, class _Ep, |
| 2485 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2486 | class = _EnableIfDeleterConvertible<_Ep> |
| 2487 | > |
| 2488 | _LIBCPP_INLINE_VISIBILITY |
| 2489 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT |
| 2490 | : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} |
| 2491 | |
| 2492 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 2493 | template <class _Up> |
| 2494 | _LIBCPP_INLINE_VISIBILITY |
| 2495 | unique_ptr(auto_ptr<_Up>&& __p, |
| 2496 | typename enable_if<is_convertible<_Up*, _Tp*>::value && |
| 2497 | is_same<_Dp, default_delete<_Tp>>::value, |
| 2498 | __nat>::type = __nat()) _NOEXCEPT |
| 2499 | : __ptr_(__p.release()) {} |
| 2500 | #endif |
| 2501 | |
| 2502 | _LIBCPP_INLINE_VISIBILITY |
| 2503 | unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { |
| 2504 | reset(__u.release()); |
| 2505 | __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); |
| 2506 | return *this; |
| 2507 | } |
| 2508 | |
| 2509 | template <class _Up, class _Ep, |
| 2510 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2511 | class = _EnableIfDeleterAssignable<_Ep> |
| 2512 | > |
| 2513 | _LIBCPP_INLINE_VISIBILITY |
| 2514 | unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { |
| 2515 | reset(__u.release()); |
| 2516 | __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); |
| 2517 | return *this; |
| 2518 | } |
| 2519 | |
| 2520 | #else // _LIBCPP_CXX03_LANG |
| 2521 | private: |
| 2522 | unique_ptr(unique_ptr&); |
| 2523 | template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&); |
| 2524 | |
| 2525 | unique_ptr& operator=(unique_ptr&); |
| 2526 | template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&); |
| 2527 | |
| 2528 | public: |
| 2529 | _LIBCPP_INLINE_VISIBILITY |
| 2530 | unique_ptr() : __ptr_(pointer()) |
| 2531 | { |
| 2532 | static_assert(!is_pointer<deleter_type>::value, |
| 2533 | "unique_ptr constructed with null function pointer deleter"); |
| 2534 | static_assert(is_default_constructible<deleter_type>::value, |
| 2535 | "unique_ptr::deleter_type is not default constructible"); |
| 2536 | } |
| 2537 | _LIBCPP_INLINE_VISIBILITY |
| 2538 | unique_ptr(nullptr_t) : __ptr_(pointer()) |
| 2539 | { |
| 2540 | static_assert(!is_pointer<deleter_type>::value, |
| 2541 | "unique_ptr constructed with null function pointer deleter"); |
| 2542 | } |
| 2543 | _LIBCPP_INLINE_VISIBILITY |
| 2544 | explicit unique_ptr(pointer __p) |
| 2545 | : __ptr_(_VSTD::move(__p)) { |
| 2546 | static_assert(!is_pointer<deleter_type>::value, |
| 2547 | "unique_ptr constructed with null function pointer deleter"); |
| 2548 | } |
| 2549 | |
| 2550 | _LIBCPP_INLINE_VISIBILITY |
| 2551 | operator __rv<unique_ptr>() { |
| 2552 | return __rv<unique_ptr>(*this); |
| 2553 | } |
| 2554 | |
| 2555 | _LIBCPP_INLINE_VISIBILITY |
| 2556 | unique_ptr(__rv<unique_ptr> __u) |
| 2557 | : __ptr_(__u->release(), |
| 2558 | _VSTD::forward<deleter_type>(__u->get_deleter())) {} |
| 2559 | |
| 2560 | template <class _Up, class _Ep> |
| 2561 | _LIBCPP_INLINE_VISIBILITY |
| 2562 | typename enable_if< |
| 2563 | !is_array<_Up>::value && |
| 2564 | is_convertible<typename unique_ptr<_Up, _Ep>::pointer, |
| 2565 | pointer>::value && |
| 2566 | is_assignable<deleter_type&, _Ep&>::value, |
| 2567 | unique_ptr&>::type |
| 2568 | operator=(unique_ptr<_Up, _Ep> __u) { |
| 2569 | reset(__u.release()); |
| 2570 | __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); |
| 2571 | return *this; |
| 2572 | } |
| 2573 | |
| 2574 | _LIBCPP_INLINE_VISIBILITY |
| 2575 | unique_ptr(pointer __p, deleter_type __d) |
| 2576 | : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {} |
| 2577 | #endif // _LIBCPP_CXX03_LANG |
| 2578 | |
| 2579 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 2580 | template <class _Up> |
| 2581 | _LIBCPP_INLINE_VISIBILITY |
| 2582 | typename enable_if<is_convertible<_Up*, _Tp*>::value && |
| 2583 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2584 | unique_ptr&>::type |
| 2585 | operator=(auto_ptr<_Up> __p) { |
| 2586 | reset(__p.release()); |
| 2587 | return *this; |
| 2588 | } |
| 2589 | #endif |
| 2590 | |
| 2591 | _LIBCPP_INLINE_VISIBILITY |
| 2592 | ~unique_ptr() { reset(); } |
| 2593 | |
| 2594 | _LIBCPP_INLINE_VISIBILITY |
| 2595 | unique_ptr& operator=(nullptr_t) _NOEXCEPT { |
| 2596 | reset(); |
| 2597 | return *this; |
| 2598 | } |
| 2599 | |
| 2600 | _LIBCPP_INLINE_VISIBILITY |
| 2601 | typename add_lvalue_reference<_Tp>::type |
| 2602 | operator*() const { |
| 2603 | return *__ptr_.first(); |
| 2604 | } |
| 2605 | _LIBCPP_INLINE_VISIBILITY |
| 2606 | pointer operator->() const _NOEXCEPT { |
| 2607 | return __ptr_.first(); |
| 2608 | } |
| 2609 | _LIBCPP_INLINE_VISIBILITY |
| 2610 | pointer get() const _NOEXCEPT { |
| 2611 | return __ptr_.first(); |
| 2612 | } |
| 2613 | _LIBCPP_INLINE_VISIBILITY |
| 2614 | deleter_type& get_deleter() _NOEXCEPT { |
| 2615 | return __ptr_.second(); |
| 2616 | } |
| 2617 | _LIBCPP_INLINE_VISIBILITY |
| 2618 | const deleter_type& get_deleter() const _NOEXCEPT { |
| 2619 | return __ptr_.second(); |
| 2620 | } |
| 2621 | _LIBCPP_INLINE_VISIBILITY |
| 2622 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { |
| 2623 | return __ptr_.first() != nullptr; |
| 2624 | } |
| 2625 | |
| 2626 | _LIBCPP_INLINE_VISIBILITY |
| 2627 | pointer release() _NOEXCEPT { |
| 2628 | pointer __t = __ptr_.first(); |
| 2629 | __ptr_.first() = pointer(); |
| 2630 | return __t; |
| 2631 | } |
| 2632 | |
| 2633 | _LIBCPP_INLINE_VISIBILITY |
| 2634 | void reset(pointer __p = pointer()) _NOEXCEPT { |
| 2635 | pointer __tmp = __ptr_.first(); |
| 2636 | __ptr_.first() = __p; |
| 2637 | if (__tmp) |
| 2638 | __ptr_.second()(__tmp); |
| 2639 | } |
| 2640 | |
| 2641 | _LIBCPP_INLINE_VISIBILITY |
| 2642 | void swap(unique_ptr& __u) _NOEXCEPT { |
| 2643 | __ptr_.swap(__u.__ptr_); |
| 2644 | } |
| 2645 | }; |
| 2646 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2647 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2648 | template <class _Tp, class _Dp> |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2649 | class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2650 | public: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2651 | typedef _Tp element_type; |
| 2652 | typedef _Dp deleter_type; |
| 2653 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2654 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2655 | private: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2656 | __compressed_pair<pointer, deleter_type> __ptr_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2657 | |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2658 | template <class _From> |
| 2659 | struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2660 | |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2661 | template <class _FromElem> |
| 2662 | struct _CheckArrayPointerConversion<_FromElem*> |
| 2663 | : integral_constant<bool, |
| 2664 | is_same<_FromElem*, pointer>::value || |
| 2665 | (is_same<pointer, element_type*>::value && |
| 2666 | is_convertible<_FromElem(*)[], element_type(*)[]>::value) |
| 2667 | > |
| 2668 | {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2669 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2670 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2671 | typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2672 | |
| 2673 | template <bool _Dummy> |
| 2674 | using _LValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2675 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2676 | |
| 2677 | template <bool _Dummy> |
| 2678 | using _GoodRValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2679 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2680 | |
| 2681 | template <bool _Dummy> |
| 2682 | using _BadRValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2683 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2684 | |
| 2685 | template <bool _Dummy, class _Deleter = typename __dependent_type< |
| 2686 | __identity<deleter_type>, _Dummy>::type> |
| 2687 | using _EnableIfDeleterDefaultConstructible = |
| 2688 | typename enable_if<is_default_constructible<_Deleter>::value && |
| 2689 | !is_pointer<_Deleter>::value>::type; |
| 2690 | |
| 2691 | template <class _ArgType> |
| 2692 | using _EnableIfDeleterConstructible = |
| 2693 | typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; |
| 2694 | |
| 2695 | template <class _Pp> |
| 2696 | using _EnableIfPointerConvertible = typename enable_if< |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2697 | _CheckArrayPointerConversion<_Pp>::value |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2698 | >::type; |
| 2699 | |
| 2700 | template <class _UPtr, class _Up, |
| 2701 | class _ElemT = typename _UPtr::element_type> |
| 2702 | using _EnableIfMoveConvertible = typename enable_if< |
| 2703 | is_array<_Up>::value && |
| 2704 | is_same<pointer, element_type*>::value && |
| 2705 | is_same<typename _UPtr::pointer, _ElemT*>::value && |
| 2706 | is_convertible<_ElemT(*)[], element_type(*)[]>::value |
| 2707 | >::type; |
| 2708 | |
| 2709 | template <class _UDel> |
| 2710 | using _EnableIfDeleterConvertible = typename enable_if< |
| 2711 | (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || |
| 2712 | (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) |
| 2713 | >::type; |
| 2714 | |
| 2715 | template <class _UDel> |
| 2716 | using _EnableIfDeleterAssignable = typename enable_if< |
| 2717 | is_assignable<_Dp&, _UDel&&>::value |
| 2718 | >::type; |
| 2719 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2720 | public: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2721 | template <bool _Dummy = true, |
| 2722 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2723 | _LIBCPP_INLINE_VISIBILITY |
| 2724 | constexpr unique_ptr() noexcept : __ptr_(pointer()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2725 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2726 | template <bool _Dummy = true, |
| 2727 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2728 | _LIBCPP_INLINE_VISIBILITY |
| 2729 | constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2730 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2731 | template <class _Pp, bool _Dummy = true, |
| 2732 | class = _EnableIfDeleterDefaultConstructible<_Dummy>, |
| 2733 | class = _EnableIfPointerConvertible<_Pp>> |
| 2734 | _LIBCPP_INLINE_VISIBILITY |
| 2735 | explicit unique_ptr(_Pp __p) noexcept |
| 2736 | : __ptr_(__p) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2737 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2738 | template <class _Pp, bool _Dummy = true, |
| 2739 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>, |
| 2740 | class = _EnableIfPointerConvertible<_Pp>> |
| 2741 | _LIBCPP_INLINE_VISIBILITY |
| 2742 | unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept |
| 2743 | : __ptr_(__p, __d) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2744 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2745 | template <bool _Dummy = true, |
| 2746 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> |
| 2747 | _LIBCPP_INLINE_VISIBILITY |
| 2748 | unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept |
| 2749 | : __ptr_(nullptr, __d) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2750 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2751 | template <class _Pp, bool _Dummy = true, |
| 2752 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>, |
| 2753 | class = _EnableIfPointerConvertible<_Pp>> |
| 2754 | _LIBCPP_INLINE_VISIBILITY |
| 2755 | unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept |
| 2756 | : __ptr_(__p, _VSTD::move(__d)) { |
| 2757 | static_assert(!is_reference<deleter_type>::value, |
| 2758 | "rvalue deleter bound to reference"); |
| 2759 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2760 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2761 | template <bool _Dummy = true, |
| 2762 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> |
| 2763 | _LIBCPP_INLINE_VISIBILITY |
| 2764 | unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept |
| 2765 | : __ptr_(nullptr, _VSTD::move(__d)) { |
| 2766 | static_assert(!is_reference<deleter_type>::value, |
| 2767 | "rvalue deleter bound to reference"); |
| 2768 | } |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2769 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2770 | template <class _Pp, bool _Dummy = true, |
| 2771 | class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>, |
| 2772 | class = _EnableIfPointerConvertible<_Pp>> |
| 2773 | _LIBCPP_INLINE_VISIBILITY |
| 2774 | unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2775 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2776 | _LIBCPP_INLINE_VISIBILITY |
| 2777 | unique_ptr(unique_ptr&& __u) noexcept |
| 2778 | : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { |
| 2779 | } |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2780 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2781 | _LIBCPP_INLINE_VISIBILITY |
| 2782 | unique_ptr& operator=(unique_ptr&& __u) noexcept { |
| 2783 | reset(__u.release()); |
| 2784 | __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); |
| 2785 | return *this; |
| 2786 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2787 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2788 | template <class _Up, class _Ep, |
| 2789 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2790 | class = _EnableIfDeleterConvertible<_Ep> |
| 2791 | > |
| 2792 | _LIBCPP_INLINE_VISIBILITY |
| 2793 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
Eric Fiselier | 3827e6a | 2017-04-17 20:20:27 +0000 | [diff] [blame] | 2794 | : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2795 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2796 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2797 | template <class _Up, class _Ep, |
| 2798 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2799 | class = _EnableIfDeleterAssignable<_Ep> |
| 2800 | > |
| 2801 | _LIBCPP_INLINE_VISIBILITY |
| 2802 | unique_ptr& |
| 2803 | operator=(unique_ptr<_Up, _Ep>&& __u) noexcept { |
| 2804 | reset(__u.release()); |
| 2805 | __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); |
| 2806 | return *this; |
| 2807 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2808 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2809 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2810 | private: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2811 | template <class _Up> explicit unique_ptr(_Up); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2812 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2813 | unique_ptr(unique_ptr&); |
| 2814 | template <class _Up> unique_ptr(unique_ptr<_Up>&); |
| 2815 | |
| 2816 | unique_ptr& operator=(unique_ptr&); |
| 2817 | template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&); |
| 2818 | |
| 2819 | template <class _Up> |
| 2820 | unique_ptr(_Up __u, |
| 2821 | typename conditional< |
| 2822 | is_reference<deleter_type>::value, deleter_type, |
| 2823 | typename add_lvalue_reference<const deleter_type>::type>::type, |
| 2824 | typename enable_if<is_convertible<_Up, pointer>::value, |
| 2825 | __nat>::type = __nat()); |
| 2826 | public: |
| 2827 | _LIBCPP_INLINE_VISIBILITY |
| 2828 | unique_ptr() : __ptr_(pointer()) { |
| 2829 | static_assert(!is_pointer<deleter_type>::value, |
| 2830 | "unique_ptr constructed with null function pointer deleter"); |
| 2831 | } |
| 2832 | _LIBCPP_INLINE_VISIBILITY |
| 2833 | unique_ptr(nullptr_t) : __ptr_(pointer()) { |
| 2834 | static_assert(!is_pointer<deleter_type>::value, |
| 2835 | "unique_ptr constructed with null function pointer deleter"); |
| 2836 | } |
| 2837 | |
| 2838 | _LIBCPP_INLINE_VISIBILITY |
| 2839 | explicit unique_ptr(pointer __p) : __ptr_(__p) { |
| 2840 | static_assert(!is_pointer<deleter_type>::value, |
| 2841 | "unique_ptr constructed with null function pointer deleter"); |
| 2842 | } |
| 2843 | |
| 2844 | _LIBCPP_INLINE_VISIBILITY |
| 2845 | unique_ptr(pointer __p, deleter_type __d) |
| 2846 | : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {} |
| 2847 | |
| 2848 | _LIBCPP_INLINE_VISIBILITY |
| 2849 | unique_ptr(nullptr_t, deleter_type __d) |
| 2850 | : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {} |
| 2851 | |
| 2852 | _LIBCPP_INLINE_VISIBILITY |
| 2853 | operator __rv<unique_ptr>() { |
| 2854 | return __rv<unique_ptr>(*this); |
| 2855 | } |
| 2856 | |
| 2857 | _LIBCPP_INLINE_VISIBILITY |
| 2858 | unique_ptr(__rv<unique_ptr> __u) |
| 2859 | : __ptr_(__u->release(), |
| 2860 | _VSTD::forward<deleter_type>(__u->get_deleter())) {} |
| 2861 | |
| 2862 | _LIBCPP_INLINE_VISIBILITY |
| 2863 | unique_ptr& operator=(__rv<unique_ptr> __u) { |
| 2864 | reset(__u->release()); |
| 2865 | __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter()); |
| 2866 | return *this; |
| 2867 | } |
| 2868 | |
| 2869 | #endif // _LIBCPP_CXX03_LANG |
| 2870 | |
| 2871 | public: |
| 2872 | _LIBCPP_INLINE_VISIBILITY |
| 2873 | ~unique_ptr() { reset(); } |
| 2874 | |
| 2875 | _LIBCPP_INLINE_VISIBILITY |
| 2876 | unique_ptr& operator=(nullptr_t) _NOEXCEPT { |
| 2877 | reset(); |
| 2878 | return *this; |
| 2879 | } |
| 2880 | |
| 2881 | _LIBCPP_INLINE_VISIBILITY |
| 2882 | typename add_lvalue_reference<_Tp>::type |
| 2883 | operator[](size_t __i) const { |
| 2884 | return __ptr_.first()[__i]; |
| 2885 | } |
| 2886 | _LIBCPP_INLINE_VISIBILITY |
| 2887 | pointer get() const _NOEXCEPT { |
| 2888 | return __ptr_.first(); |
| 2889 | } |
| 2890 | |
| 2891 | _LIBCPP_INLINE_VISIBILITY |
| 2892 | deleter_type& get_deleter() _NOEXCEPT { |
| 2893 | return __ptr_.second(); |
| 2894 | } |
| 2895 | |
| 2896 | _LIBCPP_INLINE_VISIBILITY |
| 2897 | const deleter_type& get_deleter() const _NOEXCEPT { |
| 2898 | return __ptr_.second(); |
| 2899 | } |
| 2900 | _LIBCPP_INLINE_VISIBILITY |
| 2901 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { |
| 2902 | return __ptr_.first() != nullptr; |
| 2903 | } |
| 2904 | |
| 2905 | _LIBCPP_INLINE_VISIBILITY |
| 2906 | pointer release() _NOEXCEPT { |
| 2907 | pointer __t = __ptr_.first(); |
| 2908 | __ptr_.first() = pointer(); |
| 2909 | return __t; |
| 2910 | } |
| 2911 | |
| 2912 | template <class _Pp> |
| 2913 | _LIBCPP_INLINE_VISIBILITY |
| 2914 | typename enable_if< |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2915 | _CheckArrayPointerConversion<_Pp>::value |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2916 | >::type |
| 2917 | reset(_Pp __p) _NOEXCEPT { |
| 2918 | pointer __tmp = __ptr_.first(); |
| 2919 | __ptr_.first() = __p; |
| 2920 | if (__tmp) |
| 2921 | __ptr_.second()(__tmp); |
| 2922 | } |
| 2923 | |
| 2924 | _LIBCPP_INLINE_VISIBILITY |
| 2925 | void reset(nullptr_t = nullptr) _NOEXCEPT { |
| 2926 | pointer __tmp = __ptr_.first(); |
| 2927 | __ptr_.first() = nullptr; |
| 2928 | if (__tmp) |
| 2929 | __ptr_.second()(__tmp); |
| 2930 | } |
| 2931 | |
| 2932 | _LIBCPP_INLINE_VISIBILITY |
| 2933 | void swap(unique_ptr& __u) _NOEXCEPT { |
| 2934 | __ptr_.swap(__u.__ptr_); |
| 2935 | } |
| 2936 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2937 | }; |
| 2938 | |
| 2939 | template <class _Tp, class _Dp> |
| 2940 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6bfed25 | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 2941 | typename enable_if< |
| 2942 | __is_swappable<_Dp>::value, |
| 2943 | void |
| 2944 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2945 | swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2946 | |
| 2947 | template <class _T1, class _D1, class _T2, class _D2> |
| 2948 | inline _LIBCPP_INLINE_VISIBILITY |
| 2949 | bool |
| 2950 | operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} |
| 2951 | |
| 2952 | template <class _T1, class _D1, class _T2, class _D2> |
| 2953 | inline _LIBCPP_INLINE_VISIBILITY |
| 2954 | bool |
| 2955 | operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} |
| 2956 | |
| 2957 | template <class _T1, class _D1, class _T2, class _D2> |
| 2958 | inline _LIBCPP_INLINE_VISIBILITY |
| 2959 | bool |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2960 | operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) |
| 2961 | { |
| 2962 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 2963 | typedef typename unique_ptr<_T2, _D2>::pointer _P2; |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 2964 | typedef typename common_type<_P1, _P2>::type _Vp; |
| 2965 | return less<_Vp>()(__x.get(), __y.get()); |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2966 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2967 | |
| 2968 | template <class _T1, class _D1, class _T2, class _D2> |
| 2969 | inline _LIBCPP_INLINE_VISIBILITY |
| 2970 | bool |
| 2971 | operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} |
| 2972 | |
| 2973 | template <class _T1, class _D1, class _T2, class _D2> |
| 2974 | inline _LIBCPP_INLINE_VISIBILITY |
| 2975 | bool |
| 2976 | operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} |
| 2977 | |
| 2978 | template <class _T1, class _D1, class _T2, class _D2> |
| 2979 | inline _LIBCPP_INLINE_VISIBILITY |
| 2980 | bool |
| 2981 | operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} |
| 2982 | |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2983 | template <class _T1, class _D1> |
| 2984 | inline _LIBCPP_INLINE_VISIBILITY |
| 2985 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2986 | operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2987 | { |
| 2988 | return !__x; |
| 2989 | } |
| 2990 | |
| 2991 | template <class _T1, class _D1> |
| 2992 | inline _LIBCPP_INLINE_VISIBILITY |
| 2993 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2994 | operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2995 | { |
| 2996 | return !__x; |
| 2997 | } |
| 2998 | |
| 2999 | template <class _T1, class _D1> |
| 3000 | inline _LIBCPP_INLINE_VISIBILITY |
| 3001 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3002 | operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 3003 | { |
| 3004 | return static_cast<bool>(__x); |
| 3005 | } |
| 3006 | |
| 3007 | template <class _T1, class _D1> |
| 3008 | inline _LIBCPP_INLINE_VISIBILITY |
| 3009 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3010 | operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 3011 | { |
| 3012 | return static_cast<bool>(__x); |
| 3013 | } |
| 3014 | |
| 3015 | template <class _T1, class _D1> |
| 3016 | inline _LIBCPP_INLINE_VISIBILITY |
| 3017 | bool |
| 3018 | operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3019 | { |
| 3020 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 3021 | return less<_P1>()(__x.get(), nullptr); |
| 3022 | } |
| 3023 | |
| 3024 | template <class _T1, class _D1> |
| 3025 | inline _LIBCPP_INLINE_VISIBILITY |
| 3026 | bool |
| 3027 | operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3028 | { |
| 3029 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 3030 | return less<_P1>()(nullptr, __x.get()); |
| 3031 | } |
| 3032 | |
| 3033 | template <class _T1, class _D1> |
| 3034 | inline _LIBCPP_INLINE_VISIBILITY |
| 3035 | bool |
| 3036 | operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3037 | { |
| 3038 | return nullptr < __x; |
| 3039 | } |
| 3040 | |
| 3041 | template <class _T1, class _D1> |
| 3042 | inline _LIBCPP_INLINE_VISIBILITY |
| 3043 | bool |
| 3044 | operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3045 | { |
| 3046 | return __x < nullptr; |
| 3047 | } |
| 3048 | |
| 3049 | template <class _T1, class _D1> |
| 3050 | inline _LIBCPP_INLINE_VISIBILITY |
| 3051 | bool |
| 3052 | operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3053 | { |
| 3054 | return !(nullptr < __x); |
| 3055 | } |
| 3056 | |
| 3057 | template <class _T1, class _D1> |
| 3058 | inline _LIBCPP_INLINE_VISIBILITY |
| 3059 | bool |
| 3060 | operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3061 | { |
| 3062 | return !(__x < nullptr); |
| 3063 | } |
| 3064 | |
| 3065 | template <class _T1, class _D1> |
| 3066 | inline _LIBCPP_INLINE_VISIBILITY |
| 3067 | bool |
| 3068 | operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3069 | { |
| 3070 | return !(__x < nullptr); |
| 3071 | } |
| 3072 | |
| 3073 | template <class _T1, class _D1> |
| 3074 | inline _LIBCPP_INLINE_VISIBILITY |
| 3075 | bool |
| 3076 | operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3077 | { |
| 3078 | return !(nullptr < __x); |
| 3079 | } |
| 3080 | |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 3081 | #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 3082 | |
| 3083 | template <class _Tp, class _Dp> |
| 3084 | inline _LIBCPP_INLINE_VISIBILITY |
| 3085 | unique_ptr<_Tp, _Dp> |
| 3086 | move(unique_ptr<_Tp, _Dp>& __t) |
| 3087 | { |
| 3088 | return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t)); |
| 3089 | } |
| 3090 | |
| 3091 | #endif |
| 3092 | |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3093 | #if _LIBCPP_STD_VER > 11 |
| 3094 | |
| 3095 | template<class _Tp> |
| 3096 | struct __unique_if |
| 3097 | { |
| 3098 | typedef unique_ptr<_Tp> __unique_single; |
| 3099 | }; |
| 3100 | |
| 3101 | template<class _Tp> |
| 3102 | struct __unique_if<_Tp[]> |
| 3103 | { |
| 3104 | typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; |
| 3105 | }; |
| 3106 | |
| 3107 | template<class _Tp, size_t _Np> |
| 3108 | struct __unique_if<_Tp[_Np]> |
| 3109 | { |
| 3110 | typedef void __unique_array_known_bound; |
| 3111 | }; |
| 3112 | |
| 3113 | template<class _Tp, class... _Args> |
Marshall Clow | 724e3df | 2013-07-02 20:06:09 +0000 | [diff] [blame] | 3114 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3115 | typename __unique_if<_Tp>::__unique_single |
| 3116 | make_unique(_Args&&... __args) |
| 3117 | { |
| 3118 | return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); |
| 3119 | } |
| 3120 | |
| 3121 | template<class _Tp> |
Marshall Clow | 724e3df | 2013-07-02 20:06:09 +0000 | [diff] [blame] | 3122 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3123 | typename __unique_if<_Tp>::__unique_array_unknown_bound |
| 3124 | make_unique(size_t __n) |
| 3125 | { |
| 3126 | typedef typename remove_extent<_Tp>::type _Up; |
| 3127 | return unique_ptr<_Tp>(new _Up[__n]()); |
| 3128 | } |
| 3129 | |
| 3130 | template<class _Tp, class... _Args> |
| 3131 | typename __unique_if<_Tp>::__unique_array_known_bound |
| 3132 | make_unique(_Args&&...) = delete; |
| 3133 | |
| 3134 | #endif // _LIBCPP_STD_VER > 11 |
| 3135 | |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3136 | template <class _Tp, class _Dp> |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 3137 | #ifdef _LIBCPP_CXX03_LANG |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3138 | struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> > |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 3139 | #else |
| 3140 | struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< |
| 3141 | unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>> |
| 3142 | #endif |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3143 | { |
| 3144 | typedef unique_ptr<_Tp, _Dp> argument_type; |
| 3145 | typedef size_t result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3146 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4903689 | 2017-03-23 02:40:28 +0000 | [diff] [blame] | 3147 | result_type operator()(const argument_type& __ptr) const |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3148 | { |
| 3149 | typedef typename argument_type::pointer pointer; |
| 3150 | return hash<pointer>()(__ptr.get()); |
| 3151 | } |
| 3152 | }; |
| 3153 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3154 | struct __destruct_n |
| 3155 | { |
| 3156 | private: |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3157 | size_t __size_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3158 | |
| 3159 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3160 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3161 | {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3162 | |
| 3163 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3164 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3165 | {} |
| 3166 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3167 | _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3168 | {++__size_;} |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3169 | _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3170 | {} |
| 3171 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3172 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3173 | {__size_ = __s;} |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3174 | _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3175 | {} |
| 3176 | public: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3177 | _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3178 | : __size_(__s) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3179 | |
| 3180 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3181 | _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3182 | {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3183 | |
| 3184 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3185 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3186 | {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3187 | |
| 3188 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3189 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3190 | {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3191 | }; |
| 3192 | |
| 3193 | template <class _Alloc> |
| 3194 | class __allocator_destructor |
| 3195 | { |
| 3196 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 3197 | public: |
| 3198 | typedef typename __alloc_traits::pointer pointer; |
| 3199 | typedef typename __alloc_traits::size_type size_type; |
| 3200 | private: |
| 3201 | _Alloc& __alloc_; |
| 3202 | size_type __s_; |
| 3203 | public: |
| 3204 | _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3205 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3206 | : __alloc_(__a), __s_(__s) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3207 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3208 | void operator()(pointer __p) _NOEXCEPT |
| 3209 | {__alloc_traits::deallocate(__alloc_, __p, __s_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3210 | }; |
| 3211 | |
| 3212 | template <class _InputIterator, class _ForwardIterator> |
| 3213 | _ForwardIterator |
| 3214 | uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) |
| 3215 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3216 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3217 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3218 | _ForwardIterator __s = __r; |
| 3219 | try |
| 3220 | { |
| 3221 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3222 | for (; __f != __l; ++__f, (void) ++__r) |
| 3223 | ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3224 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3225 | } |
| 3226 | catch (...) |
| 3227 | { |
| 3228 | for (; __s != __r; ++__s) |
| 3229 | __s->~value_type(); |
| 3230 | throw; |
| 3231 | } |
| 3232 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3233 | return __r; |
| 3234 | } |
| 3235 | |
| 3236 | template <class _InputIterator, class _Size, class _ForwardIterator> |
| 3237 | _ForwardIterator |
| 3238 | uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) |
| 3239 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3240 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3241 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3242 | _ForwardIterator __s = __r; |
| 3243 | try |
| 3244 | { |
| 3245 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3246 | for (; __n > 0; ++__f, (void) ++__r, (void) --__n) |
| 3247 | ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3248 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3249 | } |
| 3250 | catch (...) |
| 3251 | { |
| 3252 | for (; __s != __r; ++__s) |
| 3253 | __s->~value_type(); |
| 3254 | throw; |
| 3255 | } |
| 3256 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3257 | return __r; |
| 3258 | } |
| 3259 | |
| 3260 | template <class _ForwardIterator, class _Tp> |
| 3261 | void |
| 3262 | uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) |
| 3263 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3264 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3265 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3266 | _ForwardIterator __s = __f; |
| 3267 | try |
| 3268 | { |
| 3269 | #endif |
| 3270 | for (; __f != __l; ++__f) |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3271 | ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3272 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3273 | } |
| 3274 | catch (...) |
| 3275 | { |
| 3276 | for (; __s != __f; ++__s) |
| 3277 | __s->~value_type(); |
| 3278 | throw; |
| 3279 | } |
| 3280 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | template <class _ForwardIterator, class _Size, class _Tp> |
Howard Hinnant | 3c81109 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 3284 | _ForwardIterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3285 | uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) |
| 3286 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3287 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3288 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3289 | _ForwardIterator __s = __f; |
| 3290 | try |
| 3291 | { |
| 3292 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3293 | for (; __n > 0; ++__f, (void) --__n) |
| 3294 | ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3295 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3296 | } |
| 3297 | catch (...) |
| 3298 | { |
| 3299 | for (; __s != __f; ++__s) |
| 3300 | __s->~value_type(); |
| 3301 | throw; |
| 3302 | } |
| 3303 | #endif |
Howard Hinnant | 3c81109 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 3304 | return __f; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3305 | } |
| 3306 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3307 | #if _LIBCPP_STD_VER > 14 |
| 3308 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3309 | template <class _Tp> |
| 3310 | inline _LIBCPP_INLINE_VISIBILITY |
| 3311 | void destroy_at(_Tp* __loc) { |
| 3312 | _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); |
| 3313 | __loc->~_Tp(); |
| 3314 | } |
| 3315 | |
| 3316 | template <class _ForwardIterator> |
| 3317 | inline _LIBCPP_INLINE_VISIBILITY |
| 3318 | void destroy(_ForwardIterator __first, _ForwardIterator __last) { |
| 3319 | for (; __first != __last; ++__first) |
| 3320 | _VSTD::destroy_at(_VSTD::addressof(*__first)); |
| 3321 | } |
| 3322 | |
| 3323 | template <class _ForwardIterator, class _Size> |
| 3324 | inline _LIBCPP_INLINE_VISIBILITY |
| 3325 | _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { |
| 3326 | for (; __n > 0; (void)++__first, --__n) |
| 3327 | _VSTD::destroy_at(_VSTD::addressof(*__first)); |
| 3328 | return __first; |
| 3329 | } |
| 3330 | |
Eric Fiselier | 290c07c | 2016-10-11 21:13:44 +0000 | [diff] [blame] | 3331 | template <class _ForwardIterator> |
| 3332 | inline _LIBCPP_INLINE_VISIBILITY |
| 3333 | void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { |
| 3334 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3335 | auto __idx = __first; |
| 3336 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3337 | try { |
| 3338 | #endif |
| 3339 | for (; __idx != __last; ++__idx) |
| 3340 | ::new((void*)_VSTD::addressof(*__idx)) _Vt; |
| 3341 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3342 | } catch (...) { |
| 3343 | _VSTD::destroy(__first, __idx); |
| 3344 | throw; |
| 3345 | } |
| 3346 | #endif |
| 3347 | } |
| 3348 | |
| 3349 | template <class _ForwardIterator, class _Size> |
| 3350 | inline _LIBCPP_INLINE_VISIBILITY |
| 3351 | _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { |
| 3352 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3353 | auto __idx = __first; |
| 3354 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3355 | try { |
| 3356 | #endif |
| 3357 | for (; __n > 0; (void)++__idx, --__n) |
| 3358 | ::new((void*)_VSTD::addressof(*__idx)) _Vt; |
| 3359 | return __idx; |
| 3360 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3361 | } catch (...) { |
| 3362 | _VSTD::destroy(__first, __idx); |
| 3363 | throw; |
| 3364 | } |
| 3365 | #endif |
| 3366 | } |
| 3367 | |
| 3368 | |
| 3369 | template <class _ForwardIterator> |
| 3370 | inline _LIBCPP_INLINE_VISIBILITY |
| 3371 | void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { |
| 3372 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3373 | auto __idx = __first; |
| 3374 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3375 | try { |
| 3376 | #endif |
| 3377 | for (; __idx != __last; ++__idx) |
| 3378 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(); |
| 3379 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3380 | } catch (...) { |
| 3381 | _VSTD::destroy(__first, __idx); |
| 3382 | throw; |
| 3383 | } |
| 3384 | #endif |
| 3385 | } |
| 3386 | |
| 3387 | template <class _ForwardIterator, class _Size> |
| 3388 | inline _LIBCPP_INLINE_VISIBILITY |
| 3389 | _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { |
| 3390 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3391 | auto __idx = __first; |
| 3392 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3393 | try { |
| 3394 | #endif |
| 3395 | for (; __n > 0; (void)++__idx, --__n) |
| 3396 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(); |
| 3397 | return __idx; |
| 3398 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3399 | } catch (...) { |
| 3400 | _VSTD::destroy(__first, __idx); |
| 3401 | throw; |
| 3402 | } |
| 3403 | #endif |
| 3404 | } |
| 3405 | |
| 3406 | |
| 3407 | template <class _InputIt, class _ForwardIt> |
| 3408 | inline _LIBCPP_INLINE_VISIBILITY |
| 3409 | _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) { |
| 3410 | using _Vt = typename iterator_traits<_ForwardIt>::value_type; |
| 3411 | auto __idx = __first_res; |
| 3412 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3413 | try { |
| 3414 | #endif |
| 3415 | for (; __first != __last; (void)++__idx, ++__first) |
| 3416 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); |
| 3417 | return __idx; |
| 3418 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3419 | } catch (...) { |
| 3420 | _VSTD::destroy(__first_res, __idx); |
| 3421 | throw; |
| 3422 | } |
| 3423 | #endif |
| 3424 | } |
| 3425 | |
| 3426 | template <class _InputIt, class _Size, class _ForwardIt> |
| 3427 | inline _LIBCPP_INLINE_VISIBILITY |
| 3428 | pair<_InputIt, _ForwardIt> |
| 3429 | uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { |
| 3430 | using _Vt = typename iterator_traits<_ForwardIt>::value_type; |
| 3431 | auto __idx = __first_res; |
| 3432 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3433 | try { |
| 3434 | #endif |
| 3435 | for (; __n > 0; ++__idx, (void)++__first, --__n) |
| 3436 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); |
| 3437 | return {__first, __idx}; |
| 3438 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3439 | } catch (...) { |
| 3440 | _VSTD::destroy(__first_res, __idx); |
| 3441 | throw; |
| 3442 | } |
| 3443 | #endif |
| 3444 | } |
| 3445 | |
| 3446 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3447 | #endif // _LIBCPP_STD_VER > 14 |
| 3448 | |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3449 | // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) |
| 3450 | // should be sufficient for thread safety. |
Eric Fiselier | 5d60401 | 2017-02-17 08:37:03 +0000 | [diff] [blame] | 3451 | // See https://bugs.llvm.org/show_bug.cgi?id=22803 |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3452 | #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \ |
| 3453 | && defined(__ATOMIC_RELAXED) \ |
| 3454 | && defined(__ATOMIC_ACQ_REL) |
| 3455 | # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT |
| 3456 | #elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407 |
| 3457 | # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT |
| 3458 | #endif |
| 3459 | |
| 3460 | template <class _Tp> |
| 3461 | inline _LIBCPP_INLINE_VISIBILITY _Tp |
| 3462 | __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT |
| 3463 | { |
| 3464 | #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) |
| 3465 | return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED); |
| 3466 | #else |
| 3467 | return __t += 1; |
| 3468 | #endif |
| 3469 | } |
| 3470 | |
| 3471 | template <class _Tp> |
| 3472 | inline _LIBCPP_INLINE_VISIBILITY _Tp |
| 3473 | __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT |
| 3474 | { |
| 3475 | #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) |
| 3476 | return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); |
| 3477 | #else |
| 3478 | return __t -= 1; |
| 3479 | #endif |
| 3480 | } |
| 3481 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3482 | class _LIBCPP_EXCEPTION_ABI bad_weak_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3483 | : public std::exception |
| 3484 | { |
| 3485 | public: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3486 | virtual ~bad_weak_ptr() _NOEXCEPT; |
| 3487 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3488 | }; |
| 3489 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 3490 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 3491 | void __throw_bad_weak_ptr() |
| 3492 | { |
| 3493 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3494 | throw bad_weak_ptr(); |
| 3495 | #else |
| 3496 | _VSTD::abort(); |
| 3497 | #endif |
| 3498 | } |
| 3499 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3500 | template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3501 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3502 | class _LIBCPP_TYPE_VIS __shared_count |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3503 | { |
| 3504 | __shared_count(const __shared_count&); |
| 3505 | __shared_count& operator=(const __shared_count&); |
| 3506 | |
| 3507 | protected: |
| 3508 | long __shared_owners_; |
| 3509 | virtual ~__shared_count(); |
| 3510 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3511 | virtual void __on_zero_shared() _NOEXCEPT = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3512 | |
| 3513 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3515 | explicit __shared_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3516 | : __shared_owners_(__refs) {} |
| 3517 | |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 3518 | #if defined(_LIBCPP_BUILDING_LIBRARY) && \ |
Eric Fiselier | 9884857 | 2017-01-17 03:16:26 +0000 | [diff] [blame] | 3519 | defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) |
Eric Fiselier | e0700ff | 2017-01-17 03:05:31 +0000 | [diff] [blame] | 3520 | void __add_shared() _NOEXCEPT; |
| 3521 | bool __release_shared() _NOEXCEPT; |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3522 | #else |
| 3523 | _LIBCPP_INLINE_VISIBILITY |
| 3524 | void __add_shared() _NOEXCEPT { |
| 3525 | __libcpp_atomic_refcount_increment(__shared_owners_); |
| 3526 | } |
| 3527 | _LIBCPP_INLINE_VISIBILITY |
| 3528 | bool __release_shared() _NOEXCEPT { |
| 3529 | if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { |
| 3530 | __on_zero_shared(); |
| 3531 | return true; |
| 3532 | } |
| 3533 | return false; |
| 3534 | } |
| 3535 | #endif |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3536 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 89659d1 | 2015-07-07 00:27:16 +0000 | [diff] [blame] | 3537 | long use_count() const _NOEXCEPT { |
| 3538 | return __libcpp_relaxed_load(&__shared_owners_) + 1; |
| 3539 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3540 | }; |
| 3541 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3542 | class _LIBCPP_TYPE_VIS __shared_weak_count |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3543 | : private __shared_count |
| 3544 | { |
| 3545 | long __shared_weak_owners_; |
| 3546 | |
| 3547 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3548 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3549 | explicit __shared_weak_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3550 | : __shared_count(__refs), |
| 3551 | __shared_weak_owners_(__refs) {} |
| 3552 | protected: |
| 3553 | virtual ~__shared_weak_count(); |
| 3554 | |
| 3555 | public: |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 3556 | #if defined(_LIBCPP_BUILDING_LIBRARY) && \ |
Eric Fiselier | 9884857 | 2017-01-17 03:16:26 +0000 | [diff] [blame] | 3557 | defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) |
Eric Fiselier | e0700ff | 2017-01-17 03:05:31 +0000 | [diff] [blame] | 3558 | void __add_shared() _NOEXCEPT; |
| 3559 | void __add_weak() _NOEXCEPT; |
| 3560 | void __release_shared() _NOEXCEPT; |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3561 | #else |
| 3562 | _LIBCPP_INLINE_VISIBILITY |
| 3563 | void __add_shared() _NOEXCEPT { |
| 3564 | __shared_count::__add_shared(); |
| 3565 | } |
| 3566 | _LIBCPP_INLINE_VISIBILITY |
| 3567 | void __add_weak() _NOEXCEPT { |
| 3568 | __libcpp_atomic_refcount_increment(__shared_weak_owners_); |
| 3569 | } |
| 3570 | _LIBCPP_INLINE_VISIBILITY |
| 3571 | void __release_shared() _NOEXCEPT { |
| 3572 | if (__shared_count::__release_shared()) |
| 3573 | __release_weak(); |
| 3574 | } |
| 3575 | #endif |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3576 | void __release_weak() _NOEXCEPT; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3577 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3578 | long use_count() const _NOEXCEPT {return __shared_count::use_count();} |
| 3579 | __shared_weak_count* lock() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3580 | |
Howard Hinnant | 807d633 | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 3581 | // Define the function out only if we build static libc++ without RTTI. |
| 3582 | // Otherwise we may break clients who need to compile their projects with |
| 3583 | // -fno-rtti and yet link against a libc++.dylib compiled |
| 3584 | // without -fno-rtti. |
| 3585 | #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3586 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | 807d633 | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 3587 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3588 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3589 | virtual void __on_zero_shared_weak() _NOEXCEPT = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3590 | }; |
| 3591 | |
| 3592 | template <class _Tp, class _Dp, class _Alloc> |
| 3593 | class __shared_ptr_pointer |
| 3594 | : public __shared_weak_count |
| 3595 | { |
| 3596 | __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; |
| 3597 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3598 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3599 | __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3600 | : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3601 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3602 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3603 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3604 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3605 | |
| 3606 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3607 | virtual void __on_zero_shared() _NOEXCEPT; |
| 3608 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3609 | }; |
| 3610 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3611 | #ifndef _LIBCPP_NO_RTTI |
| 3612 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3613 | template <class _Tp, class _Dp, class _Alloc> |
| 3614 | const void* |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3615 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3616 | { |
Eric Fiselier | c7490d0 | 2017-05-04 01:06:56 +0000 | [diff] [blame] | 3617 | return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3620 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3621 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3622 | template <class _Tp, class _Dp, class _Alloc> |
| 3623 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3624 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3625 | { |
| 3626 | __data_.first().second()(__data_.first().first()); |
| 3627 | __data_.first().second().~_Dp(); |
| 3628 | } |
| 3629 | |
| 3630 | template <class _Tp, class _Dp, class _Alloc> |
| 3631 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3632 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3633 | { |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3634 | typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; |
| 3635 | typedef allocator_traits<_Al> _ATraits; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3636 | typedef pointer_traits<typename _ATraits::pointer> _PTraits; |
| 3637 | |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3638 | _Al __a(__data_.second()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3639 | __data_.second().~_Alloc(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3640 | __a.deallocate(_PTraits::pointer_to(*this), 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | template <class _Tp, class _Alloc> |
| 3644 | class __shared_ptr_emplace |
| 3645 | : public __shared_weak_count |
| 3646 | { |
| 3647 | __compressed_pair<_Alloc, _Tp> __data_; |
| 3648 | public: |
| 3649 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3650 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3651 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3652 | __shared_ptr_emplace(_Alloc __a) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3653 | : __data_(_VSTD::move(__a)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3654 | |
| 3655 | template <class ..._Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3656 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3657 | __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 3658 | : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), |
| 3659 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3660 | |
| 3661 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3662 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3663 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3664 | __shared_ptr_emplace(_Alloc __a) |
| 3665 | : __data_(__a) {} |
| 3666 | |
| 3667 | template <class _A0> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3668 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3669 | __shared_ptr_emplace(_Alloc __a, _A0& __a0) |
| 3670 | : __data_(__a, _Tp(__a0)) {} |
| 3671 | |
| 3672 | template <class _A0, class _A1> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3673 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3674 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) |
| 3675 | : __data_(__a, _Tp(__a0, __a1)) {} |
| 3676 | |
| 3677 | template <class _A0, class _A1, class _A2> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3678 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3679 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3680 | : __data_(__a, _Tp(__a0, __a1, __a2)) {} |
| 3681 | |
| 3682 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3683 | |
| 3684 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3685 | virtual void __on_zero_shared() _NOEXCEPT; |
| 3686 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3687 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3688 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | bdfdea8 | 2018-08-28 13:29:30 +0000 | [diff] [blame] | 3689 | _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3690 | }; |
| 3691 | |
| 3692 | template <class _Tp, class _Alloc> |
| 3693 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3694 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3695 | { |
| 3696 | __data_.second().~_Tp(); |
| 3697 | } |
| 3698 | |
| 3699 | template <class _Tp, class _Alloc> |
| 3700 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3701 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3702 | { |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3703 | typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; |
| 3704 | typedef allocator_traits<_Al> _ATraits; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3705 | typedef pointer_traits<typename _ATraits::pointer> _PTraits; |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3706 | _Al __a(__data_.first()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3707 | __data_.first().~_Alloc(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3708 | __a.deallocate(_PTraits::pointer_to(*this), 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 3711 | struct __shared_ptr_dummy_rebind_allocator_type; |
| 3712 | template <> |
| 3713 | class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> |
| 3714 | { |
| 3715 | public: |
| 3716 | template <class _Other> |
| 3717 | struct rebind |
| 3718 | { |
| 3719 | typedef allocator<_Other> other; |
| 3720 | }; |
| 3721 | }; |
| 3722 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3723 | template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3724 | |
| 3725 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3726 | class _LIBCPP_TEMPLATE_VIS shared_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3727 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3728 | public: |
| 3729 | typedef _Tp element_type; |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3730 | |
Eric Fiselier | ae5b667 | 2016-06-27 01:02:43 +0000 | [diff] [blame] | 3731 | #if _LIBCPP_STD_VER > 14 |
| 3732 | typedef weak_ptr<_Tp> weak_type; |
| 3733 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3734 | private: |
| 3735 | element_type* __ptr_; |
| 3736 | __shared_weak_count* __cntrl_; |
| 3737 | |
| 3738 | struct __nat {int __for_bool_;}; |
| 3739 | public: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3740 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3741 | _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3742 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3743 | _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3744 | template<class _Yp> |
| 3745 | explicit shared_ptr(_Yp* __p, |
| 3746 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
| 3747 | template<class _Yp, class _Dp> |
| 3748 | shared_ptr(_Yp* __p, _Dp __d, |
| 3749 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
| 3750 | template<class _Yp, class _Dp, class _Alloc> |
| 3751 | shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, |
| 3752 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3753 | template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); |
| 3754 | template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3755 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; |
| 3756 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3757 | shared_ptr(const shared_ptr& __r) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3758 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3759 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3760 | shared_ptr(const shared_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3761 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3762 | _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3763 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3764 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3765 | shared_ptr(shared_ptr&& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3766 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3767 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3768 | _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3769 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3770 | template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3771 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3772 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3773 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3774 | template<class _Yp> |
| 3775 | shared_ptr(auto_ptr<_Yp>&& __r, |
| 3776 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3777 | #else |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3778 | template<class _Yp> |
| 3779 | shared_ptr(auto_ptr<_Yp> __r, |
| 3780 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3781 | #endif |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3782 | #endif |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3783 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3784 | template <class _Yp, class _Dp> |
| 3785 | shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 3786 | typename enable_if |
| 3787 | < |
| 3788 | !is_lvalue_reference<_Dp>::value && |
| 3789 | !is_array<_Yp>::value && |
| 3790 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3791 | __nat |
| 3792 | >::type = __nat()); |
| 3793 | template <class _Yp, class _Dp> |
| 3794 | shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 3795 | typename enable_if |
| 3796 | < |
| 3797 | is_lvalue_reference<_Dp>::value && |
| 3798 | !is_array<_Yp>::value && |
| 3799 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3800 | __nat |
| 3801 | >::type = __nat()); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3802 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3803 | template <class _Yp, class _Dp> |
| 3804 | shared_ptr(unique_ptr<_Yp, _Dp>, |
| 3805 | typename enable_if |
| 3806 | < |
| 3807 | !is_lvalue_reference<_Dp>::value && |
| 3808 | !is_array<_Yp>::value && |
| 3809 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3810 | __nat |
| 3811 | >::type = __nat()); |
| 3812 | template <class _Yp, class _Dp> |
| 3813 | shared_ptr(unique_ptr<_Yp, _Dp>, |
| 3814 | typename enable_if |
| 3815 | < |
| 3816 | is_lvalue_reference<_Dp>::value && |
| 3817 | !is_array<_Yp>::value && |
| 3818 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3819 | __nat |
| 3820 | >::type = __nat()); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3821 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3822 | |
| 3823 | ~shared_ptr(); |
| 3824 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3825 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3826 | shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3827 | template<class _Yp> |
| 3828 | typename enable_if |
| 3829 | < |
| 3830 | is_convertible<_Yp*, element_type*>::value, |
| 3831 | shared_ptr& |
| 3832 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3833 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3834 | operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3835 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3836 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3837 | shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3838 | template<class _Yp> |
| 3839 | typename enable_if |
| 3840 | < |
| 3841 | is_convertible<_Yp*, element_type*>::value, |
| 3842 | shared_ptr<_Tp>& |
| 3843 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3844 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3845 | operator=(shared_ptr<_Yp>&& __r); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3846 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3847 | template<class _Yp> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 3848 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3849 | typename enable_if |
| 3850 | < |
| 3851 | !is_array<_Yp>::value && |
| 3852 | is_convertible<_Yp*, element_type*>::value, |
Howard Hinnant | 25bcaf6 | 2013-09-13 23:56:00 +0000 | [diff] [blame] | 3853 | shared_ptr |
| 3854 | >::type& |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3855 | operator=(auto_ptr<_Yp>&& __r); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3856 | #endif |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3857 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3858 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3859 | template<class _Yp> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 3860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3861 | typename enable_if |
| 3862 | < |
| 3863 | !is_array<_Yp>::value && |
| 3864 | is_convertible<_Yp*, element_type*>::value, |
| 3865 | shared_ptr& |
| 3866 | >::type |
| 3867 | operator=(auto_ptr<_Yp> __r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3868 | #endif |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3869 | #endif |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3870 | template <class _Yp, class _Dp> |
| 3871 | typename enable_if |
| 3872 | < |
| 3873 | !is_array<_Yp>::value && |
| 3874 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3875 | shared_ptr& |
| 3876 | >::type |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3877 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3878 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3879 | operator=(unique_ptr<_Yp, _Dp>&& __r); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3880 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 0319287 | 2015-12-09 22:32:36 +0000 | [diff] [blame] | 3881 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3882 | operator=(unique_ptr<_Yp, _Dp> __r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3883 | #endif |
| 3884 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3885 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3886 | void swap(shared_ptr& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3887 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3888 | void reset() _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3889 | template<class _Yp> |
| 3890 | typename enable_if |
| 3891 | < |
| 3892 | is_convertible<_Yp*, element_type*>::value, |
| 3893 | void |
| 3894 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3895 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3896 | reset(_Yp* __p); |
| 3897 | template<class _Yp, class _Dp> |
| 3898 | typename enable_if |
| 3899 | < |
| 3900 | is_convertible<_Yp*, element_type*>::value, |
| 3901 | void |
| 3902 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3904 | reset(_Yp* __p, _Dp __d); |
| 3905 | template<class _Yp, class _Dp, class _Alloc> |
| 3906 | typename enable_if |
| 3907 | < |
| 3908 | is_convertible<_Yp*, element_type*>::value, |
| 3909 | void |
| 3910 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3911 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3912 | reset(_Yp* __p, _Dp __d, _Alloc __a); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3913 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3914 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3915 | element_type* get() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3916 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3917 | typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT |
| 3918 | {return *__ptr_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3919 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3920 | element_type* operator->() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3921 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3922 | long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3923 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3924 | bool unique() const _NOEXCEPT {return use_count() == 1;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3925 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 86a291f | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 3926 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3927 | template <class _Up> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3928 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 3929 | bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3930 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3931 | template <class _Up> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3932 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 3933 | bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3934 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 3935 | _LIBCPP_INLINE_VISIBILITY |
| 3936 | bool |
| 3937 | __owner_equivalent(const shared_ptr& __p) const |
| 3938 | {return __cntrl_ == __p.__cntrl_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3939 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3940 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3941 | template <class _Dp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3942 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3943 | _Dp* __get_deleter() const _NOEXCEPT |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 3944 | {return static_cast<_Dp*>(__cntrl_ |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 3945 | ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 3946 | : nullptr);} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3947 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3948 | |
| 3949 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3950 | |
| 3951 | template<class ..._Args> |
| 3952 | static |
| 3953 | shared_ptr<_Tp> |
| 3954 | make_shared(_Args&& ...__args); |
| 3955 | |
| 3956 | template<class _Alloc, class ..._Args> |
| 3957 | static |
| 3958 | shared_ptr<_Tp> |
| 3959 | allocate_shared(const _Alloc& __a, _Args&& ...__args); |
| 3960 | |
| 3961 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3962 | |
| 3963 | static shared_ptr<_Tp> make_shared(); |
| 3964 | |
| 3965 | template<class _A0> |
| 3966 | static shared_ptr<_Tp> make_shared(_A0&); |
| 3967 | |
| 3968 | template<class _A0, class _A1> |
| 3969 | static shared_ptr<_Tp> make_shared(_A0&, _A1&); |
| 3970 | |
| 3971 | template<class _A0, class _A1, class _A2> |
| 3972 | static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); |
| 3973 | |
| 3974 | template<class _Alloc> |
| 3975 | static shared_ptr<_Tp> |
| 3976 | allocate_shared(const _Alloc& __a); |
| 3977 | |
| 3978 | template<class _Alloc, class _A0> |
| 3979 | static shared_ptr<_Tp> |
| 3980 | allocate_shared(const _Alloc& __a, _A0& __a0); |
| 3981 | |
| 3982 | template<class _Alloc, class _A0, class _A1> |
| 3983 | static shared_ptr<_Tp> |
| 3984 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); |
| 3985 | |
| 3986 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 3987 | static shared_ptr<_Tp> |
| 3988 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); |
| 3989 | |
| 3990 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3991 | |
| 3992 | private: |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 3993 | template <class _Yp, bool = is_function<_Yp>::value> |
| 3994 | struct __shared_ptr_default_allocator |
| 3995 | { |
| 3996 | typedef allocator<_Yp> type; |
| 3997 | }; |
| 3998 | |
| 3999 | template <class _Yp> |
| 4000 | struct __shared_ptr_default_allocator<_Yp, true> |
| 4001 | { |
| 4002 | typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; |
| 4003 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4004 | |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4005 | template <class _Yp, class _OrigPtr> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4006 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 30d5ac6 | 2017-05-10 19:35:49 +0000 | [diff] [blame] | 4007 | typename enable_if<is_convertible<_OrigPtr*, |
| 4008 | const enable_shared_from_this<_Yp>* |
| 4009 | >::value, |
| 4010 | void>::type |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4011 | __enable_weak_this(const enable_shared_from_this<_Yp>* __e, |
| 4012 | _OrigPtr* __ptr) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4013 | { |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4014 | typedef typename remove_cv<_Yp>::type _RawYp; |
Eric Fiselier | 8400686 | 2016-06-02 00:15:35 +0000 | [diff] [blame] | 4015 | if (__e && __e->__weak_this_.expired()) |
Marshall Clow | 99442fc | 2015-06-19 15:54:13 +0000 | [diff] [blame] | 4016 | { |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4017 | __e->__weak_this_ = shared_ptr<_RawYp>(*this, |
| 4018 | const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); |
Marshall Clow | 99442fc | 2015-06-19 15:54:13 +0000 | [diff] [blame] | 4019 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4020 | } |
| 4021 | |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4022 | _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4023 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4024 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
| 4025 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4026 | }; |
| 4027 | |
Eric Fiselier | 30d5ac6 | 2017-05-10 19:35:49 +0000 | [diff] [blame] | 4028 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4029 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4030 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 4031 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4032 | shared_ptr<_Tp>::shared_ptr() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4033 | : __ptr_(0), |
| 4034 | __cntrl_(0) |
| 4035 | { |
| 4036 | } |
| 4037 | |
| 4038 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4039 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 4040 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4041 | shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4042 | : __ptr_(0), |
| 4043 | __cntrl_(0) |
| 4044 | { |
| 4045 | } |
| 4046 | |
| 4047 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4048 | template<class _Yp> |
| 4049 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, |
| 4050 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4051 | : __ptr_(__p) |
| 4052 | { |
| 4053 | unique_ptr<_Yp> __hold(__p); |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4054 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 4055 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk; |
| 4056 | __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4057 | __hold.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4058 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4062 | template<class _Yp, class _Dp> |
| 4063 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, |
| 4064 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4065 | : __ptr_(__p) |
| 4066 | { |
| 4067 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4068 | try |
| 4069 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4070 | #endif // _LIBCPP_NO_EXCEPTIONS |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4071 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 4072 | typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; |
| 4073 | __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4074 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4075 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4076 | } |
| 4077 | catch (...) |
| 4078 | { |
| 4079 | __d(__p); |
| 4080 | throw; |
| 4081 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4082 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | template<class _Tp> |
| 4086 | template<class _Dp> |
| 4087 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) |
| 4088 | : __ptr_(0) |
| 4089 | { |
| 4090 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4091 | try |
| 4092 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4093 | #endif // _LIBCPP_NO_EXCEPTIONS |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4094 | typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; |
| 4095 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk; |
| 4096 | __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4097 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4098 | } |
| 4099 | catch (...) |
| 4100 | { |
| 4101 | __d(__p); |
| 4102 | throw; |
| 4103 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4104 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4108 | template<class _Yp, class _Dp, class _Alloc> |
| 4109 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, |
| 4110 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4111 | : __ptr_(__p) |
| 4112 | { |
| 4113 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4114 | try |
| 4115 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4116 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4117 | typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4118 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4119 | typedef __allocator_destructor<_A2> _D2; |
| 4120 | _A2 __a2(__a); |
| 4121 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4122 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4123 | _CntrlBlk(__p, __d, __a); |
| 4124 | __cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4125 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4126 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4127 | } |
| 4128 | catch (...) |
| 4129 | { |
| 4130 | __d(__p); |
| 4131 | throw; |
| 4132 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4133 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | template<class _Tp> |
| 4137 | template<class _Dp, class _Alloc> |
| 4138 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) |
| 4139 | : __ptr_(0) |
| 4140 | { |
| 4141 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4142 | try |
| 4143 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4144 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4145 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4146 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4147 | typedef __allocator_destructor<_A2> _D2; |
| 4148 | _A2 __a2(__a); |
| 4149 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4150 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4151 | _CntrlBlk(__p, __d, __a); |
| 4152 | __cntrl_ = _VSTD::addressof(*__hold2.release()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4153 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4154 | } |
| 4155 | catch (...) |
| 4156 | { |
| 4157 | __d(__p); |
| 4158 | throw; |
| 4159 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4160 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | template<class _Tp> |
| 4164 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4165 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4166 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4167 | : __ptr_(__p), |
| 4168 | __cntrl_(__r.__cntrl_) |
| 4169 | { |
| 4170 | if (__cntrl_) |
| 4171 | __cntrl_->__add_shared(); |
| 4172 | } |
| 4173 | |
| 4174 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4175 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4176 | shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4177 | : __ptr_(__r.__ptr_), |
| 4178 | __cntrl_(__r.__cntrl_) |
| 4179 | { |
| 4180 | if (__cntrl_) |
| 4181 | __cntrl_->__add_shared(); |
| 4182 | } |
| 4183 | |
| 4184 | template<class _Tp> |
| 4185 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4186 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4187 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4188 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4189 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4190 | : __ptr_(__r.__ptr_), |
| 4191 | __cntrl_(__r.__cntrl_) |
| 4192 | { |
| 4193 | if (__cntrl_) |
| 4194 | __cntrl_->__add_shared(); |
| 4195 | } |
| 4196 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4197 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4198 | |
| 4199 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4200 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4201 | shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4202 | : __ptr_(__r.__ptr_), |
| 4203 | __cntrl_(__r.__cntrl_) |
| 4204 | { |
| 4205 | __r.__ptr_ = 0; |
| 4206 | __r.__cntrl_ = 0; |
| 4207 | } |
| 4208 | |
| 4209 | template<class _Tp> |
| 4210 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4211 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4212 | shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4213 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4214 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4215 | : __ptr_(__r.__ptr_), |
| 4216 | __cntrl_(__r.__cntrl_) |
| 4217 | { |
| 4218 | __r.__ptr_ = 0; |
| 4219 | __r.__cntrl_ = 0; |
| 4220 | } |
| 4221 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4222 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4223 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4224 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4225 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4226 | template<class _Yp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4227 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4228 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4229 | #else |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4230 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4231 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4232 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4233 | : __ptr_(__r.get()) |
| 4234 | { |
| 4235 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 4236 | __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4237 | __enable_weak_this(__r.get(), __r.get()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4238 | __r.release(); |
| 4239 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4240 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4241 | |
| 4242 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4243 | template <class _Yp, class _Dp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4244 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4245 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 4246 | #else |
| 4247 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 4248 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4249 | typename enable_if |
| 4250 | < |
| 4251 | !is_lvalue_reference<_Dp>::value && |
| 4252 | !is_array<_Yp>::value && |
| 4253 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 4254 | __nat |
| 4255 | >::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4256 | : __ptr_(__r.get()) |
| 4257 | { |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4258 | #if _LIBCPP_STD_VER > 11 |
| 4259 | if (__ptr_ == nullptr) |
| 4260 | __cntrl_ = nullptr; |
| 4261 | else |
| 4262 | #endif |
| 4263 | { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4264 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 4265 | typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; |
| 4266 | __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4267 | __enable_weak_this(__r.get(), __r.get()); |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4268 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4269 | __r.release(); |
| 4270 | } |
| 4271 | |
| 4272 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4273 | template <class _Yp, class _Dp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4274 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4275 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 4276 | #else |
| 4277 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 4278 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4279 | typename enable_if |
| 4280 | < |
| 4281 | is_lvalue_reference<_Dp>::value && |
| 4282 | !is_array<_Yp>::value && |
| 4283 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 4284 | __nat |
| 4285 | >::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4286 | : __ptr_(__r.get()) |
| 4287 | { |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4288 | #if _LIBCPP_STD_VER > 11 |
| 4289 | if (__ptr_ == nullptr) |
| 4290 | __cntrl_ = nullptr; |
| 4291 | else |
| 4292 | #endif |
| 4293 | { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4294 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4295 | typedef __shared_ptr_pointer<_Yp*, |
| 4296 | reference_wrapper<typename remove_reference<_Dp>::type>, |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4297 | _AllocT > _CntrlBlk; |
| 4298 | __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4299 | __enable_weak_this(__r.get(), __r.get()); |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4300 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4301 | __r.release(); |
| 4302 | } |
| 4303 | |
| 4304 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 4305 | |
| 4306 | template<class _Tp> |
| 4307 | template<class ..._Args> |
| 4308 | shared_ptr<_Tp> |
| 4309 | shared_ptr<_Tp>::make_shared(_Args&& ...__args) |
| 4310 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4311 | static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4312 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4313 | typedef allocator<_CntrlBlk> _A2; |
| 4314 | typedef __allocator_destructor<_A2> _D2; |
| 4315 | _A2 __a2; |
| 4316 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4317 | ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4318 | shared_ptr<_Tp> __r; |
| 4319 | __r.__ptr_ = __hold2.get()->get(); |
| 4320 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4321 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4322 | return __r; |
| 4323 | } |
| 4324 | |
| 4325 | template<class _Tp> |
| 4326 | template<class _Alloc, class ..._Args> |
| 4327 | shared_ptr<_Tp> |
| 4328 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 4329 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4330 | static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4331 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4332 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4333 | typedef __allocator_destructor<_A2> _D2; |
| 4334 | _A2 __a2(__a); |
| 4335 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4336 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4337 | _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4338 | shared_ptr<_Tp> __r; |
| 4339 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4340 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4341 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4342 | return __r; |
| 4343 | } |
| 4344 | |
| 4345 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 4346 | |
| 4347 | template<class _Tp> |
| 4348 | shared_ptr<_Tp> |
| 4349 | shared_ptr<_Tp>::make_shared() |
| 4350 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4351 | static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4352 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4353 | typedef allocator<_CntrlBlk> _Alloc2; |
| 4354 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4355 | _Alloc2 __alloc2; |
| 4356 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 4357 | ::new(__hold2.get()) _CntrlBlk(__alloc2); |
| 4358 | shared_ptr<_Tp> __r; |
| 4359 | __r.__ptr_ = __hold2.get()->get(); |
| 4360 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4361 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4362 | return __r; |
| 4363 | } |
| 4364 | |
| 4365 | template<class _Tp> |
| 4366 | template<class _A0> |
| 4367 | shared_ptr<_Tp> |
| 4368 | shared_ptr<_Tp>::make_shared(_A0& __a0) |
| 4369 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4370 | static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4371 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4372 | typedef allocator<_CntrlBlk> _Alloc2; |
| 4373 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4374 | _Alloc2 __alloc2; |
| 4375 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 4376 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); |
| 4377 | shared_ptr<_Tp> __r; |
| 4378 | __r.__ptr_ = __hold2.get()->get(); |
| 4379 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4380 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4381 | return __r; |
| 4382 | } |
| 4383 | |
| 4384 | template<class _Tp> |
| 4385 | template<class _A0, class _A1> |
| 4386 | shared_ptr<_Tp> |
| 4387 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) |
| 4388 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4389 | static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4390 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4391 | typedef allocator<_CntrlBlk> _Alloc2; |
| 4392 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4393 | _Alloc2 __alloc2; |
| 4394 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 4395 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); |
| 4396 | shared_ptr<_Tp> __r; |
| 4397 | __r.__ptr_ = __hold2.get()->get(); |
| 4398 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4399 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4400 | return __r; |
| 4401 | } |
| 4402 | |
| 4403 | template<class _Tp> |
| 4404 | template<class _A0, class _A1, class _A2> |
| 4405 | shared_ptr<_Tp> |
| 4406 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 4407 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4408 | static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4409 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4410 | typedef allocator<_CntrlBlk> _Alloc2; |
| 4411 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4412 | _Alloc2 __alloc2; |
| 4413 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 4414 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); |
| 4415 | shared_ptr<_Tp> __r; |
| 4416 | __r.__ptr_ = __hold2.get()->get(); |
| 4417 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4418 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4419 | return __r; |
| 4420 | } |
| 4421 | |
| 4422 | template<class _Tp> |
| 4423 | template<class _Alloc> |
| 4424 | shared_ptr<_Tp> |
| 4425 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) |
| 4426 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4427 | static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4428 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4429 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4430 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4431 | _Alloc2 __alloc2(__a); |
| 4432 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4433 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4434 | _CntrlBlk(__a); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4435 | shared_ptr<_Tp> __r; |
| 4436 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4437 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4438 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4439 | return __r; |
| 4440 | } |
| 4441 | |
| 4442 | template<class _Tp> |
| 4443 | template<class _Alloc, class _A0> |
| 4444 | shared_ptr<_Tp> |
| 4445 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) |
| 4446 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4447 | static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4448 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4449 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4450 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4451 | _Alloc2 __alloc2(__a); |
| 4452 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4453 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4454 | _CntrlBlk(__a, __a0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4455 | shared_ptr<_Tp> __r; |
| 4456 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4457 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4458 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4459 | return __r; |
| 4460 | } |
| 4461 | |
| 4462 | template<class _Tp> |
| 4463 | template<class _Alloc, class _A0, class _A1> |
| 4464 | shared_ptr<_Tp> |
| 4465 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 4466 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4467 | static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4468 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4469 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4470 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4471 | _Alloc2 __alloc2(__a); |
| 4472 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4473 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4474 | _CntrlBlk(__a, __a0, __a1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4475 | shared_ptr<_Tp> __r; |
| 4476 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4477 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4478 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4479 | return __r; |
| 4480 | } |
| 4481 | |
| 4482 | template<class _Tp> |
| 4483 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 4484 | shared_ptr<_Tp> |
| 4485 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 4486 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4487 | static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" ); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4488 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4489 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4490 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4491 | _Alloc2 __alloc2(__a); |
| 4492 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4493 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4494 | _CntrlBlk(__a, __a0, __a1, __a2); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4495 | shared_ptr<_Tp> __r; |
| 4496 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4497 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4498 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4499 | return __r; |
| 4500 | } |
| 4501 | |
| 4502 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 4503 | |
| 4504 | template<class _Tp> |
| 4505 | shared_ptr<_Tp>::~shared_ptr() |
| 4506 | { |
| 4507 | if (__cntrl_) |
| 4508 | __cntrl_->__release_shared(); |
| 4509 | } |
| 4510 | |
| 4511 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4512 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4513 | shared_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4514 | shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4515 | { |
| 4516 | shared_ptr(__r).swap(*this); |
| 4517 | return *this; |
| 4518 | } |
| 4519 | |
| 4520 | template<class _Tp> |
| 4521 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4522 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4523 | typename enable_if |
| 4524 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4525 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4526 | shared_ptr<_Tp>& |
| 4527 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4528 | shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4529 | { |
| 4530 | shared_ptr(__r).swap(*this); |
| 4531 | return *this; |
| 4532 | } |
| 4533 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4534 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4535 | |
| 4536 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4537 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4538 | shared_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4539 | shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4540 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4541 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4542 | return *this; |
| 4543 | } |
| 4544 | |
| 4545 | template<class _Tp> |
| 4546 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4547 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4548 | typename enable_if |
| 4549 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4550 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4551 | shared_ptr<_Tp>& |
| 4552 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4553 | shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) |
| 4554 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4555 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4556 | return *this; |
| 4557 | } |
| 4558 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4559 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4560 | template<class _Tp> |
| 4561 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4562 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4563 | typename enable_if |
| 4564 | < |
| 4565 | !is_array<_Yp>::value && |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4566 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 25bcaf6 | 2013-09-13 23:56:00 +0000 | [diff] [blame] | 4567 | shared_ptr<_Tp> |
| 4568 | >::type& |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4569 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) |
| 4570 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4571 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4572 | return *this; |
| 4573 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4574 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4575 | |
| 4576 | template<class _Tp> |
| 4577 | template <class _Yp, class _Dp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4578 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4579 | typename enable_if |
| 4580 | < |
| 4581 | !is_array<_Yp>::value && |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 4582 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4583 | typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4584 | shared_ptr<_Tp>& |
| 4585 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4586 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) |
| 4587 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4588 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4589 | return *this; |
| 4590 | } |
| 4591 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4592 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4593 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4594 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4595 | template<class _Tp> |
| 4596 | template<class _Yp> |
| 4597 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4598 | typename enable_if |
| 4599 | < |
| 4600 | !is_array<_Yp>::value && |
Marshall Clow | b89a86e | 2017-01-10 18:40:01 +0000 | [diff] [blame] | 4601 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4602 | shared_ptr<_Tp>& |
| 4603 | >::type |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4604 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4605 | { |
| 4606 | shared_ptr(__r).swap(*this); |
| 4607 | return *this; |
| 4608 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4609 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4610 | |
| 4611 | template<class _Tp> |
| 4612 | template <class _Yp, class _Dp> |
| 4613 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4614 | typename enable_if |
| 4615 | < |
| 4616 | !is_array<_Yp>::value && |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 4617 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, |
Marshall Clow | b89a86e | 2017-01-10 18:40:01 +0000 | [diff] [blame] | 4618 | typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4619 | shared_ptr<_Tp>& |
| 4620 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4621 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) |
| 4622 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4623 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4624 | return *this; |
| 4625 | } |
| 4626 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4627 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4628 | |
| 4629 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4630 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4631 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4632 | shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4633 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4634 | _VSTD::swap(__ptr_, __r.__ptr_); |
| 4635 | _VSTD::swap(__cntrl_, __r.__cntrl_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4639 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4640 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4641 | shared_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4642 | { |
| 4643 | shared_ptr().swap(*this); |
| 4644 | } |
| 4645 | |
| 4646 | template<class _Tp> |
| 4647 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4648 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4649 | typename enable_if |
| 4650 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4651 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4652 | void |
| 4653 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4654 | shared_ptr<_Tp>::reset(_Yp* __p) |
| 4655 | { |
| 4656 | shared_ptr(__p).swap(*this); |
| 4657 | } |
| 4658 | |
| 4659 | template<class _Tp> |
| 4660 | template<class _Yp, class _Dp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4661 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4662 | typename enable_if |
| 4663 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4664 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4665 | void |
| 4666 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4667 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) |
| 4668 | { |
| 4669 | shared_ptr(__p, __d).swap(*this); |
| 4670 | } |
| 4671 | |
| 4672 | template<class _Tp> |
| 4673 | template<class _Yp, class _Dp, class _Alloc> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4674 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4675 | typename enable_if |
| 4676 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4677 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4678 | void |
| 4679 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4680 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) |
| 4681 | { |
| 4682 | shared_ptr(__p, __d, __a).swap(*this); |
| 4683 | } |
| 4684 | |
| 4685 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 4686 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4687 | template<class _Tp, class ..._Args> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4688 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4689 | typename enable_if |
| 4690 | < |
| 4691 | !is_array<_Tp>::value, |
| 4692 | shared_ptr<_Tp> |
| 4693 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4694 | make_shared(_Args&& ...__args) |
| 4695 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4696 | return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4699 | template<class _Tp, class _Alloc, class ..._Args> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4700 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4701 | typename enable_if |
| 4702 | < |
| 4703 | !is_array<_Tp>::value, |
| 4704 | shared_ptr<_Tp> |
| 4705 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4706 | allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 4707 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4708 | return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 4712 | |
| 4713 | template<class _Tp> |
| 4714 | inline _LIBCPP_INLINE_VISIBILITY |
| 4715 | shared_ptr<_Tp> |
| 4716 | make_shared() |
| 4717 | { |
| 4718 | return shared_ptr<_Tp>::make_shared(); |
| 4719 | } |
| 4720 | |
| 4721 | template<class _Tp, class _A0> |
| 4722 | inline _LIBCPP_INLINE_VISIBILITY |
| 4723 | shared_ptr<_Tp> |
| 4724 | make_shared(_A0& __a0) |
| 4725 | { |
| 4726 | return shared_ptr<_Tp>::make_shared(__a0); |
| 4727 | } |
| 4728 | |
| 4729 | template<class _Tp, class _A0, class _A1> |
| 4730 | inline _LIBCPP_INLINE_VISIBILITY |
| 4731 | shared_ptr<_Tp> |
| 4732 | make_shared(_A0& __a0, _A1& __a1) |
| 4733 | { |
| 4734 | return shared_ptr<_Tp>::make_shared(__a0, __a1); |
| 4735 | } |
| 4736 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4737 | template<class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4738 | inline _LIBCPP_INLINE_VISIBILITY |
| 4739 | shared_ptr<_Tp> |
| 4740 | make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 4741 | { |
| 4742 | return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); |
| 4743 | } |
| 4744 | |
| 4745 | template<class _Tp, class _Alloc> |
| 4746 | inline _LIBCPP_INLINE_VISIBILITY |
| 4747 | shared_ptr<_Tp> |
| 4748 | allocate_shared(const _Alloc& __a) |
| 4749 | { |
| 4750 | return shared_ptr<_Tp>::allocate_shared(__a); |
| 4751 | } |
| 4752 | |
| 4753 | template<class _Tp, class _Alloc, class _A0> |
| 4754 | inline _LIBCPP_INLINE_VISIBILITY |
| 4755 | shared_ptr<_Tp> |
| 4756 | allocate_shared(const _Alloc& __a, _A0& __a0) |
| 4757 | { |
| 4758 | return shared_ptr<_Tp>::allocate_shared(__a, __a0); |
| 4759 | } |
| 4760 | |
| 4761 | template<class _Tp, class _Alloc, class _A0, class _A1> |
| 4762 | inline _LIBCPP_INLINE_VISIBILITY |
| 4763 | shared_ptr<_Tp> |
| 4764 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 4765 | { |
| 4766 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); |
| 4767 | } |
| 4768 | |
| 4769 | template<class _Tp, class _Alloc, class _A0, class _A1, class _A2> |
| 4770 | inline _LIBCPP_INLINE_VISIBILITY |
| 4771 | shared_ptr<_Tp> |
| 4772 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 4773 | { |
| 4774 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); |
| 4775 | } |
| 4776 | |
| 4777 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 4778 | |
| 4779 | template<class _Tp, class _Up> |
| 4780 | inline _LIBCPP_INLINE_VISIBILITY |
| 4781 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4782 | operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4783 | { |
| 4784 | return __x.get() == __y.get(); |
| 4785 | } |
| 4786 | |
| 4787 | template<class _Tp, class _Up> |
| 4788 | inline _LIBCPP_INLINE_VISIBILITY |
| 4789 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4790 | operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4791 | { |
| 4792 | return !(__x == __y); |
| 4793 | } |
| 4794 | |
| 4795 | template<class _Tp, class _Up> |
| 4796 | inline _LIBCPP_INLINE_VISIBILITY |
| 4797 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4798 | operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4799 | { |
Marshall Clow | 8afdf7a | 2018-02-12 17:26:40 +0000 | [diff] [blame] | 4800 | #if _LIBCPP_STD_VER <= 11 |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 4801 | typedef typename common_type<_Tp*, _Up*>::type _Vp; |
| 4802 | return less<_Vp>()(__x.get(), __y.get()); |
Marshall Clow | 8afdf7a | 2018-02-12 17:26:40 +0000 | [diff] [blame] | 4803 | #else |
| 4804 | return less<>()(__x.get(), __y.get()); |
| 4805 | #endif |
| 4806 | |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | template<class _Tp, class _Up> |
| 4810 | inline _LIBCPP_INLINE_VISIBILITY |
| 4811 | bool |
| 4812 | operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4813 | { |
| 4814 | return __y < __x; |
| 4815 | } |
| 4816 | |
| 4817 | template<class _Tp, class _Up> |
| 4818 | inline _LIBCPP_INLINE_VISIBILITY |
| 4819 | bool |
| 4820 | operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4821 | { |
| 4822 | return !(__y < __x); |
| 4823 | } |
| 4824 | |
| 4825 | template<class _Tp, class _Up> |
| 4826 | inline _LIBCPP_INLINE_VISIBILITY |
| 4827 | bool |
| 4828 | operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4829 | { |
| 4830 | return !(__x < __y); |
| 4831 | } |
| 4832 | |
| 4833 | template<class _Tp> |
| 4834 | inline _LIBCPP_INLINE_VISIBILITY |
| 4835 | bool |
| 4836 | operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4837 | { |
| 4838 | return !__x; |
| 4839 | } |
| 4840 | |
| 4841 | template<class _Tp> |
| 4842 | inline _LIBCPP_INLINE_VISIBILITY |
| 4843 | bool |
| 4844 | operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4845 | { |
| 4846 | return !__x; |
| 4847 | } |
| 4848 | |
| 4849 | template<class _Tp> |
| 4850 | inline _LIBCPP_INLINE_VISIBILITY |
| 4851 | bool |
| 4852 | operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4853 | { |
| 4854 | return static_cast<bool>(__x); |
| 4855 | } |
| 4856 | |
| 4857 | template<class _Tp> |
| 4858 | inline _LIBCPP_INLINE_VISIBILITY |
| 4859 | bool |
| 4860 | operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4861 | { |
| 4862 | return static_cast<bool>(__x); |
| 4863 | } |
| 4864 | |
| 4865 | template<class _Tp> |
| 4866 | inline _LIBCPP_INLINE_VISIBILITY |
| 4867 | bool |
| 4868 | operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4869 | { |
| 4870 | return less<_Tp*>()(__x.get(), nullptr); |
| 4871 | } |
| 4872 | |
| 4873 | template<class _Tp> |
| 4874 | inline _LIBCPP_INLINE_VISIBILITY |
| 4875 | bool |
| 4876 | operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4877 | { |
| 4878 | return less<_Tp*>()(nullptr, __x.get()); |
| 4879 | } |
| 4880 | |
| 4881 | template<class _Tp> |
| 4882 | inline _LIBCPP_INLINE_VISIBILITY |
| 4883 | bool |
| 4884 | operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4885 | { |
| 4886 | return nullptr < __x; |
| 4887 | } |
| 4888 | |
| 4889 | template<class _Tp> |
| 4890 | inline _LIBCPP_INLINE_VISIBILITY |
| 4891 | bool |
| 4892 | operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4893 | { |
| 4894 | return __x < nullptr; |
| 4895 | } |
| 4896 | |
| 4897 | template<class _Tp> |
| 4898 | inline _LIBCPP_INLINE_VISIBILITY |
| 4899 | bool |
| 4900 | operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4901 | { |
| 4902 | return !(nullptr < __x); |
| 4903 | } |
| 4904 | |
| 4905 | template<class _Tp> |
| 4906 | inline _LIBCPP_INLINE_VISIBILITY |
| 4907 | bool |
| 4908 | operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4909 | { |
| 4910 | return !(__x < nullptr); |
| 4911 | } |
| 4912 | |
| 4913 | template<class _Tp> |
| 4914 | inline _LIBCPP_INLINE_VISIBILITY |
| 4915 | bool |
| 4916 | operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4917 | { |
| 4918 | return !(__x < nullptr); |
| 4919 | } |
| 4920 | |
| 4921 | template<class _Tp> |
| 4922 | inline _LIBCPP_INLINE_VISIBILITY |
| 4923 | bool |
| 4924 | operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4925 | { |
| 4926 | return !(nullptr < __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | template<class _Tp> |
| 4930 | inline _LIBCPP_INLINE_VISIBILITY |
| 4931 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4932 | swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4933 | { |
| 4934 | __x.swap(__y); |
| 4935 | } |
| 4936 | |
| 4937 | template<class _Tp, class _Up> |
| 4938 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4939 | typename enable_if |
| 4940 | < |
| 4941 | !is_array<_Tp>::value && !is_array<_Up>::value, |
| 4942 | shared_ptr<_Tp> |
| 4943 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4944 | static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4945 | { |
| 4946 | return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); |
| 4947 | } |
| 4948 | |
| 4949 | template<class _Tp, class _Up> |
| 4950 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4951 | typename enable_if |
| 4952 | < |
| 4953 | !is_array<_Tp>::value && !is_array<_Up>::value, |
| 4954 | shared_ptr<_Tp> |
| 4955 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4956 | dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4957 | { |
| 4958 | _Tp* __p = dynamic_cast<_Tp*>(__r.get()); |
| 4959 | return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); |
| 4960 | } |
| 4961 | |
| 4962 | template<class _Tp, class _Up> |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4963 | typename enable_if |
| 4964 | < |
| 4965 | is_array<_Tp>::value == is_array<_Up>::value, |
| 4966 | shared_ptr<_Tp> |
| 4967 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4968 | const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4969 | { |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4970 | typedef typename remove_extent<_Tp>::type _RTp; |
| 4971 | return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4972 | } |
| 4973 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4974 | #ifndef _LIBCPP_NO_RTTI |
| 4975 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4976 | template<class _Dp, class _Tp> |
| 4977 | inline _LIBCPP_INLINE_VISIBILITY |
| 4978 | _Dp* |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4979 | get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4980 | { |
| 4981 | return __p.template __get_deleter<_Dp>(); |
| 4982 | } |
| 4983 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4984 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4985 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4986 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4987 | class _LIBCPP_TEMPLATE_VIS weak_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4988 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4989 | public: |
| 4990 | typedef _Tp element_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4991 | private: |
| 4992 | element_type* __ptr_; |
| 4993 | __shared_weak_count* __cntrl_; |
| 4994 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4995 | public: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 4997 | _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4998 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4999 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 5000 | _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5001 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5002 | weak_ptr(weak_ptr const& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5003 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5004 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 5005 | _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5006 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5007 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5008 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5009 | weak_ptr(weak_ptr&& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5010 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5011 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 5012 | _NOEXCEPT; |
| 5013 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5014 | ~weak_ptr(); |
| 5015 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5016 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5017 | weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5018 | template<class _Yp> |
| 5019 | typename enable_if |
| 5020 | < |
| 5021 | is_convertible<_Yp*, element_type*>::value, |
| 5022 | weak_ptr& |
| 5023 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5024 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5025 | operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; |
| 5026 | |
| 5027 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5028 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5029 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5030 | weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; |
| 5031 | template<class _Yp> |
| 5032 | typename enable_if |
| 5033 | < |
| 5034 | is_convertible<_Yp*, element_type*>::value, |
| 5035 | weak_ptr& |
| 5036 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5037 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5038 | operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; |
| 5039 | |
| 5040 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5041 | |
| 5042 | template<class _Yp> |
| 5043 | typename enable_if |
| 5044 | < |
| 5045 | is_convertible<_Yp*, element_type*>::value, |
| 5046 | weak_ptr& |
| 5047 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5048 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5049 | operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5050 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5051 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5052 | void swap(weak_ptr& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5054 | void reset() _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5055 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5056 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5057 | long use_count() const _NOEXCEPT |
| 5058 | {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5059 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5060 | bool expired() const _NOEXCEPT |
| 5061 | {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} |
| 5062 | shared_ptr<_Tp> lock() const _NOEXCEPT; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5063 | template<class _Up> |
| 5064 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5065 | bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5066 | {return __cntrl_ < __r.__cntrl_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5067 | template<class _Up> |
| 5068 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5069 | bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5070 | {return __cntrl_ < __r.__cntrl_;} |
| 5071 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5072 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
| 5073 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5074 | }; |
| 5075 | |
| 5076 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5077 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 5078 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5079 | weak_ptr<_Tp>::weak_ptr() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5080 | : __ptr_(0), |
| 5081 | __cntrl_(0) |
| 5082 | { |
| 5083 | } |
| 5084 | |
| 5085 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5086 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5087 | weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5088 | : __ptr_(__r.__ptr_), |
| 5089 | __cntrl_(__r.__cntrl_) |
| 5090 | { |
| 5091 | if (__cntrl_) |
| 5092 | __cntrl_->__add_weak(); |
| 5093 | } |
| 5094 | |
| 5095 | template<class _Tp> |
| 5096 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5097 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5098 | weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | 3a085e8 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 5099 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5100 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5101 | : __ptr_(__r.__ptr_), |
| 5102 | __cntrl_(__r.__cntrl_) |
| 5103 | { |
| 5104 | if (__cntrl_) |
| 5105 | __cntrl_->__add_weak(); |
| 5106 | } |
| 5107 | |
| 5108 | template<class _Tp> |
| 5109 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5110 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5111 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | 3a085e8 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 5112 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5113 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5114 | : __ptr_(__r.__ptr_), |
| 5115 | __cntrl_(__r.__cntrl_) |
| 5116 | { |
| 5117 | if (__cntrl_) |
| 5118 | __cntrl_->__add_weak(); |
| 5119 | } |
| 5120 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5121 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5122 | |
| 5123 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5124 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5125 | weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT |
| 5126 | : __ptr_(__r.__ptr_), |
| 5127 | __cntrl_(__r.__cntrl_) |
| 5128 | { |
| 5129 | __r.__ptr_ = 0; |
| 5130 | __r.__cntrl_ = 0; |
| 5131 | } |
| 5132 | |
| 5133 | template<class _Tp> |
| 5134 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5135 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5136 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, |
| 5137 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
| 5138 | _NOEXCEPT |
| 5139 | : __ptr_(__r.__ptr_), |
| 5140 | __cntrl_(__r.__cntrl_) |
| 5141 | { |
| 5142 | __r.__ptr_ = 0; |
| 5143 | __r.__cntrl_ = 0; |
| 5144 | } |
| 5145 | |
| 5146 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5147 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5148 | template<class _Tp> |
| 5149 | weak_ptr<_Tp>::~weak_ptr() |
| 5150 | { |
| 5151 | if (__cntrl_) |
| 5152 | __cntrl_->__release_weak(); |
| 5153 | } |
| 5154 | |
| 5155 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5156 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5157 | weak_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5158 | weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5159 | { |
| 5160 | weak_ptr(__r).swap(*this); |
| 5161 | return *this; |
| 5162 | } |
| 5163 | |
| 5164 | template<class _Tp> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5165 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5166 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5167 | typename enable_if |
| 5168 | < |
| 5169 | is_convertible<_Yp*, _Tp*>::value, |
| 5170 | weak_ptr<_Tp>& |
| 5171 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5172 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5173 | { |
| 5174 | weak_ptr(__r).swap(*this); |
| 5175 | return *this; |
| 5176 | } |
| 5177 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5178 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5179 | |
| 5180 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5181 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5182 | weak_ptr<_Tp>& |
| 5183 | weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT |
| 5184 | { |
| 5185 | weak_ptr(_VSTD::move(__r)).swap(*this); |
| 5186 | return *this; |
| 5187 | } |
| 5188 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5189 | template<class _Tp> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5190 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5191 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5192 | typename enable_if |
| 5193 | < |
| 5194 | is_convertible<_Yp*, _Tp*>::value, |
| 5195 | weak_ptr<_Tp>& |
| 5196 | >::type |
| 5197 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT |
| 5198 | { |
| 5199 | weak_ptr(_VSTD::move(__r)).swap(*this); |
| 5200 | return *this; |
| 5201 | } |
| 5202 | |
| 5203 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5204 | |
| 5205 | template<class _Tp> |
| 5206 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5207 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5208 | typename enable_if |
| 5209 | < |
| 5210 | is_convertible<_Yp*, _Tp*>::value, |
| 5211 | weak_ptr<_Tp>& |
| 5212 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5213 | weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5214 | { |
| 5215 | weak_ptr(__r).swap(*this); |
| 5216 | return *this; |
| 5217 | } |
| 5218 | |
| 5219 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5220 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5221 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5222 | weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5223 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5224 | _VSTD::swap(__ptr_, __r.__ptr_); |
| 5225 | _VSTD::swap(__cntrl_, __r.__cntrl_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | template<class _Tp> |
| 5229 | inline _LIBCPP_INLINE_VISIBILITY |
| 5230 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5231 | swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5232 | { |
| 5233 | __x.swap(__y); |
| 5234 | } |
| 5235 | |
| 5236 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5237 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5238 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5239 | weak_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5240 | { |
| 5241 | weak_ptr().swap(*this); |
| 5242 | } |
| 5243 | |
| 5244 | template<class _Tp> |
| 5245 | template<class _Yp> |
| 5246 | shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 5247 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5248 | : __ptr_(__r.__ptr_), |
| 5249 | __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) |
| 5250 | { |
| 5251 | if (__cntrl_ == 0) |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 5252 | __throw_bad_weak_ptr(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | template<class _Tp> |
| 5256 | shared_ptr<_Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5257 | weak_ptr<_Tp>::lock() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5258 | { |
| 5259 | shared_ptr<_Tp> __r; |
| 5260 | __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; |
| 5261 | if (__r.__cntrl_) |
| 5262 | __r.__ptr_ = __ptr_; |
| 5263 | return __r; |
| 5264 | } |
| 5265 | |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5266 | #if _LIBCPP_STD_VER > 14 |
| 5267 | template <class _Tp = void> struct owner_less; |
| 5268 | #else |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5269 | template <class _Tp> struct owner_less; |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5270 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5271 | |
| 5272 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5273 | struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5274 | : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5275 | { |
| 5276 | typedef bool result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5277 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5278 | bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5279 | {return __x.owner_before(__y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5280 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5281 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5282 | {return __x.owner_before(__y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5283 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5284 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5285 | {return __x.owner_before(__y);} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5286 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5287 | |
| 5288 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5289 | struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5290 | : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> |
| 5291 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5292 | typedef bool result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5293 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5294 | bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5295 | {return __x.owner_before(__y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5296 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5297 | bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5298 | {return __x.owner_before(__y);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5299 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5300 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5301 | {return __x.owner_before(__y);} |
| 5302 | }; |
| 5303 | |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5304 | #if _LIBCPP_STD_VER > 14 |
| 5305 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5306 | struct _LIBCPP_TEMPLATE_VIS owner_less<void> |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5307 | { |
| 5308 | template <class _Tp, class _Up> |
| 5309 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5310 | bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5311 | {return __x.owner_before(__y);} |
| 5312 | template <class _Tp, class _Up> |
| 5313 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5314 | bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5315 | {return __x.owner_before(__y);} |
| 5316 | template <class _Tp, class _Up> |
| 5317 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5318 | bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5319 | {return __x.owner_before(__y);} |
| 5320 | template <class _Tp, class _Up> |
| 5321 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5322 | bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5323 | {return __x.owner_before(__y);} |
| 5324 | typedef void is_transparent; |
| 5325 | }; |
| 5326 | #endif |
| 5327 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5328 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5329 | class _LIBCPP_TEMPLATE_VIS enable_shared_from_this |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5330 | { |
| 5331 | mutable weak_ptr<_Tp> __weak_this_; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5332 | protected: |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 5333 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5334 | enable_shared_from_this() _NOEXCEPT {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5335 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5336 | enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5337 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5338 | enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT |
| 5339 | {return *this;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5340 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5341 | ~enable_shared_from_this() {} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5342 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5343 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5344 | shared_ptr<_Tp> shared_from_this() |
| 5345 | {return shared_ptr<_Tp>(__weak_this_);} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5346 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5347 | shared_ptr<_Tp const> shared_from_this() const |
| 5348 | {return shared_ptr<const _Tp>(__weak_this_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5349 | |
Eric Fiselier | 8400686 | 2016-06-02 00:15:35 +0000 | [diff] [blame] | 5350 | #if _LIBCPP_STD_VER > 14 |
| 5351 | _LIBCPP_INLINE_VISIBILITY |
| 5352 | weak_ptr<_Tp> weak_from_this() _NOEXCEPT |
| 5353 | { return __weak_this_; } |
| 5354 | |
| 5355 | _LIBCPP_INLINE_VISIBILITY |
| 5356 | weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT |
| 5357 | { return __weak_this_; } |
| 5358 | #endif // _LIBCPP_STD_VER > 14 |
| 5359 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5360 | template <class _Up> friend class shared_ptr; |
| 5361 | }; |
| 5362 | |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5363 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5364 | struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5365 | { |
| 5366 | typedef shared_ptr<_Tp> argument_type; |
| 5367 | typedef size_t result_type; |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 5368 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5369 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5370 | result_type operator()(const argument_type& __ptr) const _NOEXCEPT |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5371 | { |
| 5372 | return hash<_Tp*>()(__ptr.get()); |
| 5373 | } |
| 5374 | }; |
| 5375 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5376 | template<class _CharT, class _Traits, class _Yp> |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 5377 | inline _LIBCPP_INLINE_VISIBILITY |
| 5378 | basic_ostream<_CharT, _Traits>& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5379 | operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 5380 | |
Eric Fiselier | 9b49267 | 2016-06-18 02:12:53 +0000 | [diff] [blame] | 5381 | |
| 5382 | #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5383 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5384 | class _LIBCPP_TYPE_VIS __sp_mut |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5385 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5386 | void* __lx; |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5387 | public: |
| 5388 | void lock() _NOEXCEPT; |
| 5389 | void unlock() _NOEXCEPT; |
| 5390 | |
| 5391 | private: |
| 5392 | _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; |
| 5393 | __sp_mut(const __sp_mut&); |
| 5394 | __sp_mut& operator=(const __sp_mut&); |
| 5395 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 5396 | friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5397 | }; |
| 5398 | |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5399 | _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
| 5400 | __sp_mut& __get_sp_mut(const void*); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5401 | |
| 5402 | template <class _Tp> |
| 5403 | inline _LIBCPP_INLINE_VISIBILITY |
| 5404 | bool |
| 5405 | atomic_is_lock_free(const shared_ptr<_Tp>*) |
| 5406 | { |
| 5407 | return false; |
| 5408 | } |
| 5409 | |
| 5410 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5411 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5412 | shared_ptr<_Tp> |
| 5413 | atomic_load(const shared_ptr<_Tp>* __p) |
| 5414 | { |
| 5415 | __sp_mut& __m = __get_sp_mut(__p); |
| 5416 | __m.lock(); |
| 5417 | shared_ptr<_Tp> __q = *__p; |
| 5418 | __m.unlock(); |
| 5419 | return __q; |
| 5420 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5421 | |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5422 | template <class _Tp> |
| 5423 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5424 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5425 | shared_ptr<_Tp> |
| 5426 | atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) |
| 5427 | { |
| 5428 | return atomic_load(__p); |
| 5429 | } |
| 5430 | |
| 5431 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5432 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5433 | void |
| 5434 | atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) |
| 5435 | { |
| 5436 | __sp_mut& __m = __get_sp_mut(__p); |
| 5437 | __m.lock(); |
| 5438 | __p->swap(__r); |
| 5439 | __m.unlock(); |
| 5440 | } |
| 5441 | |
| 5442 | template <class _Tp> |
| 5443 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5444 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5445 | void |
| 5446 | atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) |
| 5447 | { |
| 5448 | atomic_store(__p, __r); |
| 5449 | } |
| 5450 | |
| 5451 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5452 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5453 | shared_ptr<_Tp> |
| 5454 | atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) |
| 5455 | { |
| 5456 | __sp_mut& __m = __get_sp_mut(__p); |
| 5457 | __m.lock(); |
| 5458 | __p->swap(__r); |
| 5459 | __m.unlock(); |
| 5460 | return __r; |
| 5461 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5462 | |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5463 | template <class _Tp> |
| 5464 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5465 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5466 | shared_ptr<_Tp> |
| 5467 | atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) |
| 5468 | { |
| 5469 | return atomic_exchange(__p, __r); |
| 5470 | } |
| 5471 | |
| 5472 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5473 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5474 | bool |
| 5475 | atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) |
| 5476 | { |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5477 | shared_ptr<_Tp> __temp; |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5478 | __sp_mut& __m = __get_sp_mut(__p); |
| 5479 | __m.lock(); |
| 5480 | if (__p->__owner_equivalent(*__v)) |
| 5481 | { |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5482 | _VSTD::swap(__temp, *__p); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5483 | *__p = __w; |
| 5484 | __m.unlock(); |
| 5485 | return true; |
| 5486 | } |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5487 | _VSTD::swap(__temp, *__v); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5488 | *__v = *__p; |
| 5489 | __m.unlock(); |
| 5490 | return false; |
| 5491 | } |
| 5492 | |
| 5493 | template <class _Tp> |
| 5494 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5495 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5496 | bool |
| 5497 | atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) |
| 5498 | { |
| 5499 | return atomic_compare_exchange_strong(__p, __v, __w); |
| 5500 | } |
| 5501 | |
| 5502 | template <class _Tp> |
| 5503 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5504 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5505 | bool |
| 5506 | atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, |
| 5507 | shared_ptr<_Tp> __w, memory_order, memory_order) |
| 5508 | { |
| 5509 | return atomic_compare_exchange_strong(__p, __v, __w); |
| 5510 | } |
| 5511 | |
| 5512 | template <class _Tp> |
| 5513 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5514 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5515 | bool |
| 5516 | atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, |
| 5517 | shared_ptr<_Tp> __w, memory_order, memory_order) |
| 5518 | { |
| 5519 | return atomic_compare_exchange_weak(__p, __v, __w); |
| 5520 | } |
| 5521 | |
Eric Fiselier | 9b49267 | 2016-06-18 02:12:53 +0000 | [diff] [blame] | 5522 | #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5523 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5524 | //enum class |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5525 | #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) |
| 5526 | # ifndef _LIBCPP_CXX03_LANG |
| 5527 | enum class pointer_safety : unsigned char { |
| 5528 | relaxed, |
| 5529 | preferred, |
| 5530 | strict |
| 5531 | }; |
| 5532 | # endif |
| 5533 | #else |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 5534 | struct _LIBCPP_TYPE_VIS pointer_safety |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5535 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5536 | enum __lx |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5537 | { |
| 5538 | relaxed, |
| 5539 | preferred, |
| 5540 | strict |
| 5541 | }; |
| 5542 | |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5543 | __lx __v_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5544 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5545 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2fdd22b | 2017-01-05 01:28:40 +0000 | [diff] [blame] | 5546 | pointer_safety() : __v_() {} |
| 5547 | |
| 5548 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5549 | pointer_safety(__lx __v) : __v_(__v) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5550 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5551 | operator int() const {return __v_;} |
| 5552 | }; |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5553 | #endif |
| 5554 | |
| 5555 | #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \ |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 5556 | defined(_LIBCPP_BUILDING_LIBRARY) |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5557 | _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; |
| 5558 | #else |
| 5559 | // This function is only offered in C++03 under ABI v1. |
| 5560 | # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG) |
| 5561 | inline _LIBCPP_INLINE_VISIBILITY |
| 5562 | pointer_safety get_pointer_safety() _NOEXCEPT { |
| 5563 | return pointer_safety::relaxed; |
| 5564 | } |
| 5565 | # endif |
| 5566 | #endif |
| 5567 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5568 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5569 | _LIBCPP_FUNC_VIS void declare_reachable(void* __p); |
| 5570 | _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); |
| 5571 | _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5572 | _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5573 | |
| 5574 | template <class _Tp> |
| 5575 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5576 | _Tp* |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5577 | undeclare_reachable(_Tp* __p) |
| 5578 | { |
| 5579 | return static_cast<_Tp*>(__undeclare_reachable(__p)); |
| 5580 | } |
| 5581 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5582 | _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5583 | |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5584 | // --- Helper for container swap -- |
| 5585 | template <typename _Alloc> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 5586 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5587 | void __swap_allocator(_Alloc & __a1, _Alloc & __a2) |
| 5588 | #if _LIBCPP_STD_VER >= 14 |
| 5589 | _NOEXCEPT |
| 5590 | #else |
| 5591 | _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) |
| 5592 | #endif |
| 5593 | { |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5594 | __swap_allocator(__a1, __a2, |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5595 | integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); |
| 5596 | } |
| 5597 | |
| 5598 | template <typename _Alloc> |
| 5599 | _LIBCPP_INLINE_VISIBILITY |
| 5600 | void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) |
| 5601 | #if _LIBCPP_STD_VER >= 14 |
| 5602 | _NOEXCEPT |
| 5603 | #else |
| 5604 | _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) |
| 5605 | #endif |
| 5606 | { |
| 5607 | using _VSTD::swap; |
| 5608 | swap(__a1, __a2); |
| 5609 | } |
| 5610 | |
| 5611 | template <typename _Alloc> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 5612 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5613 | void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} |
| 5614 | |
Marshall Clow | ff91de8 | 2015-08-18 19:51:37 +0000 | [diff] [blame] | 5615 | template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5616 | struct __noexcept_move_assign_container : public integral_constant<bool, |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 5617 | _Traits::propagate_on_container_move_assignment::value |
| 5618 | #if _LIBCPP_STD_VER > 14 |
| 5619 | || _Traits::is_always_equal::value |
| 5620 | #else |
| 5621 | && is_nothrow_move_assignable<_Alloc>::value |
| 5622 | #endif |
| 5623 | > {}; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5624 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5625 | |
| 5626 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 5627 | template <class _Tp, class _Alloc> |
| 5628 | struct __temp_value { |
| 5629 | typedef allocator_traits<_Alloc> _Traits; |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5630 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5631 | typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v; |
| 5632 | _Alloc &__a; |
| 5633 | |
| 5634 | _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } |
| 5635 | _Tp & get() { return *__addr(); } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5636 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5637 | template<class... _Args> |
Peter Collingbourne | cb12615 | 2018-08-15 17:49:30 +0000 | [diff] [blame] | 5638 | _LIBCPP_NO_CFI |
| 5639 | __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { |
| 5640 | _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)), |
| 5641 | _VSTD::forward<_Args>(__args)...); |
| 5642 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5643 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5644 | ~__temp_value() { _Traits::destroy(__a, __addr()); } |
| 5645 | }; |
| 5646 | #endif |
| 5647 | |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 5648 | template<typename _Alloc, typename = void, typename = void> |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5649 | struct __is_allocator : false_type {}; |
| 5650 | |
| 5651 | template<typename _Alloc> |
| 5652 | struct __is_allocator<_Alloc, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 5653 | typename __void_t<typename _Alloc::value_type>::type, |
| 5654 | typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type |
| 5655 | > |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5656 | : true_type {}; |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5657 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5658 | _LIBCPP_END_NAMESPACE_STD |
| 5659 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 5660 | _LIBCPP_POP_MACROS |
| 5661 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5662 | #endif // _LIBCPP_MEMORY |