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