MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Mcro::Error::TMaybe< T > Struct Template Reference

A TValueOrError alternative for IError which allows implicit conversion from values and errors (no need for MakeError or MakeValue) and is boolean testable. It also doesn't have ambiguous state such as TValueOrError has, so a TMaybe will always have either an error or a value, it will never have neither of them or both of them. More...

#include <Error.h>

Public Types

using ValueType = T
 

Public Member Functions

template<typename = T>
requires (!CDefaultInitializable<T>)
 TMaybe ()
 Default initializing a TMaybe while its value is not default initializable, initializes the resulting TMaybe to an erroneous state.
 
template<CDefaultInitializable = T>
 TMaybe ()
 If T is default initializable then the default state of TMaybe will be the default value of T, and not an error.
 
template<CConvertibleToDecayed< T > From, CCopyConstructible = T>
 TMaybe (From const &value)
 Enable copy constructor for T only when T is copy constructable.
 
template<CConvertibleToDecayed< T > From, CMoveConstructible = T>
 TMaybe (From &&value)
 Enable move constructor for T only when T is move constructable.
 
template<CConvertibleToDecayed< T > From, CCopyConstructible = T>
 TMaybe (TMaybe< From > const &other)
 Enable copy constructor for TMaybe only when T is copy constructable.
 
template<CConvertibleToDecayed< T > From, CMoveConstructible = T>
 TMaybe (TMaybe< From > &&other)
 Enable move constructor for TMaybe only when T is move constructable.
 
template<CError ErrorType>
 TMaybe (TSharedRef< ErrorType > const &error)
 Set this TMaybe to an erroneous state.
 
bool HasValue () const
 
bool HasError () const
 
auto TryGetValue () -> TOptional< T > &
 
auto TryGetValue () const -> TOptional< T > const &
 
auto GetValue () -> T &
 
auto GetValue () const -> T const &
 
T && StealValue () &&
 
auto GetError () const -> IErrorPtr
 
auto GetErrorRef () const -> IErrorRef
 
 operator bool () const
 
template<typename Self , CFunctionCompatible_ArgumentsDecay< void(IErrorRef)> Function>
Self && ModifyError (this Self &&self, Function &&mod)
 Modify a potential error stored in this monad.
 
 operator TValueOrError< T, IErrorPtr > () const
 

Detailed Description

template<CNonVoid T>
struct Mcro::Error::TMaybe< T >

A TValueOrError alternative for IError which allows implicit conversion from values and errors (no need for MakeError or MakeValue) and is boolean testable. It also doesn't have ambiguous state such as TValueOrError has, so a TMaybe will always have either an error or a value, it will never have neither of them or both of them.

Definition at line 589 of file Error.h.

Member Typedef Documentation

◆ ValueType

template<CNonVoid T>
using Mcro::Error::TMaybe< T >::ValueType = T

Definition at line 591 of file Error.h.

Constructor & Destructor Documentation

◆ TMaybe() [1/7]

template<CNonVoid T>
template<typename = T>
requires (!CDefaultInitializable<T>)
Mcro::Error::TMaybe< T >::TMaybe ( )
inline

Default initializing a TMaybe while its value is not default initializable, initializes the resulting TMaybe to an erroneous state.

Definition at line 600 of file Error.h.

◆ TMaybe() [2/7]

template<CNonVoid T>
template<CDefaultInitializable = T>
Mcro::Error::TMaybe< T >::TMaybe ( )
inline

If T is default initializable then the default state of TMaybe will be the default value of T, and not an error.

Definition at line 609 of file Error.h.

◆ TMaybe() [3/7]

template<CNonVoid T>
template<CConvertibleToDecayed< T > From, CCopyConstructible = T>
Mcro::Error::TMaybe< T >::TMaybe ( From const & value)
inline

Enable copy constructor for T only when T is copy constructable.

Definition at line 613 of file Error.h.

◆ TMaybe() [4/7]

