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