MT Core (C++)
Core library for replacing C++ standard in project usage
|
Represents a value that may or may not exist (an "Optional" value) Similar concept to std::optional, but different implementation and additional nicety methods which makes this a better alternative for simple loop-based iteration (via copy_if_present and move_if_present) More...
#include <optional.hpp>
Public Member Functions | |
Optional () | |
Creates an empty Optional. | |
Optional (const T &value) | |
Creates an Optional from a value. | |
Optional (T &&value) | |
Creates an Optional from a value. | |
bool | operator== (const Optional &other) const noexcept |
Checks if value is equal to another Optional. | |
bool | operator== (const T &other) const noexcept |
Checks if value is equal to a non-Optional value. | |
T | value_or (const T &def) const noexcept |
Returns the value in the optional, or a default value if the optional is empty. | |
bool | has_value () const noexcept |
bool | empty () const noexcept |
T & | value () noexcept |
const T & | value () const noexcept |
bool | copy_if_present (std::remove_const_t< T > &out) const noexcept |
Copies a value to a reference output destination if a value is present Designed to be used by simple iterators as part of a while loop on a next() method Example: | |
bool | move_if_present (T &out) noexcept |
Moves a value to a reference output destination if a value is present. | |
const T & | operator* () const |
Dereferences the internal value. | |
const T * | operator-> () const |
Dereferences the internal value. | |
T & | operator* () |
Dereferences the internal value. | |
T * | operator-> () |
Dereferences the internal value. | |
Represents a value that may or may not exist (an "Optional" value) Similar concept to std::optional, but different implementation and additional nicety methods which makes this a better alternative for simple loop-based iteration (via copy_if_present and move_if_present)
Definition at line 235 of file optional.hpp.
|
inline |
Creates an empty Optional.
Definition at line 243 of file optional.hpp.
|
inline |
Creates an Optional from a value.
Definition at line 248 of file optional.hpp.
|
inline |
Creates an Optional from a value.
Definition at line 253 of file optional.hpp.
|
inlinenodiscardnoexcept |
Copies a value to a reference output destination if a value is present Designed to be used by simple iterators as part of a while loop on a next()
method Example:
out | Where to put the destination |
Definition at line 327 of file optional.hpp.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Definition at line 294 of file optional.hpp.
|
inlinenodiscardnoexcept |
Moves a value to a reference output destination if a value is present.
Will mark the Optional as empty Designed to be used by simple iterators as part of a while loop on a next()
method Example:
out | Where to put the destination |
Definition at line 352 of file optional.hpp.
|
inline |
Dereferences the internal value.
Definition at line 380 of file optional.hpp.
|
inline |
Dereferences the internal value.
Definition at line 364 of file optional.hpp.
|
inline |
Dereferences the internal value.
Definition at line 388 of file optional.hpp.
|
inline |
Dereferences the internal value.
Definition at line 372 of file optional.hpp.
|
inlinenoexcept |
Checks if value is equal to another Optional.
Definition at line 258 of file optional.hpp.
|
inlinenoexcept |
Checks if value is equal to a non-Optional value.
Definition at line 273 of file optional.hpp.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Definition at line 301 of file optional.hpp.
|
inlinenodiscardnoexcept |
Returns the value in the optional, or a default value if the optional is empty.
def | Default value |
Definition at line 284 of file optional.hpp.