STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Private Member Functions | List of all members
shared_ptr< _Ty > Class Template Reference
Inheritance diagram for shared_ptr< _Ty >:
_Ptr_base< _Ty >

Public Types

typedef shared_ptr< _Ty > _Myt
 
typedef _Ptr_base< _Ty > _Mybase
 
- Public Types inherited from _Ptr_base< _Ty >
typedef _Ptr_base< _Ty > _Myt
 
typedef _Ty element_type
 

Public Member Functions

constexpr shared_ptr () _NOEXCEPT
 
template<class _Ux >
 shared_ptr (_Ux *_Px)
 
template<class _Ux , class _Dx >
 shared_ptr (_Ux *_Px, _Dx _Dt)
 
constexpr shared_ptr (nullptr_t) _NOEXCEPT
 
template<class _Dx >
 shared_ptr (nullptr_t, _Dx _Dt)
 
template<class _Dx , class _Alloc >
 shared_ptr (nullptr_t, _Dx _Dt, _Alloc _Ax)
 
template<class _Ux , class _Dx , class _Alloc >
 shared_ptr (_Ux *_Px, _Dx _Dt, _Alloc _Ax)
 
template<class _Ty2 >
 shared_ptr (const shared_ptr< _Ty2 > &_Right, _Ty *_Px) _NOEXCEPT
 
 shared_ptr (const _Myt &_Other) _NOEXCEPT
 
template<class _Ty2 , class = enable_if_t<is_convertible<_Ty2 *, _Ty *>::value>>
 shared_ptr (const shared_ptr< _Ty2 > &_Other) _NOEXCEPT
 
template<class _Ty2 >
 shared_ptr (const weak_ptr< _Ty2 > &_Other)
 
 shared_ptr (_No_bad_weak_ptr, const weak_ptr< _Ty > &_Other) _NOEXCEPT
 
 shared_ptr (_Myt &&_Right) _NOEXCEPT
 
template<class _Ty2 , class = enable_if_t<is_convertible<_Ty2 *, _Ty *>::value>>
 shared_ptr (shared_ptr< _Ty2 > &&_Right) _NOEXCEPT
 
template<class _Ux , class _Dx , class = enable_if_t<is_convertible< typename unique_ptr<_Ux, _Dx>::pointer, _Ty *>::value>>
 shared_ptr (unique_ptr< _Ux, _Dx > &&_Right)
 
template<class _Ux , class _Dx >
_Mytoperator= (unique_ptr< _Ux, _Dx > &&_Right)
 
_Mytoperator= (_Myt &&_Right) _NOEXCEPT
 
template<class _Ty2 >
_Mytoperator= (shared_ptr< _Ty2 > &&_Right) _NOEXCEPT
 
 ~shared_ptr () _NOEXCEPT
 
_Mytoperator= (const _Myt &_Right) _NOEXCEPT
 
template<class _Ty2 >
_Mytoperator= (const shared_ptr< _Ty2 > &_Right) _NOEXCEPT
 
void reset () _NOEXCEPT
 
template<class _Ux >
void reset (_Ux *_Px)
 
template<class _Ux , class _Dx >
void reset (_Ux *_Px, _Dx _Dt)
 
template<class _Ux , class _Dx , class _Alloc >
void reset (_Ux *_Px, _Dx _Dt, _Alloc _Ax)
 
void swap (_Myt &_Other) _NOEXCEPT
 
_Ty * get () const _NOEXCEPT
 
add_lvalue_reference< _Ty >::type operator* () const _NOEXCEPT
 
_Ty * operator-> () const _NOEXCEPT
 
bool unique () const _NOEXCEPT
 
 operator bool () const _NOEXCEPT
 
template<class _Ux >
void _Resetp0 (_Ux *_Px, _Ref_count_base *_Rx)
 
- Public Member Functions inherited from _Ptr_base< _Ty >
constexpr _Ptr_base () _NOEXCEPT
 
 _Ptr_base (_Myt &&_Right)
 
template<class _Ty2 >
 _Ptr_base (_Ptr_base< _Ty2 > &&_Right)
 
