std::shared_ptr< _Tp >(3cxx) | std::shared_ptr< _Tp >(3cxx) |
NAME¶
std::shared_ptr< _Tp > - A smart pointer with reference-counted copy semantics.
SYNOPSIS¶
#include <shared_ptr.h>
Inherits std::__shared_ptr< _Tp, _Lp >.
Public Types¶
using element_type = typename
__shared_ptr< _Tp >::element_type
Public Member Functions¶
constexpr shared_ptr () noexcept
Construct an empty shared_ptr. template<typename _Yp ,
typename = _Constructible<_Yp*>> shared_ptr
(_Yp *__p)
Construct a shared_ptr that owns the pointer __p.
template<typename _Yp , typename _Deleter ,
typename = _Constructible<_Yp*, _Deleter>> shared_ptr
(_Yp *__p, _Deleter __d)
Construct a shared_ptr that owns the pointer __p and the deleter
__d. template<typename _Yp , typename
_Deleter , typename _Alloc , typename =
_Constructible<_Yp*, _Deleter, _Alloc>> shared_ptr
(_Yp *__p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns the pointer __p and the deleter
__d. shared_ptr (const shared_ptr &)
noexcept=default
template<typename _Yp , typename =
_Constructible<const shared_ptr<_Yp>&>> shared_ptr
(const shared_ptr< _Yp > &__r)
noexcept
If __r is empty, constructs an empty shared_ptr; otherwise construct a
shared_ptr that shares ownership with __r.
template<typename _Yp > shared_ptr (const
shared_ptr< _Yp > &__r, element_type *__p)
noexcept
Constructs a shared_ptr instance that stores __p and shares ownership
with __r. template<typename _Yp , typename =
_Constructible<const weak_ptr<_Yp>&>> shared_ptr
(const weak_ptr< _Yp > &__r)
Constructs a shared_ptr that shares ownership with __r and stores a
copy of the pointer stored in __r. template<typename
_Deleter > shared_ptr (nullptr_t __p, _Deleter __d)
Construct a shared_ptr that owns a null pointer and the deleter __d.
template<typename _Deleter , typename _Alloc >
shared_ptr (nullptr_t __p, _Deleter __d, _Alloc __a)
Construct a shared_ptr that owns a null pointer and the deleter __d.
constexpr shared_ptr (nullptr_t) noexcept
Construct an empty shared_ptr. shared_ptr (shared_ptr
&&__r) noexcept
Move-constructs a shared_ptr instance from __r.
template<typename _Yp , typename =
_Constructible<shared_ptr<_Yp>>> shared_ptr
(shared_ptr< _Yp > &&__r) noexcept
Move-constructs a shared_ptr instance from __r.
template<typename _Tp1 , typename >
shared_ptr (std::auto_ptr< _Tp1 > &&__r)
template<typename _Yp , typename _Del ,
typename = _Constructible<unique_ptr<_Yp, _Del>>>
shared_ptr (unique_ptr< _Yp, _Del >
&&__r)
element_type * get () const noexcept
operator bool () const
element_type & operator* () const noexcept
element_type * operator-> () const noexcept
shared_ptr & operator= (const shared_ptr
&) noexcept=default
template<typename _Yp > _Assignable< const
shared_ptr< _Yp > & > operator=
(const shared_ptr< _Yp > &__r)
noexcept
shared_ptr & operator= (shared_ptr &&__r)
noexcept
template<class _Yp > _Assignable< shared_ptr<
_Yp > > operator= (shared_ptr< _Yp >
&&__r) noexcept
template<typename _Yp , typename _Del >
_Assignable< unique_ptr< _Yp, _Del > >
operator= (unique_ptr< _Yp, _Del >
&&__r)
template<typename _Tp1 > bool owner_before
(__shared_ptr< _Tp1, _Lp > const
&__rhs) const noexcept
template<typename _Tp1 > bool owner_before
(__weak_ptr< _Tp1, _Lp > const &__rhs)
const noexcept
void reset () noexcept
template<typename _Yp > _SafeConv< _Yp >
reset (_Yp *__p)
template<typename _Yp , typename _Deleter >
_SafeConv< _Yp > reset (_Yp *__p, _Deleter __d)
template<typename _Yp , typename _Deleter ,
typename _Alloc > _SafeConv< _Yp > reset
(_Yp *__p, _Deleter __d, _Alloc __a)
void swap (__shared_ptr< _Tp, _Lp > &__other)
noexcept
bool unique () const noexcept
long use_count () const noexcept
Friends¶
template<typename _Yp , typename _Alloc ,
typename... _Args> shared_ptr< _Yp >
allocate_shared (const _Alloc &__a, _Args
&&... __args)
Create an object that is owned by a shared_ptr. class weak_ptr<
_Tp >
Detailed Description¶
template<typename _Tp>¶
class std::shared_ptr< _Tp >"A smart pointer with reference-counted copy semantics.
The object pointed to is deleted when the last shared_ptr pointing to it is destroyed or reset.
Definition at line 103 of file bits/shared_ptr.h.
Member Typedef Documentation¶
template<typename _Tp > using std::shared_ptr< _Tp >::element_type = typename __shared_ptr<_Tp>::element_type¶
Definition at line 117 of file bits/shared_ptr.h.
Constructor & Destructor Documentation¶
template<typename _Tp > constexpr std::shared_ptr< _Tp >::shared_ptr () [inline], [constexpr], [noexcept]¶
Construct an empty shared_ptr.
Postcondition
Definition at line 127 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp , typename = _Constructible<_Yp*>> std::shared_ptr< _Tp >::shared_ptr (_Yp * __p) [inline], [explicit]¶
Construct a shared_ptr that owns the pointer __p.
Parameters
Postcondition
Exceptions
Definition at line 139 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp , typename _Deleter , typename = _Constructible<_Yp*, _Deleter>> std::shared_ptr< _Tp >::shared_ptr (_Yp * __p, _Deleter __d) [inline]¶
Construct a shared_ptr that owns the pointer __p and the deleter __d.
Parameters
__d A deleter.
Postcondition
Exceptions
Requirements: _Deleter's copy constructor and destructor must not throw
__shared_ptr will release __p by calling __d(__p)
Definition at line 156 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Deleter > std::shared_ptr< _Tp >::shared_ptr (nullptr_t __p, _Deleter __d) [inline]¶
Construct a shared_ptr that owns a null pointer and the deleter __d.
Parameters
__d A deleter.
Postcondition
Exceptions
Requirements: _Deleter's copy constructor and destructor must not throw
The last owner will call __d(__p)
Definition at line 173 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp , typename _Deleter , typename _Alloc , typename = _Constructible<_Yp*, _Deleter, _Alloc>> std::shared_ptr< _Tp >::shared_ptr (_Yp * __p, _Deleter __d, _Alloc __a) [inline]¶
Construct a shared_ptr that owns the pointer __p and the deleter __d.
Parameters
__d A deleter.
__a An allocator.
Postcondition
Exceptions
Requirements: _Deleter's copy constructor and destructor must not throw _Alloc's copy constructor and destructor must not throw.
__shared_ptr will release __p by calling __d(__p)
Definition at line 193 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Deleter , typename _Alloc > std::shared_ptr< _Tp >::shared_ptr (nullptr_t __p, _Deleter __d, _Alloc __a) [inline]¶
Construct a shared_ptr that owns a null pointer and the deleter __d.
Parameters
__d A deleter.
__a An allocator.
Postcondition
Exceptions
Requirements: _Deleter's copy constructor and destructor must not throw _Alloc's copy constructor and destructor must not throw.
The last owner will call __d(__p)
Definition at line 212 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp > std::shared_ptr< _Tp >::shared_ptr (const shared_ptr< _Yp > & __r, element_type * __p) [inline], [noexcept]¶
Constructs a shared_ptr instance that stores __p and shares ownership with __r.
Parameters
__p A pointer that will remain valid while *__r is valid.
Postcondition
This can be used to construct a shared_ptr to a sub-object of an object managed by an existing shared_ptr.
shared_ptr< pair<int,int> > pii(new pair<int,int>()); shared_ptr<int> pi(pii, &pii->first); assert(pii.use_count() == 2);
Definition at line 234 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp , typename = _Constructible<const shared_ptr<_Yp>&>> std::shared_ptr< _Tp >::shared_ptr (const shared_ptr< _Yp > & __r) [inline], [noexcept]¶
If __r is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownership with __r.
Parameters
Postcondition
Definition at line 246 of file bits/shared_ptr.h.
template<typename _Tp > std::shared_ptr< _Tp >::shared_ptr (shared_ptr< _Tp > && __r) [inline], [noexcept]¶
Move-constructs a shared_ptr instance from __r.
Parameters
Postcondition
Definition at line 254 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp , typename = _Constructible<shared_ptr<_Yp>>> std::shared_ptr< _Tp >::shared_ptr (shared_ptr< _Yp > && __r) [inline], [noexcept]¶
Move-constructs a shared_ptr instance from __r.
Parameters
Postcondition
Definition at line 263 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp , typename = _Constructible<const weak_ptr<_Yp>&>> std::shared_ptr< _Tp >::shared_ptr (const weak_ptr< _Yp > & __r) [inline], [explicit]¶
Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r.
Parameters
Postcondition
Exceptions
Definition at line 275 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp , typename _Del , typename = _Constructible<unique_ptr<_Yp, _Del>>> std::shared_ptr< _Tp >::shared_ptr (unique_ptr< _Yp, _Del > && __r) [inline]¶
Definition at line 290 of file bits/shared_ptr.h.
template<typename _Tp > constexpr std::shared_ptr< _Tp >::shared_ptr (nullptr_t) [inline], [constexpr], [noexcept]¶
Construct an empty shared_ptr.
Postcondition
Definition at line 307 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Tp1 , typename > std::shared_ptr< _Tp >::shared_ptr (std::auto_ptr< _Tp1 > && __r) [inline]¶
Definition at line 322 of file auto_ptr.h.
Member Function Documentation¶
template<typename _Tp , _Lock_policy _Lp> element_type * std::__shared_ptr< _Tp, _Lp >::get () const [inline], [noexcept], [inherited]¶
Definition at line 1309 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> std::__shared_ptr< _Tp, _Lp >::operator bool () const [inline], [explicit], [inherited]¶
Definition at line 1312 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp, bool = is_array<_Tp>::value, bool = is_void<_Tp>::value> element_type & std::__shared_ptr_access< _Tp, _Lp, bool, bool >::operator* () const [inline], [noexcept], [inherited]¶
Definition at line 1005 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp, bool = is_array<_Tp>::value, bool = is_void<_Tp>::value> element_type * std::__shared_ptr_access< _Tp, _Lp, bool, bool >::operator-> () const [inline], [noexcept], [inherited]¶
Definition at line 1012 of file shared_ptr_base.h.
template<typename _Tp > template<typename _Yp > _Assignable< const shared_ptr< _Yp > & > std::shared_ptr< _Tp >::operator= (const shared_ptr< _Yp > & __r) [inline], [noexcept]¶
Definition at line 313 of file bits/shared_ptr.h.
template<typename _Tp > shared_ptr & std::shared_ptr< _Tp >::operator= (shared_ptr< _Tp > && __r) [inline], [noexcept]¶
Definition at line 333 of file bits/shared_ptr.h.
template<typename _Tp > template<class _Yp > _Assignable< shared_ptr< _Yp > > std::shared_ptr< _Tp >::operator= (shared_ptr< _Yp > && __r) [inline], [noexcept]¶
Definition at line 341 of file bits/shared_ptr.h.
template<typename _Tp > template<typename _Yp , typename _Del > _Assignable< unique_ptr< _Yp, _Del > > std::shared_ptr< _Tp >::operator= (unique_ptr< _Yp, _Del > && __r) [inline]¶
Definition at line 349 of file bits/shared_ptr.h.
template<typename _Tp , _Lock_policy _Lp> template<typename _Tp1 > bool std::__shared_ptr< _Tp, _Lp >::owner_before (__shared_ptr< _Tp1, _Lp > const & __rhs) const [inline], [noexcept], [inherited]¶
Definition at line 1332 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> template<typename _Tp1 > bool std::__shared_ptr< _Tp, _Lp >::owner_before (__weak_ptr< _Tp1, _Lp > const & __rhs) const [inline], [noexcept], [inherited]¶
Definition at line 1337 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> void std::__shared_ptr< _Tp, _Lp >::reset () [inline], [noexcept], [inherited]¶
Definition at line 1286 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> template<typename _Yp > _SafeConv< _Yp > std::__shared_ptr< _Tp, _Lp >::reset (_Yp * __p) [inline], [inherited]¶
Definition at line 1291 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> template<typename _Yp , typename _Deleter > _SafeConv< _Yp > std::__shared_ptr< _Tp, _Lp >::reset (_Yp * __p, _Deleter __d) [inline], [inherited]¶
Definition at line 1300 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> template<typename _Yp , typename _Deleter , typename _Alloc > _SafeConv< _Yp > std::__shared_ptr< _Tp, _Lp >::reset (_Yp * __p, _Deleter __d, _Alloc __a) [inline], [inherited]¶
Definition at line 1305 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> void std::__shared_ptr< _Tp, _Lp >::swap (__shared_ptr< _Tp, _Lp > & __other) [inline], [noexcept], [inherited]¶
Definition at line 1324 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> bool std::__shared_ptr< _Tp, _Lp >::unique () const [inline], [noexcept], [inherited]¶
Definition at line 1316 of file shared_ptr_base.h.
template<typename _Tp , _Lock_policy _Lp> long std::__shared_ptr< _Tp, _Lp >::use_count () const [inline], [noexcept], [inherited]¶
Definition at line 1320 of file shared_ptr_base.h.
Friends And Related Symbol Documentation¶
template<typename _Tp > template<typename _Yp , typename _Alloc , typename... _Args> shared_ptr< _Yp > allocate_shared (const _Alloc & __a, _Args &&... __args) [friend]¶
Create an object that is owned by a shared_ptr.
Parameters
__args Arguments for the _Tp object's constructor.
Returns
Exceptions
A copy of __a will be used to allocate memory for the shared_ptr and the new object.
Definition at line 699 of file bits/shared_ptr.h.
template<typename _Tp > friend class weak_ptr< _Tp > [friend]¶
Definition at line 367 of file bits/shared_ptr.h.
Author¶
Generated automatically by Doxygen for libstdc++ from the source code.
libstdc++ |