std::variant stored on Base's heap. More...
#include <StormByte/safe/variant.hxx>
Public Member Functions | |
| Variant () | |
| Default-construct the first alternative. | |
| template<class T> requires (Variant::template AlternativeIndex<T>() != npos) | |
| Variant (T &&value) | |
| Copy an alternative into Base storage. | |
| template<std::size_t I, class... Args> | |
| Variant (std::in_place_index_t< I > index, Args &&... args) | |
Construct the alternative at I. | |
| template<class T, class... Args> | |
| Variant (std::in_place_type_t< T > tag, Args &&... args) | |
Construct the alternative T. | |
| Variant (const std::variant< Ts... > &value) | |
| Copy a caller-owned std::variant. | |
| Variant (std::variant< Ts... > &&value) | |
| Move a caller-owned std::variant by copying the alternative into Base storage. | |
| Variant (const Variant &other) | |
| Copy the active alternative into a new Base block. | |
| Variant (Variant &&other) noexcept | |
| Take the active block. | |
| ~Variant () noexcept | |
| Destroy the active alternative and release its block. | |
| Variant & | operator= (const Variant &other) |
| Copy-assign. | |
| Variant & | operator= (Variant &&other) noexcept |
| Move-assign. | |
| template<class T> requires (Variant::template AlternativeIndex<T>() != npos) | |
| Variant & | operator= (T &&value) |
| Assign an alternative. | |
| std::size_t | index () const noexcept |
| Index of the active alternative, or npos when valueless. | |
| bool | valueless_by_exception () const noexcept |
| Whether a throwing operation left this variant without an alternative. | |
| template<std::size_t I, class... Args> | |
| auto & | emplace (Args &&... args) |
Construct the alternative at I, replacing the current one only after construction. | |
| template<class T, class... Args> | |
| T & | emplace (Args &&... args) |
Construct T, replacing the current alternative only after construction. | |
| void | swap (Variant &other) noexcept |
| Exchange storage. | |
| bool | operator== (const Variant &other) const |
| Content equality. | |
| STORMBYTE_FORCE_INLINE std::strong_ordering | operator<=> (const Variant &other) const |
| Index order, then alternative order when the indices match. | |
| STORMBYTE_FORCE_INLINE | operator std::variant< Ts... > () const |
| Copy the active alternative into caller-owned STL storage. | |
Static Public Member Functions | |
| template<class T> | |
| static constexpr std::size_t | AlternativeIndex () noexcept |
Index of the single alternative constructible from T, or npos. | |
Static Public Attributes | |
| static constexpr std::size_t | npos = static_cast<std::size_t>(-1) |
| No alternative. | |
Friends | |
| template<std::size_t I, Type::SafeValue... Us> | |
| auto * | get_if (Variant< Us... > *value) noexcept |
| template<std::size_t I, Type::SafeValue... Us> | |
| const auto * | get_if (const Variant< Us... > *value) noexcept |
| template<class T, Type::SafeValue... Us> | |
| T * | get_if (Variant< Us... > *value) noexcept |
| template<class T, Type::SafeValue... Us> | |
| const T * | get_if (const Variant< Us... > *value) noexcept |
| template<class Visitor, Type::SafeValue... Us> | |
| decltype(auto) | visit (Visitor &&visitor, Variant< Us... > &value) |
| template<class Visitor, Type::SafeValue... Us> | |
| decltype(auto) | visit (Visitor &&visitor, const Variant< Us... > &value) |
std::variant stored on Base's heap.
| Ts | Alternatives. Each one is a StormByte::Type::SafeValue. |
Not a std::variant. The active alternative is constructed in a block from Heap::Allocate and released with Heap::Free. A move of this variant leaves the source valueless. A move from std::variant does not change its index. emplace builds the replacement first, so a throw keeps the previous alternative. get and visit are found by argument lookup; std::get and std::visit do not accept this type.
| StormByte::Safe::Variant< Ts >::Variant | ( | ) |
Default-construct the first alternative.
| AllocationError | The block could not be allocated. |
|
inline |
Copy an alternative into Base storage.
| T | Alternative. Exactly one alternative is constructible from value. |
| value | Source. |
| AllocationError | The block could not be allocated. |
|
explicit |
Construct the alternative at I.
| I | Alternative index. |
| Args | Constructor argument types. |
| index | In-place index tag. |
| args | Arguments forwarded to the alternative. |
| AllocationError | The block could not be allocated. |
|
explicit |
Construct the alternative T.
| T | Alternative. It occurs once. |
| Args | Constructor argument types. |
| tag | In-place type tag. |
| args | Arguments forwarded to T. |
| AllocationError | The block could not be allocated. |
|
explicit |
Copy a caller-owned std::variant.
A valueless source stays valueless.
| value | Source. Its index is unchanged. |
| AllocationError | The block could not be allocated. |
|
explicit |
Move a caller-owned std::variant by copying the alternative into Base storage.
| value | Source. Its index is unchanged; a held alternative is moved-from. |
| AllocationError | The block could not be allocated. |
| StormByte::Safe::Variant< Ts >::Variant | ( | const Variant< Ts > & | other | ) |
Copy the active alternative into a new Base block.
| other | Source. |
| AllocationError | The block could not be allocated. |
|
noexcept |
Take the active block.
other becomes valueless.
| other | Source. |
|
noexcept |
Destroy the active alternative and release its block.
|
staticconstexprnoexcept |
| T & StormByte::Safe::Variant< Ts >::emplace | ( | Args &&... | args | ) |
Construct T, replacing the current alternative only after construction.
| T | Alternative. It occurs once. |
| Args | Constructor argument types. |
| args | Arguments forwarded to T. |
| AllocationError | The block could not be allocated. The previous alternative is kept. |
| auto & StormByte::Safe::Variant< Ts >::emplace | ( | Args &&... | args | ) |
Construct the alternative at I, replacing the current one only after construction.
| I | Alternative index. |
| Args | Constructor argument types. |
| args | Arguments forwarded to the alternative. |
| AllocationError | The block could not be allocated. The previous alternative is kept. |
|
noexcept |
Index of the active alternative, or npos when valueless.
|
inlineexplicit |
Copy the active alternative into caller-owned STL storage.
| BadVariantAccess | This variant is valueless. |
| STORMBYTE_FORCE_INLINE std::strong_ordering StormByte::Safe::Variant< Ts >::operator<=> | ( | const Variant< Ts > & | other | ) | const |
Index order, then alternative order when the indices match.
| other | Other variant. |
| Variant & StormByte::Safe::Variant< Ts >::operator= | ( | const Variant< Ts > & | other | ) |
Copy-assign.
The replacement is built first.
| other | Source. |
| AllocationError | The block could not be allocated. The previous alternative is kept. |
|
inline |
Assign an alternative.
The replacement is built first.
| T | Alternative. |
| value | Source. |
| AllocationError | The block could not be allocated. The previous alternative is kept. |
|
noexcept |
Move-assign.
The block is taken. other becomes valueless.
| other | Source. |
| bool StormByte::Safe::Variant< Ts >::operator== | ( | const Variant< Ts > & | other | ) | const |
Content equality.
Two valueless variants are equal.
| other | Other variant. |
|
noexcept |
Exchange storage.
Both blocks stay on Base's heap.
| other | Other variant. |
|
noexcept |
Whether a throwing operation left this variant without an alternative.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
staticconstexpr |
No alternative.