Porytiles
Loading...
Searching...
No Matches
porytiles2::ChainableResult< void, E > Class Template Reference

Template specialization of ChainableResult for void success type. More...

#include <chainable_result.hpp>

Inheritance diagram for porytiles2::ChainableResult< void, E >:
[legend]
Collaboration diagram for porytiles2::ChainableResult< void, E >:
[legend]

Public Member Functions

 ChainableResult ()
 Default constructor creating a successful void result.
 
 ChainableResult (const E &error)
 Constructs a ChainableResult from an error value.
 
template<typename CauseT , typename CauseE >
 ChainableResult (const E &error, const ChainableResult< CauseT, CauseE > &cause_result)
 Constructs a ChainableResult by chaining a new error with an existing error chain.
 
void value () &
 Accesses the void success value.
 
void value () const &
 Accesses the void success value (const version).
 
void value () &&
 Accesses the void success value (rvalue version).
 
- Public Member Functions inherited from porytiles2::ChainableResult< detail::Empty, E >
 ChainableResult (detail::Empty value)
 Constructs a ChainableResult from a success value.
 
 ChainableResult (const E &error)
 Constructs a ChainableResult from an error value.
 
 ChainableResult (const E &error, const ChainableResult< CauseT, CauseE > &cause_result)
 Constructs a ChainableResult by chaining a new error with an existing error chain.
 
 ChainableResult (ChainableResult &&)=default
 
 ChainableResult (const ChainableResult &)=delete
 
ChainableResultoperator= (ChainableResult &&)=default
 
ChainableResultoperator= (const ChainableResult &)=delete
 
void add_cause (const ChainableResult< OtherT, OtherE > &cause_result)
 Adds all errors from another ChainableResult's chain to this result's chain.
 
bool has_value () const
 Checks whether the result contains a success value.
 
detail::Empty & value () &
 Returns a reference to the contained success value.
 
const detail::Empty & value () const &
 Returns a const reference to the contained success value.
 
detail::Empty && value () &&
 Returns an rvalue reference to the contained success value.
 
const E & error () const
 Returns a const reference to the immediate error.
 
const std::vector< std::unique_ptr< Error > > & chain () const
 Returns the complete error chain.
 

Additional Inherited Members

- Protected Member Functions inherited from porytiles2::ChainableResult< detail::Empty, E >
 ChainableResult ()=default
 

Detailed Description

template<typename E>
class porytiles2::ChainableResult< void, E >

Template specialization of ChainableResult for void success type.

This specialization handles the case where no value needs to be returned on success, similar to std::expected<void, E>. It is implemented as a thin wrapper around the primary template, using a private detail::Empty struct as a placeholder for the void type. This approach avoids code duplication while providing a void-like interface.

Template Parameters
EThe error type, must be derived from Error interface

Definition at line 225 of file chainable_result.hpp.

Constructor & Destructor Documentation

◆ ChainableResult() [1/3]

template<typename E >
porytiles2::ChainableResult< void, E >::ChainableResult ( )
inline

Default constructor creating a successful void result.

Constructs a ChainableResult representing success with no value. This allows functions returning ChainableResult<void, E> to use the syntax return {} for successful completion.

Definition at line 237 of file chainable_result.hpp.

◆ ChainableResult() [2/3]

template<typename E >
porytiles2::ChainableResult< void, E >::ChainableResult ( const E &  error)
inline

Constructs a ChainableResult from an error value.

This constructor allows implicit conversion from an error value of type E to a ChainableResult. The error is stored as the initial error in the chain. This provides ergonomic construction for error cases at the bottom level of an error chain.

Parameters
errorThe error value to store

Definition at line 249 of file chainable_result.hpp.

◆ ChainableResult() [3/3]

template<typename E >
template<typename CauseT , typename CauseE >
porytiles2::ChainableResult< void, E >::ChainableResult ( const E &  error,
const ChainableResult< CauseT, CauseE > &  cause_result 
)
inlineexplicit

Constructs a ChainableResult by chaining a new error with an existing error chain.

This constructor creates a new error result that includes both a new error message and the complete error chain from a cause result. This is the primary mechanism for building error context as errors propagate up through application layers. The new error is added to the beginning of the chain, followed by all errors from the cause result's chain.

Template Parameters
CauseTThe success type of the cause result (may be void)
CauseEThe error type of the cause result, must be derived from Error
Parameters
errorThe new error to add at this level
cause_resultThe ChainableResult containing the error chain to chain

Definition at line 266 of file chainable_result.hpp.

Member Function Documentation

◆ value() [1/3]

template<typename E >
void porytiles2::ChainableResult< void, E >::value ( ) &
inline

Accesses the void success value.

For the void specialization, this method returns void and simply validates that the result is indeed a success. It will throw std::bad_expected_access if called when the result contains an error.

Definition at line 279 of file chainable_result.hpp.

◆ value() [2/3]

template<typename E >
void porytiles2::ChainableResult< void, E >::value ( ) &&
inline

Accesses the void success value (rvalue version).

For the void specialization, this method returns void and simply validates that the result is indeed a success when called on an rvalue ChainableResult. It will throw std::bad_expected_access if called when the result contains an error.

Definition at line 305 of file chainable_result.hpp.

◆ value() [3/3]

template<typename E >
void porytiles2::ChainableResult< void, E >::value ( ) const &
inline

Accesses the void success value (const version).

For the void specialization, this method returns void and simply validates that the result is indeed a success. It will throw std::bad_expected_access if called when the result contains an error.

Definition at line 292 of file chainable_result.hpp.


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