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