template<CNonVoid T>
template<CConvertibleToDecayed< T > From, CMoveConstructible = T>
Mcro::Error::TMaybe< T >::TMaybe ( From && value)
inline

Enable move constructor for T only when T is move constructable.

Definition at line 617 of file Error.h.

◆ TMaybe() [5/7]

template<CNonVoid T>
template<CConvertibleToDecayed< T > From, CCopyConstructible = T>
Mcro::Error::TMaybe< T >::TMaybe ( TMaybe< From > const & other)
inline

Enable copy constructor for TMaybe only when T is copy constructable.

Definition at line 621 of file Error.h.

◆ TMaybe() [6/7]

template<CNonVoid T>
template<CConvertibleToDecayed< T > From, CMoveConstructible = T>
Mcro::Error::TMaybe< T >::TMaybe ( TMaybe< From > && other)
inline

Enable move constructor for TMaybe only when T is move constructable.

Definition at line 625 of file Error.h.

◆ TMaybe() [7/7]

template<CNonVoid T>
template<CError ErrorType>
Mcro::Error::TMaybe< T >::TMaybe ( TSharedRef< ErrorType > const & error)
inline

Set this TMaybe to an erroneous state.

Definition at line 629 of file Error.h.

Member Function Documentation

◆ GetError()

template<CNonVoid T>
auto Mcro::Error::TMaybe< T >::GetError ( ) const -> IErrorPtr
inline

Definition at line 642 of file Error.h.

◆ GetErrorRef()

template<CNonVoid T>
auto Mcro::Error::TMaybe< T >::GetErrorRef ( ) const -> IErrorRef
inline

Definition at line 643 of file Error.h.

◆ GetValue() [1/2]

template<CNonVoid T>
auto Mcro::Error::TMaybe< T >::GetValue ( ) -> T&
inline

Definition at line 637 of file Error.h.

◆ GetValue() [2/2]

template<CNonVoid T>
auto Mcro::Error::TMaybe< T >::GetValue ( ) const -> T const&
inline

Definition at line 638 of file Error.h.

◆ HasError()

template<CNonVoid T>
bool Mcro::Error::TMaybe< T >::HasError ( ) const
inline

Definition at line 632 of file Error.h.

◆ HasValue()

template<CNonVoid T>
bool Mcro::Error::TMaybe< T >::HasValue ( ) const
inline

Definition at line 631 of file Error.h.

◆ ModifyError()

template<CNonVoid T>
template<typename Self , CFunctionCompatible_ArgumentsDecay< void(IErrorRef)> Function>
Self && Mcro::Error::TMaybe< T >::ModifyError ( this Self && self,
Function && mod )
inline

Modify a potential error stored in this monad.

Template Parameters
SelfDeducing this
FunctionModifying function type
Parameters
selfDeducing this
modInput function modifying a potential error
Returns
Self, preserving qualifiers.

Definition at line 656 of file Error.h.

◆ operator bool()

template<CNonVoid T>
Mcro::Error::TMaybe< T >::operator bool ( ) const
inline

Definition at line 645 of file Error.h.

◆ operator TValueOrError< T, IErrorPtr >()

template<CNonVoid T>
Mcro::Error::TMaybe< T >::operator TValueOrError< T, IErrorPtr > ( ) const
inline

Definition at line 662 of file Error.h.

◆ StealValue()

template<CNonVoid T>
T && Mcro::Error::TMaybe< T >::StealValue ( ) &&
inline

Definition at line 640 of file Error.h.

◆ TryGetValue() [1/2]

template<CNonVoid T>
auto Mcro::Error::TMaybe< T >::TryGetValue ( ) -> TOptional<T>&
inline

Definition at line 634 of file Error.h.

◆ TryGetValue() [2/2]

template<CNonVoid T>
auto Mcro::Error::TMaybe< T >::TryGetValue ( ) const -> TOptional<T> const&
inline

Definition at line 635 of file Error.h.


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