_Mytoperator= (_Myt &&_Right)
 
void _Assign_rv (_Myt &&_Right)
 
long use_count () const _NOEXCEPT
 
void _Swap (_Ptr_base &_Right) _NOEXCEPT
 
template<class _Ty2 >
bool owner_before (const _Ptr_base< _Ty2 > &_Right) const
 
void_Get_deleter (const type_info &_Typeid) const _NOEXCEPT
 
_Ty * _Get () const _NOEXCEPT
 
bool _Expired () const _NOEXCEPT
 
void _Decref ()
 
void _Reset ()
 
template<class _Ty2 >
void _Reset (const _Ptr_base< _Ty2 > &_Other)
 
template<class _Ty2 >
bool _Reset_weak (const _Ptr_base< _Ty2 > &_Other)
 
template<class _Ty2 >
void _Reset (_Ty *_Other_ptr, const _Ptr_base< _Ty2 > &_Other)
 
void _Reset (_Ty *_Other_ptr, _Ref_count_base *_Other_rep)
 
bool _Reset_weak (_Ty *_Other_ptr, _Ref_count_base *_Other_rep)
 
void _Reset0 (_Ty *_Other_ptr, _Ref_count_base *_Other_rep)
 
void _Decwref ()
 
void _Resetw ()
 
template<class _Ty2 >
void _Resetw (const _Ptr_base< _Ty2 > &_Other)
 
template<class _Ty2 >
void _Resetw (_Ty2 *_Other_ptr, _Ref_count_base *_Other_rep)
 

Private Member Functions

template<class _Ux >
void _Resetp (_Ux *_Px)
 
template<class _Ux , class _Dx >
void _Resetp (_Ux *_Px, _Dx _Dt)
 
template<class _Ux , class _Dx , class _Alloc >
void _Resetp (_Ux *_Px, _Dx _Dt, _Alloc _Ax)
 

Member Typedef Documentation

template<class _Ty>
typedef _Ptr_base<_Ty> shared_ptr< _Ty >::_Mybase
template<class _Ty>
typedef shared_ptr<_Ty> shared_ptr< _Ty >::_Myt

Constructor & Destructor Documentation

