mrdocs::Optional
A compact optional that automatically uses nullable_traits<T> when available.
Description
Design
-
If nullable_traits<T> exists, the null state is encoded inside T (via sentinel or clearable‐empty semantics). Storage is exactly one T.
-
Otherwise, this falls back to std::optional<T> and uses its discriminator.
This single implementation uses a conditional storage type plus if constexpr on has_nullable_traits_v<T> to select the appropriate behavior at compile time.
Member Functions
Name |
Description |
|
Constructors |
Assignment operators |
|
In‐place construct a new value, replacing any existing one. |
|
True if engaged (contains a value). |
|
Dereference‐like access. |
|
Pointer‐like access. |
|
Reset to the null state. * |
|
Value access. Preconditions: has_value() is true. |
|
Contextual bool. |
Static Member Functions
Name |
Description |
Determine if the value is inlined via nullable traits. |
Non-Member Functions
Name |
Description |
Return the human‐readable name of the operator |
|
Return the inner type. |
|
Return the inner type. |
|
Compares an Optional to a value for inequality. Returns true if the Optional is disengaged or its value does not equal rhs. |
|
Compares two Optional values for inequality. Returns true if their engagement states differ or their contained values are not equal. |
|
Checks if the left Optional is less than the right Optional. Returns true if the right is engaged and either the left is disengaged or its value is less. |
|
Checks if the Optional is less than a value. Returns true if the Optional is disengaged or its value is less than rhs. |
|
Checks if the left Optional is less than or equal to the right Optional. Returns true if the left is disengaged or the right is engaged and the left's value is less or equal. |
|
Checks if the Optional is less than or equal to a value. Returns true if the Optional is disengaged or its value is less than or equal to rhs. |
|
Performs a three‐way comparison between an Optional and a value. If the Optional is engaged, compares its value to v; otherwise, returns less. |
|
Performs a three‐way comparison between two Optional values. If both are engaged, compares their contained values; otherwise, compares engagement state. |
|
Performs a three‐way comparison between an Optional and std::nullopt. Returns std::strong_ordering::greater if engaged, std::strong_ordering::equal if disengaged. |
|
Three‐way comparison operator |
|
Three‐way comparison operator |
|
Compares two Optional values for equality. Returns true if both are engaged and their contained values are equal, or both are disengaged. |
|
Checks if the Optional is disengaged (equal to std::nullopt). Returns true if the Optional does not contain a value. |
|
Equality operator |
|
Equality operator |
|
Compares an engaged Optional to a value for equality. Returns true if the Optional is engaged and its value equals rhs. |
|
Checks if the left Optional is greater than the right Optional. Returns true if the left is engaged and either the right is disengaged or its value is greater. |
|
Checks if the Optional is greater than a value. Returns true if the Optional is engaged and its value is greater than rhs. |
|
Checks if the left Optional is greater than or equal to the right Optional. Returns true if the right is disengaged or the left is engaged and its value is greater or equal. |
|
Checks if the Optional is greater than or equal to a value. Returns true if the Optional is engaged and its value is greater than or equal to rhs. |
|
Return a non‐empty string, or a null. |
Created with MrDocs