mrdocs::Optional

A compact optional that automatically uses nullable_traits<T> when available.

Synopsis

Declared in <mrdocs/ADT/Optional.hpp>

template<class T>
class Optional;

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.

Types

Name

value_type

Member Functions

Name

Description

Optional [constructor]

Constructors

operator=

Assignment operators

emplace

In‐place construct a new value, replacing any existing one.

has_value

True if engaged (contains a value).

operator*

Dereference‐like access.

operator‐>

Pointer‐like access.

reset

Reset to the null state. *

value

Value access. Preconditions: has_value() is true.

operator bool

Contextual bool.

Static Member Functions

Name

Description

is_inlined

Determine if the value is inlined via nullable traits.

Non-Member Functions

Name

Description

getOperatorReadableName

Return the human‐readable name of the operator

innerType

Return the inner type.

innerType

Return the inner type.

operator!=

Compares an Optional to a value for inequality. Returns true if the Optional is disengaged or its value does not equal rhs.

operator!=

Compares two Optional values for inequality. Returns true if their engagement states differ or their contained values are not equal.

operator<

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.

operator<

Checks if the Optional is less than a value. Returns true if the Optional is disengaged or its value is less than rhs.

operator<=

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.

operator<=

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.

operator<=>

Performs a three‐way comparison between an Optional and a value. If the Optional is engaged, compares its value to v; otherwise, returns less.

operator<=>

Performs a three‐way comparison between two Optional values. If both are engaged, compares their contained values; otherwise, compares engagement state.

operator<=>

Performs a three‐way comparison between an Optional and std::nullopt. Returns std::strong_ordering::greater if engaged, std::strong_ordering::equal if disengaged.

operator<=>

Three‐way comparison operator

operator<=>

Three‐way comparison operator

operator==

Compares two Optional values for equality. Returns true if both are engaged and their contained values are equal, or both are disengaged.

operator==

Checks if the Optional is disengaged (equal to std::nullopt). Returns true if the Optional does not contain a value.

operator==

Equality operator

operator==

Equality operator

operator==

Compares an engaged Optional to a value for equality. Returns true if the Optional is engaged and its value equals rhs.

operator>

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.

operator>

Checks if the Optional is greater than a value. Returns true if the Optional is engaged and its value is greater than rhs.

operator>=

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.

operator>=

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.

dom::stringOrNull

Return a non‐empty string, or a null.

Created with MrDocs