template<class _Ty>
constexpr shared_ptr< _Ty >::shared_ptr ( )
inline
874  { // construct empty shared_ptr
875  }
template<class _Ty>
template<class _Ux >
shared_ptr< _Ty >::shared_ptr ( _Ux *  _Px)
inlineexplicit
879  { // construct shared_ptr object that owns _Px
880  _Resetp(_Px);
881  }
void _Resetp(_Ux *_Px)
Definition: memory:1083
template<class _Ty>
template<class _Ux , class _Dx >
shared_ptr< _Ty >::shared_ptr ( _Ux *  _Px,
_Dx  _Dt 
)
inline
886  { // construct with _Px, deleter
887  _Resetp(_Px, _Dt);
888  }
void _Resetp(_Ux *_Px)
Definition: memory:1083
template<class _Ty>
constexpr shared_ptr< _Ty >::shared_ptr ( nullptr_t  )
inline
891  { // construct empty shared_ptr
892  }
template<class _Ty>
template<class _Dx >
shared_ptr< _Ty >::shared_ptr ( nullptr_t  ,
_Dx  _Dt 
)
inline
896  { // construct with nullptr, deleter
897  _Resetp((_Ty *)0, _Dt);
898  }
void _Resetp(_Ux *_Px)
Definition: memory:1083
template<class _Ty>
template<class _Dx , class _Alloc >
shared_ptr< _Ty >::shared_ptr ( nullptr_t  ,
_Dx  _Dt,
_Alloc  _Ax 
)
inline
903  { // construct with nullptr, deleter, allocator
904  _Resetp((_Ty *)0, _Dt, _Ax);
905  }
void _Resetp(_Ux *_Px)
Definition: memory:1083
template<class _Ty>
template<class _Ux , class _Dx , class _Alloc >
shared_ptr< _Ty >::shared_ptr ( _Ux *  _Px,
_Dx  _Dt,
_Alloc  _Ax 
)
inline
911  { // construct with _Px, deleter, allocator
912  _Resetp(_Px, _Dt, _Ax);
913  }
void _Resetp(_Ux *_Px)
Definition: memory:1083
template<class _Ty>
template<class _Ty2 >
shared_ptr< _Ty >::shared_ptr ( const shared_ptr< _Ty2 > &  _Right,
_Ty *  _Px 
)
inline
917  { // construct shared_ptr object that aliases _Right
918  this->_Reset(_Px, _Right);
919  }
void _Reset()
Definition: memory:764
template<class _Ty>
shared_ptr< _Ty >::shared_ptr ( const _Myt _Other)
inline
922  { // construct shared_ptr object that owns same resource as _Other
923  this->_Reset(_Other);
924  }
void _Reset()
Definition: memory:764
template<class _Ty>
template<class _Ty2 , class = enable_if_t<is_convertible<_Ty2 *, _Ty *>::value>>
shared_ptr< _Ty >::shared_ptr ( const shared_ptr< _Ty2 > &  _Other)
inline
929  { // construct shared_ptr object that owns same resource as _Other
930  this->_Reset(_Other);
931  }
void _Reset()
Definition: memory:764
template<class _Ty>
template<class _Ty2 >
shared_ptr< _Ty >::shared_ptr ( const weak_ptr< _Ty2 > &  _Other)
inlineexplicit
935  { // construct shared_ptr object that owns resource *_Other
936  if (!this->_Reset_weak(_Other))
937  {
939  }
940  }
Definition: memory:458
#define _THROW_NCEE(x, y)
Definition: xstddef:51
#define _EMPTY_ARGUMENT
Definition: xstddef:77
bool _Reset_weak(const _Ptr_base< _Ty2 > &_Other)
Definition: memory:776
template<class _Ty>
shared_ptr< _Ty >::shared_ptr ( _No_bad_weak_ptr  ,
const weak_ptr< _Ty > &  _Other 
)
inline
943  { // construct shared_ptr object that owns resource *_Other, no throw
944  (void)this->_Reset_weak(_Other);
945  }
_CRT_BEGIN_C_HEADER typedef void(__CRTDECL *terminate_handler)()
bool _Reset_weak(const _Ptr_base< _Ty2 > &_Other)
Definition: memory:776
template<class _Ty>
shared_ptr< _Ty >::shared_ptr ( _Myt &&  _Right)
inline
956  : _Mybase(_STD move(_Right))
957  { // construct shared_ptr object that takes resource from _Right
958  }
_Ptr_base< _Ty > _Mybase
Definition: memory:867
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349
constexpr const _Ty &() _Right
Definition: algorithm:3723
template<class _Ty>
template<class _Ty2 , class = enable_if_t<is_convertible<_Ty2 *, _Ty *>::value>>
shared_ptr< _Ty >::shared_ptr ( shared_ptr< _Ty2 > &&  _Right)
inline
963  : _Mybase(_STD move(_Right))
964  { // construct shared_ptr object that takes resource from _Right
965  }
_Ptr_base< _Ty > _Mybase
Definition: memory:867
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349
template<class _Ty>
template<class _Ux , class _Dx , class = enable_if_t<is_convertible< typename unique_ptr<_Ux, _Dx>::pointer, _Ty *>::value>>
shared_ptr< _Ty >::shared_ptr ( unique_ptr< _Ux, _Dx > &&  _Right)
inline
973  { // construct from unique_ptr
974  _Resetp(_Right.release(), _Right.get_deleter());
975  }
void _Resetp(_Ux *_Px)
Definition: memory:1083
pointer release() _NOEXCEPT
Definition: memory:1842
_Dx & get_deleter() _NOEXCEPT
Definition: memory:1673
template<class _Ty>
shared_ptr< _Ty >::~shared_ptr ( )
inline
999  { // release resource
1000  this->_Decref();
1001  }
void _Decref()
Definition: memory:758

Member Function Documentation

