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