JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
JKQTPExpected< T, E > Struct Template Reference

an "expected" datatype, which can either represent a function result of type T or an error of type E More...

#include <jkqtpexpected.h>

Public Member Functions

 JKQTPExpected ()=delete
 
 JKQTPExpected (const JKQTPExpected< T, E > &other)=default
 
 JKQTPExpected (const T &value_)
 
 JKQTPExpected (JKQTPExpectedUnexpectedType, const E &error_)
 
const E & error () const
 
bool has_value () const
 
 operator bool () const
 
const T & value () const
 

Private Attributes

const E m_error
 
const bool m_hasValue
 
const T m_value
 

Detailed Description

template<class T, class E>
struct JKQTPExpected< T, E >

an "expected" datatype, which can either represent a function result of type T or an error of type E

Usage example:

bool ok=false;
int i=s.toInt(&ok);
if (ok) return {i}
else return { JKQTPUnexpected, QString("cannot convert to int") };
}
auto r=toInt("1.0a");
if (r.hasValue()) qDebug()<<"SUCCESS! i="<<r.value();
else qDebug()<<"FAILURE: "<<r.error();
#define JKQTPUnexpected
tag for an unexpected/error result in JKQTPExpected
Definition jkqtpexpected.h:38
an "expected" datatype, which can either represent a function result of type T or an error of type E
Definition jkqtpexpected.h:61
See also
JKQTPExpectedUnexpectedType, JKQTPUnexpected

Constructor & Destructor Documentation

◆ JKQTPExpected() [1/4]

template<class T , class E >
JKQTPExpected< T, E >::JKQTPExpected ( )
delete

◆ JKQTPExpected() [2/4]

template<class T , class E >
JKQTPExpected< T, E >::JKQTPExpected ( const T &  value_)
inline

◆ JKQTPExpected() [3/4]

template<class T , class E >
JKQTPExpected< T, E >::JKQTPExpected ( const JKQTPExpected< T, E > &  other)
default

◆ JKQTPExpected() [4/4]

template<class T , class E >
JKQTPExpected< T, E >::JKQTPExpected ( JKQTPExpectedUnexpectedType  ,
const E &  error_ 
)
inline

Member Function Documentation

◆ error()

template<class T , class E >
const E & JKQTPExpected< T, E >::error ( ) const
inline

◆ has_value()

template<class T , class E >
bool JKQTPExpected< T, E >::has_value ( ) const
inline

◆ operator bool()

template<class T , class E >
JKQTPExpected< T, E >::operator bool ( ) const
inline

◆ value()

template<class T , class E >
const T & JKQTPExpected< T, E >::value ( ) const
inline

Member Data Documentation

◆ m_error

template<class T , class E >
const E JKQTPExpected< T, E >::m_error
private

◆ m_hasValue

template<class T , class E >
const bool JKQTPExpected< T, E >::m_hasValue
private

◆ m_value

template<class T , class E >
const T JKQTPExpected< T, E >::m_value
private

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