template<class _Ty>
template<class _Ux >
void shared_ptr< _Ty >::_Resetp ( _Ux *  _Px)
inlineprivate
1084  { // release, take ownership of _Px
1085  _TRY_BEGIN // allocate control block and reset
1086  _Resetp0(_Px, new _Ref_count<_Ux>(_Px));
1087  _CATCH_ALL // allocation failed, delete resource
1088  delete _Px;
1089  _RERAISE;
1090  _CATCH_END
1091  }
#define _TRY_BEGIN
Definition: xstddef:26
#define _CATCH_END
Definition: xstddef:29
void _Resetp0(_Ux *_Px, _Ref_count_base *_Rx)
Definition: memory:1126
#define _CATCH_ALL
Definition: xstddef:28
Definition: memory:566
#define _RERAISE
Definition: xstddef:32
template<class _Ty>
template<class _Ux , class _Dx >
void shared_ptr< _Ty >::_Resetp ( _Ux *  _Px,
_Dx  _Dt 
)
inlineprivate
1096  { // release, take ownership of _Px, deleter _Dt
1097  _TRY_BEGIN // allocate control block and reset
1098  _Resetp0(_Px, new _Ref_count_del<_Ux, _Dx>(_Px, _Dt));
1099  _CATCH_ALL // allocation failed, delete resource
1100  _Dt(_Px);
1101  _RERAISE;
1102  _CATCH_END
1103  }
#define _TRY_BEGIN
Definition: xstddef:26
#define _CATCH_END
Definition: xstddef:29
Definition: memory:592
void _Resetp0(_Ux *_Px, _Ref_count_base *_Rx)
Definition: memory:1126
#define _CATCH_ALL
Definition: xstddef:28
#define _RERAISE
Definition: xstddef:32
template<class _Ty>
template<class _Ux , class _Dx , class _Alloc >
void shared_ptr< _Ty >::_Resetp ( _Ux *  _Px,
_Dx  _Dt,
_Alloc  _Ax 
)
inlineprivate
1109  { // release, take ownership of _Px, deleter _Dt, allocator _Ax
1111  typedef _Wrap_alloc<_Alloc> _Alref0;
1112  typename _Alref0::template rebind<_Refd>::other _Alref(_Ax);
1113 
1114  _TRY_BEGIN // allocate control block and reset
1115  _Refd *_Pref = _Unfancy(_Alref.allocate(1));
1116  _Alref.construct(_Pref, _Px, _Dt, _Ax);
1117  _Resetp0(_Px, _Pref);
1118  _CATCH_ALL // allocation failed, delete resource
1119  _Dt(_Px);
1120  _RERAISE;
1121  _CATCH_END
1122  }
#define _TRY_BEGIN
Definition: xstddef:26
#define _CATCH_END
Definition: xstddef:29
void _Resetp0(_Ux *_Px, _Ref_count_base *_Rx)
Definition: memory:1126
Definition: memory:625
#define _CATCH_ALL
Definition: xstddef:28
Definition: xmemory0:483
auto _Unfancy(_Ptrty _Ptr)
Definition: xstddef:635
#define _RERAISE
Definition: xstddef:32
template<class _Ty>
template<class _Ux >
void shared_ptr< _Ty >::_Resetp0 ( _Ux *  _Px,
_Ref_count_base _Rx 
)
inline
1127  { // release resource and take ownership of _Px
1128  this->_Reset0(_Px, _Rx);
1129  _Enable_shared(_Px, _Rx);
1130  }
void _Enable_shared(_Ty *_Ptr, _Ref_count_base *_Refptr, typename _Ty::_EStype *=0)
Definition: memory:675
void _Reset0(_Ty *_Other_ptr, _Ref_count_base *_Other_rep)
Definition: memory:817
template<class _Ty>
_Ty* shared_ptr< _Ty >::get ( ) const
inline
1057  { // return pointer to resource
1058  return (this->_Get());
1059  }
_Ty * _Get() const _NOEXCEPT
Definition: memory:748
template<class _Ty>
shared_ptr< _Ty >::operator bool ( ) const
inlineexplicit
1077  { // test if shared_ptr object owns no resource
1078  return (this->_Get() != 0);
1079  }
_Ty * _Get() const _NOEXCEPT
Definition: memory:748
template<class _Ty>
add_lvalue_reference<_Ty>::type shared_ptr< _Ty >::operator* ( ) const
inline
1062  { // return reference to resource
1063  return (*this->_Get());
1064  }
_Ty * _Get() const _NOEXCEPT
Definition: memory:748
template<class _Ty>
_Ty* shared_ptr< _Ty >::operator-> ( ) const
inline
1067  { // return pointer to resource
1068  return (this->_Get());
1069  }
_Ty * _Get() const _NOEXCEPT
Definition: memory:748
template<class _Ty>
template<class _Ux , class _Dx >
_Myt& shared_ptr< _Ty >::operator= ( unique_ptr< _Ux, _Dx > &&  _Right)
inline
980  { // move from unique_ptr
981  shared_ptr(_STD move(_Right)).swap(*this);
982  return (*this);
983  }
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
template<class _Ty>
_Myt& shared_ptr< _Ty >::operator= ( _Myt &&  _Right)
inline
986  { // take resource from _Right
987  shared_ptr(_STD move(_Right)).swap(*this);
988  return (*this);
989  }
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
constexpr const _Ty &() _Right
Definition: algorithm:3723
template<class _Ty>
template<class _Ty2 >
_Myt& shared_ptr< _Ty >::operator= ( shared_ptr< _Ty2 > &&  _Right)
inline
993  { // take resource from _Right
994  shared_ptr(_STD move(_Right)).swap(*this);
995  return (*this);
996  }
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
template<class _Ty>
_Myt& shared_ptr< _Ty >::operator= ( const _Myt _Right)
inline
1004  { // assign shared ownership of resource owned by _Right
1005  shared_ptr(_Right).swap(*this);
1006  return (*this);
1007  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
constexpr const _Ty &() _Right
Definition: algorithm:3723
template<class _Ty>
template<class _Ty2 >
_Myt& shared_ptr< _Ty >::operator= ( const shared_ptr< _Ty2 > &  _Right)
inline
1011  { // assign shared ownership of resource owned by _Right
1012  shared_ptr(_Right).swap(*this);
1013  return (*this);
1014  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
template<class _Ty>
void shared_ptr< _Ty >::reset ( )
inline
1026  { // release resource and convert to empty shared_ptr object
1027  shared_ptr().swap(*this);
1028  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
template<class _Ty>
template<class _Ux >
void shared_ptr< _Ty >::reset ( _Ux *  _Px)
inline
1032  { // release, take ownership of _Px
1033  shared_ptr(_Px).swap(*this);
1034  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
template<class _Ty>
template<class _Ux , class _Dx >
void shared_ptr< _Ty >::reset ( _Ux *  _Px,
_Dx  _Dt 
)
inline
1039  { // release, take ownership of _Px, with deleter _Dt
1040  shared_ptr(_Px, _Dt).swap(*this);
1041  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
template<class _Ty>
template<class _Ux , class _Dx , class _Alloc >
void shared_ptr< _Ty >::reset ( _Ux *  _Px,
_Dx  _Dt,
_Alloc  _Ax 
)
inline
1047  { // release, take ownership of _Px, with deleter _Dt, allocator _Ax
1048  shared_ptr(_Px, _Dt, _Ax).swap(*this);
1049  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:873
template<class _Ty>
void shared_ptr< _Ty >::swap ( _Myt _Other)
inline
1052  { // swap pointers
1053  this->_Swap(_Other);
1054  }
void _Swap(_Ptr_base &_Right) _NOEXCEPT
Definition: memory:731
template<class _Ty>
bool shared_ptr< _Ty >::unique ( ) const
inline
1072  { // return true if no other shared_ptr object owns this resource
1073  return (this->use_count() == 1);
1074  }
long use_count() const _NOEXCEPT
Definition: memory:726

The documentation for this class was generated from the following file: