zpp
Zephyr C++20 Framework
zpp::result< void, T_Error > Class Template Reference

result class More...

#include <result.hpp>

Public Member Functions

 result () noexcept=default
 default initialization to error state More...
 
 result (const error_result< T_Error > &rhs) noexcept
 initialization to error state More...
 
 result (error_result< T_Error > &&rhs) noexcept
 
 result (const result &rhs) noexcept=default
 copy contructor More...
 
 result (result &&rhs) noexcept=default
 move contructor More...
 
 ~result () noexcept=default
 destructor More...
 
resultoperator= (const result &rhs) noexcept=default
 copy operator More...
 
resultoperator= (result &&rhs) noexcept=default
 move operator More...
 
void assign_value () noexcept
 
void assign_error (const T_Error &e) noexcept
 
void assign_error (T_Error &&e) noexcept
 
resultoperator= (const error_result< T_Error > &rhs) noexcept
 copy operator More...
 
resultoperator= (error_result< T_Error > &&rhs) noexcept
 move operator More...
 
void value () noexcept
 return a reference to the OK value More...
 
void value () const noexcept
 return a const reference to the result value More...
 
T_Error & error () noexcept
 return a reference to the OK value More...
 
const T_Error & error () const noexcept
 return a const reference to the result value More...
 
constexpr bool has_value () const noexcept
 convert the result to a bool More...
 
constexpr operator bool () const noexcept
 convert the result to a bool More...
 

Detailed Description

template<typename T_Error>
class zpp::result< void, T_Error >

result class

Parameters
T_Okthe type for the OK result
T_Errorthe type for the error result

Definition at line 467 of file result.hpp.

Constructor & Destructor Documentation

◆ result() [1/5]

template<typename T_Error >
zpp::result< void, T_Error >::result ( )
defaultnoexcept

default initialization to error state

◆ result() [2/5]

template<typename T_Error >
zpp::result< void, T_Error >::result ( const error_result< T_Error > &  rhs)
inlinenoexcept

initialization to error state

Parameters
rhsthe error value to assign

Definition at line 484 of file result.hpp.

485  : m_is_ok(false)
486  , m_error_value( rhs.error() )
487  {
488  }

◆ result() [3/5]

template<typename T_Error >
zpp::result< void, T_Error >::result ( error_result< T_Error > &&  rhs)
inlinenoexcept

Definition at line 490 of file result.hpp.

491  : m_is_ok(false)
492  , m_error_value( std::move(rhs.error()) )
493  {
494  }

◆ result() [4/5]

template<typename T_Error >
zpp::result< void, T_Error >::result ( const result< void, T_Error > &  rhs)
defaultnoexcept

copy contructor

Parameters
rhsthe value to assign

◆ result() [5/5]

template<typename T_Error >
zpp::result< void, T_Error >::result ( result< void, T_Error > &&  rhs)
defaultnoexcept

move contructor

Parameters
rhsthe value to assign

◆ ~result()

template<typename T_Error >
zpp::result< void, T_Error >::~result ( )
defaultnoexcept

destructor

Member Function Documentation

◆ assign_error() [1/2]

template<typename T_Error >
void zpp::result< void, T_Error >::assign_error ( const T_Error &  e)
inlinenoexcept

Definition at line 534 of file result.hpp.

534  {
535  m_is_ok = false;
536  m_error_value = T_Error(e);
537  }

References zpp::result< T_Ok, T_Error >::m_error_value.

◆ assign_error() [2/2]

template<typename T_Error >
void zpp::result< void, T_Error >::assign_error ( T_Error &&  e)
inlinenoexcept

Definition at line 539 of file result.hpp.

539  {
540  m_is_ok = false;
541  m_error_value = T_Error(std::move(e));
542  }

References zpp::result< T_Ok, T_Error >::m_error_value.

◆ assign_value()

template<typename T_Error >
void zpp::result< void, T_Error >::assign_value ( )
inlinenoexcept

Definition at line 530 of file result.hpp.

530  {
531  m_is_ok = true;
532  }

◆ error() [1/2]

template<typename T_Error >
const T_Error& zpp::result< void, T_Error >::error ( ) const
inlinenoexcept

return a const reference to the result value

Returns
T_Ok const reference
Warning
when the result is in error state the the thread will terminate

Definition at line 614 of file result.hpp.

614  {
615  if (m_is_ok) {
616  // unhandeld error
617  }
618 
619  return m_error_value;
620  }

References zpp::result< T_Ok, T_Error >::m_error_value.

◆ error() [2/2]

template<typename T_Error >
T_Error& zpp::result< void, T_Error >::error ( )
inlinenoexcept

return a reference to the OK value

Returns
T_Ok reference
Warning
when the result is in error state the the thread will terminate

Definition at line 599 of file result.hpp.

599  {
600  if (m_is_ok) {
601  // unhandeld error
602  }
603 
604  return m_error_value;
605  }

References zpp::result< T_Ok, T_Error >::m_error_value.

◆ has_value()

template<typename T_Error >
constexpr bool zpp::result< void, T_Error >::has_value ( ) const
inlineconstexprnoexcept

convert the result to a bool

Returns
true if the result is valid

Definition at line 627 of file result.hpp.

627  {
628  return m_is_ok;
629  }

◆ operator bool()

template<typename T_Error >
constexpr zpp::result< void, T_Error >::operator bool ( ) const
inlineexplicitconstexprnoexcept

convert the result to a bool

Returns
true if the result is valid

Definition at line 636 of file result.hpp.

636  {
637  return m_is_ok;
638  }

◆ operator=() [1/4]

template<typename T_Error >
result& zpp::result< void, T_Error >::operator= ( const error_result< T_Error > &  rhs)
inlinenoexcept

copy operator

Parameters
rhsthe value to assign

Definition at line 549 of file result.hpp.

550  {
551  assign_error(rhs.error());
552  return *this;
553  }
void assign_error(const T_Error &e) noexcept
Definition: result.hpp:534

References zpp::result< T_Ok, T_Error >::assign_error().

◆ operator=() [2/4]

template<typename T_Error >
result& zpp::result< void, T_Error >::operator= ( const result< void, T_Error > &  rhs)
defaultnoexcept

copy operator

Parameters
rhsthe value to assign

◆ operator=() [3/4]

template<typename T_Error >
result& zpp::result< void, T_Error >::operator= ( error_result< T_Error > &&  rhs)
inlinenoexcept

move operator

Parameters
rhsthe value to assign

Definition at line 560 of file result.hpp.

561  {
562  assign_error(std::move(rhs.error()));
563  return *this;
564  }

References zpp::result< T_Ok, T_Error >::assign_error().

◆ operator=() [4/4]

template<typename T_Error >
result& zpp::result< void, T_Error >::operator= ( result< void, T_Error > &&  rhs)
defaultnoexcept

move operator

Parameters
rhsthe value to assign

◆ value() [1/2]

template<typename T_Error >
void zpp::result< void, T_Error >::value ( ) const
inlinenoexcept

return a const reference to the result value

Returns
T_Ok const reference
Warning
when the result is in error state the the thread will terminate

Definition at line 586 of file result.hpp.

586  {
587  if (!m_is_ok) {
588  // unhandeld error
589  }
590  }

◆ value() [2/2]

template<typename T_Error >
void zpp::result< void, T_Error >::value ( )
inlinenoexcept

return a reference to the OK value

Returns
T_Ok reference
Warning
when the result is in error state the the thread will terminate

Definition at line 573 of file result.hpp.

573  {
574  if (!m_is_ok) {
575  // unhandeld error
576  }
577  }

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