Spicy
Public Member Functions | Friends | List of all members
hilti::rt::Result< T > Class Template Reference

#include <result.h>

Public Member Functions

 Result (const T &t)
 
 Result (T &&t)
 
 Result (const result::Error &e)
 
 Result (result::Error &&e)
 
 Result (const Result &o)=default
 
 Result (Result &&o)=default
 
const T & value () const
 
T & value ()
 
const T & valueOrThrow () const
 
T & valueOrThrow ()
 
const result::Errorerror () const
 
const result::ErrorerrorOrThrow () const
 
bool hasValue () const
 
const T & operator* () const
 
T & operator* ()
 
const T * operator-> () const
 
T * operator-> ()
 
 operator bool () const
 
 operator std::optional< T > () const
 
Resultoperator= (const Result &other)=default
 
Resultoperator= (Result &&other)=default
 

Friends

bool operator== (const Result &a, const Result &b)
 
bool operator!= (const Result &a, const Result &b)
 

Detailed Description

template<typename T>
class hilti::rt::Result< T >

Represents either a successful result from function if it returned one, or reflects an error if the function was unsuccessful.

Constructor & Destructor Documentation

◆ Result() [1/4]

template<typename T>
hilti::rt::Result< T >::Result ( const T &  t)
inline

Creates a successful result from a value.

◆ Result() [2/4]

template<typename T>
hilti::rt::Result< T >::Result ( T &&  t)
inline

Creates a successful result from a value.

◆ Result() [3/4]

template<typename T>
hilti::rt::Result< T >::Result ( const result::Error e)
inline

Creates an result reflecting an error.

◆ Result() [4/4]

template<typename T>
hilti::rt::Result< T >::Result ( result::Error &&  e)
inline

Creates an result reflecting an error.

Member Function Documentation

◆ error()

template<typename T>
const result::Error& hilti::rt::Result< T >::error ( ) const
inline

Returns the result's error, assuming it reflect one.

Exceptions
<tt>std::bad_variant_access</tt>if the result doe not reflect an error state

◆ errorOrThrow()

template<typename T>
const result::Error& hilti::rt::Result< T >::errorOrThrow ( ) const
inline

Returns the result's error if it indicates failure, or throws an exception if not.

Exceptions
<tt>result::NoError</tt>if the result does not reflect an error state

◆ hasValue()

template<typename T>
bool hilti::rt::Result< T >::hasValue ( ) const
inline

Returns true if the result represents a successful return value.

◆ operator bool()

template<typename T>
hilti::rt::Result< T >::operator bool ( ) const
inlineexplicit

Returns true if the result represents a successful return value.

◆ operator std::optional< T >()

template<typename T>
hilti::rt::Result< T >::operator std::optional< T > ( ) const
inline

Converts the result to an optional that's set if it represents a successful return value.

◆ operator*() [1/2]

template<typename T>
const T& hilti::rt::Result< T >::operator* ( ) const
inline

Returns the result's value, assuming it indicates success.

◆ operator*() [2/2]

template<typename T>
T& hilti::rt::Result< T >::operator* ( )
inline

Returns the result's value, assuming it indicates success.

◆ operator->() [1/2]

template<typename T>
const T* hilti::rt::Result< T >::operator-> ( ) const
inline

Returns the result's value, assuming it indicates success.

◆ operator->() [2/2]

template<typename T>
T* hilti::rt::Result< T >::operator-> ( )
inline

Returns the result's value, assuming it indicates success.

◆ value() [1/2]

template<typename T>
const T& hilti::rt::Result< T >::value ( ) const
inline

Returns the result's value, assuming it indicates success.

Exceptions
<tt>std::bad_variant_access</tt>if the result reflects an error state

◆ value() [2/2]

template<typename T>
T& hilti::rt::Result< T >::value ( )
inline

Returns the result's value, assuming it indicates success.

Exceptions
<tt>std::bad_variant_access</tt>if the result reflects an error state

◆ valueOrThrow() [1/2]

template<typename T>
const T& hilti::rt::Result< T >::valueOrThrow ( ) const
inline

Returns the result's value if it indicates success, or throws an exception if not.

Exceptions
<tt>result::NoResult</tt>if the result reflects an error state

◆ valueOrThrow() [2/2]

template<typename T>
T& hilti::rt::Result< T >::valueOrThrow ( )
inline

Returns the result's value if it indicates success, or throws an exception if not.

Exceptions
<tt>result::NoResult</tt>if the result reflects an error state

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