jubilant-funicular
|
#include <Option.h>
Classes | |
struct | Nop |
Only exists to avoid a warning when using Option<T&> More... | |
Public Member Functions | |
Option () | |
Defaults to none variant. | |
Option (const Option &)=default | |
template<typename S > | |
Option (const Option< S > &) | |
operator bool () const | |
Same as is_some. | |
bool | is_some () const |
Does this hold some data. | |
bool | is_none () const |
Does this hold nothing? | |
T | get () const |
T | unwrap () const |
unwrap and get are the same thing | |
T | get_or (const T &optb) |
Return the data held by this Option or optb if it's None. | |
T | unwrap_or (const T &optb) |
void | destroy () |
Turns this into None variant, calling destructor if necessary. | |
template<typename S > | |
Option< S > | map (std::function< S(T)> func) |
template<typename S > | |
Option< S > | map (std::function< Option< S >(T)> func) |
template<typename S > | |
S | map_or (std::function< S(T)> func, const S &def) |
void | map (std::function< void(T)> func) |
Static Public Member Functions | |
static Option | some (const T &data) |
Creates an Option holding some data. | |
static Option | none () |
Creates a None variant Option. | |
Private Types | |
using | type = typename std::remove_reference< T >::type |
using | storage_type = typename std::conditional< std::is_reference< T >::value, void *, T >::type |
using | placement_type = typename std::conditional< std::is_reference< T >::value, Nop, type >::type |
Private Member Functions | |
Option (const T &d) | |
Private constructor (use some or none instead) | |
Private Attributes | |
std::aligned_storage_t< sizeof(storage_type), alignof(storage_type)> | m_data |
bool | m_some |
A class that optionally holds some data
Used to signal that a value may or may not be present
T can be a reference type (e.g. Option<std::string&> works as expected)
T nta::utils::Option< T >::get |
Retrieve the underlying data
You should always call is_some/is_none beforehand
Definition at line 86 of file Option.h.
Referenced by nta::utils::Option< T >::get_or(), and nta::utils::Option< T >::unwrap().
Option< S > nta::utils::Option< T >::map | ( | std::function< S(T)> | func | ) |