An Option monadic type. More...
#include <Optional.h>
Public Member Functions | |
Constructors | |
constexpr | Optional () |
Default constructor. More... | |
constexpr | Optional (T value) |
Value constructor. | |
Information | |
PURITY_WEAK constexpr bool | hasValue () const |
Returns whether the optional contains a value. More... | |
PURITY_WEAK constexpr T | value () const |
Returns the contained value unchecked. More... | |
template<class UnaryFunction > | |
constexpr auto | map (UnaryFunction &&function) const |
Monadic bind with function of signature T -> U. More... | |
template<class UnaryFunction > | |
constexpr auto | flatMap (UnaryFunction &&function) const |
Monadic bind with function of signature T -> Optional<U> More... | |
PURITY_WEAK constexpr T | valueOr (const T &alternative) const |
Returns a value if initialized, and another if not. More... | |
Operators | |
constexpr Optional & | operator= (T assignment) |
Assignment from T. | |
PURITY_WEAK constexpr | operator bool () const |
Convert-to-bool operator. | |
PURITY_WEAK constexpr bool | operator== (const Optional &other) const |
Compares on basis of contained value. Nones do compare equal. | |
PURITY_WEAK constexpr bool | operator!= (const Optional &other) const |
Compares on basis of contained value. Nones do compare equal. | |
PURITY_WEAK constexpr bool | operator< (const Optional &other) const |
Lexicographical-like comparison. | |
PURITY_WEAK constexpr bool | operator> (const Optional &other) const |
Lexicographical-like comparison. | |
Private Attributes | |
T | value_ = T {} |
bool | hasValue_ = false |
An Option monadic type.
A constexpr option type much like std::optional with the limitation that T must be:
(see the C++ standard definitions)
|
inline |
Default constructor.
None value. Default constructs a contained type.
|
inline |
|
inline |
Returns whether the optional contains a value.
Complexity \(\Theta(1)\)
|
inline |
Monadic bind with function of signature T -> U.
UnaryFunction,: | Function of signature T -> U |
|
inline |
Returns the contained value unchecked.
Complexity \(\Theta(1)\)
hasValue
is false, this is UB.
|
inline |
Returns a value if initialized, and another if not.
Complexity \(\Theta(1)\)