Unique owner of a T allocated on Base's heap.
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 that calls Heap::Free. | |
Public Member Functions | |
| Unique () noexcept=default | |
| Empty owner. | |
| Unique (std::nullptr_t) noexcept | |
Empty owner from nullptr. | |
| template<class U > requires Type::SameAs<U, T> || (Type::DerivedFrom<U, T> && std::has_virtual_destructor_v<T>) | |
| Unique (Unique< U > &&other) noexcept | |
Take ownership from other. | |
| Unique (const Unique &)=delete | |
| Copy constructor. | |
| Unique (Unique &&) noexcept=default | |
| Move constructor. | |
| Unique & | operator= (const Unique &)=delete |
| Copy assignment. | |
| Unique & | operator= (Unique &&) noexcept=default |
| Move assignment. | |
| ~Unique ()=default | |
| Destructor. | |
| T * | get () const noexcept |
| Raw pointer, or null. | |
| T & | operator* () const |
| Dereference. | |
| T * | operator-> () const noexcept |
| Member access. | |
| operator bool () const noexcept | |
| Whether this owner holds an object. | |
| operator std::unique_ptr< T, Heap::ObjectDeleter > () &&noexcept | |
Release as std::unique_ptr with Base's deleter. | |
| deleter_type & | get_deleter () noexcept |
| Deleter stored in this owner. | |
| const deleter_type & | get_deleter () const noexcept |
| Deleter stored in this owner. | |
| void | reset () noexcept |
| Destroy the object and drop this owner. | |
| void | swap (Unique &other) noexcept |
Exchange owners with other. | |
Static Public Member Functions | |
| template<class Target , class... Args> requires Type::SameAs<Target, T> || (Type::DerivedFrom<Target, T> && std::has_virtual_destructor_v<T>) | |
| static Unique< T > | MakePointer (Args &&... args) |
Allocate Target on Base's heap and own it as T. | |
Friends | |
| template<class U > | |
| class | Unique |
| bool | operator== (const Unique &lhs, std::nullptr_t) noexcept |
| Equality with null. | |
| bool | operator!= (const Unique &lhs, std::nullptr_t) noexcept |
| Inequality with null. | |
| bool | operator== (std::nullptr_t, const Unique &rhs) noexcept |
| Equality with null. | |
| bool | operator!= (std::nullptr_t, const Unique &rhs) noexcept |
| Inequality with null. | |
| bool | operator== (const Unique &lhs, const Unique &rhs) noexcept |
| Same stored pointer. | |
| auto | operator<=> (const Unique &lhs, const Unique &rhs) noexcept |
| Order of the stored pointers. | |
| void | swap (Unique &left, Unique &right) noexcept |
Exchange left and right. | |
| template<class U , class... Args> | |
| Unique< U > | Heap::MakeUnique (Args &&...) |
Unique owner of a T allocated on Base's heap.
| T | Pointee type. |
Complements std::unique_ptr. It does not replace it. Use std::unique_ptr when the object does not cross a DLL. Use Unique when the object must be freed on Base's heap.
Construct the exact type with Heap::MakeUnique. Construct a derived type with Unique::MakePointer. ~T must be virtual when Target is not T, because the deleter calls ~T. There is no release and no constructor from a raw pointer. Converts on move to std::unique_ptr<T, Heap::ObjectDeleter>, not to std::unique_ptr<T>. A signature that takes std::unique_ptr<T> has to change.
| using StormByte::Unique< T >::deleter_type = Heap::ObjectDeleter |
Deleter that calls Heap::Free.
| using StormByte::Unique< T >::element_type = T |
Pointee type.
| using StormByte::Unique< T >::pointer = T* |
Stored pointer.
|
defaultnoexcept |
Empty owner.
|
inlinenoexcept |
Empty owner from nullptr.
|
inlinenoexcept |
Take ownership from other.
| U | Pointee convertible to T. |
| other | Other owner. |
|
delete |
Copy constructor.
Deleted.
|
defaultnoexcept |
Move constructor.
|
default |
Destructor.
|
inlinenoexcept |
Raw pointer, or null.
|
inlinenoexcept |
Deleter stored in this owner.
|
inlinenoexcept |
Deleter stored in this owner.
|
inlinestatic |
Allocate Target on Base's heap and own it as T.
| Target | Concrete type (T or derived from T). |
| Args | Constructor argument types. |
| args | Forwarded to Target. |
Target object. Target is not T, T must have a virtual destructor.
|
inlineexplicitnoexcept |
Whether this owner holds an object.
true when non-empty.
|
inlinenoexcept |
Release as std::unique_ptr with Base's deleter.
std::unique_ptr<T, Heap::ObjectDeleter>.
|
inline |
Dereference.
|
inlinenoexcept |
Member access.
|
delete |
Copy assignment.
Deleted.
*this.
|
defaultnoexcept |
Move assignment.
*this.
|
inlinenoexcept |
Destroy the object and drop this owner.
|
inlinenoexcept |
Exchange owners with other.
| other | Other owner. |
|
friend |
|
friend |
Inequality with null.
| lhs | Owner. |
lhs is non-empty.
|
friend |
Inequality with null.
| rhs | Owner. |
rhs is non-empty. Order of the stored pointers.
| lhs | Owner. |
| rhs | Owner. |
Same stored pointer.
| lhs | Owner. |
| rhs | Owner. |
|
friend |
Equality with null.
| lhs | Owner. |
lhs is empty.
|
friend |
Equality with null.
| rhs | Owner. |
rhs is empty. Exchange left and right.
| left | Owner. |
| right | Owner. |