Quick Links: |
#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 () | |
enable_shared_from_this & | operator= (const enable_shared_from_this &rhs) BSLS_KEYWORD_NOEXCEPT |
Friends | |
struct | BloombergLP::bslstl::SharedPtr_ImpUtil |
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 Component bslstl_sharedptr
bsl::enable_shared_from_this< ELEMENT_TYPE >::enable_shared_from_this | ( | ) | [protected] |
Create an enable_shared_from_this
object that is not owned by any shared_ptr
object.
bsl::enable_shared_from_this< ELEMENT_TYPE >::enable_shared_from_this | ( | const enable_shared_from_this< ELEMENT_TYPE > & | unused | ) | [protected] |
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.
bsl::enable_shared_from_this< ELEMENT_TYPE >::~enable_shared_from_this | ( | ) | [protected] |
Destroy this enable_shared_form_this
.
enable_shared_from_this& bsl::enable_shared_from_this< ELEMENT_TYPE >::operator= | ( | const enable_shared_from_this< ELEMENT_TYPE > & | rhs | ) | [protected] |
Return *this
. This object is unchanged. Note that the specified rhs
is not used.
bsl::shared_ptr<ELEMENT_TYPE> bsl::enable_shared_from_this< ELEMENT_TYPE >::shared_from_this | ( | ) |
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_ptr
s are managing this object, the returned shared_ptr
will share ownership with the group that first managed this object.
bsl::weak_ptr<ELEMENT_TYPE> bsl::enable_shared_from_this< ELEMENT_TYPE >::weak_from_this | ( | ) |
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_ptr
s are managing this object, the returned weak_ptr
will hold a weak reference to the group that first managed this object.
bsl::shared_ptr<const ELEMENT_TYPE> bsl::enable_shared_from_this< ELEMENT_TYPE >::shared_from_this | ( | ) | const |
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_ptr
s are managing this object, the returned shared_ptr
will share ownership with the group that first managed this object.
bsl::weak_ptr<const ELEMENT_TYPE> bsl::enable_shared_from_this< ELEMENT_TYPE >::weak_from_this | ( | ) | const |
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_ptr
s are managing this object, the returned weak_ptr
will hold a weak reference to the group that first managed this object.
friend struct BloombergLP::bslstl::SharedPtr_ImpUtil [friend] |