Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::expected< T > Class Template Reference

A lightweight result type that holds either a success value of type T or an Error. More...

#include <error.hpp>

Public Member Functions

 expected (const T &val)
 Construct a successful result by copying the value (enabled only for copyable types).
 
 expected (T &&val)
 Construct a successful result by moving the value.
 
 expected (const Error &err)
 Construct a failed result from a const Error reference.
 
 expected (Error &&err)
 Construct a failed result by moving an Error.
 
 expected (ErrorCode code, std::string msg)
 Convenience constructor: build an Error in-place from a code and message.
 
bool has_value () const
 Return true if the result holds a success value, false if it holds an Error.
 
 operator bool () const
 Return true if the result holds a success value.
 
const T & value () const &
 Access the success value (const lvalue reference).
 
T & value () &
 Access the success value (mutable lvalue reference).
 
T && value () &&
 Move-access the success value (rvalue reference).
 
const Errorerror () const
 Access the error payload.
 
const T & operator* () const &
 Dereference the success value (const lvalue).
 
T & operator* () &
 Dereference the success value (mutable lvalue).
 
T && operator* () &&
 Dereference the success value (rvalue, moves out).
 
const T * operator-> () const
 Arrow operator for member access on the success value (const).
 
T * operator-> ()
 Arrow operator for member access on the success value (mutable).
 

Detailed Description

template<typename T>
class signet::forge::expected< T >

A lightweight result type that holds either a success value of type T or an Error.

Modeled after C++23 std::expected but self-contained for C++20 compatibility. Every Signet Forge function that can fail returns expected<T> (or expected<void> for side-effect-only operations). Callers should always check has_value() or operator bool() before accessing the payload:

auto result = reader.read_column<double>("price");
if (!result) {
handle_error(result.error());
return;
}
const auto& values = *result; // operator* dereference
Template Parameters
TThe success value type. Must not be Error.
See also
expected<void> for the void specialization.
Error for the error payload type.

Definition at line 145 of file error.hpp.

Constructor & Destructor Documentation

◆ expected() [1/5]

template<typename T >
signet::forge::expected< T >::expected ( const T &  val)
inline

Construct a successful result by copying the value (enabled only for copyable types).

Parameters
valThe success value to store.

Definition at line 149 of file error.hpp.

◆ expected() [2/5]

template<typename T >
signet::forge::expected< T >::expected ( T &&  val)
inline

Construct a successful result by moving the value.

Parameters
valThe success value to move-store.

Definition at line 153 of file error.hpp.

◆ expected() [3/5]

template<typename T >
signet::forge::expected< T >::expected ( const Error err)
inline

Construct a failed result from a const Error reference.

Parameters
errThe error to store.

Definition at line 157 of file error.hpp.

◆ expected() [4/5]

template<typename T >
signet::forge::expected< T >::expected ( Error &&  err)
inline

Construct a failed result by moving an Error.

Parameters
errThe error to move-store.

Definition at line 160 of file error.hpp.

◆ expected() [5/5]

template<typename T >
signet::forge::expected< T >::expected ( ErrorCode  code,
std::string  msg 
)
inline

Convenience constructor: build an Error in-place from a code and message.

Parameters
codeThe ErrorCode category.
msgA human-readable error description.

Definition at line 165 of file error.hpp.

Member Function Documentation

◆ error()

template<typename T >
const Error & signet::forge::expected< T >::error ( ) const
inline

Access the error payload.

Precondition
has_value() == false.
Returns
Const reference to the stored Error.

Definition at line 199 of file error.hpp.

◆ has_value()

template<typename T >
bool signet::forge::expected< T >::has_value ( ) const
inline

Return true if the result holds a success value, false if it holds an Error.

Definition at line 169 of file error.hpp.

◆ operator bool()

template<typename T >
signet::forge::expected< T >::operator bool ( ) const
inlineexplicit

Return true if the result holds a success value.

Note
Explicit to prevent accidental implicit conversions.

Definition at line 172 of file error.hpp.

◆ operator*() [1/3]

template<typename T >
T & signet::forge::expected< T >::operator* ( ) &
inline

Dereference the success value (mutable lvalue).

Precondition
has_value() == true.

Definition at line 209 of file error.hpp.

◆ operator*() [2/3]

template<typename T >
T && signet::forge::expected< T >::operator* ( ) &&
inline

Dereference the success value (rvalue, moves out).

Precondition
has_value() == true.

Definition at line 212 of file error.hpp.

◆ operator*() [3/3]

template<typename T >
const T & signet::forge::expected< T >::operator* ( ) const &
inline

Dereference the success value (const lvalue).

Precondition
has_value() == true.

Definition at line 206 of file error.hpp.

◆ operator->() [1/2]

template<typename T >
T * signet::forge::expected< T >::operator-> ( )
inline

Arrow operator for member access on the success value (mutable).

Precondition
has_value() == true.

Definition at line 218 of file error.hpp.

◆ operator->() [2/2]

template<typename T >
const T * signet::forge::expected< T >::operator-> ( ) const
inline

Arrow operator for member access on the success value (const).

Precondition
has_value() == true.

Definition at line 215 of file error.hpp.

◆ value() [1/3]

template<typename T >
T & signet::forge::expected< T >::value ( ) &
inline

Access the success value (mutable lvalue reference).

Precondition
has_value() == true.
Returns
Mutable reference to the stored value.

Definition at line 184 of file error.hpp.

◆ value() [2/3]

template<typename T >
T && signet::forge::expected< T >::value ( ) &&
inline

Move-access the success value (rvalue reference).

Precondition
has_value() == true.
Returns
Rvalue reference to the stored value.

Definition at line 191 of file error.hpp.

◆ value() [3/3]

template<typename T >
const T & signet::forge::expected< T >::value ( ) const &
inline

Access the success value (const lvalue reference).

Precondition
has_value() == true. Asserts in debug builds.
Returns
Const reference to the stored value.

Definition at line 177 of file error.hpp.


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