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 = typename enable_if<is_convertible<_Ty2 *, _Ty *>::value, void>::type>
 shared_ptr (const shared_ptr< _Ty2 > &_Other) _NOEXCEPT
 
template<class _Ty2 >
 shared_ptr (const weak_ptr< _Ty2 > &_Other, bool _Throw=true)
 
 shared_ptr (_Myt &&_Right) _NOEXCEPT
 
template<class _Ty2 , class = typename enable_if<is_convertible<_Ty2 *, _Ty *>::value, void>::type>
 shared_ptr (shared_ptr< _Ty2 > &&_Right) _NOEXCEPT
 
template<class _Ux , class _Dx , class = typename enable_if<is_convertible< typename unique_ptr<_Ux, _Dx>::pointer, _Ty *>::value, void>::type>
 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 _XSTD2 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 >
void _Reset (const _Ptr_base< _Ty2 > &_Other, bool _Throw)
 
template<class _Ty2 >
void _Reset (_Ty *_Other_ptr, const _Ptr_base< _Ty2 > &_Other)
 
void _Reset (_Ty *_Other_ptr, _Ref_count_base *_Other_rep)
 
void _Reset (_Ty *_Other_ptr, _Ref_count_base *_Other_rep, bool _Throw)
 
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
445  { // construct empty shared_ptr
446  }
template<class _Ty>
template<class _Ux >
shared_ptr< _Ty >::shared_ptr ( _Ux *  _Px)
inlineexplicit
450  { // construct shared_ptr object that owns _Px
451  _Resetp(_Px);
452  }
void _Resetp(_Ux *_Px)
Definition: memory:650
template<class _Ty>
template<class _Ux , class _Dx >
shared_ptr< _Ty >::shared_ptr ( _Ux *  _Px,
_Dx  _Dt 
)
inline
457  { // construct with _Px, deleter
458  _Resetp(_Px, _Dt);
459  }
void _Resetp(_Ux *_Px)
Definition: memory:650
template<class _Ty>
constexpr shared_ptr< _Ty >::shared_ptr ( nullptr_t  )
inline
462  { // construct empty shared_ptr
463  }
template<class _Ty>
template<class _Dx >
shared_ptr< _Ty >::shared_ptr ( nullptr_t  ,
_Dx  _Dt 
)
inline
467  { // construct with nullptr, deleter
468  _Resetp((_Ty *)0, _Dt);
469  }
void _Resetp(_Ux *_Px)
Definition: memory:650
template<class _Ty>
template<class _Dx , class _Alloc >
shared_ptr< _Ty >::shared_ptr ( nullptr_t  ,
_Dx  _Dt,
_Alloc  _Ax 
)
inline
474  { // construct with nullptr, deleter, allocator
475  _Resetp((_Ty *)0, _Dt, _Ax);
476  }
void _Resetp(_Ux *_Px)
Definition: memory:650
template<class _Ty>
template<class _Ux , class _Dx , class _Alloc >
shared_ptr< _Ty >::shared_ptr ( _Ux *  _Px,
_Dx  _Dt,
_Alloc  _Ax 
)
inline
482  { // construct with _Px, deleter, allocator
483  _Resetp(_Px, _Dt, _Ax);
484  }
void _Resetp(_Ux *_Px)
Definition: memory:650
template<class _Ty>
template<class _Ty2 >
shared_ptr< _Ty >::shared_ptr ( const shared_ptr< _Ty2 > &  _Right,
_Ty *  _Px 
)
inline
488  { // construct shared_ptr object that aliases _Right
489  this->_Reset(_Px, _Right);
490  }
void _Reset()
Definition: memory:341
template<class _Ty>
shared_ptr< _Ty >::shared_ptr ( const _Myt _Other)
inline
493  { // construct shared_ptr object that owns same resource as _Other
494  this->_Reset(_Other);
495  }
void _Reset()
Definition: memory:341
template<class _Ty>
template<class _Ty2 , class = typename enable_if<is_convertible<_Ty2 *, _Ty *>::value, void>::type>
shared_ptr< _Ty >::shared_ptr ( const shared_ptr< _Ty2 > &  _Other)
inline
501  { // construct shared_ptr object that owns same resource as _Other
502  this->_Reset(_Other);
503  }
void _Reset()
Definition: memory:341
template<class _Ty>
template<class _Ty2 >
shared_ptr< _Ty >::shared_ptr ( const weak_ptr< _Ty2 > &  _Other,
bool  _Throw = true 
)
inlineexplicit
508  { // construct shared_ptr object that owns resource *_Other
509  this->_Reset(_Other, _Throw);
510  }
void _Reset()
Definition: memory:341
template<class _Ty>
shared_ptr< _Ty >::shared_ptr ( _Myt &&  _Right)
inline
521  : _Mybase(_STD move(_Right))
522  { // construct shared_ptr object that takes resource from _Right
523  }
_Ptr_base< _Ty > _Mybase
Definition: memory:442
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
constexpr const _Ty &() _Right
Definition: algorithm:3591
template<class _Ty>
template<class _Ty2 , class = typename enable_if<is_convertible<_Ty2 *, _Ty *>::value, void>::type>
shared_ptr< _Ty >::shared_ptr ( shared_ptr< _Ty2 > &&  _Right)
inline
529  : _Mybase(_STD move(_Right))
530  { // construct shared_ptr object that takes resource from _Right
531  }
_Ptr_base< _Ty > _Mybase
Definition: memory:442
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
template<class _Ty>
template<class _Ux , class _Dx , class = typename enable_if<is_convertible< typename unique_ptr<_Ux, _Dx>::pointer, _Ty *>::value, void>::type>
shared_ptr< _Ty >::shared_ptr ( unique_ptr< _Ux, _Dx > &&  _Right)
inline
540  { // construct from unique_ptr
541  _Resetp(_Right.release(), _Right.get_deleter());
542  }
void _Resetp(_Ux *_Px)
Definition: memory:650
pointer release() _NOEXCEPT
Definition: memory:1420
_Dx & get_deleter() _NOEXCEPT
Definition: memory:1251
template<class _Ty>
shared_ptr< _Ty >::~shared_ptr ( )
inline
566  { // release resource
567  this->_Decref();
568  }
void _Decref()
Definition: memory:335

