Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Memory & storage
  5. pw_allocator
  6. Core interfaces
  7. pw::EnableSharedFromThis< T > Class Template Reference
Loading...
Searching...
No Matches
pw::EnableSharedFromThis< T > Class Template Reference

Overview

template<typename T>
class pw::EnableSharedFromThis< T >

Allows an object managed by a pw::SharedPtr to safely generate additional pw::SharedPtr or pw::WeakPtr instances to itself.

Inheriting from EnableSharedFromThis<T> provides shared_from_this() and weak_from_this(), mirroring std::enable_shared_from_this.

Preconditions and Limitations

Template Parameters
TThe derived class type (CRTP pattern).

Public Member Functions

SharedPtr< T > shared_from_this ()
 
SharedPtr< const T > shared_from_this () const
 
WeakPtr< T > weak_from_this () noexcept
 
WeakPtr< const T > weak_from_this () const noexcept
 

Protected Member Functions

constexpr EnableSharedFromThis (const EnableSharedFromThis &) noexcept
 
constexpr EnableSharedFromThis (EnableSharedFromThis &&) noexcept
 
constexpr EnableSharedFromThis & operator= (const EnableSharedFromThis &) noexcept
 
constexpr EnableSharedFromThis & operator= (EnableSharedFromThis &&) noexcept
 

Friends

template<typename , typename >
struct allocator::internal::HasInitializeWeakThis
 
template<typename U >
void allocator::internal::EnableWeakThis (allocator::internal::ControlBlock *, U *)
 

Member Function Documentation

◆ shared_from_this() [1/2]

template<typename T >
SharedPtr< T > pw::EnableSharedFromThis< T >::shared_from_this ( )
inline

Returns a SharedPtr<T> that shares ownership of this.

Asserts that this is managed by an existing SharedPtr.

◆ shared_from_this() [2/2]

template<typename T >
SharedPtr< const T > pw::EnableSharedFromThis< T >::shared_from_this ( ) const
inline

Returns a SharedPtr<const T> that shares ownership of this.

Asserts that this is managed by an existing SharedPtr.

◆ weak_from_this() [1/2]

template<typename T >
WeakPtr< const T > pw::EnableSharedFromThis< T >::weak_from_this ( ) const
inlinenoexcept

Returns a WeakPtr<const T> tracking this.

Returns an empty WeakPtr<const T> if this is not managed by a SharedPtr.

◆ weak_from_this() [2/2]

template<typename T >
WeakPtr< T > pw::EnableSharedFromThis< T >::weak_from_this ( )
inlinenoexcept

Returns a WeakPtr<T> tracking this.

Returns an empty WeakPtr<T> if this is not managed by a SharedPtr.


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