|
| bool | constructed () const noexcept |
| | Reports whether a value is currently constructed.
|
| |
| void const * | control_address () const noexcept |
| | Returns the storage control-block address for diagnostics.
|
| |
| void | destroy () noexcept |
| | Destroy the contained object while keeping the control block alive.
|
| |
template<typename... Args>
requires std::constructible_from<T, Args...> |
| T & | emplace (Args &&... args) |
| | Destroy any existing value and construct a new one in place.
|
| |
| const T * | get () const noexcept |
| | Returns a const pointer to the constructed value.
|
| |
| T * | get () noexcept |
| | Returns a mutable pointer to the constructed value.
|
| |
| bool | has_lifetime_owner () const noexcept |
| | Reports whether this value retains another storage control block.
|
| |
| | operator bool () const noexcept |
| | Returns true when a control block is present.
|
| |
| bool | operator! () const noexcept |
| | Returns true when no control block is present.
|
| |
| const T & | operator* () const noexcept |
| | Dereference access to the constructed value.
|
| |
| T & | operator* () noexcept |
| | Dereference access to the constructed value.
|
| |
| const T * | operator-> () const noexcept |
| | Pointer-style const access to the constructed value.
|
| |
| T * | operator-> () noexcept |
| | Pointer-style mutable access to the constructed value.
|
| |
| shared_storage & | operator= (const shared_storage &other) noexcept |
| | Copy assignment shares the control block.
|
| |
| shared_storage & | operator= (shared_storage &&other) noexcept |
| | Move assignment transfers the control block pointer.
|
| |
| void | reset () noexcept |
| | Release this handle's reference to the control block.
|
| |
| | shared_storage () noexcept=default |
| | Construct an empty handle with no control block.
|
| |
| | shared_storage (const shared_storage &other) noexcept |
| | Copy constructor increments control block reference count.
|
| |
| | shared_storage (shared_storage &&other) noexcept |
| | Move constructor transfers ownership of the control block pointer.
|
| |
| T const * | storage_address () const noexcept |
| | Return the const address reserved for the contained value.
|
| |
| T * | storage_address () noexcept |
| | Return the address reserved for the contained value.
|
| |
| T | take () noexcept(std::is_nothrow_move_constructible_v< T >) |
| | Move the contained value out and destroy the in-place object.
|
| |
| size_t | use_count () const noexcept |
| | Returns the current strong reference count.
|
| |
| bool | valid () const noexcept |
| | Reports whether a control block is present.
|
| |
| | ~shared_storage () |
| | Destructor releases one reference to the control block.
|
| |
template<typename T>
class uni20::async::shared_storage< T >
A lightweight, thread-safe, reference-counted storage for a single object.
Unlike std::shared_ptr<T>, shared_storage<T> can exist in an unconstructed state, allowing delayed or conditional in-place construction via .emplace().
This is useful for async or deferred initialization scenarios, where the lifetime and ownership of an object must be shared across tasks, but construction may not yet have occurred.
Key features:
- Shared ownership via atomic reference counting
- Deferred or repeated construction via
.emplace()
- Thread-safe refcounting (like
std::shared_ptr)
- Minimal overhead (single heap allocation)
Example:
A lightweight, thread-safe, reference-counted storage for a single object.
Definition shared_storage.hpp:94
void destroy() noexcept
Destroy the contained object while keeping the control block alive.
Definition shared_storage.hpp:286
bool constructed() const noexcept
Reports whether a value is currently constructed.
Definition shared_storage.hpp:234
T & emplace(Args &&... args)
Destroy any existing value and construct a new one in place.
Definition shared_storage.hpp:270
T * get() noexcept
Returns a mutable pointer to the constructed value.
Definition shared_storage.hpp:293
Alias storage can own a lightweight value such as a tensor-view descriptor while retaining one strong reference to another shared_storage control block that owns the underlying data.
template<typename T >
template<typename U , typename Owner , typename... Args>
Create storage for a value that keeps another storage value alive.
The alias has its own local strong count. Its control block retains one reference to owner, which is released after the alias value is destroyed. Copies of the alias increment only the local count.
- Template Parameters
-
| T | Alias value type. |
| Owner | Lifetime-owner value type. |
| Args | Alias constructor argument types. |
- Parameters
-
| owner | Storage whose lifetime must cover the alias value. |
| args | Arguments forwarded to the alias value constructor. |
- Returns
- Constructed alias storage sharing the owner's lifetime.