Pigweed
 
Loading...
Searching...
No Matches
pw::WeakPtr< T > Class Template Reference

#include <weak_ptr.h>

Inheritance diagram for pw::WeakPtr< T >:

Public Types

using element_type = typename Base::element_type
 

Public Member Functions

constexpr WeakPtr () noexcept=default
 Creates an empty (nullptr) instance.
 
constexpr WeakPtr (std::nullptr_t) noexcept
 Creates an empty (nullptr) instance.
 
 WeakPtr (const WeakPtr &other) noexcept
 Copy-constructs a WeakPtr<T> from a WeakPtr<T>.
 
template<typename U >
 WeakPtr (const WeakPtr< U > &other) noexcept
 
template<typename U >
 WeakPtr (const SharedPtr< U > &other) noexcept
 
template<typename U >
 WeakPtr (WeakPtr< U > &&other) noexcept
 
constexpr WeakPtroperator= (const WeakPtr &other) noexcept
 Copy-assigns a WeakPtr<T> from a WeakPtr<T>.
 
template<typename U >
WeakPtroperator= (const WeakPtr< U > &other) noexcept
 
template<typename U >
WeakPtroperator= (const SharedPtr< U > &other) noexcept
 
template<typename U >
WeakPtroperator= (WeakPtr< U > &&other) noexcept
 
void reset () noexcept
 
void swap (WeakPtr &other) noexcept
 Swaps the managed pointer and deallocator of this and another object.
 
uint32_t use_count () const noexcept
 
bool expired () const noexcept
 
SharedPtr< T > Lock () const noexcept
 
template<typename PtrType >
bool owner_before (const PtrType &other) const noexcept
 
template<typename U >
WeakPtr< T > & operator= (const WeakPtr< U > &other) noexcept
 
template<typename U >
WeakPtr< T > & operator= (const SharedPtr< U > &other) noexcept
 
template<typename U >
WeakPtr< T > & operator= (WeakPtr< U > &&other) noexcept
 

Detailed Description

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

A std::weak_ptr<T>-like type that integrates with pw::SharedPtr.

Template Parameters
TThe type being pointed to. This may be an array type, e.g. pw::WeakPtr<T[]>.

Constructor & Destructor Documentation

◆ WeakPtr() [1/3]

template<typename T >
template<typename U >
pw::WeakPtr< T >::WeakPtr ( const WeakPtr< U > &  other)
inlinenoexcept

Copy-constructs a WeakPtr<T> from a WeakPtr<U>.

This allows not only pure move construction where T == U, but also converting construction where T is a base class of U.

◆ WeakPtr() [2/3]

template<typename T >
template<typename U >
pw::WeakPtr< T >::WeakPtr ( const SharedPtr< U > &  other)
inlinenoexcept

Copy-constructs a WeakPtr<T> from a SharedPtr<U>.

This allows not only pure move construction where T == U, but also converting construction where T is a base class of U.

◆ WeakPtr() [3/3]

template<typename T >
template<typename U >
pw::WeakPtr< T >::WeakPtr ( WeakPtr< U > &&  other)
inlinenoexcept

Move-constructs a SharedPtr<T> from a SharedPtr<U>.

This allows not only pure move construction where T == U, but also converting construction where T is a base class of U, like SharedPtr<Base> base(deallocator.MakeShared<Child>());.

Member Function Documentation

◆ expired()

template<typename T >
bool pw::WeakPtr< T >::expired ( ) const
inlinenoexcept

Returns true if the associated object has been destroyed; otherwise returns false.

◆ Lock()

template<typename T >
SharedPtr< T > pw::WeakPtr< T >::Lock
noexcept

Creates a new SharedPtr to the associated object, or an empty SharedPtr if this object is empty.

◆ operator=() [1/3]

template<typename T >
template<typename U >
WeakPtr & pw::WeakPtr< T >::operator= ( const SharedPtr< U > &  other)
noexcept

Copy-assigns a WeakPtr<T> from a SharedPtr<U>.

This allows not only pure move construction where T == U, but also converting construction where T is a base class of U.

◆ operator=() [2/3]

template<typename T >
template<typename U >
WeakPtr & pw::WeakPtr< T >::operator= ( const WeakPtr< U > &  other)
noexcept

Copy-assigns a SharedPtr<T> from a SharedPtr<U>.

This allows not only pure copy assignment where T == U, but also converting assignment where T is a base class of U.

◆ operator=() [3/3]

template<typename T >
template<typename U >
WeakPtr & pw::WeakPtr< T >::operator= ( WeakPtr< U > &&  other)
noexcept

Move-assigns a WeakPtr<T> from a SharedPtr<U>.

This allows not only pure move construction where T == U, but also converting construction where T is a base class of U.

◆ owner_before()

template<typename T >
template<typename PtrType >
bool pw::WeakPtr< T >::owner_before ( const PtrType &  other) const
inlinenoexcept

Checks whether this precedes other based on an ordering of their control blocks.

◆ reset()

template<typename T >
void pw::WeakPtr< T >::reset
noexcept

Resets this object to an empty state.

If this is the last shared or weak pointer associated with the control block, it is deallocated.

◆ use_count()

template<typename T >
uint32_t pw::WeakPtr< T >::use_count ( ) const
inlinenoexcept

Returns the number of shared pointers to the associated object, or 0 if this object is empty.


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