Loading...
Searching...
No Matches
by::tres< T, R > Class Template Reference

Template result container with typed error information. More...

#include <tres.hpp>

Inheritance diagram for by::tres< T, R >:
by::tmay< T >

Public Member Functions

 tres (const T &value)
 
 tres (const R &value)
 
RgetErr ()
 Gets the contained error.
 
const RgetErr () const BY_CONST_FUNC(getErr()) void rel() override
 Releases/clears both the contained value and the error, making the instance empty.
 
void set (const T &arg) override
 Sets the contained value and clears any existing error.
 
void setErr (const R &arg)
 Sets the contained error and clears any existing value.
 
- Public Member Functions inherited from by::tmay< T >
 tmay (const T &value)
 
 tmay (const tmedium< T > &value)
 
Toperator-> ()
 
const Toperator-> () const BY_CONST_FUNC(operator->())
 
Toperator* ()
 
const Toperator* () const BY_CONST_FUNC(operator*())
 
 operator T& ()
 
 operator const T & () const
 
 operator nbool () const
 
nbool has () const
 
Tget ()
 Gets the contained value.
 
const Tget () const BY_CONST_FUNC(get()) virtual void rel()
 Releases/clears the contained value, making the instance empty.
 

Detailed Description

template<typename T, typename R>
class by::tres< T, R >

Template result container with typed error information.

Identical to tmay but allows defining a custom error type when errors occur. While tmay<T> can only indicate whether an error occurred or not, tres<T, R> can provide detailed error information of type R when an error occurs.

Usage

Example comparing tmay and tres:

// Using tmay - can only tell if error occurred:
if(!result1.has()) {
// Know there's an error, but not what kind
}
// Using tres - can get error details:
if(!result2.has()) {
std::string errorMsg = result2.getErr(); // Get specific error message
BY_E("Parse failed: %s", errorMsg.c_str());
}
#define BY_E(fmt,...)
Log macro: prints debug log on console and file.
Definition macro.hpp:22
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34

Common error types include std::string for error messages, or custom error enums for categorized error handling.

Member Function Documentation

◆ getErr()

template<typename T , typename R >
R & by::tres< T, R >::getErr ( )

Gets the contained error.

Warning
Should only be called when has() returns false. Accessing when has() is true results in undefined behavior.
Returns
A reference to the contained error object.

◆ set()

template<typename T , typename R >
void by::tres< T, R >::set ( const T & arg)
overridevirtual

Sets the contained value and clears any existing error.

Reimplemented from by::tmay< T >.


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