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

Forward declaration of unique ownership. More...

#include <StormByte/safe/pointers.hxx>

Public Types

using element_type = T
 Pointee type.
using pointer = T*
 Stored pointer.
using deleter_type = Heap::ObjectDeleter
 Deleter used by the STL conversion.

Public Member Functions

 Unique () noexcept
 Construct an empty owner.
 Unique (std::nullptr_t null) noexcept
 Construct an empty owner from null.
template<class U>
requires Type::ConvertibleTo<U*, T*>
 Unique (Unique< U > &&other) noexcept
 Take ownership from another owner.
 Unique (const Unique &other)=delete
 Copy constructor.
 Unique (Unique &&other) noexcept
 Take ownership.
Unique & operator= (const Unique &other)=delete
 Copy assignment.
Unique & operator= (Unique &&other) noexcept
 Take ownership.
 ~Unique ()
 Destroy the object through its concrete destructor and free the block.
T * get () const noexcept
 Return the stored pointer.
std::add_lvalue_reference_t< T > operator* () const noexcept
 Dereference the stored pointer.
T * operator-> () const noexcept
 Access a member of the pointee.
 operator bool () const noexcept
 Test whether this owner holds an object.
void reset () noexcept
 Destroy the object and leave this owner empty.
void swap (Unique &other) noexcept
 Exchange owners.
STORMBYTE_FORCE_INLINE operator std::unique_ptr< T, Heap::ObjectDeleter > () &&noexcept
 Move the owner into caller-owned STL storage.

Static Public Member Functions

template<class Target, class... Args>
requires Type::SameAs<Target, T> || Type::DerivedFrom<Target, T>
static Unique< T > MakePointer (Args &&... args)
 Allocate Target on Base's heap and own it as T.

Friends

template<class U>
class Unique
template<class U, class... Args>
Unique< U > MakeUnique (Args &&...)

Detailed Description

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

Forward declaration of unique ownership.

Unique owner of an object allocated on Base's heap.

Template Parameters
TPointee.
TPointee type. void is allowed when the concrete destructor was stored by the source.

The object and its concrete destructor live on Base's heap. There is no release and no constructor from a raw pointer.

Member Typedef Documentation

◆ deleter_type

template<class T>
using StormByte::Safe::Unique< T >::deleter_type = Heap::ObjectDeleter

Deleter used by the STL conversion.

◆ element_type

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

Pointee type.

◆ pointer

template<class T>
using StormByte::Safe::Unique< T >::pointer = T*

Stored pointer.

Constructor & Destructor Documentation

◆ Unique() [1/5]

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

Construct an empty owner.

◆ Unique() [2/5]

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

Construct an empty owner from null.

Parameters
nullNull pointer constant.

◆ Unique() [3/5]

template<class T>
template<class U>
requires Type::ConvertibleTo<U*, T*>
StormByte::Safe::Unique< T >::Unique ( Unique< U > && other)
noexcept

Take ownership from another owner.

Template Parameters
USource pointee. U* must convert to T*.
Parameters
otherOwner to take. Left empty.

◆ Unique() [4/5]

template<class T>
StormByte::Safe::Unique< T >::Unique ( const Unique< T > & other)
delete

Copy constructor.

Deleted.

Parameters
otherIgnored.

◆ Unique() [5/5]

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

Take ownership.

other is left empty.

Parameters
otherOwner to take.

◆ ~Unique()

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

Destroy the object through its concrete destructor and free the block.

Member Function Documentation

◆ get()

template<class T>
T * StormByte::Safe::Unique< T >::get ( ) const
noexcept

Return the stored pointer.

Returns
Pointee, or null.

◆ MakePointer()

template<class T>
template<class Target, class... Args>
requires Type::SameAs<Target, T> || Type::DerivedFrom<Target, T>
Unique< T > StormByte::Safe::Unique< T >::MakePointer ( Args &&... args)
static

Allocate Target on Base's heap and own it as T.

Template Parameters
TargetConcrete type. It is T or derived from T.
ArgsConstructor argument types.
Parameters
argsArguments forwarded to Target.
Returns
Owner. The stored destructor is Target's, so T does not need a virtual destructor.
Exceptions
AllocationErrorThe block could not be allocated.

◆ operator bool()

template<class T>
StormByte::Safe::Unique< T >::operator bool ( ) const
explicitnoexcept

Test whether this owner holds an object.

Returns
Whether the stored pointer is non-null.

◆ operator std::unique_ptr< T, Heap::ObjectDeleter >()

template<class T>
STORMBYTE_FORCE_INLINE StormByte::Safe::Unique< T >::operator std::unique_ptr< T, Heap::ObjectDeleter > ( ) &&
inlinenoexcept

Move the owner into caller-owned STL storage.

Returns
A std::unique_ptr whose deleter still frees Base's block. There is no conversion back.

◆ operator*()

template<class T>
std::add_lvalue_reference_t< T > StormByte::Safe::Unique< T >::operator* ( ) const
noexcept

Dereference the stored pointer.

Returns
Pointee. void when T is void, so the class can be formed.

◆ operator->()

template<class T>
T * StormByte::Safe::Unique< T >::operator-> ( ) const
noexcept

Access a member of the pointee.

Returns
Stored pointer.

◆ operator=() [1/2]

template<class T>
Unique & StormByte::Safe::Unique< T >::operator= ( const Unique< T > & other)
delete

Copy assignment.

Deleted.

Parameters
otherIgnored.
Returns
This owner.

◆ operator=() [2/2]

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

Take ownership.

other is left empty.

Parameters
otherOwner to take.
Returns
This owner.

◆ reset()

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

Destroy the object and leave this owner empty.

◆ swap()

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

Exchange owners.

Parameters
otherOwner to exchange with.

◆ MakeUnique

template<class T>
template<class U, class... Args>
Unique< U > MakeUnique ( Args && ...)
friend

◆ Unique

template<class T>
template<class U>
friend class Unique
friend

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