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 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 215 | template <class Y> struct auto_ptr_ref {}; // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | |
| 217 | template<class X> |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 218 | class auto_ptr // 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 | |
| 1786 | template <class _Up> |
| 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);} |
Marshall Clow | 0e58cae | 2017-11-26 02:55:38 +0000 | [diff] [blame] | 1794 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 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> |
| 1891 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 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> |
Peter Collingbourne | cd00019 | 2018-01-17 19:32:35 +0000 | [diff] [blame] | 2007 | _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> |
| 2060 | struct auto_ptr_ref |
| 2061 | { |
| 2062 | _Tp* __ptr_; |
| 2063 | }; |
| 2064 | |
| 2065 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2066 | class _LIBCPP_TEMPLATE_VIS 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 <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2110 | class _LIBCPP_TEMPLATE_VIS 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) |
| 2134 | : __value_(_VSTD::forward<_Up>(__u)){}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2135 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2136 | template <class... _Args, size_t... _Indexes> |
| 2137 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2138 | __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, |
| 2139 | __tuple_indices<_Indexes...>) |
| 2140 | : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} |
| 2141 | #else |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2142 | _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {} |
| 2143 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2144 | __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {} |
| 2145 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2146 | |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2147 | _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } |
| 2148 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2149 | const_reference __get() const _NOEXCEPT { return __value_; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2150 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2151 | private: |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2152 | _Tp __value_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2153 | }; |
| 2154 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2155 | template <class _Tp, int _Idx> |
| 2156 | struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { |
| 2157 | typedef _Tp _ParamT; |
| 2158 | typedef _Tp& reference; |
| 2159 | typedef const _Tp& const_reference; |
| 2160 | typedef _Tp __value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2161 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2162 | #ifndef _LIBCPP_CXX03_LANG |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2163 | _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2164 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2165 | template <class _Up, class = typename enable_if< |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2166 | !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value |
| 2167 | >::type> |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2168 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2169 | constexpr explicit |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2170 | __compressed_pair_elem(_Up&& __u) |
| 2171 | : __value_type(_VSTD::forward<_Up>(__u)){}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2172 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2173 | template <class... _Args, size_t... _Indexes> |
| 2174 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2175 | __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, |
| 2176 | __tuple_indices<_Indexes...>) |
| 2177 | : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} |
| 2178 | #else |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2179 | _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {} |
| 2180 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2181 | __compressed_pair_elem(_ParamT __p) |
| 2182 | : __value_type(std::forward<_ParamT>(__p)) {} |
| 2183 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2184 | |
Alex Lorenz | 7613211 | 2017-11-09 17:54:49 +0000 | [diff] [blame] | 2185 | _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } |
| 2186 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2187 | const_reference __get() const _NOEXCEPT { return *this; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2188 | }; |
| 2189 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2190 | // Tag used to construct the second element of the compressed pair. |
| 2191 | struct __second_tag {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2192 | |
| 2193 | template <class _T1, class _T2> |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2194 | class __compressed_pair : private __compressed_pair_elem<_T1, 0>, |
| 2195 | private __compressed_pair_elem<_T2, 1> { |
| 2196 | typedef __compressed_pair_elem<_T1, 0> _Base1; |
| 2197 | typedef __compressed_pair_elem<_T2, 1> _Base2; |
| 2198 | |
| 2199 | // NOTE: This static assert should never fire because __compressed_pair |
| 2200 | // is *almost never* used in a scenario where it's possible for T1 == T2. |
| 2201 | // (The exception is std::function where it is possible that the function |
| 2202 | // object and the allocator have the same type). |
Eric Fiselier | c5adf47 | 2017-04-13 01:13:58 +0000 | [diff] [blame] | 2203 | static_assert((!is_same<_T1, _T2>::value), |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2204 | "__compressed_pair cannot be instantated when T1 and T2 are the same type; " |
| 2205 | "The current implementation is NOT ABI-compatible with the previous " |
| 2206 | "implementation for this configuration"); |
| 2207 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2208 | public: |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2209 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2210 | template <bool _Dummy = true, |
| 2211 | class = typename enable_if< |
| 2212 | __dependent_type<is_default_constructible<_T1>, _Dummy>::value && |
| 2213 | __dependent_type<is_default_constructible<_T2>, _Dummy>::value |
| 2214 | >::type |
| 2215 | > |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2216 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 209ecde | 2017-04-17 22:32:02 +0000 | [diff] [blame] | 2217 | constexpr __compressed_pair() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2218 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2219 | template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type, |
| 2220 | __compressed_pair>::value, |
| 2221 | bool>::type = true> |
| 2222 | _LIBCPP_INLINE_VISIBILITY constexpr explicit |
| 2223 | __compressed_pair(_Tp&& __t) |
| 2224 | : _Base1(std::forward<_Tp>(__t)), _Base2() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2225 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2226 | template <class _Tp> |
| 2227 | _LIBCPP_INLINE_VISIBILITY constexpr |
| 2228 | __compressed_pair(__second_tag, _Tp&& __t) |
| 2229 | : _Base1(), _Base2(std::forward<_Tp>(__t)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2230 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2231 | template <class _U1, class _U2> |
| 2232 | _LIBCPP_INLINE_VISIBILITY constexpr |
| 2233 | __compressed_pair(_U1&& __t1, _U2&& __t2) |
| 2234 | : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2235 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2236 | template <class... _Args1, class... _Args2> |
| 2237 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 2238 | __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, |
| 2239 | tuple<_Args2...> __second_args) |
| 2240 | : _Base1(__pc, _VSTD::move(__first_args), |
| 2241 | typename __make_tuple_indices<sizeof...(_Args1)>::type()), |
| 2242 | _Base2(__pc, _VSTD::move(__second_args), |
| 2243 | typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 2244 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2245 | #else |
| 2246 | _LIBCPP_INLINE_VISIBILITY |
| 2247 | __compressed_pair() {} |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 2248 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2249 | _LIBCPP_INLINE_VISIBILITY explicit |
| 2250 | __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {} |
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 |
| 2253 | __compressed_pair(__second_tag, _T2 __t2) |
| 2254 | : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2255 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2256 | _LIBCPP_INLINE_VISIBILITY |
| 2257 | __compressed_pair(_T1 __t1, _T2 __t2) |
| 2258 | : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {} |
| 2259 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2260 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2261 | _LIBCPP_INLINE_VISIBILITY |
| 2262 | typename _Base1::reference first() _NOEXCEPT { |
| 2263 | return static_cast<_Base1&>(*this).__get(); |
| 2264 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2265 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2266 | _LIBCPP_INLINE_VISIBILITY |
| 2267 | typename _Base1::const_reference first() const _NOEXCEPT { |
| 2268 | return static_cast<_Base1 const&>(*this).__get(); |
| 2269 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2270 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2271 | _LIBCPP_INLINE_VISIBILITY |
| 2272 | typename _Base2::reference second() _NOEXCEPT { |
| 2273 | return static_cast<_Base2&>(*this).__get(); |
| 2274 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2275 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2276 | _LIBCPP_INLINE_VISIBILITY |
| 2277 | typename _Base2::const_reference second() const _NOEXCEPT { |
| 2278 | return static_cast<_Base2 const&>(*this).__get(); |
| 2279 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2280 | |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2281 | _LIBCPP_INLINE_VISIBILITY |
| 2282 | void swap(__compressed_pair& __x) |
| 2283 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2284 | __is_nothrow_swappable<_T2>::value) |
| 2285 | { |
| 2286 | using std::swap; |
| 2287 | swap(first(), __x.first()); |
| 2288 | swap(second(), __x.second()); |
| 2289 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2290 | }; |
| 2291 | |
| 2292 | template <class _T1, class _T2> |
| 2293 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 9d35598 | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 2294 | void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) |
| 2295 | _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && |
| 2296 | __is_nothrow_swappable<_T2>::value) { |
| 2297 | __x.swap(__y); |
| 2298 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2299 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 2300 | // default_delete |
| 2301 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2302 | template <class _Tp> |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2303 | struct _LIBCPP_TEMPLATE_VIS default_delete { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 2304 | static_assert(!is_function<_Tp>::value, |
| 2305 | "default_delete cannot be instantiated for function types"); |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2306 | #ifndef _LIBCPP_CXX03_LANG |
| 2307 | _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2308 | #else |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2309 | _LIBCPP_INLINE_VISIBILITY default_delete() {} |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2310 | #endif |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2311 | template <class _Up> |
| 2312 | _LIBCPP_INLINE_VISIBILITY |
| 2313 | default_delete(const default_delete<_Up>&, |
| 2314 | typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = |
| 2315 | 0) _NOEXCEPT {} |
| 2316 | |
| 2317 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT { |
| 2318 | static_assert(sizeof(_Tp) > 0, |
| 2319 | "default_delete can not delete incomplete type"); |
| 2320 | static_assert(!is_void<_Tp>::value, |
| 2321 | "default_delete can not delete incomplete type"); |
| 2322 | delete __ptr; |
| 2323 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2324 | }; |
| 2325 | |
| 2326 | template <class _Tp> |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2327 | struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { |
| 2328 | private: |
| 2329 | template <class _Up> |
| 2330 | struct _EnableIfConvertible |
| 2331 | : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; |
| 2332 | |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2333 | public: |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2334 | #ifndef _LIBCPP_CXX03_LANG |
| 2335 | _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2336 | #else |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2337 | _LIBCPP_INLINE_VISIBILITY default_delete() {} |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2338 | #endif |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2339 | |
| 2340 | template <class _Up> |
| 2341 | _LIBCPP_INLINE_VISIBILITY |
| 2342 | default_delete(const default_delete<_Up[]>&, |
| 2343 | typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} |
| 2344 | |
| 2345 | template <class _Up> |
| 2346 | _LIBCPP_INLINE_VISIBILITY |
| 2347 | typename _EnableIfConvertible<_Up>::type |
| 2348 | operator()(_Up* __ptr) const _NOEXCEPT { |
| 2349 | static_assert(sizeof(_Tp) > 0, |
| 2350 | "default_delete can not delete incomplete type"); |
| 2351 | static_assert(!is_void<_Tp>::value, |
| 2352 | "default_delete can not delete void type"); |
| 2353 | delete[] __ptr; |
| 2354 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2355 | }; |
| 2356 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2357 | |
Eric Fiselier | 6779b06 | 2017-04-16 02:06:25 +0000 | [diff] [blame] | 2358 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2359 | #ifndef _LIBCPP_CXX03_LANG |
| 2360 | template <class _Deleter> |
| 2361 | struct __unique_ptr_deleter_sfinae { |
| 2362 | static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); |
| 2363 | typedef const _Deleter& __lval_ref_type; |
| 2364 | typedef _Deleter&& __good_rval_ref_type; |
| 2365 | typedef true_type __enable_rval_overload; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2366 | }; |
| 2367 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2368 | template <class _Deleter> |
| 2369 | struct __unique_ptr_deleter_sfinae<_Deleter const&> { |
| 2370 | typedef const _Deleter& __lval_ref_type; |
| 2371 | typedef const _Deleter&& __bad_rval_ref_type; |
| 2372 | typedef false_type __enable_rval_overload; |
| 2373 | }; |
| 2374 | |
| 2375 | template <class _Deleter> |
| 2376 | struct __unique_ptr_deleter_sfinae<_Deleter&> { |
| 2377 | typedef _Deleter& __lval_ref_type; |
| 2378 | typedef _Deleter&& __bad_rval_ref_type; |
| 2379 | typedef false_type __enable_rval_overload; |
| 2380 | }; |
| 2381 | #endif // !defined(_LIBCPP_CXX03_LANG) |
| 2382 | |
| 2383 | template <class _Tp, class _Dp = default_delete<_Tp> > |
| 2384 | class _LIBCPP_TEMPLATE_VIS unique_ptr { |
| 2385 | public: |
| 2386 | typedef _Tp element_type; |
| 2387 | typedef _Dp deleter_type; |
| 2388 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2389 | |
| 2390 | static_assert(!is_rvalue_reference<deleter_type>::value, |
| 2391 | "the specified deleter type cannot be an rvalue reference"); |
| 2392 | |
| 2393 | private: |
| 2394 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 2395 | |
| 2396 | struct __nat { int __for_bool_; }; |
| 2397 | |
| 2398 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2399 | typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2400 | |
| 2401 | template <bool _Dummy> |
| 2402 | using _LValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2403 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2404 | |
| 2405 | template <bool _Dummy> |
| 2406 | using _GoodRValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2407 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2408 | |
| 2409 | template <bool _Dummy> |
| 2410 | using _BadRValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2411 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2412 | |
| 2413 | template <bool _Dummy, class _Deleter = typename __dependent_type< |
| 2414 | __identity<deleter_type>, _Dummy>::type> |
| 2415 | using _EnableIfDeleterDefaultConstructible = |
| 2416 | typename enable_if<is_default_constructible<_Deleter>::value && |
| 2417 | !is_pointer<_Deleter>::value>::type; |
| 2418 | |
| 2419 | template <class _ArgType> |
| 2420 | using _EnableIfDeleterConstructible = |
| 2421 | typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; |
| 2422 | |
| 2423 | template <class _UPtr, class _Up> |
| 2424 | using _EnableIfMoveConvertible = typename enable_if< |
| 2425 | is_convertible<typename _UPtr::pointer, pointer>::value && |
| 2426 | !is_array<_Up>::value |
| 2427 | >::type; |
| 2428 | |
| 2429 | template <class _UDel> |
| 2430 | using _EnableIfDeleterConvertible = typename enable_if< |
| 2431 | (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || |
| 2432 | (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) |
| 2433 | >::type; |
| 2434 | |
| 2435 | template <class _UDel> |
| 2436 | using _EnableIfDeleterAssignable = typename enable_if< |
| 2437 | is_assignable<_Dp&, _UDel&&>::value |
| 2438 | >::type; |
| 2439 | |
| 2440 | public: |
| 2441 | template <bool _Dummy = true, |
| 2442 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2443 | _LIBCPP_INLINE_VISIBILITY |
| 2444 | constexpr unique_ptr() noexcept : __ptr_(pointer()) {} |
| 2445 | |
| 2446 | template <bool _Dummy = true, |
| 2447 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2448 | _LIBCPP_INLINE_VISIBILITY |
| 2449 | constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} |
| 2450 | |
| 2451 | template <bool _Dummy = true, |
| 2452 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2453 | _LIBCPP_INLINE_VISIBILITY |
| 2454 | explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {} |
| 2455 | |
| 2456 | template <bool _Dummy = true, |
| 2457 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> |
| 2458 | _LIBCPP_INLINE_VISIBILITY |
| 2459 | unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept |
| 2460 | : __ptr_(__p, __d) {} |
| 2461 | |
| 2462 | template <bool _Dummy = true, |
| 2463 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> |
| 2464 | _LIBCPP_INLINE_VISIBILITY |
| 2465 | unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept |
| 2466 | : __ptr_(__p, _VSTD::move(__d)) { |
| 2467 | static_assert(!is_reference<deleter_type>::value, |
| 2468 | "rvalue deleter bound to reference"); |
| 2469 | } |
| 2470 | |
| 2471 | template <bool _Dummy = true, |
| 2472 | class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>> |
| 2473 | _LIBCPP_INLINE_VISIBILITY |
| 2474 | unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; |
| 2475 | |
| 2476 | _LIBCPP_INLINE_VISIBILITY |
| 2477 | unique_ptr(unique_ptr&& __u) noexcept |
| 2478 | : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { |
| 2479 | } |
| 2480 | |
| 2481 | template <class _Up, class _Ep, |
| 2482 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2483 | class = _EnableIfDeleterConvertible<_Ep> |
| 2484 | > |
| 2485 | _LIBCPP_INLINE_VISIBILITY |
| 2486 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT |
| 2487 | : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} |
| 2488 | |
| 2489 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 2490 | template <class _Up> |
| 2491 | _LIBCPP_INLINE_VISIBILITY |
| 2492 | unique_ptr(auto_ptr<_Up>&& __p, |
| 2493 | typename enable_if<is_convertible<_Up*, _Tp*>::value && |
| 2494 | is_same<_Dp, default_delete<_Tp>>::value, |
| 2495 | __nat>::type = __nat()) _NOEXCEPT |
| 2496 | : __ptr_(__p.release()) {} |
| 2497 | #endif |
| 2498 | |
| 2499 | _LIBCPP_INLINE_VISIBILITY |
| 2500 | unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { |
| 2501 | reset(__u.release()); |
| 2502 | __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); |
| 2503 | return *this; |
| 2504 | } |
| 2505 | |
| 2506 | template <class _Up, class _Ep, |
| 2507 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2508 | class = _EnableIfDeleterAssignable<_Ep> |
| 2509 | > |
| 2510 | _LIBCPP_INLINE_VISIBILITY |
| 2511 | unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { |
| 2512 | reset(__u.release()); |
| 2513 | __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); |
| 2514 | return *this; |
| 2515 | } |
| 2516 | |
| 2517 | #else // _LIBCPP_CXX03_LANG |
| 2518 | private: |
| 2519 | unique_ptr(unique_ptr&); |
| 2520 | template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&); |
| 2521 | |
| 2522 | unique_ptr& operator=(unique_ptr&); |
| 2523 | template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&); |
| 2524 | |
| 2525 | public: |
| 2526 | _LIBCPP_INLINE_VISIBILITY |
| 2527 | unique_ptr() : __ptr_(pointer()) |
| 2528 | { |
| 2529 | static_assert(!is_pointer<deleter_type>::value, |
| 2530 | "unique_ptr constructed with null function pointer deleter"); |
| 2531 | static_assert(is_default_constructible<deleter_type>::value, |
| 2532 | "unique_ptr::deleter_type is not default constructible"); |
| 2533 | } |
| 2534 | _LIBCPP_INLINE_VISIBILITY |
| 2535 | unique_ptr(nullptr_t) : __ptr_(pointer()) |
| 2536 | { |
| 2537 | static_assert(!is_pointer<deleter_type>::value, |
| 2538 | "unique_ptr constructed with null function pointer deleter"); |
| 2539 | } |
| 2540 | _LIBCPP_INLINE_VISIBILITY |
| 2541 | explicit unique_ptr(pointer __p) |
| 2542 | : __ptr_(_VSTD::move(__p)) { |
| 2543 | static_assert(!is_pointer<deleter_type>::value, |
| 2544 | "unique_ptr constructed with null function pointer deleter"); |
| 2545 | } |
| 2546 | |
| 2547 | _LIBCPP_INLINE_VISIBILITY |
| 2548 | operator __rv<unique_ptr>() { |
| 2549 | return __rv<unique_ptr>(*this); |
| 2550 | } |
| 2551 | |
| 2552 | _LIBCPP_INLINE_VISIBILITY |
| 2553 | unique_ptr(__rv<unique_ptr> __u) |
| 2554 | : __ptr_(__u->release(), |
| 2555 | _VSTD::forward<deleter_type>(__u->get_deleter())) {} |
| 2556 | |
| 2557 | template <class _Up, class _Ep> |
| 2558 | _LIBCPP_INLINE_VISIBILITY |
| 2559 | typename enable_if< |
| 2560 | !is_array<_Up>::value && |
| 2561 | is_convertible<typename unique_ptr<_Up, _Ep>::pointer, |
| 2562 | pointer>::value && |
| 2563 | is_assignable<deleter_type&, _Ep&>::value, |
| 2564 | unique_ptr&>::type |
| 2565 | operator=(unique_ptr<_Up, _Ep> __u) { |
| 2566 | reset(__u.release()); |
| 2567 | __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); |
| 2568 | return *this; |
| 2569 | } |
| 2570 | |
| 2571 | _LIBCPP_INLINE_VISIBILITY |
| 2572 | unique_ptr(pointer __p, deleter_type __d) |
| 2573 | : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {} |
| 2574 | #endif // _LIBCPP_CXX03_LANG |
| 2575 | |
| 2576 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 2577 | template <class _Up> |
| 2578 | _LIBCPP_INLINE_VISIBILITY |
| 2579 | typename enable_if<is_convertible<_Up*, _Tp*>::value && |
| 2580 | is_same<_Dp, default_delete<_Tp> >::value, |
| 2581 | unique_ptr&>::type |
| 2582 | operator=(auto_ptr<_Up> __p) { |
| 2583 | reset(__p.release()); |
| 2584 | return *this; |
| 2585 | } |
| 2586 | #endif |
| 2587 | |
| 2588 | _LIBCPP_INLINE_VISIBILITY |
| 2589 | ~unique_ptr() { reset(); } |
| 2590 | |
| 2591 | _LIBCPP_INLINE_VISIBILITY |
| 2592 | unique_ptr& operator=(nullptr_t) _NOEXCEPT { |
| 2593 | reset(); |
| 2594 | return *this; |
| 2595 | } |
| 2596 | |
| 2597 | _LIBCPP_INLINE_VISIBILITY |
| 2598 | typename add_lvalue_reference<_Tp>::type |
| 2599 | operator*() const { |
| 2600 | return *__ptr_.first(); |
| 2601 | } |
| 2602 | _LIBCPP_INLINE_VISIBILITY |
| 2603 | pointer operator->() const _NOEXCEPT { |
| 2604 | return __ptr_.first(); |
| 2605 | } |
| 2606 | _LIBCPP_INLINE_VISIBILITY |
| 2607 | pointer get() const _NOEXCEPT { |
| 2608 | return __ptr_.first(); |
| 2609 | } |
| 2610 | _LIBCPP_INLINE_VISIBILITY |
| 2611 | deleter_type& get_deleter() _NOEXCEPT { |
| 2612 | return __ptr_.second(); |
| 2613 | } |
| 2614 | _LIBCPP_INLINE_VISIBILITY |
| 2615 | const deleter_type& get_deleter() const _NOEXCEPT { |
| 2616 | return __ptr_.second(); |
| 2617 | } |
| 2618 | _LIBCPP_INLINE_VISIBILITY |
| 2619 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { |
| 2620 | return __ptr_.first() != nullptr; |
| 2621 | } |
| 2622 | |
| 2623 | _LIBCPP_INLINE_VISIBILITY |
| 2624 | pointer release() _NOEXCEPT { |
| 2625 | pointer __t = __ptr_.first(); |
| 2626 | __ptr_.first() = pointer(); |
| 2627 | return __t; |
| 2628 | } |
| 2629 | |
| 2630 | _LIBCPP_INLINE_VISIBILITY |
| 2631 | void reset(pointer __p = pointer()) _NOEXCEPT { |
| 2632 | pointer __tmp = __ptr_.first(); |
| 2633 | __ptr_.first() = __p; |
| 2634 | if (__tmp) |
| 2635 | __ptr_.second()(__tmp); |
| 2636 | } |
| 2637 | |
| 2638 | _LIBCPP_INLINE_VISIBILITY |
| 2639 | void swap(unique_ptr& __u) _NOEXCEPT { |
| 2640 | __ptr_.swap(__u.__ptr_); |
| 2641 | } |
| 2642 | }; |
| 2643 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2644 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2645 | template <class _Tp, class _Dp> |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2646 | class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2647 | public: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2648 | typedef _Tp element_type; |
| 2649 | typedef _Dp deleter_type; |
| 2650 | typedef typename __pointer_type<_Tp, deleter_type>::type pointer; |
| 2651 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2652 | private: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2653 | __compressed_pair<pointer, deleter_type> __ptr_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2654 | |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2655 | template <class _From> |
| 2656 | struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; |
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 _FromElem> |
| 2659 | struct _CheckArrayPointerConversion<_FromElem*> |
| 2660 | : integral_constant<bool, |
| 2661 | is_same<_FromElem*, pointer>::value || |
| 2662 | (is_same<pointer, element_type*>::value && |
| 2663 | is_convertible<_FromElem(*)[], element_type(*)[]>::value) |
| 2664 | > |
| 2665 | {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2666 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2667 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2668 | typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2669 | |
| 2670 | template <bool _Dummy> |
| 2671 | using _LValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2672 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2673 | |
| 2674 | template <bool _Dummy> |
| 2675 | using _GoodRValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2676 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2677 | |
| 2678 | template <bool _Dummy> |
| 2679 | using _BadRValRefType = |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2680 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2681 | |
| 2682 | template <bool _Dummy, class _Deleter = typename __dependent_type< |
| 2683 | __identity<deleter_type>, _Dummy>::type> |
| 2684 | using _EnableIfDeleterDefaultConstructible = |
| 2685 | typename enable_if<is_default_constructible<_Deleter>::value && |
| 2686 | !is_pointer<_Deleter>::value>::type; |
| 2687 | |
| 2688 | template <class _ArgType> |
| 2689 | using _EnableIfDeleterConstructible = |
| 2690 | typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; |
| 2691 | |
| 2692 | template <class _Pp> |
| 2693 | using _EnableIfPointerConvertible = typename enable_if< |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2694 | _CheckArrayPointerConversion<_Pp>::value |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2695 | >::type; |
| 2696 | |
| 2697 | template <class _UPtr, class _Up, |
| 2698 | class _ElemT = typename _UPtr::element_type> |
| 2699 | using _EnableIfMoveConvertible = typename enable_if< |
| 2700 | is_array<_Up>::value && |
| 2701 | is_same<pointer, element_type*>::value && |
| 2702 | is_same<typename _UPtr::pointer, _ElemT*>::value && |
| 2703 | is_convertible<_ElemT(*)[], element_type(*)[]>::value |
| 2704 | >::type; |
| 2705 | |
| 2706 | template <class _UDel> |
| 2707 | using _EnableIfDeleterConvertible = typename enable_if< |
| 2708 | (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || |
| 2709 | (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) |
| 2710 | >::type; |
| 2711 | |
| 2712 | template <class _UDel> |
| 2713 | using _EnableIfDeleterAssignable = typename enable_if< |
| 2714 | is_assignable<_Dp&, _UDel&&>::value |
| 2715 | >::type; |
| 2716 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2717 | public: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2718 | template <bool _Dummy = true, |
| 2719 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2720 | _LIBCPP_INLINE_VISIBILITY |
| 2721 | constexpr unique_ptr() noexcept : __ptr_(pointer()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2722 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2723 | template <bool _Dummy = true, |
| 2724 | class = _EnableIfDeleterDefaultConstructible<_Dummy>> |
| 2725 | _LIBCPP_INLINE_VISIBILITY |
| 2726 | constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2727 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2728 | template <class _Pp, bool _Dummy = true, |
| 2729 | class = _EnableIfDeleterDefaultConstructible<_Dummy>, |
| 2730 | class = _EnableIfPointerConvertible<_Pp>> |
| 2731 | _LIBCPP_INLINE_VISIBILITY |
| 2732 | explicit unique_ptr(_Pp __p) noexcept |
| 2733 | : __ptr_(__p) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2734 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2735 | template <class _Pp, bool _Dummy = true, |
| 2736 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>, |
| 2737 | class = _EnableIfPointerConvertible<_Pp>> |
| 2738 | _LIBCPP_INLINE_VISIBILITY |
| 2739 | unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept |
| 2740 | : __ptr_(__p, __d) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2741 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2742 | template <bool _Dummy = true, |
| 2743 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> |
| 2744 | _LIBCPP_INLINE_VISIBILITY |
| 2745 | unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept |
| 2746 | : __ptr_(nullptr, __d) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2747 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2748 | template <class _Pp, bool _Dummy = true, |
| 2749 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>, |
| 2750 | class = _EnableIfPointerConvertible<_Pp>> |
| 2751 | _LIBCPP_INLINE_VISIBILITY |
| 2752 | unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept |
| 2753 | : __ptr_(__p, _VSTD::move(__d)) { |
| 2754 | static_assert(!is_reference<deleter_type>::value, |
| 2755 | "rvalue deleter bound to reference"); |
| 2756 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2757 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2758 | template <bool _Dummy = true, |
| 2759 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> |
| 2760 | _LIBCPP_INLINE_VISIBILITY |
| 2761 | unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept |
| 2762 | : __ptr_(nullptr, _VSTD::move(__d)) { |
| 2763 | static_assert(!is_reference<deleter_type>::value, |
| 2764 | "rvalue deleter bound to reference"); |
| 2765 | } |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2766 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2767 | template <class _Pp, bool _Dummy = true, |
| 2768 | class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>, |
| 2769 | class = _EnableIfPointerConvertible<_Pp>> |
| 2770 | _LIBCPP_INLINE_VISIBILITY |
| 2771 | unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2772 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2773 | _LIBCPP_INLINE_VISIBILITY |
| 2774 | unique_ptr(unique_ptr&& __u) noexcept |
| 2775 | : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { |
| 2776 | } |
Howard Hinnant | 4500ca5 | 2011-12-18 21:19:44 +0000 | [diff] [blame] | 2777 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2778 | _LIBCPP_INLINE_VISIBILITY |
| 2779 | unique_ptr& operator=(unique_ptr&& __u) noexcept { |
| 2780 | reset(__u.release()); |
| 2781 | __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); |
| 2782 | return *this; |
| 2783 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2784 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2785 | template <class _Up, class _Ep, |
| 2786 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2787 | class = _EnableIfDeleterConvertible<_Ep> |
| 2788 | > |
| 2789 | _LIBCPP_INLINE_VISIBILITY |
| 2790 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
Eric Fiselier | 3827e6a | 2017-04-17 20:20:27 +0000 | [diff] [blame] | 2791 | : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2792 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2793 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2794 | template <class _Up, class _Ep, |
| 2795 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 2796 | class = _EnableIfDeleterAssignable<_Ep> |
| 2797 | > |
| 2798 | _LIBCPP_INLINE_VISIBILITY |
| 2799 | unique_ptr& |
| 2800 | operator=(unique_ptr<_Up, _Ep>&& __u) noexcept { |
| 2801 | reset(__u.release()); |
| 2802 | __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); |
| 2803 | return *this; |
| 2804 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2805 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2806 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2807 | private: |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2808 | template <class _Up> explicit unique_ptr(_Up); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2809 | |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2810 | unique_ptr(unique_ptr&); |
| 2811 | template <class _Up> unique_ptr(unique_ptr<_Up>&); |
| 2812 | |
| 2813 | unique_ptr& operator=(unique_ptr&); |
| 2814 | template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&); |
| 2815 | |
| 2816 | template <class _Up> |
| 2817 | unique_ptr(_Up __u, |
| 2818 | typename conditional< |
| 2819 | is_reference<deleter_type>::value, deleter_type, |
| 2820 | typename add_lvalue_reference<const deleter_type>::type>::type, |
| 2821 | typename enable_if<is_convertible<_Up, pointer>::value, |
| 2822 | __nat>::type = __nat()); |
| 2823 | public: |
| 2824 | _LIBCPP_INLINE_VISIBILITY |
| 2825 | unique_ptr() : __ptr_(pointer()) { |
| 2826 | static_assert(!is_pointer<deleter_type>::value, |
| 2827 | "unique_ptr constructed with null function pointer deleter"); |
| 2828 | } |
| 2829 | _LIBCPP_INLINE_VISIBILITY |
| 2830 | unique_ptr(nullptr_t) : __ptr_(pointer()) { |
| 2831 | static_assert(!is_pointer<deleter_type>::value, |
| 2832 | "unique_ptr constructed with null function pointer deleter"); |
| 2833 | } |
| 2834 | |
| 2835 | _LIBCPP_INLINE_VISIBILITY |
| 2836 | explicit unique_ptr(pointer __p) : __ptr_(__p) { |
| 2837 | static_assert(!is_pointer<deleter_type>::value, |
| 2838 | "unique_ptr constructed with null function pointer deleter"); |
| 2839 | } |
| 2840 | |
| 2841 | _LIBCPP_INLINE_VISIBILITY |
| 2842 | unique_ptr(pointer __p, deleter_type __d) |
| 2843 | : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {} |
| 2844 | |
| 2845 | _LIBCPP_INLINE_VISIBILITY |
| 2846 | unique_ptr(nullptr_t, deleter_type __d) |
| 2847 | : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {} |
| 2848 | |
| 2849 | _LIBCPP_INLINE_VISIBILITY |
| 2850 | operator __rv<unique_ptr>() { |
| 2851 | return __rv<unique_ptr>(*this); |
| 2852 | } |
| 2853 | |
| 2854 | _LIBCPP_INLINE_VISIBILITY |
| 2855 | unique_ptr(__rv<unique_ptr> __u) |
| 2856 | : __ptr_(__u->release(), |
| 2857 | _VSTD::forward<deleter_type>(__u->get_deleter())) {} |
| 2858 | |
| 2859 | _LIBCPP_INLINE_VISIBILITY |
| 2860 | unique_ptr& operator=(__rv<unique_ptr> __u) { |
| 2861 | reset(__u->release()); |
| 2862 | __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter()); |
| 2863 | return *this; |
| 2864 | } |
| 2865 | |
| 2866 | #endif // _LIBCPP_CXX03_LANG |
| 2867 | |
| 2868 | public: |
| 2869 | _LIBCPP_INLINE_VISIBILITY |
| 2870 | ~unique_ptr() { reset(); } |
| 2871 | |
| 2872 | _LIBCPP_INLINE_VISIBILITY |
| 2873 | unique_ptr& operator=(nullptr_t) _NOEXCEPT { |
| 2874 | reset(); |
| 2875 | return *this; |
| 2876 | } |
| 2877 | |
| 2878 | _LIBCPP_INLINE_VISIBILITY |
| 2879 | typename add_lvalue_reference<_Tp>::type |
| 2880 | operator[](size_t __i) const { |
| 2881 | return __ptr_.first()[__i]; |
| 2882 | } |
| 2883 | _LIBCPP_INLINE_VISIBILITY |
| 2884 | pointer get() const _NOEXCEPT { |
| 2885 | return __ptr_.first(); |
| 2886 | } |
| 2887 | |
| 2888 | _LIBCPP_INLINE_VISIBILITY |
| 2889 | deleter_type& get_deleter() _NOEXCEPT { |
| 2890 | return __ptr_.second(); |
| 2891 | } |
| 2892 | |
| 2893 | _LIBCPP_INLINE_VISIBILITY |
| 2894 | const deleter_type& get_deleter() const _NOEXCEPT { |
| 2895 | return __ptr_.second(); |
| 2896 | } |
| 2897 | _LIBCPP_INLINE_VISIBILITY |
| 2898 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { |
| 2899 | return __ptr_.first() != nullptr; |
| 2900 | } |
| 2901 | |
| 2902 | _LIBCPP_INLINE_VISIBILITY |
| 2903 | pointer release() _NOEXCEPT { |
| 2904 | pointer __t = __ptr_.first(); |
| 2905 | __ptr_.first() = pointer(); |
| 2906 | return __t; |
| 2907 | } |
| 2908 | |
| 2909 | template <class _Pp> |
| 2910 | _LIBCPP_INLINE_VISIBILITY |
| 2911 | typename enable_if< |
Eric Fiselier | 31127cd | 2017-04-16 02:14:31 +0000 | [diff] [blame] | 2912 | _CheckArrayPointerConversion<_Pp>::value |
Eric Fiselier | fecf9ea | 2017-04-16 01:51:04 +0000 | [diff] [blame] | 2913 | >::type |
| 2914 | reset(_Pp __p) _NOEXCEPT { |
| 2915 | pointer __tmp = __ptr_.first(); |
| 2916 | __ptr_.first() = __p; |
| 2917 | if (__tmp) |
| 2918 | __ptr_.second()(__tmp); |
| 2919 | } |
| 2920 | |
| 2921 | _LIBCPP_INLINE_VISIBILITY |
| 2922 | void reset(nullptr_t = nullptr) _NOEXCEPT { |
| 2923 | pointer __tmp = __ptr_.first(); |
| 2924 | __ptr_.first() = nullptr; |
| 2925 | if (__tmp) |
| 2926 | __ptr_.second()(__tmp); |
| 2927 | } |
| 2928 | |
| 2929 | _LIBCPP_INLINE_VISIBILITY |
| 2930 | void swap(unique_ptr& __u) _NOEXCEPT { |
| 2931 | __ptr_.swap(__u.__ptr_); |
| 2932 | } |
| 2933 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2934 | }; |
| 2935 | |
| 2936 | template <class _Tp, class _Dp> |
| 2937 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6bfed25 | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 2938 | typename enable_if< |
| 2939 | __is_swappable<_Dp>::value, |
| 2940 | void |
| 2941 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 2942 | 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] | 2943 | |
| 2944 | template <class _T1, class _D1, class _T2, class _D2> |
| 2945 | inline _LIBCPP_INLINE_VISIBILITY |
| 2946 | bool |
| 2947 | operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} |
| 2948 | |
| 2949 | template <class _T1, class _D1, class _T2, class _D2> |
| 2950 | inline _LIBCPP_INLINE_VISIBILITY |
| 2951 | bool |
| 2952 | operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} |
| 2953 | |
| 2954 | template <class _T1, class _D1, class _T2, class _D2> |
| 2955 | inline _LIBCPP_INLINE_VISIBILITY |
| 2956 | bool |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2957 | operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) |
| 2958 | { |
| 2959 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 2960 | typedef typename unique_ptr<_T2, _D2>::pointer _P2; |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 2961 | typedef typename common_type<_P1, _P2>::type _Vp; |
| 2962 | return less<_Vp>()(__x.get(), __y.get()); |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2963 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2964 | |
| 2965 | template <class _T1, class _D1, class _T2, class _D2> |
| 2966 | inline _LIBCPP_INLINE_VISIBILITY |
| 2967 | bool |
| 2968 | operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} |
| 2969 | |
| 2970 | template <class _T1, class _D1, class _T2, class _D2> |
| 2971 | inline _LIBCPP_INLINE_VISIBILITY |
| 2972 | bool |
| 2973 | operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} |
| 2974 | |
| 2975 | template <class _T1, class _D1, class _T2, class _D2> |
| 2976 | inline _LIBCPP_INLINE_VISIBILITY |
| 2977 | bool |
| 2978 | operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} |
| 2979 | |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2980 | template <class _T1, class _D1> |
| 2981 | inline _LIBCPP_INLINE_VISIBILITY |
| 2982 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2983 | operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2984 | { |
| 2985 | return !__x; |
| 2986 | } |
| 2987 | |
| 2988 | template <class _T1, class _D1> |
| 2989 | inline _LIBCPP_INLINE_VISIBILITY |
| 2990 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2991 | operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 2992 | { |
| 2993 | return !__x; |
| 2994 | } |
| 2995 | |
| 2996 | template <class _T1, class _D1> |
| 2997 | inline _LIBCPP_INLINE_VISIBILITY |
| 2998 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 2999 | operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 3000 | { |
| 3001 | return static_cast<bool>(__x); |
| 3002 | } |
| 3003 | |
| 3004 | template <class _T1, class _D1> |
| 3005 | inline _LIBCPP_INLINE_VISIBILITY |
| 3006 | bool |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3007 | operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 3008 | { |
| 3009 | return static_cast<bool>(__x); |
| 3010 | } |
| 3011 | |
| 3012 | template <class _T1, class _D1> |
| 3013 | inline _LIBCPP_INLINE_VISIBILITY |
| 3014 | bool |
| 3015 | operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3016 | { |
| 3017 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 3018 | return less<_P1>()(__x.get(), nullptr); |
| 3019 | } |
| 3020 | |
| 3021 | template <class _T1, class _D1> |
| 3022 | inline _LIBCPP_INLINE_VISIBILITY |
| 3023 | bool |
| 3024 | operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3025 | { |
| 3026 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 3027 | return less<_P1>()(nullptr, __x.get()); |
| 3028 | } |
| 3029 | |
| 3030 | template <class _T1, class _D1> |
| 3031 | inline _LIBCPP_INLINE_VISIBILITY |
| 3032 | bool |
| 3033 | operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3034 | { |
| 3035 | return nullptr < __x; |
| 3036 | } |
| 3037 | |
| 3038 | template <class _T1, class _D1> |
| 3039 | inline _LIBCPP_INLINE_VISIBILITY |
| 3040 | bool |
| 3041 | operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3042 | { |
| 3043 | return __x < nullptr; |
| 3044 | } |
| 3045 | |
| 3046 | template <class _T1, class _D1> |
| 3047 | inline _LIBCPP_INLINE_VISIBILITY |
| 3048 | bool |
| 3049 | operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3050 | { |
| 3051 | return !(nullptr < __x); |
| 3052 | } |
| 3053 | |
| 3054 | template <class _T1, class _D1> |
| 3055 | inline _LIBCPP_INLINE_VISIBILITY |
| 3056 | bool |
| 3057 | operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3058 | { |
| 3059 | return !(__x < nullptr); |
| 3060 | } |
| 3061 | |
| 3062 | template <class _T1, class _D1> |
| 3063 | inline _LIBCPP_INLINE_VISIBILITY |
| 3064 | bool |
| 3065 | operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 3066 | { |
| 3067 | return !(__x < nullptr); |
| 3068 | } |
| 3069 | |
| 3070 | template <class _T1, class _D1> |
| 3071 | inline _LIBCPP_INLINE_VISIBILITY |
| 3072 | bool |
| 3073 | operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 3074 | { |
| 3075 | return !(nullptr < __x); |
| 3076 | } |
| 3077 | |
Howard Hinnant | 9e028f1 | 2012-05-01 15:37:54 +0000 | [diff] [blame] | 3078 | #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 3079 | |
| 3080 | template <class _Tp, class _Dp> |
| 3081 | inline _LIBCPP_INLINE_VISIBILITY |
| 3082 | unique_ptr<_Tp, _Dp> |
| 3083 | move(unique_ptr<_Tp, _Dp>& __t) |
| 3084 | { |
| 3085 | return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t)); |
| 3086 | } |
| 3087 | |
| 3088 | #endif |
| 3089 | |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3090 | #if _LIBCPP_STD_VER > 11 |
| 3091 | |
| 3092 | template<class _Tp> |
| 3093 | struct __unique_if |
| 3094 | { |
| 3095 | typedef unique_ptr<_Tp> __unique_single; |
| 3096 | }; |
| 3097 | |
| 3098 | template<class _Tp> |
| 3099 | struct __unique_if<_Tp[]> |
| 3100 | { |
| 3101 | typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; |
| 3102 | }; |
| 3103 | |
| 3104 | template<class _Tp, size_t _Np> |
| 3105 | struct __unique_if<_Tp[_Np]> |
| 3106 | { |
| 3107 | typedef void __unique_array_known_bound; |
| 3108 | }; |
| 3109 | |
| 3110 | template<class _Tp, class... _Args> |
Marshall Clow | 724e3df | 2013-07-02 20:06:09 +0000 | [diff] [blame] | 3111 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3112 | typename __unique_if<_Tp>::__unique_single |
| 3113 | make_unique(_Args&&... __args) |
| 3114 | { |
| 3115 | return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); |
| 3116 | } |
| 3117 | |
| 3118 | template<class _Tp> |
Marshall Clow | 724e3df | 2013-07-02 20:06:09 +0000 | [diff] [blame] | 3119 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 9e8f4a9 | 2013-07-01 18:16:03 +0000 | [diff] [blame] | 3120 | typename __unique_if<_Tp>::__unique_array_unknown_bound |
| 3121 | make_unique(size_t __n) |
| 3122 | { |
| 3123 | typedef typename remove_extent<_Tp>::type _Up; |
| 3124 | return unique_ptr<_Tp>(new _Up[__n]()); |
| 3125 | } |
| 3126 | |
| 3127 | template<class _Tp, class... _Args> |
| 3128 | typename __unique_if<_Tp>::__unique_array_known_bound |
| 3129 | make_unique(_Args&&...) = delete; |
| 3130 | |
| 3131 | #endif // _LIBCPP_STD_VER > 11 |
| 3132 | |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3133 | template <class _Tp, class _Dp> |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 3134 | #ifdef _LIBCPP_CXX03_LANG |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3135 | struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> > |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 3136 | #else |
| 3137 | struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< |
| 3138 | unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>> |
| 3139 | #endif |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3140 | { |
| 3141 | typedef unique_ptr<_Tp, _Dp> argument_type; |
| 3142 | typedef size_t result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3143 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4903689 | 2017-03-23 02:40:28 +0000 | [diff] [blame] | 3144 | result_type operator()(const argument_type& __ptr) const |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3145 | { |
| 3146 | typedef typename argument_type::pointer pointer; |
| 3147 | return hash<pointer>()(__ptr.get()); |
| 3148 | } |
| 3149 | }; |
| 3150 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3151 | struct __destruct_n |
| 3152 | { |
| 3153 | private: |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3154 | size_t __size_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3155 | |
| 3156 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3157 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3158 | {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3159 | |
| 3160 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3161 | _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3162 | {} |
| 3163 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3164 | _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3165 | {++__size_;} |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3166 | _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3167 | {} |
| 3168 | |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3169 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3170 | {__size_ = __s;} |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3171 | _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3172 | {} |
| 3173 | public: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3174 | _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 3175 | : __size_(__s) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3176 | |
| 3177 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3178 | _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3179 | {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3180 | |
| 3181 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3182 | _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3183 | {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3184 | |
| 3185 | template <class _Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3186 | _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 3187 | {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3188 | }; |
| 3189 | |
| 3190 | template <class _Alloc> |
| 3191 | class __allocator_destructor |
| 3192 | { |
| 3193 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 3194 | public: |
| 3195 | typedef typename __alloc_traits::pointer pointer; |
| 3196 | typedef typename __alloc_traits::size_type size_type; |
| 3197 | private: |
| 3198 | _Alloc& __alloc_; |
| 3199 | size_type __s_; |
| 3200 | public: |
| 3201 | _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3202 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3203 | : __alloc_(__a), __s_(__s) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3204 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3205 | void operator()(pointer __p) _NOEXCEPT |
| 3206 | {__alloc_traits::deallocate(__alloc_, __p, __s_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3207 | }; |
| 3208 | |
| 3209 | template <class _InputIterator, class _ForwardIterator> |
| 3210 | _ForwardIterator |
| 3211 | uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) |
| 3212 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3213 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3214 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3215 | _ForwardIterator __s = __r; |
| 3216 | try |
| 3217 | { |
| 3218 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3219 | for (; __f != __l; ++__f, (void) ++__r) |
| 3220 | ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3221 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3222 | } |
| 3223 | catch (...) |
| 3224 | { |
| 3225 | for (; __s != __r; ++__s) |
| 3226 | __s->~value_type(); |
| 3227 | throw; |
| 3228 | } |
| 3229 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3230 | return __r; |
| 3231 | } |
| 3232 | |
| 3233 | template <class _InputIterator, class _Size, class _ForwardIterator> |
| 3234 | _ForwardIterator |
| 3235 | uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) |
| 3236 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3237 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3238 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3239 | _ForwardIterator __s = __r; |
| 3240 | try |
| 3241 | { |
| 3242 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3243 | for (; __n > 0; ++__f, (void) ++__r, (void) --__n) |
| 3244 | ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3245 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3246 | } |
| 3247 | catch (...) |
| 3248 | { |
| 3249 | for (; __s != __r; ++__s) |
| 3250 | __s->~value_type(); |
| 3251 | throw; |
| 3252 | } |
| 3253 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3254 | return __r; |
| 3255 | } |
| 3256 | |
| 3257 | template <class _ForwardIterator, class _Tp> |
| 3258 | void |
| 3259 | uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) |
| 3260 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3261 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3262 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3263 | _ForwardIterator __s = __f; |
| 3264 | try |
| 3265 | { |
| 3266 | #endif |
| 3267 | for (; __f != __l; ++__f) |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3268 | ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3269 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3270 | } |
| 3271 | catch (...) |
| 3272 | { |
| 3273 | for (; __s != __f; ++__s) |
| 3274 | __s->~value_type(); |
| 3275 | throw; |
| 3276 | } |
| 3277 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | template <class _ForwardIterator, class _Size, class _Tp> |
Howard Hinnant | 3c81109 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 3281 | _ForwardIterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3282 | uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) |
| 3283 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3284 | typedef typename iterator_traits<_ForwardIterator>::value_type value_type; |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3285 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3286 | _ForwardIterator __s = __f; |
| 3287 | try |
| 3288 | { |
| 3289 | #endif |
Marshall Clow | 5e9cb8f | 2015-05-19 15:01:48 +0000 | [diff] [blame] | 3290 | for (; __n > 0; ++__f, (void) --__n) |
| 3291 | ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); |
Howard Hinnant | 2fa038c | 2011-12-29 17:45:35 +0000 | [diff] [blame] | 3292 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3293 | } |
| 3294 | catch (...) |
| 3295 | { |
| 3296 | for (; __s != __f; ++__s) |
| 3297 | __s->~value_type(); |
| 3298 | throw; |
| 3299 | } |
| 3300 | #endif |
Howard Hinnant | 3c81109 | 2010-11-18 16:13:03 +0000 | [diff] [blame] | 3301 | return __f; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3304 | #if _LIBCPP_STD_VER > 14 |
| 3305 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3306 | template <class _Tp> |
| 3307 | inline _LIBCPP_INLINE_VISIBILITY |
| 3308 | void destroy_at(_Tp* __loc) { |
| 3309 | _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); |
| 3310 | __loc->~_Tp(); |
| 3311 | } |
| 3312 | |
| 3313 | template <class _ForwardIterator> |
| 3314 | inline _LIBCPP_INLINE_VISIBILITY |
| 3315 | void destroy(_ForwardIterator __first, _ForwardIterator __last) { |
| 3316 | for (; __first != __last; ++__first) |
| 3317 | _VSTD::destroy_at(_VSTD::addressof(*__first)); |
| 3318 | } |
| 3319 | |
| 3320 | template <class _ForwardIterator, class _Size> |
| 3321 | inline _LIBCPP_INLINE_VISIBILITY |
| 3322 | _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { |
| 3323 | for (; __n > 0; (void)++__first, --__n) |
| 3324 | _VSTD::destroy_at(_VSTD::addressof(*__first)); |
| 3325 | return __first; |
| 3326 | } |
| 3327 | |
Eric Fiselier | 290c07c | 2016-10-11 21:13:44 +0000 | [diff] [blame] | 3328 | template <class _ForwardIterator> |
| 3329 | inline _LIBCPP_INLINE_VISIBILITY |
| 3330 | void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { |
| 3331 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3332 | auto __idx = __first; |
| 3333 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3334 | try { |
| 3335 | #endif |
| 3336 | for (; __idx != __last; ++__idx) |
| 3337 | ::new((void*)_VSTD::addressof(*__idx)) _Vt; |
| 3338 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3339 | } catch (...) { |
| 3340 | _VSTD::destroy(__first, __idx); |
| 3341 | throw; |
| 3342 | } |
| 3343 | #endif |
| 3344 | } |
| 3345 | |
| 3346 | template <class _ForwardIterator, class _Size> |
| 3347 | inline _LIBCPP_INLINE_VISIBILITY |
| 3348 | _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { |
| 3349 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3350 | auto __idx = __first; |
| 3351 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3352 | try { |
| 3353 | #endif |
| 3354 | for (; __n > 0; (void)++__idx, --__n) |
| 3355 | ::new((void*)_VSTD::addressof(*__idx)) _Vt; |
| 3356 | return __idx; |
| 3357 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3358 | } catch (...) { |
| 3359 | _VSTD::destroy(__first, __idx); |
| 3360 | throw; |
| 3361 | } |
| 3362 | #endif |
| 3363 | } |
| 3364 | |
| 3365 | |
| 3366 | template <class _ForwardIterator> |
| 3367 | inline _LIBCPP_INLINE_VISIBILITY |
| 3368 | void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { |
| 3369 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3370 | auto __idx = __first; |
| 3371 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3372 | try { |
| 3373 | #endif |
| 3374 | for (; __idx != __last; ++__idx) |
| 3375 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(); |
| 3376 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3377 | } catch (...) { |
| 3378 | _VSTD::destroy(__first, __idx); |
| 3379 | throw; |
| 3380 | } |
| 3381 | #endif |
| 3382 | } |
| 3383 | |
| 3384 | template <class _ForwardIterator, class _Size> |
| 3385 | inline _LIBCPP_INLINE_VISIBILITY |
| 3386 | _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { |
| 3387 | using _Vt = typename iterator_traits<_ForwardIterator>::value_type; |
| 3388 | auto __idx = __first; |
| 3389 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3390 | try { |
| 3391 | #endif |
| 3392 | for (; __n > 0; (void)++__idx, --__n) |
| 3393 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(); |
| 3394 | return __idx; |
| 3395 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3396 | } catch (...) { |
| 3397 | _VSTD::destroy(__first, __idx); |
| 3398 | throw; |
| 3399 | } |
| 3400 | #endif |
| 3401 | } |
| 3402 | |
| 3403 | |
| 3404 | template <class _InputIt, class _ForwardIt> |
| 3405 | inline _LIBCPP_INLINE_VISIBILITY |
| 3406 | _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) { |
| 3407 | using _Vt = typename iterator_traits<_ForwardIt>::value_type; |
| 3408 | auto __idx = __first_res; |
| 3409 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3410 | try { |
| 3411 | #endif |
| 3412 | for (; __first != __last; (void)++__idx, ++__first) |
| 3413 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); |
| 3414 | return __idx; |
| 3415 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3416 | } catch (...) { |
| 3417 | _VSTD::destroy(__first_res, __idx); |
| 3418 | throw; |
| 3419 | } |
| 3420 | #endif |
| 3421 | } |
| 3422 | |
| 3423 | template <class _InputIt, class _Size, class _ForwardIt> |
| 3424 | inline _LIBCPP_INLINE_VISIBILITY |
| 3425 | pair<_InputIt, _ForwardIt> |
| 3426 | uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { |
| 3427 | using _Vt = typename iterator_traits<_ForwardIt>::value_type; |
| 3428 | auto __idx = __first_res; |
| 3429 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3430 | try { |
| 3431 | #endif |
| 3432 | for (; __n > 0; ++__idx, (void)++__first, --__n) |
| 3433 | ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); |
| 3434 | return {__first, __idx}; |
| 3435 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3436 | } catch (...) { |
| 3437 | _VSTD::destroy(__first_res, __idx); |
| 3438 | throw; |
| 3439 | } |
| 3440 | #endif |
| 3441 | } |
| 3442 | |
| 3443 | |
Eric Fiselier | 383f6cf | 2016-07-24 03:51:39 +0000 | [diff] [blame] | 3444 | #endif // _LIBCPP_STD_VER > 14 |
| 3445 | |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3446 | // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) |
| 3447 | // should be sufficient for thread safety. |
Eric Fiselier | 5d60401 | 2017-02-17 08:37:03 +0000 | [diff] [blame] | 3448 | // See https://bugs.llvm.org/show_bug.cgi?id=22803 |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3449 | #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \ |
| 3450 | && defined(__ATOMIC_RELAXED) \ |
| 3451 | && defined(__ATOMIC_ACQ_REL) |
| 3452 | # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT |
| 3453 | #elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407 |
| 3454 | # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT |
| 3455 | #endif |
| 3456 | |
| 3457 | template <class _Tp> |
| 3458 | inline _LIBCPP_INLINE_VISIBILITY _Tp |
| 3459 | __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT |
| 3460 | { |
| 3461 | #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) |
| 3462 | return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED); |
| 3463 | #else |
| 3464 | return __t += 1; |
| 3465 | #endif |
| 3466 | } |
| 3467 | |
| 3468 | template <class _Tp> |
| 3469 | inline _LIBCPP_INLINE_VISIBILITY _Tp |
| 3470 | __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT |
| 3471 | { |
| 3472 | #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) |
| 3473 | return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); |
| 3474 | #else |
| 3475 | return __t -= 1; |
| 3476 | #endif |
| 3477 | } |
| 3478 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3479 | class _LIBCPP_EXCEPTION_ABI bad_weak_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3480 | : public std::exception |
| 3481 | { |
| 3482 | public: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3483 | virtual ~bad_weak_ptr() _NOEXCEPT; |
| 3484 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3485 | }; |
| 3486 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 3487 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 3488 | void __throw_bad_weak_ptr() |
| 3489 | { |
| 3490 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3491 | throw bad_weak_ptr(); |
| 3492 | #else |
| 3493 | _VSTD::abort(); |
| 3494 | #endif |
| 3495 | } |
| 3496 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3497 | template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3498 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3499 | class _LIBCPP_TYPE_VIS __shared_count |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3500 | { |
| 3501 | __shared_count(const __shared_count&); |
| 3502 | __shared_count& operator=(const __shared_count&); |
| 3503 | |
| 3504 | protected: |
| 3505 | long __shared_owners_; |
| 3506 | virtual ~__shared_count(); |
| 3507 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3508 | virtual void __on_zero_shared() _NOEXCEPT = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3509 | |
| 3510 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3511 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3512 | explicit __shared_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3513 | : __shared_owners_(__refs) {} |
| 3514 | |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 3515 | #if defined(_LIBCPP_BUILDING_LIBRARY) && \ |
Eric Fiselier | 9884857 | 2017-01-17 03:16:26 +0000 | [diff] [blame] | 3516 | defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) |
Eric Fiselier | e0700ff | 2017-01-17 03:05:31 +0000 | [diff] [blame] | 3517 | void __add_shared() _NOEXCEPT; |
| 3518 | bool __release_shared() _NOEXCEPT; |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3519 | #else |
| 3520 | _LIBCPP_INLINE_VISIBILITY |
| 3521 | void __add_shared() _NOEXCEPT { |
| 3522 | __libcpp_atomic_refcount_increment(__shared_owners_); |
| 3523 | } |
| 3524 | _LIBCPP_INLINE_VISIBILITY |
| 3525 | bool __release_shared() _NOEXCEPT { |
| 3526 | if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { |
| 3527 | __on_zero_shared(); |
| 3528 | return true; |
| 3529 | } |
| 3530 | return false; |
| 3531 | } |
| 3532 | #endif |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3533 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 89659d1 | 2015-07-07 00:27:16 +0000 | [diff] [blame] | 3534 | long use_count() const _NOEXCEPT { |
| 3535 | return __libcpp_relaxed_load(&__shared_owners_) + 1; |
| 3536 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3537 | }; |
| 3538 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3539 | class _LIBCPP_TYPE_VIS __shared_weak_count |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3540 | : private __shared_count |
| 3541 | { |
| 3542 | long __shared_weak_owners_; |
| 3543 | |
| 3544 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3545 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3546 | explicit __shared_weak_count(long __refs = 0) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3547 | : __shared_count(__refs), |
| 3548 | __shared_weak_owners_(__refs) {} |
| 3549 | protected: |
| 3550 | virtual ~__shared_weak_count(); |
| 3551 | |
| 3552 | public: |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 3553 | #if defined(_LIBCPP_BUILDING_LIBRARY) && \ |
Eric Fiselier | 9884857 | 2017-01-17 03:16:26 +0000 | [diff] [blame] | 3554 | defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) |
Eric Fiselier | e0700ff | 2017-01-17 03:05:31 +0000 | [diff] [blame] | 3555 | void __add_shared() _NOEXCEPT; |
| 3556 | void __add_weak() _NOEXCEPT; |
| 3557 | void __release_shared() _NOEXCEPT; |
Kevin Hu | 4bdc8a0 | 2017-01-17 02:46:33 +0000 | [diff] [blame] | 3558 | #else |
| 3559 | _LIBCPP_INLINE_VISIBILITY |
| 3560 | void __add_shared() _NOEXCEPT { |
| 3561 | __shared_count::__add_shared(); |
| 3562 | } |
| 3563 | _LIBCPP_INLINE_VISIBILITY |
| 3564 | void __add_weak() _NOEXCEPT { |
| 3565 | __libcpp_atomic_refcount_increment(__shared_weak_owners_); |
| 3566 | } |
| 3567 | _LIBCPP_INLINE_VISIBILITY |
| 3568 | void __release_shared() _NOEXCEPT { |
| 3569 | if (__shared_count::__release_shared()) |
| 3570 | __release_weak(); |
| 3571 | } |
| 3572 | #endif |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3573 | void __release_weak() _NOEXCEPT; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3575 | long use_count() const _NOEXCEPT {return __shared_count::use_count();} |
| 3576 | __shared_weak_count* lock() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3577 | |
Howard Hinnant | 807d633 | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 3578 | // Define the function out only if we build static libc++ without RTTI. |
| 3579 | // Otherwise we may break clients who need to compile their projects with |
| 3580 | // -fno-rtti and yet link against a libc++.dylib compiled |
| 3581 | // without -fno-rtti. |
| 3582 | #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3583 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | 807d633 | 2013-02-25 15:50:36 +0000 | [diff] [blame] | 3584 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3585 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3586 | virtual void __on_zero_shared_weak() _NOEXCEPT = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3587 | }; |
| 3588 | |
| 3589 | template <class _Tp, class _Dp, class _Alloc> |
| 3590 | class __shared_ptr_pointer |
| 3591 | : public __shared_weak_count |
| 3592 | { |
| 3593 | __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_; |
| 3594 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3595 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3596 | __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3597 | : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3598 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3599 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3600 | virtual const void* __get_deleter(const type_info&) const _NOEXCEPT; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3601 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3602 | |
| 3603 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3604 | virtual void __on_zero_shared() _NOEXCEPT; |
| 3605 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3606 | }; |
| 3607 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3608 | #ifndef _LIBCPP_NO_RTTI |
| 3609 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3610 | template <class _Tp, class _Dp, class _Alloc> |
| 3611 | const void* |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3612 | __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] | 3613 | { |
Eric Fiselier | c7490d0 | 2017-05-04 01:06:56 +0000 | [diff] [blame] | 3614 | return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3617 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3618 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3619 | template <class _Tp, class _Dp, class _Alloc> |
| 3620 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3621 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3622 | { |
| 3623 | __data_.first().second()(__data_.first().first()); |
| 3624 | __data_.first().second().~_Dp(); |
| 3625 | } |
| 3626 | |
| 3627 | template <class _Tp, class _Dp, class _Alloc> |
| 3628 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3629 | __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3630 | { |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3631 | typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; |
| 3632 | typedef allocator_traits<_Al> _ATraits; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3633 | typedef pointer_traits<typename _ATraits::pointer> _PTraits; |
| 3634 | |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3635 | _Al __a(__data_.second()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3636 | __data_.second().~_Alloc(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3637 | __a.deallocate(_PTraits::pointer_to(*this), 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | template <class _Tp, class _Alloc> |
| 3641 | class __shared_ptr_emplace |
| 3642 | : public __shared_weak_count |
| 3643 | { |
| 3644 | __compressed_pair<_Alloc, _Tp> __data_; |
| 3645 | public: |
| 3646 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3647 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3648 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3649 | __shared_ptr_emplace(_Alloc __a) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3650 | : __data_(_VSTD::move(__a)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3651 | |
| 3652 | template <class ..._Args> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3653 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3654 | __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) |
Howard Hinnant | 83b1c05 | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 3655 | : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), |
| 3656 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3657 | |
| 3658 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3659 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3660 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3661 | __shared_ptr_emplace(_Alloc __a) |
| 3662 | : __data_(__a) {} |
| 3663 | |
| 3664 | template <class _A0> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3665 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3666 | __shared_ptr_emplace(_Alloc __a, _A0& __a0) |
| 3667 | : __data_(__a, _Tp(__a0)) {} |
| 3668 | |
| 3669 | template <class _A0, class _A1> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3670 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3671 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1) |
| 3672 | : __data_(__a, _Tp(__a0, __a1)) {} |
| 3673 | |
| 3674 | template <class _A0, class _A1, class _A2> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3675 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3676 | __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 3677 | : __data_(__a, _Tp(__a0, __a1, __a2)) {} |
| 3678 | |
| 3679 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3680 | |
| 3681 | private: |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3682 | virtual void __on_zero_shared() _NOEXCEPT; |
| 3683 | virtual void __on_zero_shared_weak() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3684 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3685 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | bdfdea8 | 2018-08-28 13:29:30 +0000 | [diff] [blame] | 3686 | _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3687 | }; |
| 3688 | |
| 3689 | template <class _Tp, class _Alloc> |
| 3690 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3691 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3692 | { |
| 3693 | __data_.second().~_Tp(); |
| 3694 | } |
| 3695 | |
| 3696 | template <class _Tp, class _Alloc> |
| 3697 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3698 | __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3699 | { |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3700 | typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; |
| 3701 | typedef allocator_traits<_Al> _ATraits; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3702 | typedef pointer_traits<typename _ATraits::pointer> _PTraits; |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 3703 | _Al __a(__data_.first()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3704 | __data_.first().~_Alloc(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 3705 | __a.deallocate(_PTraits::pointer_to(*this), 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3706 | } |
| 3707 | |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 3708 | struct __shared_ptr_dummy_rebind_allocator_type; |
| 3709 | template <> |
| 3710 | class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> |
| 3711 | { |
| 3712 | public: |
| 3713 | template <class _Other> |
| 3714 | struct rebind |
| 3715 | { |
| 3716 | typedef allocator<_Other> other; |
| 3717 | }; |
| 3718 | }; |
| 3719 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3720 | template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3721 | |
| 3722 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3723 | class _LIBCPP_TEMPLATE_VIS shared_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3724 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3725 | public: |
| 3726 | typedef _Tp element_type; |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3727 | |
Eric Fiselier | ae5b667 | 2016-06-27 01:02:43 +0000 | [diff] [blame] | 3728 | #if _LIBCPP_STD_VER > 14 |
| 3729 | typedef weak_ptr<_Tp> weak_type; |
| 3730 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3731 | private: |
| 3732 | element_type* __ptr_; |
| 3733 | __shared_weak_count* __cntrl_; |
| 3734 | |
| 3735 | struct __nat {int __for_bool_;}; |
| 3736 | public: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3737 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3738 | _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3739 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 3740 | _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3741 | template<class _Yp> |
| 3742 | explicit shared_ptr(_Yp* __p, |
| 3743 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
| 3744 | template<class _Yp, class _Dp> |
| 3745 | shared_ptr(_Yp* __p, _Dp __d, |
| 3746 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
| 3747 | template<class _Yp, class _Dp, class _Alloc> |
| 3748 | shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, |
| 3749 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3750 | template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d); |
| 3751 | 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] | 3752 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; |
| 3753 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3754 | shared_ptr(const shared_ptr& __r) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3755 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3756 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3757 | shared_ptr(const shared_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3758 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3759 | _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3760 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3761 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3762 | shared_ptr(shared_ptr&& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3763 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3764 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3765 | _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3766 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3767 | template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 3768 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3769 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3770 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3771 | template<class _Yp> |
| 3772 | shared_ptr(auto_ptr<_Yp>&& __r, |
| 3773 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3774 | #else |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3775 | template<class _Yp> |
| 3776 | shared_ptr(auto_ptr<_Yp> __r, |
| 3777 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3778 | #endif |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3779 | #endif |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3780 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3781 | template <class _Yp, class _Dp> |
| 3782 | shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 3783 | typename enable_if |
| 3784 | < |
| 3785 | !is_lvalue_reference<_Dp>::value && |
| 3786 | !is_array<_Yp>::value && |
| 3787 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3788 | __nat |
| 3789 | >::type = __nat()); |
| 3790 | template <class _Yp, class _Dp> |
| 3791 | shared_ptr(unique_ptr<_Yp, _Dp>&&, |
| 3792 | typename enable_if |
| 3793 | < |
| 3794 | is_lvalue_reference<_Dp>::value && |
| 3795 | !is_array<_Yp>::value && |
| 3796 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3797 | __nat |
| 3798 | >::type = __nat()); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3799 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 3800 | template <class _Yp, class _Dp> |
| 3801 | shared_ptr(unique_ptr<_Yp, _Dp>, |
| 3802 | typename enable_if |
| 3803 | < |
| 3804 | !is_lvalue_reference<_Dp>::value && |
| 3805 | !is_array<_Yp>::value && |
| 3806 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3807 | __nat |
| 3808 | >::type = __nat()); |
| 3809 | template <class _Yp, class _Dp> |
| 3810 | shared_ptr(unique_ptr<_Yp, _Dp>, |
| 3811 | typename enable_if |
| 3812 | < |
| 3813 | is_lvalue_reference<_Dp>::value && |
| 3814 | !is_array<_Yp>::value && |
| 3815 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3816 | __nat |
| 3817 | >::type = __nat()); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3818 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3819 | |
| 3820 | ~shared_ptr(); |
| 3821 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3822 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3823 | shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3824 | template<class _Yp> |
| 3825 | typename enable_if |
| 3826 | < |
| 3827 | is_convertible<_Yp*, element_type*>::value, |
| 3828 | shared_ptr& |
| 3829 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3830 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3831 | operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT; |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3832 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3833 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3834 | shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3835 | template<class _Yp> |
| 3836 | typename enable_if |
| 3837 | < |
| 3838 | is_convertible<_Yp*, element_type*>::value, |
| 3839 | shared_ptr<_Tp>& |
| 3840 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3841 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3842 | operator=(shared_ptr<_Yp>&& __r); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3843 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3844 | template<class _Yp> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 3845 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3846 | typename enable_if |
| 3847 | < |
| 3848 | !is_array<_Yp>::value && |
| 3849 | is_convertible<_Yp*, element_type*>::value, |
Howard Hinnant | 25bcaf6 | 2013-09-13 23:56:00 +0000 | [diff] [blame] | 3850 | shared_ptr |
| 3851 | >::type& |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3852 | operator=(auto_ptr<_Yp>&& __r); |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3853 | #endif |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3854 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3855 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3856 | template<class _Yp> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 3857 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3858 | typename enable_if |
| 3859 | < |
| 3860 | !is_array<_Yp>::value && |
| 3861 | is_convertible<_Yp*, element_type*>::value, |
| 3862 | shared_ptr& |
| 3863 | >::type |
| 3864 | operator=(auto_ptr<_Yp> __r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3865 | #endif |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 3866 | #endif |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3867 | template <class _Yp, class _Dp> |
| 3868 | typename enable_if |
| 3869 | < |
| 3870 | !is_array<_Yp>::value && |
| 3871 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 3872 | shared_ptr& |
| 3873 | >::type |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3874 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3875 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3876 | operator=(unique_ptr<_Yp, _Dp>&& __r); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3877 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 0319287 | 2015-12-09 22:32:36 +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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3880 | #endif |
| 3881 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3882 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3883 | void swap(shared_ptr& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3884 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3885 | void reset() _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3886 | template<class _Yp> |
| 3887 | typename enable_if |
| 3888 | < |
| 3889 | is_convertible<_Yp*, element_type*>::value, |
| 3890 | void |
| 3891 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3892 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3893 | reset(_Yp* __p); |
| 3894 | template<class _Yp, class _Dp> |
| 3895 | typename enable_if |
| 3896 | < |
| 3897 | is_convertible<_Yp*, element_type*>::value, |
| 3898 | void |
| 3899 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3900 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3901 | reset(_Yp* __p, _Dp __d); |
| 3902 | template<class _Yp, class _Dp, class _Alloc> |
| 3903 | typename enable_if |
| 3904 | < |
| 3905 | is_convertible<_Yp*, element_type*>::value, |
| 3906 | void |
| 3907 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3908 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 3909 | reset(_Yp* __p, _Dp __d, _Alloc __a); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3910 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3911 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3912 | element_type* get() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3913 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3914 | typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT |
| 3915 | {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 | element_type* operator->() const _NOEXCEPT {return __ptr_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3918 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3919 | long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3920 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3921 | bool unique() const _NOEXCEPT {return use_count() == 1;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3922 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 86a291f | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 3923 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3924 | template <class _Up> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3925 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 3926 | bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3927 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3928 | template <class _Up> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3929 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 3930 | bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3931 | {return __cntrl_ < __p.__cntrl_;} |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 3932 | _LIBCPP_INLINE_VISIBILITY |
| 3933 | bool |
| 3934 | __owner_equivalent(const shared_ptr& __p) const |
| 3935 | {return __cntrl_ == __p.__cntrl_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3936 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3937 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3938 | template <class _Dp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 3939 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 3940 | _Dp* __get_deleter() const _NOEXCEPT |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 3941 | {return static_cast<_Dp*>(__cntrl_ |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 3942 | ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) |
Marshall Clow | 31350ab | 2017-06-14 16:54:43 +0000 | [diff] [blame] | 3943 | : nullptr);} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3944 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3945 | |
| 3946 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 3947 | |
| 3948 | template<class ..._Args> |
| 3949 | static |
| 3950 | shared_ptr<_Tp> |
| 3951 | make_shared(_Args&& ...__args); |
| 3952 | |
| 3953 | template<class _Alloc, class ..._Args> |
| 3954 | static |
| 3955 | shared_ptr<_Tp> |
| 3956 | allocate_shared(const _Alloc& __a, _Args&& ...__args); |
| 3957 | |
| 3958 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 3959 | |
| 3960 | static shared_ptr<_Tp> make_shared(); |
| 3961 | |
| 3962 | template<class _A0> |
| 3963 | static shared_ptr<_Tp> make_shared(_A0&); |
| 3964 | |
| 3965 | template<class _A0, class _A1> |
| 3966 | static shared_ptr<_Tp> make_shared(_A0&, _A1&); |
| 3967 | |
| 3968 | template<class _A0, class _A1, class _A2> |
| 3969 | static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); |
| 3970 | |
| 3971 | template<class _Alloc> |
| 3972 | static shared_ptr<_Tp> |
| 3973 | allocate_shared(const _Alloc& __a); |
| 3974 | |
| 3975 | template<class _Alloc, class _A0> |
| 3976 | static shared_ptr<_Tp> |
| 3977 | allocate_shared(const _Alloc& __a, _A0& __a0); |
| 3978 | |
| 3979 | template<class _Alloc, class _A0, class _A1> |
| 3980 | static shared_ptr<_Tp> |
| 3981 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); |
| 3982 | |
| 3983 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 3984 | static shared_ptr<_Tp> |
| 3985 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); |
| 3986 | |
| 3987 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 3988 | |
| 3989 | private: |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 3990 | template <class _Yp, bool = is_function<_Yp>::value> |
| 3991 | struct __shared_ptr_default_allocator |
| 3992 | { |
| 3993 | typedef allocator<_Yp> type; |
| 3994 | }; |
| 3995 | |
| 3996 | template <class _Yp> |
| 3997 | struct __shared_ptr_default_allocator<_Yp, true> |
| 3998 | { |
| 3999 | typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; |
| 4000 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4001 | |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4002 | template <class _Yp, class _OrigPtr> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 4003 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 30d5ac6 | 2017-05-10 19:35:49 +0000 | [diff] [blame] | 4004 | typename enable_if<is_convertible<_OrigPtr*, |
| 4005 | const enable_shared_from_this<_Yp>* |
| 4006 | >::value, |
| 4007 | void>::type |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4008 | __enable_weak_this(const enable_shared_from_this<_Yp>* __e, |
| 4009 | _OrigPtr* __ptr) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4010 | { |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4011 | typedef typename remove_cv<_Yp>::type _RawYp; |
Eric Fiselier | 8400686 | 2016-06-02 00:15:35 +0000 | [diff] [blame] | 4012 | if (__e && __e->__weak_this_.expired()) |
Marshall Clow | 99442fc | 2015-06-19 15:54:13 +0000 | [diff] [blame] | 4013 | { |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4014 | __e->__weak_this_ = shared_ptr<_RawYp>(*this, |
| 4015 | const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr))); |
Marshall Clow | 99442fc | 2015-06-19 15:54:13 +0000 | [diff] [blame] | 4016 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4019 | _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4020 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4021 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
| 4022 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4023 | }; |
| 4024 | |
Eric Fiselier | 30d5ac6 | 2017-05-10 19:35:49 +0000 | [diff] [blame] | 4025 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4026 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4027 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 4028 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4029 | shared_ptr<_Tp>::shared_ptr() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4030 | : __ptr_(0), |
| 4031 | __cntrl_(0) |
| 4032 | { |
| 4033 | } |
| 4034 | |
| 4035 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4036 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 4037 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4038 | shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4039 | : __ptr_(0), |
| 4040 | __cntrl_(0) |
| 4041 | { |
| 4042 | } |
| 4043 | |
| 4044 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4045 | template<class _Yp> |
| 4046 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, |
| 4047 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4048 | : __ptr_(__p) |
| 4049 | { |
| 4050 | unique_ptr<_Yp> __hold(__p); |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4051 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 4052 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk; |
| 4053 | __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4054 | __hold.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4055 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4056 | } |
| 4057 | |
| 4058 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4059 | template<class _Yp, class _Dp> |
| 4060 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, |
| 4061 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4062 | : __ptr_(__p) |
| 4063 | { |
| 4064 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4065 | try |
| 4066 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4067 | #endif // _LIBCPP_NO_EXCEPTIONS |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4068 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 4069 | typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; |
| 4070 | __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4071 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4072 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4073 | } |
| 4074 | catch (...) |
| 4075 | { |
| 4076 | __d(__p); |
| 4077 | throw; |
| 4078 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4079 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | template<class _Tp> |
| 4083 | template<class _Dp> |
| 4084 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) |
| 4085 | : __ptr_(0) |
| 4086 | { |
| 4087 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4088 | try |
| 4089 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4090 | #endif // _LIBCPP_NO_EXCEPTIONS |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4091 | typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; |
| 4092 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk; |
| 4093 | __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4094 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4095 | } |
| 4096 | catch (...) |
| 4097 | { |
| 4098 | __d(__p); |
| 4099 | throw; |
| 4100 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4101 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4105 | template<class _Yp, class _Dp, class _Alloc> |
| 4106 | shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, |
| 4107 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4108 | : __ptr_(__p) |
| 4109 | { |
| 4110 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4111 | try |
| 4112 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4113 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4114 | typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4115 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4116 | typedef __allocator_destructor<_A2> _D2; |
| 4117 | _A2 __a2(__a); |
| 4118 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4119 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4120 | _CntrlBlk(__p, __d, __a); |
| 4121 | __cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4122 | __enable_weak_this(__p, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4123 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4124 | } |
| 4125 | catch (...) |
| 4126 | { |
| 4127 | __d(__p); |
| 4128 | throw; |
| 4129 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4130 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | template<class _Tp> |
| 4134 | template<class _Dp, class _Alloc> |
| 4135 | shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) |
| 4136 | : __ptr_(0) |
| 4137 | { |
| 4138 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4139 | try |
| 4140 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4141 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4142 | typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4143 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4144 | typedef __allocator_destructor<_A2> _D2; |
| 4145 | _A2 __a2(__a); |
| 4146 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4147 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4148 | _CntrlBlk(__p, __d, __a); |
| 4149 | __cntrl_ = _VSTD::addressof(*__hold2.release()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4150 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4151 | } |
| 4152 | catch (...) |
| 4153 | { |
| 4154 | __d(__p); |
| 4155 | throw; |
| 4156 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4157 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | template<class _Tp> |
| 4161 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4162 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4163 | 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] | 4164 | : __ptr_(__p), |
| 4165 | __cntrl_(__r.__cntrl_) |
| 4166 | { |
| 4167 | if (__cntrl_) |
| 4168 | __cntrl_->__add_shared(); |
| 4169 | } |
| 4170 | |
| 4171 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4172 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4173 | shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4174 | : __ptr_(__r.__ptr_), |
| 4175 | __cntrl_(__r.__cntrl_) |
| 4176 | { |
| 4177 | if (__cntrl_) |
| 4178 | __cntrl_->__add_shared(); |
| 4179 | } |
| 4180 | |
| 4181 | template<class _Tp> |
| 4182 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4183 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4184 | shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4185 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4186 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4187 | : __ptr_(__r.__ptr_), |
| 4188 | __cntrl_(__r.__cntrl_) |
| 4189 | { |
| 4190 | if (__cntrl_) |
| 4191 | __cntrl_->__add_shared(); |
| 4192 | } |
| 4193 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4194 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4195 | |
| 4196 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4197 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4198 | shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4199 | : __ptr_(__r.__ptr_), |
| 4200 | __cntrl_(__r.__cntrl_) |
| 4201 | { |
| 4202 | __r.__ptr_ = 0; |
| 4203 | __r.__cntrl_ = 0; |
| 4204 | } |
| 4205 | |
| 4206 | template<class _Tp> |
| 4207 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4208 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4209 | shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4210 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4211 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4212 | : __ptr_(__r.__ptr_), |
| 4213 | __cntrl_(__r.__cntrl_) |
| 4214 | { |
| 4215 | __r.__ptr_ = 0; |
| 4216 | __r.__cntrl_ = 0; |
| 4217 | } |
| 4218 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4219 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4220 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4221 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4222 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4223 | template<class _Yp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4224 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4225 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4226 | #else |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4227 | shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4228 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4229 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4230 | : __ptr_(__r.get()) |
| 4231 | { |
| 4232 | typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; |
| 4233 | __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4234 | __enable_weak_this(__r.get(), __r.get()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4235 | __r.release(); |
| 4236 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4237 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4238 | |
| 4239 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4240 | template <class _Yp, class _Dp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4241 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4242 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 4243 | #else |
| 4244 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 4245 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4246 | typename enable_if |
| 4247 | < |
| 4248 | !is_lvalue_reference<_Dp>::value && |
| 4249 | !is_array<_Yp>::value && |
| 4250 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 4251 | __nat |
| 4252 | >::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4253 | : __ptr_(__r.get()) |
| 4254 | { |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4255 | #if _LIBCPP_STD_VER > 11 |
| 4256 | if (__ptr_ == nullptr) |
| 4257 | __cntrl_ = nullptr; |
| 4258 | else |
| 4259 | #endif |
| 4260 | { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4261 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
| 4262 | typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; |
| 4263 | __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4264 | __enable_weak_this(__r.get(), __r.get()); |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4265 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4266 | __r.release(); |
| 4267 | } |
| 4268 | |
| 4269 | template<class _Tp> |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4270 | template <class _Yp, class _Dp> |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4271 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4272 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, |
| 4273 | #else |
| 4274 | shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, |
| 4275 | #endif |
Logan Chien | d435f8b | 2014-01-31 09:30:46 +0000 | [diff] [blame] | 4276 | typename enable_if |
| 4277 | < |
| 4278 | is_lvalue_reference<_Dp>::value && |
| 4279 | !is_array<_Yp>::value && |
| 4280 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value, |
| 4281 | __nat |
| 4282 | >::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4283 | : __ptr_(__r.get()) |
| 4284 | { |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4285 | #if _LIBCPP_STD_VER > 11 |
| 4286 | if (__ptr_ == nullptr) |
| 4287 | __cntrl_ = nullptr; |
| 4288 | else |
| 4289 | #endif |
| 4290 | { |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4291 | typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4292 | typedef __shared_ptr_pointer<_Yp*, |
| 4293 | reference_wrapper<typename remove_reference<_Dp>::type>, |
Erik Pilkington | 2a39876 | 2017-05-25 15:43:31 +0000 | [diff] [blame] | 4294 | _AllocT > _CntrlBlk; |
| 4295 | __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4296 | __enable_weak_this(__r.get(), __r.get()); |
Marshall Clow | 35cde74 | 2015-05-10 13:59:45 +0000 | [diff] [blame] | 4297 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4298 | __r.release(); |
| 4299 | } |
| 4300 | |
| 4301 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 4302 | |
| 4303 | template<class _Tp> |
| 4304 | template<class ..._Args> |
| 4305 | shared_ptr<_Tp> |
| 4306 | shared_ptr<_Tp>::make_shared(_Args&& ...__args) |
| 4307 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4308 | 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] | 4309 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4310 | typedef allocator<_CntrlBlk> _A2; |
| 4311 | typedef __allocator_destructor<_A2> _D2; |
| 4312 | _A2 __a2; |
| 4313 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4314 | ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4315 | shared_ptr<_Tp> __r; |
| 4316 | __r.__ptr_ = __hold2.get()->get(); |
| 4317 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4318 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4319 | return __r; |
| 4320 | } |
| 4321 | |
| 4322 | template<class _Tp> |
| 4323 | template<class _Alloc, class ..._Args> |
| 4324 | shared_ptr<_Tp> |
| 4325 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 4326 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4327 | 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] | 4328 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4329 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4330 | typedef __allocator_destructor<_A2> _D2; |
| 4331 | _A2 __a2(__a); |
| 4332 | unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4333 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4334 | _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4335 | shared_ptr<_Tp> __r; |
| 4336 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4337 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4338 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4339 | return __r; |
| 4340 | } |
| 4341 | |
| 4342 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 4343 | |
| 4344 | template<class _Tp> |
| 4345 | shared_ptr<_Tp> |
| 4346 | shared_ptr<_Tp>::make_shared() |
| 4347 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4348 | 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] | 4349 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4350 | typedef allocator<_CntrlBlk> _Alloc2; |
| 4351 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4352 | _Alloc2 __alloc2; |
| 4353 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 4354 | ::new(__hold2.get()) _CntrlBlk(__alloc2); |
| 4355 | shared_ptr<_Tp> __r; |
| 4356 | __r.__ptr_ = __hold2.get()->get(); |
| 4357 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4358 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4359 | return __r; |
| 4360 | } |
| 4361 | |
| 4362 | template<class _Tp> |
| 4363 | template<class _A0> |
| 4364 | shared_ptr<_Tp> |
| 4365 | shared_ptr<_Tp>::make_shared(_A0& __a0) |
| 4366 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4367 | 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] | 4368 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4369 | typedef allocator<_CntrlBlk> _Alloc2; |
| 4370 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4371 | _Alloc2 __alloc2; |
| 4372 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 4373 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); |
| 4374 | shared_ptr<_Tp> __r; |
| 4375 | __r.__ptr_ = __hold2.get()->get(); |
| 4376 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4377 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4378 | return __r; |
| 4379 | } |
| 4380 | |
| 4381 | template<class _Tp> |
| 4382 | template<class _A0, class _A1> |
| 4383 | shared_ptr<_Tp> |
| 4384 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) |
| 4385 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4386 | 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] | 4387 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4388 | typedef allocator<_CntrlBlk> _Alloc2; |
| 4389 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4390 | _Alloc2 __alloc2; |
| 4391 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 4392 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); |
| 4393 | shared_ptr<_Tp> __r; |
| 4394 | __r.__ptr_ = __hold2.get()->get(); |
| 4395 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4396 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4397 | return __r; |
| 4398 | } |
| 4399 | |
| 4400 | template<class _Tp> |
| 4401 | template<class _A0, class _A1, class _A2> |
| 4402 | shared_ptr<_Tp> |
| 4403 | shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 4404 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4405 | 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] | 4406 | typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; |
| 4407 | typedef allocator<_CntrlBlk> _Alloc2; |
| 4408 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4409 | _Alloc2 __alloc2; |
| 4410 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
| 4411 | ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); |
| 4412 | shared_ptr<_Tp> __r; |
| 4413 | __r.__ptr_ = __hold2.get()->get(); |
| 4414 | __r.__cntrl_ = __hold2.release(); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4415 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4416 | return __r; |
| 4417 | } |
| 4418 | |
| 4419 | template<class _Tp> |
| 4420 | template<class _Alloc> |
| 4421 | shared_ptr<_Tp> |
| 4422 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) |
| 4423 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4424 | 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] | 4425 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4426 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4427 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4428 | _Alloc2 __alloc2(__a); |
| 4429 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4430 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4431 | _CntrlBlk(__a); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4432 | shared_ptr<_Tp> __r; |
| 4433 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4434 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4435 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4436 | return __r; |
| 4437 | } |
| 4438 | |
| 4439 | template<class _Tp> |
| 4440 | template<class _Alloc, class _A0> |
| 4441 | shared_ptr<_Tp> |
| 4442 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) |
| 4443 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4444 | 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] | 4445 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4446 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4447 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4448 | _Alloc2 __alloc2(__a); |
| 4449 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4450 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4451 | _CntrlBlk(__a, __a0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4452 | shared_ptr<_Tp> __r; |
| 4453 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4454 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4455 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4456 | return __r; |
| 4457 | } |
| 4458 | |
| 4459 | template<class _Tp> |
| 4460 | template<class _Alloc, class _A0, class _A1> |
| 4461 | shared_ptr<_Tp> |
| 4462 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 4463 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4464 | 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] | 4465 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4466 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4467 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4468 | _Alloc2 __alloc2(__a); |
| 4469 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4470 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4471 | _CntrlBlk(__a, __a0, __a1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4472 | shared_ptr<_Tp> __r; |
| 4473 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4474 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4475 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4476 | return __r; |
| 4477 | } |
| 4478 | |
| 4479 | template<class _Tp> |
| 4480 | template<class _Alloc, class _A0, class _A1, class _A2> |
| 4481 | shared_ptr<_Tp> |
| 4482 | shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 4483 | { |
Marshall Clow | dec75c7 | 2017-12-05 04:09:49 +0000 | [diff] [blame] | 4484 | 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] | 4485 | typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4486 | typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4487 | typedef __allocator_destructor<_Alloc2> _D2; |
| 4488 | _Alloc2 __alloc2(__a); |
| 4489 | unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4490 | ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get()))) |
| 4491 | _CntrlBlk(__a, __a0, __a1, __a2); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4492 | shared_ptr<_Tp> __r; |
| 4493 | __r.__ptr_ = __hold2.get()->get(); |
Eric Fiselier | 6bd814f | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 4494 | __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); |
Eric Fiselier | f16c93f | 2016-06-26 23:56:32 +0000 | [diff] [blame] | 4495 | __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4496 | return __r; |
| 4497 | } |
| 4498 | |
| 4499 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 4500 | |
| 4501 | template<class _Tp> |
| 4502 | shared_ptr<_Tp>::~shared_ptr() |
| 4503 | { |
| 4504 | if (__cntrl_) |
| 4505 | __cntrl_->__release_shared(); |
| 4506 | } |
| 4507 | |
| 4508 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4509 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4510 | shared_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4511 | shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4512 | { |
| 4513 | shared_ptr(__r).swap(*this); |
| 4514 | return *this; |
| 4515 | } |
| 4516 | |
| 4517 | template<class _Tp> |
| 4518 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4519 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4520 | typename enable_if |
| 4521 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4522 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4523 | shared_ptr<_Tp>& |
| 4524 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4525 | shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4526 | { |
| 4527 | shared_ptr(__r).swap(*this); |
| 4528 | return *this; |
| 4529 | } |
| 4530 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4531 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4532 | |
| 4533 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4534 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4535 | shared_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4536 | shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4537 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4538 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4539 | return *this; |
| 4540 | } |
| 4541 | |
| 4542 | template<class _Tp> |
| 4543 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4544 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4545 | typename enable_if |
| 4546 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4547 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4548 | shared_ptr<_Tp>& |
| 4549 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4550 | shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) |
| 4551 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4552 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4553 | return *this; |
| 4554 | } |
| 4555 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4556 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4557 | template<class _Tp> |
| 4558 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4559 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4560 | typename enable_if |
| 4561 | < |
| 4562 | !is_array<_Yp>::value && |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4563 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 25bcaf6 | 2013-09-13 23:56:00 +0000 | [diff] [blame] | 4564 | shared_ptr<_Tp> |
| 4565 | >::type& |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4566 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) |
| 4567 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4568 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4569 | return *this; |
| 4570 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4571 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4572 | |
| 4573 | template<class _Tp> |
| 4574 | template <class _Yp, class _Dp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4575 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4576 | typename enable_if |
| 4577 | < |
| 4578 | !is_array<_Yp>::value && |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 4579 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4580 | typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4581 | shared_ptr<_Tp>& |
| 4582 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4583 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) |
| 4584 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4585 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4586 | return *this; |
| 4587 | } |
| 4588 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4589 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4590 | |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4591 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4592 | template<class _Tp> |
| 4593 | template<class _Yp> |
| 4594 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4595 | typename enable_if |
| 4596 | < |
| 4597 | !is_array<_Yp>::value && |
Marshall Clow | b89a86e | 2017-01-10 18:40:01 +0000 | [diff] [blame] | 4598 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4599 | shared_ptr<_Tp>& |
| 4600 | >::type |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4601 | shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4602 | { |
| 4603 | shared_ptr(__r).swap(*this); |
| 4604 | return *this; |
| 4605 | } |
Marshall Clow | b22274f | 2017-01-24 22:22:33 +0000 | [diff] [blame] | 4606 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4607 | |
| 4608 | template<class _Tp> |
| 4609 | template <class _Yp, class _Dp> |
| 4610 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4611 | typename enable_if |
| 4612 | < |
| 4613 | !is_array<_Yp>::value && |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 4614 | is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, |
Marshall Clow | b89a86e | 2017-01-10 18:40:01 +0000 | [diff] [blame] | 4615 | typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4616 | shared_ptr<_Tp>& |
| 4617 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4618 | shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) |
| 4619 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4620 | shared_ptr(_VSTD::move(__r)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4621 | return *this; |
| 4622 | } |
| 4623 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 4624 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4625 | |
| 4626 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4627 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4628 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4629 | shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4630 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4631 | _VSTD::swap(__ptr_, __r.__ptr_); |
| 4632 | _VSTD::swap(__cntrl_, __r.__cntrl_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4636 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4637 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4638 | shared_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4639 | { |
| 4640 | shared_ptr().swap(*this); |
| 4641 | } |
| 4642 | |
| 4643 | template<class _Tp> |
| 4644 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4645 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4646 | typename enable_if |
| 4647 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4648 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4649 | void |
| 4650 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4651 | shared_ptr<_Tp>::reset(_Yp* __p) |
| 4652 | { |
| 4653 | shared_ptr(__p).swap(*this); |
| 4654 | } |
| 4655 | |
| 4656 | template<class _Tp> |
| 4657 | template<class _Yp, class _Dp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4658 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4659 | typename enable_if |
| 4660 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4661 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4662 | void |
| 4663 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4664 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) |
| 4665 | { |
| 4666 | shared_ptr(__p, __d).swap(*this); |
| 4667 | } |
| 4668 | |
| 4669 | template<class _Tp> |
| 4670 | template<class _Yp, class _Dp, class _Alloc> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4671 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4672 | typename enable_if |
| 4673 | < |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 4674 | is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4675 | void |
| 4676 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4677 | shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) |
| 4678 | { |
| 4679 | shared_ptr(__p, __d, __a).swap(*this); |
| 4680 | } |
| 4681 | |
| 4682 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 4683 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4684 | template<class _Tp, class ..._Args> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4685 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4686 | typename enable_if |
| 4687 | < |
| 4688 | !is_array<_Tp>::value, |
| 4689 | shared_ptr<_Tp> |
| 4690 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4691 | make_shared(_Args&& ...__args) |
| 4692 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4693 | return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4696 | template<class _Tp, class _Alloc, class ..._Args> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4697 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4698 | typename enable_if |
| 4699 | < |
| 4700 | !is_array<_Tp>::value, |
| 4701 | shared_ptr<_Tp> |
| 4702 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4703 | allocate_shared(const _Alloc& __a, _Args&& ...__args) |
| 4704 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4705 | return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 4709 | |
| 4710 | template<class _Tp> |
| 4711 | inline _LIBCPP_INLINE_VISIBILITY |
| 4712 | shared_ptr<_Tp> |
| 4713 | make_shared() |
| 4714 | { |
| 4715 | return shared_ptr<_Tp>::make_shared(); |
| 4716 | } |
| 4717 | |
| 4718 | template<class _Tp, class _A0> |
| 4719 | inline _LIBCPP_INLINE_VISIBILITY |
| 4720 | shared_ptr<_Tp> |
| 4721 | make_shared(_A0& __a0) |
| 4722 | { |
| 4723 | return shared_ptr<_Tp>::make_shared(__a0); |
| 4724 | } |
| 4725 | |
| 4726 | template<class _Tp, class _A0, class _A1> |
| 4727 | inline _LIBCPP_INLINE_VISIBILITY |
| 4728 | shared_ptr<_Tp> |
| 4729 | make_shared(_A0& __a0, _A1& __a1) |
| 4730 | { |
| 4731 | return shared_ptr<_Tp>::make_shared(__a0, __a1); |
| 4732 | } |
| 4733 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4734 | template<class _Tp, class _A0, class _A1, class _A2> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4735 | inline _LIBCPP_INLINE_VISIBILITY |
| 4736 | shared_ptr<_Tp> |
| 4737 | make_shared(_A0& __a0, _A1& __a1, _A2& __a2) |
| 4738 | { |
| 4739 | return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); |
| 4740 | } |
| 4741 | |
| 4742 | template<class _Tp, class _Alloc> |
| 4743 | inline _LIBCPP_INLINE_VISIBILITY |
| 4744 | shared_ptr<_Tp> |
| 4745 | allocate_shared(const _Alloc& __a) |
| 4746 | { |
| 4747 | return shared_ptr<_Tp>::allocate_shared(__a); |
| 4748 | } |
| 4749 | |
| 4750 | template<class _Tp, class _Alloc, class _A0> |
| 4751 | inline _LIBCPP_INLINE_VISIBILITY |
| 4752 | shared_ptr<_Tp> |
| 4753 | allocate_shared(const _Alloc& __a, _A0& __a0) |
| 4754 | { |
| 4755 | return shared_ptr<_Tp>::allocate_shared(__a, __a0); |
| 4756 | } |
| 4757 | |
| 4758 | template<class _Tp, class _Alloc, class _A0, class _A1> |
| 4759 | inline _LIBCPP_INLINE_VISIBILITY |
| 4760 | shared_ptr<_Tp> |
| 4761 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) |
| 4762 | { |
| 4763 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); |
| 4764 | } |
| 4765 | |
| 4766 | template<class _Tp, class _Alloc, class _A0, class _A1, class _A2> |
| 4767 | inline _LIBCPP_INLINE_VISIBILITY |
| 4768 | shared_ptr<_Tp> |
| 4769 | allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) |
| 4770 | { |
| 4771 | return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); |
| 4772 | } |
| 4773 | |
| 4774 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 4775 | |
| 4776 | template<class _Tp, class _Up> |
| 4777 | inline _LIBCPP_INLINE_VISIBILITY |
| 4778 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4779 | operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4780 | { |
| 4781 | return __x.get() == __y.get(); |
| 4782 | } |
| 4783 | |
| 4784 | template<class _Tp, class _Up> |
| 4785 | inline _LIBCPP_INLINE_VISIBILITY |
| 4786 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4787 | operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4788 | { |
| 4789 | return !(__x == __y); |
| 4790 | } |
| 4791 | |
| 4792 | template<class _Tp, class _Up> |
| 4793 | inline _LIBCPP_INLINE_VISIBILITY |
| 4794 | bool |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4795 | operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4796 | { |
Marshall Clow | 8afdf7a | 2018-02-12 17:26:40 +0000 | [diff] [blame] | 4797 | #if _LIBCPP_STD_VER <= 11 |
Eric Fiselier | f8898c8 | 2015-02-05 23:01:40 +0000 | [diff] [blame] | 4798 | typedef typename common_type<_Tp*, _Up*>::type _Vp; |
| 4799 | return less<_Vp>()(__x.get(), __y.get()); |
Marshall Clow | 8afdf7a | 2018-02-12 17:26:40 +0000 | [diff] [blame] | 4800 | #else |
| 4801 | return less<>()(__x.get(), __y.get()); |
| 4802 | #endif |
| 4803 | |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
| 4806 | template<class _Tp, class _Up> |
| 4807 | inline _LIBCPP_INLINE_VISIBILITY |
| 4808 | bool |
| 4809 | operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4810 | { |
| 4811 | return __y < __x; |
| 4812 | } |
| 4813 | |
| 4814 | template<class _Tp, class _Up> |
| 4815 | inline _LIBCPP_INLINE_VISIBILITY |
| 4816 | bool |
| 4817 | operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4818 | { |
| 4819 | return !(__y < __x); |
| 4820 | } |
| 4821 | |
| 4822 | template<class _Tp, class _Up> |
| 4823 | inline _LIBCPP_INLINE_VISIBILITY |
| 4824 | bool |
| 4825 | operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT |
| 4826 | { |
| 4827 | return !(__x < __y); |
| 4828 | } |
| 4829 | |
| 4830 | template<class _Tp> |
| 4831 | inline _LIBCPP_INLINE_VISIBILITY |
| 4832 | bool |
| 4833 | operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4834 | { |
| 4835 | return !__x; |
| 4836 | } |
| 4837 | |
| 4838 | template<class _Tp> |
| 4839 | inline _LIBCPP_INLINE_VISIBILITY |
| 4840 | bool |
| 4841 | operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4842 | { |
| 4843 | return !__x; |
| 4844 | } |
| 4845 | |
| 4846 | template<class _Tp> |
| 4847 | inline _LIBCPP_INLINE_VISIBILITY |
| 4848 | bool |
| 4849 | operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4850 | { |
| 4851 | return static_cast<bool>(__x); |
| 4852 | } |
| 4853 | |
| 4854 | template<class _Tp> |
| 4855 | inline _LIBCPP_INLINE_VISIBILITY |
| 4856 | bool |
| 4857 | operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4858 | { |
| 4859 | return static_cast<bool>(__x); |
| 4860 | } |
| 4861 | |
| 4862 | template<class _Tp> |
| 4863 | inline _LIBCPP_INLINE_VISIBILITY |
| 4864 | bool |
| 4865 | operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4866 | { |
| 4867 | return less<_Tp*>()(__x.get(), nullptr); |
| 4868 | } |
| 4869 | |
| 4870 | template<class _Tp> |
| 4871 | inline _LIBCPP_INLINE_VISIBILITY |
| 4872 | bool |
| 4873 | operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4874 | { |
| 4875 | return less<_Tp*>()(nullptr, __x.get()); |
| 4876 | } |
| 4877 | |
| 4878 | template<class _Tp> |
| 4879 | inline _LIBCPP_INLINE_VISIBILITY |
| 4880 | bool |
| 4881 | operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4882 | { |
| 4883 | return nullptr < __x; |
| 4884 | } |
| 4885 | |
| 4886 | template<class _Tp> |
| 4887 | inline _LIBCPP_INLINE_VISIBILITY |
| 4888 | bool |
| 4889 | operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4890 | { |
| 4891 | return __x < nullptr; |
| 4892 | } |
| 4893 | |
| 4894 | template<class _Tp> |
| 4895 | inline _LIBCPP_INLINE_VISIBILITY |
| 4896 | bool |
| 4897 | operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4898 | { |
| 4899 | return !(nullptr < __x); |
| 4900 | } |
| 4901 | |
| 4902 | template<class _Tp> |
| 4903 | inline _LIBCPP_INLINE_VISIBILITY |
| 4904 | bool |
| 4905 | operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4906 | { |
| 4907 | return !(__x < nullptr); |
| 4908 | } |
| 4909 | |
| 4910 | template<class _Tp> |
| 4911 | inline _LIBCPP_INLINE_VISIBILITY |
| 4912 | bool |
| 4913 | operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT |
| 4914 | { |
| 4915 | return !(__x < nullptr); |
| 4916 | } |
| 4917 | |
| 4918 | template<class _Tp> |
| 4919 | inline _LIBCPP_INLINE_VISIBILITY |
| 4920 | bool |
| 4921 | operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT |
| 4922 | { |
| 4923 | return !(nullptr < __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | template<class _Tp> |
| 4927 | inline _LIBCPP_INLINE_VISIBILITY |
| 4928 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4929 | swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4930 | { |
| 4931 | __x.swap(__y); |
| 4932 | } |
| 4933 | |
| 4934 | template<class _Tp, class _Up> |
| 4935 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4936 | typename enable_if |
| 4937 | < |
| 4938 | !is_array<_Tp>::value && !is_array<_Up>::value, |
| 4939 | shared_ptr<_Tp> |
| 4940 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4941 | static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4942 | { |
| 4943 | return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); |
| 4944 | } |
| 4945 | |
| 4946 | template<class _Tp, class _Up> |
| 4947 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4948 | typename enable_if |
| 4949 | < |
| 4950 | !is_array<_Tp>::value && !is_array<_Up>::value, |
| 4951 | shared_ptr<_Tp> |
| 4952 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4953 | dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4954 | { |
| 4955 | _Tp* __p = dynamic_cast<_Tp*>(__r.get()); |
| 4956 | return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); |
| 4957 | } |
| 4958 | |
| 4959 | template<class _Tp, class _Up> |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4960 | typename enable_if |
| 4961 | < |
| 4962 | is_array<_Tp>::value == is_array<_Up>::value, |
| 4963 | shared_ptr<_Tp> |
| 4964 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4965 | const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4966 | { |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 4967 | typedef typename remove_extent<_Tp>::type _RTp; |
| 4968 | return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4969 | } |
| 4970 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4971 | #ifndef _LIBCPP_NO_RTTI |
| 4972 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4973 | template<class _Dp, class _Tp> |
| 4974 | inline _LIBCPP_INLINE_VISIBILITY |
| 4975 | _Dp* |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4976 | get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4977 | { |
| 4978 | return __p.template __get_deleter<_Dp>(); |
| 4979 | } |
| 4980 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4981 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4982 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4983 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4984 | class _LIBCPP_TEMPLATE_VIS weak_ptr |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4985 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4986 | public: |
| 4987 | typedef _Tp element_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4988 | private: |
| 4989 | element_type* __ptr_; |
| 4990 | __shared_weak_count* __cntrl_; |
| 4991 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4992 | public: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4993 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 4994 | _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4995 | 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] | 4996 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 4997 | _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4998 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 4999 | weak_ptr(weak_ptr const& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5000 | 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] | 5001 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 5002 | _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5003 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5004 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5005 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5006 | weak_ptr(weak_ptr&& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5007 | template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r, |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5008 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0) |
| 5009 | _NOEXCEPT; |
| 5010 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5011 | ~weak_ptr(); |
| 5012 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5013 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5014 | weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5015 | template<class _Yp> |
| 5016 | typename enable_if |
| 5017 | < |
| 5018 | is_convertible<_Yp*, element_type*>::value, |
| 5019 | weak_ptr& |
| 5020 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5021 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5022 | operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT; |
| 5023 | |
| 5024 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5025 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5026 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5027 | weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; |
| 5028 | template<class _Yp> |
| 5029 | typename enable_if |
| 5030 | < |
| 5031 | is_convertible<_Yp*, element_type*>::value, |
| 5032 | weak_ptr& |
| 5033 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5034 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5035 | operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; |
| 5036 | |
| 5037 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5038 | |
| 5039 | template<class _Yp> |
| 5040 | typename enable_if |
| 5041 | < |
| 5042 | is_convertible<_Yp*, element_type*>::value, |
| 5043 | weak_ptr& |
| 5044 | >::type |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5045 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5046 | operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5047 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5048 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5049 | void swap(weak_ptr& __r) _NOEXCEPT; |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5050 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5051 | void reset() _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5052 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5054 | long use_count() const _NOEXCEPT |
| 5055 | {return __cntrl_ ? __cntrl_->use_count() : 0;} |
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 | bool expired() const _NOEXCEPT |
| 5058 | {return __cntrl_ == 0 || __cntrl_->use_count() == 0;} |
| 5059 | shared_ptr<_Tp> lock() const _NOEXCEPT; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5060 | template<class _Up> |
| 5061 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5062 | bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5063 | {return __cntrl_ < __r.__cntrl_;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5064 | template<class _Up> |
| 5065 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5066 | bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5067 | {return __cntrl_ < __r.__cntrl_;} |
| 5068 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5069 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; |
| 5070 | template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5071 | }; |
| 5072 | |
| 5073 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5074 | inline |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 5075 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5076 | weak_ptr<_Tp>::weak_ptr() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5077 | : __ptr_(0), |
| 5078 | __cntrl_(0) |
| 5079 | { |
| 5080 | } |
| 5081 | |
| 5082 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5083 | inline |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5084 | weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5085 | : __ptr_(__r.__ptr_), |
| 5086 | __cntrl_(__r.__cntrl_) |
| 5087 | { |
| 5088 | if (__cntrl_) |
| 5089 | __cntrl_->__add_weak(); |
| 5090 | } |
| 5091 | |
| 5092 | template<class _Tp> |
| 5093 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5094 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5095 | weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r, |
Howard Hinnant | 3a085e8 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 5096 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5097 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5098 | : __ptr_(__r.__ptr_), |
| 5099 | __cntrl_(__r.__cntrl_) |
| 5100 | { |
| 5101 | if (__cntrl_) |
| 5102 | __cntrl_->__add_weak(); |
| 5103 | } |
| 5104 | |
| 5105 | template<class _Tp> |
| 5106 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5107 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5108 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r, |
Howard Hinnant | 3a085e8 | 2011-05-22 00:09:02 +0000 | [diff] [blame] | 5109 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5110 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5111 | : __ptr_(__r.__ptr_), |
| 5112 | __cntrl_(__r.__cntrl_) |
| 5113 | { |
| 5114 | if (__cntrl_) |
| 5115 | __cntrl_->__add_weak(); |
| 5116 | } |
| 5117 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5118 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5119 | |
| 5120 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5121 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5122 | weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT |
| 5123 | : __ptr_(__r.__ptr_), |
| 5124 | __cntrl_(__r.__cntrl_) |
| 5125 | { |
| 5126 | __r.__ptr_ = 0; |
| 5127 | __r.__cntrl_ = 0; |
| 5128 | } |
| 5129 | |
| 5130 | template<class _Tp> |
| 5131 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5132 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5133 | weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r, |
| 5134 | typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type) |
| 5135 | _NOEXCEPT |
| 5136 | : __ptr_(__r.__ptr_), |
| 5137 | __cntrl_(__r.__cntrl_) |
| 5138 | { |
| 5139 | __r.__ptr_ = 0; |
| 5140 | __r.__cntrl_ = 0; |
| 5141 | } |
| 5142 | |
| 5143 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5144 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5145 | template<class _Tp> |
| 5146 | weak_ptr<_Tp>::~weak_ptr() |
| 5147 | { |
| 5148 | if (__cntrl_) |
| 5149 | __cntrl_->__release_weak(); |
| 5150 | } |
| 5151 | |
| 5152 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5153 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5154 | weak_ptr<_Tp>& |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5155 | weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5156 | { |
| 5157 | weak_ptr(__r).swap(*this); |
| 5158 | return *this; |
| 5159 | } |
| 5160 | |
| 5161 | template<class _Tp> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5162 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5163 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5164 | typename enable_if |
| 5165 | < |
| 5166 | is_convertible<_Yp*, _Tp*>::value, |
| 5167 | weak_ptr<_Tp>& |
| 5168 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5169 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5170 | { |
| 5171 | weak_ptr(__r).swap(*this); |
| 5172 | return *this; |
| 5173 | } |
| 5174 | |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5175 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5176 | |
| 5177 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5178 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5179 | weak_ptr<_Tp>& |
| 5180 | weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT |
| 5181 | { |
| 5182 | weak_ptr(_VSTD::move(__r)).swap(*this); |
| 5183 | return *this; |
| 5184 | } |
| 5185 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5186 | template<class _Tp> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5187 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5188 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5189 | typename enable_if |
| 5190 | < |
| 5191 | is_convertible<_Yp*, _Tp*>::value, |
| 5192 | weak_ptr<_Tp>& |
| 5193 | >::type |
| 5194 | weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT |
| 5195 | { |
| 5196 | weak_ptr(_VSTD::move(__r)).swap(*this); |
| 5197 | return *this; |
| 5198 | } |
| 5199 | |
| 5200 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 5201 | |
| 5202 | template<class _Tp> |
| 5203 | template<class _Yp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5204 | inline |
Howard Hinnant | 741c8fa | 2012-01-02 17:56:02 +0000 | [diff] [blame] | 5205 | typename enable_if |
| 5206 | < |
| 5207 | is_convertible<_Yp*, _Tp*>::value, |
| 5208 | weak_ptr<_Tp>& |
| 5209 | >::type |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5210 | weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5211 | { |
| 5212 | weak_ptr(__r).swap(*this); |
| 5213 | return *this; |
| 5214 | } |
| 5215 | |
| 5216 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5217 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5218 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5219 | weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5220 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5221 | _VSTD::swap(__ptr_, __r.__ptr_); |
| 5222 | _VSTD::swap(__cntrl_, __r.__cntrl_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | template<class _Tp> |
| 5226 | inline _LIBCPP_INLINE_VISIBILITY |
| 5227 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5228 | swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5229 | { |
| 5230 | __x.swap(__y); |
| 5231 | } |
| 5232 | |
| 5233 | template<class _Tp> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5234 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5235 | void |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5236 | weak_ptr<_Tp>::reset() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5237 | { |
| 5238 | weak_ptr().swap(*this); |
| 5239 | } |
| 5240 | |
| 5241 | template<class _Tp> |
| 5242 | template<class _Yp> |
| 5243 | shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, |
Marshall Clow | 7e384b7 | 2017-01-10 16:59:33 +0000 | [diff] [blame] | 5244 | typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5245 | : __ptr_(__r.__ptr_), |
| 5246 | __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) |
| 5247 | { |
| 5248 | if (__cntrl_ == 0) |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 5249 | __throw_bad_weak_ptr(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | template<class _Tp> |
| 5253 | shared_ptr<_Tp> |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5254 | weak_ptr<_Tp>::lock() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5255 | { |
| 5256 | shared_ptr<_Tp> __r; |
| 5257 | __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_; |
| 5258 | if (__r.__cntrl_) |
| 5259 | __r.__ptr_ = __ptr_; |
| 5260 | return __r; |
| 5261 | } |
| 5262 | |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5263 | #if _LIBCPP_STD_VER > 14 |
| 5264 | template <class _Tp = void> struct owner_less; |
| 5265 | #else |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5266 | template <class _Tp> struct owner_less; |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5267 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5268 | |
| 5269 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5270 | struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5271 | : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5272 | { |
| 5273 | typedef bool result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5274 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5275 | 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] | 5276 | {return __x.owner_before(__y);} |
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, weak_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()( weak_ptr<_Tp> const& __x, shared_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 | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5283 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5284 | |
| 5285 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5286 | struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5287 | : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> |
| 5288 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5289 | typedef bool result_type; |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5290 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5291 | 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] | 5292 | {return __x.owner_before(__y);} |
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()(shared_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()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5298 | {return __x.owner_before(__y);} |
| 5299 | }; |
| 5300 | |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5301 | #if _LIBCPP_STD_VER > 14 |
| 5302 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5303 | struct _LIBCPP_TEMPLATE_VIS owner_less<void> |
Marshall Clow | 3c2d8a4 | 2015-11-12 15:56:44 +0000 | [diff] [blame] | 5304 | { |
| 5305 | template <class _Tp, class _Up> |
| 5306 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5307 | 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] | 5308 | {return __x.owner_before(__y);} |
| 5309 | template <class _Tp, class _Up> |
| 5310 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5311 | 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] | 5312 | {return __x.owner_before(__y);} |
| 5313 | template <class _Tp, class _Up> |
| 5314 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5315 | 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] | 5316 | {return __x.owner_before(__y);} |
| 5317 | template <class _Tp, class _Up> |
| 5318 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 18a7cd5 | 2017-04-11 17:08:53 +0000 | [diff] [blame] | 5319 | 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] | 5320 | {return __x.owner_before(__y);} |
| 5321 | typedef void is_transparent; |
| 5322 | }; |
| 5323 | #endif |
| 5324 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5325 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5326 | class _LIBCPP_TEMPLATE_VIS enable_shared_from_this |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5327 | { |
| 5328 | mutable weak_ptr<_Tp> __weak_this_; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5329 | protected: |
Howard Hinnant | b5fffe8 | 2012-07-07 20:56:04 +0000 | [diff] [blame] | 5330 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5331 | enable_shared_from_this() _NOEXCEPT {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5332 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5333 | enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5334 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5335 | enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT |
| 5336 | {return *this;} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5337 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5338 | ~enable_shared_from_this() {} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5339 | public: |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5340 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5341 | shared_ptr<_Tp> shared_from_this() |
| 5342 | {return shared_ptr<_Tp>(__weak_this_);} |
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 const> shared_from_this() const |
| 5345 | {return shared_ptr<const _Tp>(__weak_this_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5346 | |
Eric Fiselier | 8400686 | 2016-06-02 00:15:35 +0000 | [diff] [blame] | 5347 | #if _LIBCPP_STD_VER > 14 |
| 5348 | _LIBCPP_INLINE_VISIBILITY |
| 5349 | weak_ptr<_Tp> weak_from_this() _NOEXCEPT |
| 5350 | { return __weak_this_; } |
| 5351 | |
| 5352 | _LIBCPP_INLINE_VISIBILITY |
| 5353 | weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT |
| 5354 | { return __weak_this_; } |
| 5355 | #endif // _LIBCPP_STD_VER > 14 |
| 5356 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5357 | template <class _Up> friend class shared_ptr; |
| 5358 | }; |
| 5359 | |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5360 | template <class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5361 | struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5362 | { |
| 5363 | typedef shared_ptr<_Tp> argument_type; |
| 5364 | typedef size_t result_type; |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 5365 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5366 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 719bda3 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 5367 | result_type operator()(const argument_type& __ptr) const _NOEXCEPT |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 5368 | { |
| 5369 | return hash<_Tp*>()(__ptr.get()); |
| 5370 | } |
| 5371 | }; |
| 5372 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5373 | template<class _CharT, class _Traits, class _Yp> |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 5374 | inline _LIBCPP_INLINE_VISIBILITY |
| 5375 | basic_ostream<_CharT, _Traits>& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5376 | operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p); |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 5377 | |
Eric Fiselier | 9b49267 | 2016-06-18 02:12:53 +0000 | [diff] [blame] | 5378 | |
| 5379 | #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5380 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5381 | class _LIBCPP_TYPE_VIS __sp_mut |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5382 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5383 | void* __lx; |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5384 | public: |
| 5385 | void lock() _NOEXCEPT; |
| 5386 | void unlock() _NOEXCEPT; |
| 5387 | |
| 5388 | private: |
| 5389 | _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT; |
| 5390 | __sp_mut(const __sp_mut&); |
| 5391 | __sp_mut& operator=(const __sp_mut&); |
| 5392 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 5393 | friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5394 | }; |
| 5395 | |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5396 | _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
| 5397 | __sp_mut& __get_sp_mut(const void*); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5398 | |
| 5399 | template <class _Tp> |
| 5400 | inline _LIBCPP_INLINE_VISIBILITY |
| 5401 | bool |
| 5402 | atomic_is_lock_free(const shared_ptr<_Tp>*) |
| 5403 | { |
| 5404 | return false; |
| 5405 | } |
| 5406 | |
| 5407 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5408 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5409 | shared_ptr<_Tp> |
| 5410 | atomic_load(const shared_ptr<_Tp>* __p) |
| 5411 | { |
| 5412 | __sp_mut& __m = __get_sp_mut(__p); |
| 5413 | __m.lock(); |
| 5414 | shared_ptr<_Tp> __q = *__p; |
| 5415 | __m.unlock(); |
| 5416 | return __q; |
| 5417 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5418 | |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5419 | template <class _Tp> |
| 5420 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5421 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5422 | shared_ptr<_Tp> |
| 5423 | atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) |
| 5424 | { |
| 5425 | return atomic_load(__p); |
| 5426 | } |
| 5427 | |
| 5428 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5429 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5430 | void |
| 5431 | atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) |
| 5432 | { |
| 5433 | __sp_mut& __m = __get_sp_mut(__p); |
| 5434 | __m.lock(); |
| 5435 | __p->swap(__r); |
| 5436 | __m.unlock(); |
| 5437 | } |
| 5438 | |
| 5439 | template <class _Tp> |
| 5440 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5441 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5442 | void |
| 5443 | atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) |
| 5444 | { |
| 5445 | atomic_store(__p, __r); |
| 5446 | } |
| 5447 | |
| 5448 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5449 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5450 | shared_ptr<_Tp> |
| 5451 | atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) |
| 5452 | { |
| 5453 | __sp_mut& __m = __get_sp_mut(__p); |
| 5454 | __m.lock(); |
| 5455 | __p->swap(__r); |
| 5456 | __m.unlock(); |
| 5457 | return __r; |
| 5458 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5459 | |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5460 | template <class _Tp> |
| 5461 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5462 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5463 | shared_ptr<_Tp> |
| 5464 | atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) |
| 5465 | { |
| 5466 | return atomic_exchange(__p, __r); |
| 5467 | } |
| 5468 | |
| 5469 | template <class _Tp> |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5470 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5471 | bool |
| 5472 | atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) |
| 5473 | { |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5474 | shared_ptr<_Tp> __temp; |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5475 | __sp_mut& __m = __get_sp_mut(__p); |
| 5476 | __m.lock(); |
| 5477 | if (__p->__owner_equivalent(*__v)) |
| 5478 | { |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5479 | _VSTD::swap(__temp, *__p); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5480 | *__p = __w; |
| 5481 | __m.unlock(); |
| 5482 | return true; |
| 5483 | } |
Marshall Clow | 4201ee8 | 2016-05-18 17:50:13 +0000 | [diff] [blame] | 5484 | _VSTD::swap(__temp, *__v); |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5485 | *__v = *__p; |
| 5486 | __m.unlock(); |
| 5487 | return false; |
| 5488 | } |
| 5489 | |
| 5490 | template <class _Tp> |
| 5491 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5492 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5493 | bool |
| 5494 | atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) |
| 5495 | { |
| 5496 | return atomic_compare_exchange_strong(__p, __v, __w); |
| 5497 | } |
| 5498 | |
| 5499 | template <class _Tp> |
| 5500 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5501 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5502 | bool |
| 5503 | atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, |
| 5504 | shared_ptr<_Tp> __w, memory_order, memory_order) |
| 5505 | { |
| 5506 | return atomic_compare_exchange_strong(__p, __v, __w); |
| 5507 | } |
| 5508 | |
| 5509 | template <class _Tp> |
| 5510 | inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 5511 | _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5512 | bool |
| 5513 | atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, |
| 5514 | shared_ptr<_Tp> __w, memory_order, memory_order) |
| 5515 | { |
| 5516 | return atomic_compare_exchange_weak(__p, __v, __w); |
| 5517 | } |
| 5518 | |
Eric Fiselier | 9b49267 | 2016-06-18 02:12:53 +0000 | [diff] [blame] | 5519 | #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
Howard Hinnant | 9fa3020 | 2012-07-30 01:40:57 +0000 | [diff] [blame] | 5520 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5521 | //enum class |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5522 | #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) |
| 5523 | # ifndef _LIBCPP_CXX03_LANG |
| 5524 | enum class pointer_safety : unsigned char { |
| 5525 | relaxed, |
| 5526 | preferred, |
| 5527 | strict |
| 5528 | }; |
| 5529 | # endif |
| 5530 | #else |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 5531 | struct _LIBCPP_TYPE_VIS pointer_safety |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5532 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5533 | enum __lx |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5534 | { |
| 5535 | relaxed, |
| 5536 | preferred, |
| 5537 | strict |
| 5538 | }; |
| 5539 | |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5540 | __lx __v_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5541 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5542 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2fdd22b | 2017-01-05 01:28:40 +0000 | [diff] [blame] | 5543 | pointer_safety() : __v_() {} |
| 5544 | |
| 5545 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5546 | pointer_safety(__lx __v) : __v_(__v) {} |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 5547 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5548 | operator int() const {return __v_;} |
| 5549 | }; |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5550 | #endif |
| 5551 | |
| 5552 | #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \ |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 5553 | defined(_LIBCPP_BUILDING_LIBRARY) |
Eric Fiselier | ab6bb30 | 2017-01-05 01:15:42 +0000 | [diff] [blame] | 5554 | _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; |
| 5555 | #else |
| 5556 | // This function is only offered in C++03 under ABI v1. |
| 5557 | # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG) |
| 5558 | inline _LIBCPP_INLINE_VISIBILITY |
| 5559 | pointer_safety get_pointer_safety() _NOEXCEPT { |
| 5560 | return pointer_safety::relaxed; |
| 5561 | } |
| 5562 | # endif |
| 5563 | #endif |
| 5564 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5565 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5566 | _LIBCPP_FUNC_VIS void declare_reachable(void* __p); |
| 5567 | _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); |
| 5568 | _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5569 | _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5570 | |
| 5571 | template <class _Tp> |
| 5572 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5573 | _Tp* |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5574 | undeclare_reachable(_Tp* __p) |
| 5575 | { |
| 5576 | return static_cast<_Tp*>(__undeclare_reachable(__p)); |
| 5577 | } |
| 5578 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5579 | _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] | 5580 | |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5581 | // --- Helper for container swap -- |
| 5582 | template <typename _Alloc> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 5583 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5584 | void __swap_allocator(_Alloc & __a1, _Alloc & __a2) |
| 5585 | #if _LIBCPP_STD_VER >= 14 |
| 5586 | _NOEXCEPT |
| 5587 | #else |
| 5588 | _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) |
| 5589 | #endif |
| 5590 | { |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5591 | __swap_allocator(__a1, __a2, |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5592 | integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); |
| 5593 | } |
| 5594 | |
| 5595 | template <typename _Alloc> |
| 5596 | _LIBCPP_INLINE_VISIBILITY |
| 5597 | void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) |
| 5598 | #if _LIBCPP_STD_VER >= 14 |
| 5599 | _NOEXCEPT |
| 5600 | #else |
| 5601 | _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) |
| 5602 | #endif |
| 5603 | { |
| 5604 | using _VSTD::swap; |
| 5605 | swap(__a1, __a2); |
| 5606 | } |
| 5607 | |
| 5608 | template <typename _Alloc> |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 5609 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5610 | void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} |
| 5611 | |
Marshall Clow | ff91de8 | 2015-08-18 19:51:37 +0000 | [diff] [blame] | 5612 | template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5613 | struct __noexcept_move_assign_container : public integral_constant<bool, |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 5614 | _Traits::propagate_on_container_move_assignment::value |
| 5615 | #if _LIBCPP_STD_VER > 14 |
| 5616 | || _Traits::is_always_equal::value |
| 5617 | #else |
| 5618 | && is_nothrow_move_assignable<_Alloc>::value |
| 5619 | #endif |
| 5620 | > {}; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 5621 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5622 | |
| 5623 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 5624 | template <class _Tp, class _Alloc> |
| 5625 | struct __temp_value { |
| 5626 | typedef allocator_traits<_Alloc> _Traits; |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5627 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5628 | typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v; |
| 5629 | _Alloc &__a; |
| 5630 | |
| 5631 | _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } |
| 5632 | _Tp & get() { return *__addr(); } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5633 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5634 | template<class... _Args> |
Peter Collingbourne | cb12615 | 2018-08-15 17:49:30 +0000 | [diff] [blame] | 5635 | _LIBCPP_NO_CFI |
| 5636 | __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { |
| 5637 | _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)), |
| 5638 | _VSTD::forward<_Args>(__args)...); |
| 5639 | } |
Aditya Kumar | 7c5db69 | 2017-08-20 10:38:55 +0000 | [diff] [blame] | 5640 | |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 5641 | ~__temp_value() { _Traits::destroy(__a, __addr()); } |
| 5642 | }; |
| 5643 | #endif |
| 5644 | |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 5645 | template<typename _Alloc, typename = void, typename = void> |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5646 | struct __is_allocator : false_type {}; |
| 5647 | |
| 5648 | template<typename _Alloc> |
| 5649 | struct __is_allocator<_Alloc, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 5650 | typename __void_t<typename _Alloc::value_type>::type, |
| 5651 | typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type |
| 5652 | > |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5653 | : true_type {}; |
Marshall Clow | 82c90aa | 2018-01-11 19:36:22 +0000 | [diff] [blame] | 5654 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5655 | _LIBCPP_END_NAMESPACE_STD |
| 5656 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 5657 | _LIBCPP_POP_MACROS |
| 5658 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5659 | #endif // _LIBCPP_MEMORY |