cgrapht 1.0.0
A modern C++20 header-only graph library
Loading...
Searching...
No Matches
cgrapht::Result< SUCCESS, ERROR > Class Template Reference

Result wrapper for success or error values. More...

#include <models.hpp>

Public Member Functions

bool operator== (const Result &other) const
 Equality comparison based on status and payload.
 
bool is_ok () const
 Check if the result represents success.
 
const SUCCESS & get_ok () const &
 Access success value as const reference.
 
SUCCESS consume_ok () &&
 Move success value out of the result.
 
const ERROR & get_error () const &
 Access error value as const reference.
 
ERROR consume_error () &&
 Move the error value out of the result.
 

Static Public Member Functions

static Result success (const SUCCESS &s)
 Construct a success result from a const reference.
 
static Result success (SUCCESS &&s)
 Construct a success result from an rvalue.
 
static Result error (const ERROR &e)
 Construct an error result from a const reference.
 
static Result error (ERROR &&e)
 Construct an error result from an rvalue.
 

Detailed Description

template<typename SUCCESS, typename ERROR>
class cgrapht::Result< SUCCESS, ERROR >

Result wrapper for success or error values.

Template Parameters
SUCCESSSuccess value type.
ERRORError value type.

Definition at line 18 of file models.hpp.

Member Function Documentation

◆ consume_error()

template<typename SUCCESS , typename ERROR >
ERROR cgrapht::Result< SUCCESS, ERROR >::consume_error ( ) &&
inline

Move the error value out of the result.

Returns
Error value.
Exceptions
std::runtime_errorif this is a success result.

Definition at line 127 of file models.hpp.

References cgrapht::Result< SUCCESS, ERROR >::is_ok().

◆ consume_ok()

template<typename SUCCESS , typename ERROR >
SUCCESS cgrapht::Result< SUCCESS, ERROR >::consume_ok ( ) &&
inline

Move success value out of the result.

Returns
Success value.
Exceptions
std::runtime_errorif this is an error result.

Definition at line 103 of file models.hpp.

References cgrapht::Result< SUCCESS, ERROR >::is_ok().

◆ error() [1/2]

template<typename SUCCESS , typename ERROR >
static Result cgrapht::Result< SUCCESS, ERROR >::error ( const ERROR &  e)
inlinestatic

Construct an error result from a const reference.

Parameters
eError value.
Returns
Result containing error.

Definition at line 52 of file models.hpp.

Referenced by cgrapht::DirectedGraph< V, E >::add_edge(), cgrapht::DirectedGraph< V, E >::delete_edge(), cgrapht::DirectedGraph< V, E >::delete_vertex(), and cgrapht::DirectedGraph< V, E >::get_vertex().

◆ error() [2/2]

template<typename SUCCESS , typename ERROR >
static Result cgrapht::Result< SUCCESS, ERROR >::error ( ERROR &&  e)
inlinestatic

Construct an error result from an rvalue.

Parameters
eError value.
Returns
Result containing error.

Definition at line 64 of file models.hpp.

◆ get_error()

template<typename SUCCESS , typename ERROR >
const ERROR & cgrapht::Result< SUCCESS, ERROR >::get_error ( ) const &
inline

Access error value as const reference.

Returns
Error value.
Exceptions
std::runtime_errorif this is a success result.

Definition at line 115 of file models.hpp.

References cgrapht::Result< SUCCESS, ERROR >::is_ok().

◆ get_ok()

template<typename SUCCESS , typename ERROR >
const SUCCESS & cgrapht::Result< SUCCESS, ERROR >::get_ok ( ) const &
inline

Access success value as const reference.

Returns
Success value.
Exceptions
std::runtime_errorif this is an error result.

Definition at line 91 of file models.hpp.

◆ is_ok()

template<typename SUCCESS , typename ERROR >
bool cgrapht::Result< SUCCESS, ERROR >::is_ok ( ) const
inline

Check if the result represents success.

Returns
True if success.

Definition at line 82 of file models.hpp.

Referenced by cgrapht::Result< SUCCESS, ERROR >::consume_error(), cgrapht::Result< SUCCESS, ERROR >::consume_ok(), and cgrapht::Result< SUCCESS, ERROR >::get_error().

◆ operator==()

template<typename SUCCESS , typename ERROR >
bool cgrapht::Result< SUCCESS, ERROR >::operator== ( const Result< SUCCESS, ERROR > &  other) const
inline

Equality comparison based on status and payload.

Definition at line 74 of file models.hpp.

◆ success() [1/2]

template<typename SUCCESS , typename ERROR >
static Result cgrapht::Result< SUCCESS, ERROR >::success ( const SUCCESS &  s)
inlinestatic

Construct a success result from a const reference.

Parameters
sSuccess value.
Returns
Result containing success.

Definition at line 30 of file models.hpp.

Referenced by cgrapht::DirectedGraph< V, E >::add_edge(), cgrapht::DirectedGraph< V, E >::add_vertex(), cgrapht::DirectedGraph< V, E >::delete_edge(), cgrapht::DirectedGraph< V, E >::delete_vertex(), and cgrapht::DirectedGraph< V, E >::get_vertex().

◆ success() [2/2]

template<typename SUCCESS , typename ERROR >
static Result cgrapht::Result< SUCCESS, ERROR >::success ( SUCCESS &&  s)
inlinestatic

Construct a success result from an rvalue.

Parameters
sSuccess value.
Returns
Result containing success.

Definition at line 41 of file models.hpp.


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