|
ORIGINAL
|
A type-safe container that may or may not contain a value. More...
#include <optional.h>

Public Member Functions | |
| alternative () | |
| Constructs an empty alternative. | |
| template<typename... Args> | |
| alternative (Args &&... args) | |
| Constructs an alternative containing a value. | |
| alternative (const alternative &other) | |
| Copy constructor. | |
| alternative & | operator= (const alternative &other) |
| Copy assignment. | |
| alternative (alternative &&other) noexcept | |
| Move constructor. | |
| alternative & | operator= (alternative &&other) noexcept |
| Move assignment. | |
| void | swap (alternative &other) noexcept |
| Swaps contents with another alternative. | |
| const TYPE & | operator* () const |
| Const value access. | |
| TYPE & | operator* () |
| Mutable value access. | |
| const TYPE * | operator-> () const |
| Const member access. | |
| TYPE * | operator-> () |
| Mutable member access. | |
| const TYPE * | get () const |
| Gets const pointer to value. | |
| TYPE * | get () |
| Gets mutable pointer to value. | |
| void | reset () noexcept |
| Resets to empty state. | |
| template<typename... Args> | |
| void | emplace (Args &&... args) |
| Constructs value in-place. | |
| void | set (const TYPE &t) |
| Sets value by copy. | |
| alternative & | operator= (const TYPE &t) |
| Copy assignment from value type. | |
| operator bool () const | |
| Checks if contains a value. | |
| bool | hasValue () const |
| Checks if contains a value. | |
| ~alternative () | |
| Destructor. | |
A type-safe container that may or may not contain a value.
Specialization for void type alternative.
| TYPE | The type of value to store |
This class provides a way to represent optional values without using pointers. It can either contain a value of type TYPE or be empty. The empty state is represented using original::none from types.h.
The implementation uses a union for storage to avoid dynamic allocation and ensure optimal performance. All operations provide strong exception safety guarantee when TYPE operations are exception-safe.
Example usage:
Represents a simple boolean flag indicating presence or absence of a value without storing actual data. Useful for signaling states without associated data, similar to std::optional<std::monostate>.
This specialization is more memory efficient than alternative<bool> and provides a clean interface for presence/absence signaling.
Example usage:
|
explicit |
Constructs an empty alternative.
|
explicit |
Constructs an alternative containing a value.
| Args | Argument types for TYPE construction |
| args | Arguments to forward to TYPE constructor |
| original::alternative< TYPE >::alternative | ( | const alternative< TYPE > & | other | ) |
Copy constructor.
| other | Alternative to copy from |
|
noexcept |
Move constructor.
| other | Alternative to move from |
| original::alternative< TYPE >::~alternative | ( | ) |
Destructor.
| void original::alternative< TYPE >::emplace | ( | Args &&... | args | ) |
Constructs value in-place.
| Args | Argument types for TYPE construction |
| args | Arguments to forward to TYPE constructor |
| TYPE * original::alternative< TYPE >::get | ( | ) |
Gets mutable pointer to value.
Gets const pointer to value.
| bool original::alternative< TYPE >::hasValue | ( | ) | const |
Checks if contains a value.
|
explicit |
Checks if contains a value.
| TYPE & original::alternative< TYPE >::operator* | ( | ) |
| TYPE * original::alternative< TYPE >::operator-> | ( | ) |
|
noexcept |
Move assignment.
| other | Alternative to move from |
| original::alternative< TYPE > & original::alternative< TYPE >::operator= | ( | const alternative< TYPE > & | other | ) |
Copy assignment.
| other | Alternative to copy from |
| original::alternative< TYPE > & original::alternative< TYPE >::operator= | ( | const TYPE & | t | ) |
Copy assignment from value type.
| t | Value to copy into the alternative |
Replaces the current contents (if any) with a copy of the given value. If the alternative was previously empty, constructs a new value. If it already contained a value, assigns the new value using TYPE's copy assignment operator. Provides strong exception safety guarantee if TYPE's copy constructor/assignment is exception-safe.
Example usage:
|
noexcept |
Resets to empty state.
|
noexcept |
Swaps contents with another alternative.
| other | Alternative to swap with |
Efficiently exchanges contents without copying