Member Function Documentation

template<class _Ty>
template<class _Ux >
void shared_ptr< _Ty >::_Resetp ( _Ux *  _Px)
inlineprivate
651  { // release, take ownership of _Px
652  _TRY_BEGIN // allocate control block and reset
653  _Resetp0(_Px, new _Ref_count<_Ux>(_Px));
654  _CATCH_ALL // allocation failed, delete resource
655  delete _Px;
656  _RERAISE;
657  _CATCH_END
658  }
#define _TRY_BEGIN
Definition: xstddef:60
#define _CATCH_END
Definition: xstddef:63
void _Resetp0(_Ux *_Px, _Ref_count_base *_Rx)
Definition: memory:693
#define _CATCH_ALL
Definition: xstddef:62
Definition: memory:141
#define _RERAISE
Definition: xstddef:74
template<class _Ty>
template<class _Ux , class _Dx >
void shared_ptr< _Ty >::_Resetp ( _Ux *  _Px,
_Dx  _Dt 
)
inlineprivate
663  { // release, take ownership of _Px, deleter _Dt
664  _TRY_BEGIN // allocate control block and reset
665  _Resetp0(_Px, new _Ref_count_del<_Ux, _Dx>(_Px, _Dt));
666  _CATCH_ALL // allocation failed, delete resource
667  _Dt(_Px);
668  _RERAISE;
669  _CATCH_END
670  }
#define _TRY_BEGIN
Definition: xstddef:60
#define _CATCH_END
Definition: xstddef:63
Definition: memory:167
void _Resetp0(_Ux *_Px, _Ref_count_base *_Rx)
Definition: memory:693
#define _CATCH_ALL
Definition: xstddef:62
#define _RERAISE
Definition: xstddef:74
template<class _Ty>
template<class _Ux , class _Dx , class _Alloc >
void shared_ptr< _Ty >::_Resetp ( _Ux *  _Px,
_Dx  _Dt,
_Alloc  _Ax 
)
inlineprivate
676  { // release, take ownership of _Px, deleter _Dt, allocator _Ax
678  typedef _Wrap_alloc<_Alloc> _Alref0;
679  typename _Alref0::template rebind<_Refd>::other _Alref(_Ax);
680 
681  _TRY_BEGIN // allocate control block and reset
682  _Refd *_Pref = _Alref.allocate(1);
683  _Alref.construct(_Pref, _Px, _Dt, _Ax);
684  _Resetp0(_Px, _Pref);
685  _CATCH_ALL // allocation failed, delete resource
686  _Dt(_Px);
687  _RERAISE;
688  _CATCH_END
689  }
#define _TRY_BEGIN
Definition: xstddef:60
#define _CATCH_END
Definition: xstddef:63
void _Resetp0(_Ux *_Px, _Ref_count_base *_Rx)
Definition: memory:693
Definition: memory:201
#define _CATCH_ALL
Definition: xstddef:62
Definition: xmemory0:380
#define _RERAISE
Definition: xstddef:74
template<class _Ty>
template<class _Ux >
void shared_ptr< _Ty >::_Resetp0 ( _Ux *  _Px,
_Ref_count_base _Rx 
)
inline
694  { // release resource and take ownership of _Px
695  this->_Reset0(_Px, _Rx);
696  _Enable_shared(_Px, _Rx);
697  }
void _Enable_shared(_Ty *_Ptr, _Ref_count_base *_Refptr, typename _Ty::_EStype *=0)
Definition: memory:252
void _Reset0(_Ty *_Other_ptr, _Ref_count_base *_Other_rep)
Definition: memory:392
template<class _Ty>
_Ty* shared_ptr< _Ty >::get ( ) const
inline
624  { // return pointer to resource
625  return (this->_Get());
626  }
_Ty * _Get() const _NOEXCEPT
Definition: memory:325
template<class _Ty>
shared_ptr< _Ty >::operator bool ( ) const
inlineexplicit
644  { // test if shared_ptr object owns no resource
645  return (this->_Get() != 0);
646  }
_Ty * _Get() const _NOEXCEPT
Definition: memory:325
template<class _Ty>
add_lvalue_reference<_Ty>::type shared_ptr< _Ty >::operator* ( ) const
inline
629  { // return reference to resource
630  return (*this->_Get());
631  }
_Ty * _Get() const _NOEXCEPT
Definition: memory:325
template<class _Ty>
_Ty* shared_ptr< _Ty >::operator-> ( ) const
inline
634  { // return pointer to resource
635  return (this->_Get());
636  }
_Ty * _Get() const _NOEXCEPT
Definition: memory:325
template<class _Ty>
template<class _Ux , class _Dx >
_Myt& shared_ptr< _Ty >::operator= ( unique_ptr< _Ux, _Dx > &&  _Right)
inline
547  { // move from unique_ptr
548  shared_ptr(_STD move(_Right)).swap(*this);
549  return (*this);
550  }
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
template<class _Ty>
_Myt& shared_ptr< _Ty >::operator= ( _Myt &&  _Right)
inline
553  { // take resource from _Right
554  shared_ptr(_STD move(_Right)).swap(*this);
555  return (*this);
556  }
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
constexpr const _Ty &() _Right
Definition: algorithm:3591
template<class _Ty>
template<class _Ty2 >
_Myt& shared_ptr< _Ty >::operator= ( shared_ptr< _Ty2 > &&  _Right)
inline
560  { // take resource from _Right
561  shared_ptr(_STD move(_Right)).swap(*this);
562  return (*this);
563  }
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
template<class _Ty>
_Myt& shared_ptr< _Ty >::operator= ( const _Myt _Right)
inline
571  { // assign shared ownership of resource owned by _Right
572  shared_ptr(_Right).swap(*this);
573  return (*this);
574  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
constexpr const _Ty &() _Right
Definition: algorithm:3591
template<class _Ty>
template<class _Ty2 >
_Myt& shared_ptr< _Ty >::operator= ( const shared_ptr< _Ty2 > &  _Right)
inline
578  { // assign shared ownership of resource owned by _Right
579  shared_ptr(_Right).swap(*this);
580  return (*this);
581  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
template<class _Ty>
void shared_ptr< _Ty >::reset ( )
inline
593  { // release resource and convert to empty shared_ptr object
594  shared_ptr().swap(*this);
595  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
template<class _Ty>
template<class _Ux >
void shared_ptr< _Ty >::reset ( _Ux *  _Px)
inline
599  { // release, take ownership of _Px
600  shared_ptr(_Px).swap(*this);
601  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
template<class _Ty>
template<class _Ux , class _Dx >
void shared_ptr< _Ty >::reset ( _Ux *  _Px,
_Dx  _Dt 
)
inline
606  { // release, take ownership of _Px, with deleter _Dt
607  shared_ptr(_Px, _Dt).swap(*this);
608  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
template<class _Ty>
template<class _Ux , class _Dx , class _Alloc >
void shared_ptr< _Ty >::reset ( _Ux *  _Px,
_Dx  _Dt,
_Alloc  _Ax 
)
inline
614  { // release, take ownership of _Px, with deleter _Dt, allocator _Ax
615  shared_ptr(_Px, _Dt, _Ax).swap(*this);
616  }
constexpr shared_ptr() _NOEXCEPT
Definition: memory:444
template<class _Ty>
void shared_ptr< _Ty >::swap ( _Myt _Other)
inline
619  { // swap pointers
620  this->_Swap(_Other);
621  }
void _Swap(_Ptr_base &_Right) _NOEXCEPT
Definition: memory:308
template<class _Ty>
bool shared_ptr< _Ty >::unique ( ) const
inline
639  { // return true if no other shared_ptr object owns this resource
640  return (this->use_count() == 1);
641  }
long use_count() const _NOEXCEPT
Definition: memory:303

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