BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsl::enable_shared_from_this< ELEMENT_TYPE > Class Template Reference

#include <bslstl_sharedptr.h>

Public Member Functions

bsl::shared_ptr< ELEMENT_TYPE > shared_from_this ()
 
bsl::weak_ptr< ELEMENT_TYPE > weak_from_this () BSLS_KEYWORD_NOEXCEPT
 
bsl::shared_ptr< const ELEMENT_TYPE > shared_from_this () const
 
bsl::weak_ptr< const ELEMENT_TYPE > weak_from_this () const BSLS_KEYWORD_NOEXCEPT
 

Protected Member Functions

 enable_shared_from_this () BSLS_KEYWORD_NOEXCEPT
 
 enable_shared_from_this (const enable_shared_from_this &unused) BSLS_KEYWORD_NOEXCEPT
 
 ~enable_shared_from_this ()
 Destroy this enable_shared_form_this.
 
enable_shared_from_thisoperator= (const enable_shared_from_this &rhs) BSLS_KEYWORD_NOEXCEPT
 

Friends

struct BloombergLP::bslstl::SharedPtr_ImpUtil
 

Detailed Description

template<class ELEMENT_TYPE>
class bsl::enable_shared_from_this< ELEMENT_TYPE >

This class allows an object that is currently managed by a shared_ptr to safely generate a copy of the managing shared_ptr object. Inheriting from enable_shared_from_this<ELEMENT_TYPE> provides the (template parameter) ELEMENT_TYPE type with a member function shared_from_this. If an object of type ELEMENT_TYPE is managed by a shared_ptr then calling shared_from_this will return a shared_ptr<ELEMENT_TYPE> that shares ownership of that object. It is undefined behavior to call shared_from_this on an object unless that object is managed by a shared_ptr.

The intended use of enable_shared_from_this is that the (template parameter) type ELEMENT_TYPE inherits directly from the enable_shared_from_this class template. In the case of multiple inheritance, only one of the base classes should inherit from the enable_shared_from_this class template. If multiple base classes inherit from enable_shared_from_this, then there will be ambiguous calls to the shared_from_this function.

See bslstl_sharedptr

Constructor & Destructor Documentation

◆ enable_shared_from_this() [1/2]

template<class ELEMENT_TYPE >
bsl::enable_shared_from_this< ELEMENT_TYPE >::enable_shared_from_this ( )
inlineprotected

Create an enable_shared_from_this object that is not owned by any shared_ptr object.

◆ enable_shared_from_this() [2/2]

template<class ELEMENT_TYPE >
bsl::enable_shared_from_this< ELEMENT_TYPE >::enable_shared_from_this ( const enable_shared_from_this< ELEMENT_TYPE > &  unused)
inlineprotected

Create an enable_shared_from_this object that is not owned by any shared_ptr object. Note that the specified unused argument is not used by this constructor.

◆ ~enable_shared_from_this()

template<class ELEMENT_TYPE >
bsl::enable_shared_from_this< ELEMENT_TYPE >::~enable_shared_from_this ( )
inlineprotected

Member Function Documentation

◆ operator=()

template<class ELEMENT_TYPE >
enable_shared_from_this< ELEMENT_TYPE > & bsl::enable_shared_from_this< ELEMENT_TYPE >::operator= ( const enable_shared_from_this< ELEMENT_TYPE > &  rhs)
inlineprotected

Return *this. This object is unchanged. Note that the specified rhs is not used.

◆ shared_from_this() [1/2]

template<class ELEMENT_TYPE >
shared_ptr< ELEMENT_TYPE > bsl::enable_shared_from_this< ELEMENT_TYPE >::shared_from_this ( )
inline

Return a shared_ptr<ELEMENT_TYPE> that shares ownership with an existing shared_ptr object that managed this object, and throw a std::bad_weak_ptr exception if there is no shared_ptr currently managing this object. If multiple groups of shared_ptrs are managing this object, the returned shared_ptr will share ownership with the group that first managed this object.

◆ shared_from_this() [2/2]

template<class ELEMENT_TYPE >
shared_ptr< const ELEMENT_TYPE > bsl::enable_shared_from_this< ELEMENT_TYPE >::shared_from_this ( ) const
inline

Return a shared_ptr<const ELEMENT_TYPE> that shares ownership with an existing shared_ptr object that managed this object, and throw a std::bad_weak_ptr exception if there is no shared_ptr currently managing this object. If multiple groups of shared_ptrs are managing this object, the returned shared_ptr will share ownership with the group that first managed this object.

◆ weak_from_this() [1/2]

template<class ELEMENT_TYPE >
weak_ptr< ELEMENT_TYPE > bsl::enable_shared_from_this< ELEMENT_TYPE >::weak_from_this ( )
inline

Return a weak_ptr holding a weak reference to this managed object if this object is currently managed by shared_ptr, and return an expired weak_ptr otherwise. If multiple groups of shared_ptrs are managing this object, the returned weak_ptr will hold a weak reference to the group that first managed this object.

◆ weak_from_this() [2/2]

template<class ELEMENT_TYPE >
weak_ptr< const ELEMENT_TYPE > bsl::enable_shared_from_this< ELEMENT_TYPE >::weak_from_this ( ) const
inline

Return a weak_ptr holding a weak reference (with only const access) to this managed object if this object is currently managed by shared_ptr, and return an expired weak_ptr otherwise. If multiple groups of shared_ptrs are managing this object, the returned weak_ptr will hold a weak reference to the group that first managed this object.

Friends And Related Symbol Documentation

◆ BloombergLP::bslstl::SharedPtr_ImpUtil

template<class ELEMENT_TYPE >
friend struct BloombergLP::bslstl::SharedPtr_ImpUtil
friend

Allows shared_ptr to initialize d_weakThis when it detects an enable_shared_from_this base class.


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