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