Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
live_cells::maybe< T > Class Template Reference

Container holding a cell value or an exception that occurred while computing a value. More...

#include <maybe.hpp>

Public Member Functions

 maybe ()
 Create a container holding an uninitialized_cell_error exception.
 
 maybe (const T &val)
 Create a container holding a value.
 
 maybe (std::exception_ptr error)
 Create a container holding an exception that was thrown.
 
unwrap () const
 Get the value or throw the exception stored in this container.
 
std::optional< T > value () const
 Get the value held in this.
 
std::exception_ptr error () const
 Get the exception held in this maybe.
 

Static Public Member Functions

static maybe< T > error (const auto &error)
 Create a container holding an exception that was thrown.
 
static maybe< T > wrap (const std::invocable auto &f)
 Create a maybe holding the result of calling f.
 

Detailed Description

template<typename T>
class live_cells::maybe< T >

Container holding a cell value or an exception that occurred while computing a value.

Constructor & Destructor Documentation

◆ maybe() [1/2]

template<typename T >
live_cells::maybe< T >::maybe ( const T & val)
inline

Create a container holding a value.

Parameters
valThe value

◆ maybe() [2/2]

template<typename T >
live_cells::maybe< T >::maybe ( std::exception_ptr error)
inline

Create a container holding an exception that was thrown.

Parameters
errorThe exception that was thrown.

Member Function Documentation

◆ error() [1/2]

template<typename T >
std::exception_ptr live_cells::maybe< T >::error ( ) const
inline

Get the exception held in this maybe.

Returns
The exception held in this maybe.

◆ error() [2/2]

template<typename T >
static maybe< T > live_cells::maybe< T >::error ( const auto & error)
inlinestatic

Create a container holding an exception that was thrown.

Note
This should be used instead of the constructor when the type of the exception is known and the exception is not wrapped in an std::exception_ptr.
Parameters
errorThe exception that was thrown.
Returns
A maybe holding an exception.

◆ unwrap()

template<typename T >
T live_cells::maybe< T >::unwrap ( ) const
inline

Get the value or throw the exception stored in this container.

Returns
The value stored in this container.

◆ value()

template<typename T >
std::optional< T > live_cells::maybe< T >::value ( ) const
inline

Get the value held in this.

Returns
The value held in this container.
Exceptions
std::bad_optional_accessIf the maybe does not hold a value.

◆ wrap()

template<typename T >
static maybe< T > live_cells::maybe< T >::wrap ( const std::invocable auto & f)
inlinestatic

Create a maybe holding the result of calling f.

f is called with no arguments. If it returns normally, the resulting maybe holds the returned value. If f throws an exception the resulting maybe holds the thrown exception.

Parameters
Afunction of no arguments.
Returns
A maybe holding the result of calling f.

The documentation for this class was generated from the following file: