Home | History | Annotate | Download | only in bits

Lines Matching defs:shared_ptr

0 // shared_ptr and weak_ptr implementation -*- C++ -*-
30 // shared_ptr.hpp
44 /** @file bits/shared_ptr.h
63 /// 2.2.3.7 shared_ptr I/O
73 /// 2.2.3.10 shared_ptr get_deleter (experimental)
89 * The object pointed to is deleted when the last shared_ptr pointing to
93 class shared_ptr : public __shared_ptr<_Tp>
97 * @brief Construct an empty %shared_ptr.
100 constexpr shared_ptr() noexcept
103 shared_ptr(const shared_ptr&) noexcept = default;
106 * @brief Construct a %shared_ptr that owns the pointer @a __p.
112 explicit shared_ptr(_Tp1* __p)
116 * @brief Construct a %shared_ptr that owns the pointer @a __p
129 shared_ptr(_Tp1* __p, _Deleter __d)
133 * @brief Construct a %shared_ptr that owns a null pointer
146 shared_ptr(nullptr_t __p, _Deleter __d)
150 * @brief Construct a %shared_ptr that owns the pointer @a __p
165 shared_ptr(_Tp1* __p, _Deleter __d, _Alloc __a)
169 * @brief Construct a %shared_ptr that owns a null pointer
184 shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
190 * @brief Constructs a %shared_ptr instance that stores @a __p
192 * @param __r A %shared_ptr.
196 * This can be used to construct a @c shared_ptr to a sub-object
197 * of an object managed by an existing @c shared_ptr.
200 * shared_ptr< pair<int,int> > pii(new pair<int,int>());
201 * shared_ptr<int> pi(pii, &pii->first);
206 shared_ptr(const shared_ptr<_Tp1>& __r, _Tp* __p) noexcept
210 * @brief If @a __r is empty, constructs an empty %shared_ptr;
211 * otherwise construct a %shared_ptr that shares ownership
213 * @param __r A %shared_ptr.
218 shared_ptr(const shared_ptr<_Tp1>& __r) noexcept
222 * @brief Move-constructs a %shared_ptr instance from @a __r.
223 * @param __r A %shared_ptr rvalue.
226 shared_ptr(shared_ptr&& __r) noexcept
230 * @brief Move-constructs a %shared_ptr instance from @a __r.
231 * @param __r A %shared_ptr rvalue.
236 shared_ptr(shared_ptr<_Tp1>&& __r) noexcept
240 * @brief Constructs a %shared_ptr that shares ownership with @a __r
248 explicit shared_ptr(const weak_ptr<_Tp1>& __r)
253 shared_ptr(std::auto_ptr<_Tp1>&& __r);
257 shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r)
261 * @brief Construct an empty %shared_ptr.
265 constexpr shared_ptr(nullptr_t __p) noexcept
268 shared_ptr& operator=(const shared_ptr&) noexcept = default;
271 shared_ptr&
272 operator=(const shared_ptr<_Tp1>& __r) noexcept
280 shared_ptr&
288 shared_ptr&
289 operator=(shared_ptr&& __r) noexcept
296 shared_ptr&
297 operator=(shared_ptr<_Tp1>&& __r) noexcept
304 shared_ptr&
314 shared_ptr(_Sp_make_shared_tag __tag, const _Alloc& __a,
320 friend shared_ptr<_Tp1>
324 // 20.7.2.2.7 shared_ptr comparisons
327 operator==(const shared_ptr<_Tp1>& __a,
328 const shared_ptr<_Tp2>& __b) noexcept
333 operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
338 operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
343 operator!=(const shared_ptr<_Tp1>& __a,
344 const shared_ptr<_Tp2>& __b) noexcept
349 operator!=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
354 operator!=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
359 operator<(const shared_ptr<_Tp1>& __a,
360 const shared_ptr<_Tp2>& __b) noexcept
368 operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
373 operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
378 operator<=(const shared_ptr<_Tp1>& __a,
379 const shared_ptr<_Tp2>& __b) noexcept
384 operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
389 operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
394 operator>(const shared_ptr<_Tp1>& __a,
395 const shared_ptr<_Tp2>& __b) noexcept
400 operator>(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
405 operator>(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
410 operator>=(const shared_ptr<_Tp1>& __a,
411 const shared_ptr<_Tp2>& __b) noexcept
416 operator>=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
421 operator>=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
425 struct less<shared_ptr<_Tp>> : public _Sp_less<shared_ptr<_Tp>>
428 // 20.7.2.2.8 shared_ptr specialized algorithms.
431 swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
434 // 20.7.2.2.9 shared_ptr casts.
436 inline shared_ptr<_Tp>
437 static_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
438 { return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); }
441 inline shared_ptr<_Tp>
442 const_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
443 { return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get())); }
446 inline shared_ptr<_Tp>
447 dynamic_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
450 return shared_ptr<_Tp>(__r, __p);
451 return shared_ptr<_Tp>();
474 weak_ptr(const shared_ptr<_Tp1>& __r) noexcept
487 operator=(const shared_ptr<_Tp1>& __r) noexcept
493 shared_ptr<_Tp>
498 return shared_ptr<_Tp>();
502 return shared_ptr<_Tp>(*this);
506 return shared_ptr<_Tp>();
509 return this->expired() ? shared_ptr<_Tp>() : shared_ptr<_Tp>(*this);
525 /// Partial specialization of owner_less for shared_ptr.
527 struct owner_less<shared_ptr<_Tp>>
528 : public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
534 : public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
555 shared_ptr<_Tp>
557 { return shared_ptr<_Tp>(this->_M_weak_this); }
559 shared_ptr<const _Tp>
561 { return shared_ptr<const _Tp>(this->_M_weak_this); }
583 * @brief Create an object that is owned by a shared_ptr.
586 * @return A shared_ptr that owns the newly created object.
590 * A copy of @a __a will be used to allocate memory for the shared_ptr
594 inline shared_ptr<_Tp>
597 return shared_ptr<_Tp>(_Sp_make_shared_tag(), __a,
602 * @brief Create an object that is owned by a shared_ptr.
604 * @return A shared_ptr that owns the newly created object.
609 inline shared_ptr<_Tp>
617 /// std::hash specialization for shared_ptr.
619 struct hash<shared_ptr<_Tp>>
620 : public __hash_base<size_t, shared_ptr<_Tp>>
623 operator()(const shared_ptr<_Tp>& __s) const noexcept