StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::Weak< T > Class Template Reference

Forward declaration of weak ownership. More...

#include <StormByte/safe/pointers.hxx>

Public Types

using element_type = T
 Pointee type.

Public Member Functions

 Weak () noexcept
 Construct an empty observer.
 Weak (std::nullptr_t null) noexcept
 Construct an empty observer from null.
template<class U>
requires Type::ConvertibleTo<U*, T*>
 Weak (const Shared< U > &owner) noexcept
 Observe an owner.
 Weak (const Weak &other) noexcept
 Copy an observer.
 Weak (Weak &&other) noexcept
 Take an observer.
Weak & operator= (const Weak &other) noexcept
 Copy an observer.
Weak & operator= (Weak &&other) noexcept
 Take an observer.
 ~Weak ()
 Drop this observer.
Shared< T > lock () const noexcept
 Lock the control block.
bool expired () const noexcept
 Test whether the object is already gone.
long use_count () const noexcept
 Return the number of owners.
void reset () noexcept
 Drop this observer.
void swap (Weak &other) noexcept
 Exchange observers.
template<class U>
bool owner_before (const Weak< U > &other) const noexcept
 Order control blocks by identity.
template<class U>
bool owner_before (const Shared< U > &other) const noexcept
 Order this control block against an owner.

Friends

template<class U>
class Weak
template<class U>
class Shared
template<class U>
class EnableSharedFromThis

Detailed Description

template<class T>
class StormByte::Safe::Weak< T >

Forward declaration of weak ownership.

Non-owning observer of a Shared control block.

Template Parameters
TPointee.
TPointee type. void is allowed.

Construct it only from a Shared. lock returns a Shared, or an empty owner when the object is gone.

Member Typedef Documentation

◆ element_type

template<class T>
using StormByte::Safe::Weak< T >::element_type = T

Pointee type.

Constructor & Destructor Documentation

◆ Weak() [1/5]

template<class T>
StormByte::Safe::Weak< T >::Weak ( )
noexcept

Construct an empty observer.

◆ Weak() [2/5]

template<class T>
StormByte::Safe::Weak< T >::Weak ( std::nullptr_t null)
noexcept

Construct an empty observer from null.

Parameters
nullNull pointer constant.

◆ Weak() [3/5]

template<class T>
template<class U>
requires Type::ConvertibleTo<U*, T*>
StormByte::Safe::Weak< T >::Weak ( const Shared< U > & owner)
noexcept

Observe an owner.

Template Parameters
USource pointee. U* must convert to T*.
Parameters
ownerOwner to watch.

◆ Weak() [4/5]

template<class T>
StormByte::Safe::Weak< T >::Weak ( const Weak< T > & other)
noexcept

Copy an observer.

Parameters
otherObserver to copy.

◆ Weak() [5/5]

template<class T>
StormByte::Safe::Weak< T >::Weak ( Weak< T > && other)
noexcept

Take an observer.

other is left empty.

Parameters
otherObserver to take.

◆ ~Weak()

template<class T>
StormByte::Safe::Weak< T >::~Weak ( )

Drop this observer.

The last observer frees an expired block.

Member Function Documentation

◆ expired()

template<class T>
bool StormByte::Safe::Weak< T >::expired ( ) const
noexcept

Test whether the object is already gone.

Returns
Whether lock would return empty.

◆ lock()

template<class T>
Shared< T > StormByte::Safe::Weak< T >::lock ( ) const
noexcept

Lock the control block.

Returns
Owner of the object, or empty when expired.

◆ operator=() [1/2]

template<class T>
Weak & StormByte::Safe::Weak< T >::operator= ( const Weak< T > & other)
noexcept

Copy an observer.

Parameters
otherObserver to copy.
Returns
This observer.

◆ operator=() [2/2]

template<class T>
Weak & StormByte::Safe::Weak< T >::operator= ( Weak< T > && other)
noexcept

Take an observer.

other is left empty.

Parameters
otherObserver to take.
Returns
This observer.

◆ owner_before() [1/2]

template<class T>
template<class U>
bool StormByte::Safe::Weak< T >::owner_before ( const Shared< U > & other) const
noexcept

Order this control block against an owner.

Template Parameters
UOther pointee.
Parameters
otherOwner.
Returns
Whether this control block precedes other.

◆ owner_before() [2/2]

template<class T>
template<class U>
bool StormByte::Safe::Weak< T >::owner_before ( const Weak< U > & other) const
noexcept

Order control blocks by identity.

Template Parameters
UOther pointee.
Parameters
otherOther observer.
Returns
Whether this control block precedes other.

◆ reset()

template<class T>
void StormByte::Safe::Weak< T >::reset ( )
noexcept

Drop this observer.

◆ swap()

template<class T>
void StormByte::Safe::Weak< T >::swap ( Weak< T > & other)
noexcept

Exchange observers.

Parameters
otherObserver to exchange with.

◆ use_count()

template<class T>
long StormByte::Safe::Weak< T >::use_count ( ) const
noexcept

Return the number of owners.

Returns
Strong count, or zero when expired.

◆ EnableSharedFromThis

template<class T>
template<class U>
friend class EnableSharedFromThis
friend

◆ Shared

template<class T>
template<class U>
friend class Shared
friend

◆ Weak

template<class T>
template<class U>
friend class Weak
friend

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