arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::utility::result< ResultType, ExceptionType > Class Template Reference

#include <arg_router/utility/result.hpp>

Public Types

using result_type = std::decay_t< ResultType >
 
using exception_type = ExceptionType
 

Public Member Functions

constexpr result (result_type value) noexcept
 
constexpr result (ExceptionType ex) noexcept
 
constexpr bool has_result () const noexcept
 
constexpr bool has_error () const noexcept
 
constexpr operator bool () const noexcept
 
constexpr bool operator! () const noexcept
 
constexpr bool operator== (const result &other) const noexcept
 
constexpr bool operator!= (const result &other) const noexcept
 
result_typeget_if () noexcept
 
const result_typeget_if () const noexcept
 
result_type extract ()
 
auto get () const -> std::conditional_t<(sizeof(std::size_t) >=sizeof(result_type)) &&std::is_copy_constructible_v< result_type >, result_type, const result_type & >
 
void throw_exception () const
 

Friends

constexpr friend bool operator== (const result &lhs, const result_type &rhs) noexcept
 
constexpr friend bool operator!= (const result &lhs, const result_type &rhs) noexcept
 
constexpr friend bool operator== (const result_type &lhs, const result &rhs) noexcept
 
constexpr friend bool operator!= (const result_type &lhs, const result &rhs) noexcept
 

Detailed Description

template<typename ResultType, typename ExceptionType>
class arg_router::utility::result< ResultType, ExceptionType >

Result or exception wrapper.

Template Parameters
ValueTypeResult type
ExceptionTypeException type

Definition at line 19 of file result.hpp.

Member Typedef Documentation

◆ exception_type

template<typename ResultType , typename ExceptionType >
using arg_router::utility::result< ResultType, ExceptionType >::exception_type = ExceptionType

Exception type.

Definition at line 28 of file result.hpp.

◆ result_type

template<typename ResultType , typename ExceptionType >
using arg_router::utility::result< ResultType, ExceptionType >::result_type = std::decay_t<ResultType>

Result type.

Definition at line 26 of file result.hpp.

Constructor & Destructor Documentation

◆ result() [1/2]

template<typename ResultType , typename ExceptionType >
constexpr arg_router::utility::result< ResultType, ExceptionType >::result ( result_type  value)
inlineconstexprnoexcept

Result constructor.

Parameters
valueResult value

Definition at line 35 of file result.hpp.

◆ result() [2/2]

template<typename ResultType , typename ExceptionType >
constexpr arg_router::utility::result< ResultType, ExceptionType >::result ( ExceptionType  ex)
inlineconstexprnoexcept

Exception constructor.

Parameters
exException

Definition at line 42 of file result.hpp.

Member Function Documentation

◆ extract()

template<typename ResultType , typename ExceptionType >
result_type arg_router::utility::result< ResultType, ExceptionType >::extract ( )
inline

Move the result of this instance, or throw the exception if one is held.

As this method moves the value or exception out of the instance, it should not be called again unless you know the value or exception is not move-constructible.

Returns
Result
Exceptions
ExceptionTypeThrown if the instance holds an exception

Definition at line 168 of file result.hpp.

◆ get()

template<typename ResultType , typename ExceptionType >
auto arg_router::utility::result< ResultType, ExceptionType >::get ( ) const -> std::conditional_t<(sizeof(std::size_t) >= sizeof(result_type)) && std::is_copy_constructible_v<result_type>, result_type, const result_type&>
inline

Returns the the result of this instance, or throw the exception if one is held.

Returns
Result Either a copy of the result, or a const reference to it if the object is larger than a word and trivially constructible
Exceptions
ExceptionTypeThrown if the instance holds an exception

Definition at line 182 of file result.hpp.

◆ get_if() [1/2]

template<typename ResultType , typename ExceptionType >
const result_type* arg_router::utility::result< ResultType, ExceptionType >::get_if ( ) const
inlinenoexcept

Const overload

Returns
Pointer to the result, or nullptr

Definition at line 156 of file result.hpp.

◆ get_if() [2/2]

template<typename ResultType , typename ExceptionType >
result_type* arg_router::utility::result< ResultType, ExceptionType >::get_if ( )
inlinenoexcept

Returns a pointer to the result, or nullptr if this instance holds an exception.

Returns
Pointer to the result, or nullptr

Definition at line 147 of file result.hpp.

◆ has_error()

template<typename ResultType , typename ExceptionType >
constexpr bool arg_router::utility::result< ResultType, ExceptionType >::has_error ( ) const
inlineconstexprnoexcept

True if this instance holds an exception.

Returns
True if exception

Definition at line 54 of file result.hpp.

◆ has_result()

template<typename ResultType , typename ExceptionType >
constexpr bool arg_router::utility::result< ResultType, ExceptionType >::has_result ( ) const
inlineconstexprnoexcept

True if this instance holds a result.

Returns
True if result

Definition at line 48 of file result.hpp.

◆ operator bool()

template<typename ResultType , typename ExceptionType >
constexpr arg_router::utility::result< ResultType, ExceptionType >::operator bool ( ) const
inlineexplicitconstexprnoexcept

True if this instance holds a result.

Returns
True if result

Definition at line 60 of file result.hpp.

◆ operator!()

template<typename ResultType , typename ExceptionType >
constexpr bool arg_router::utility::result< ResultType, ExceptionType >::operator! ( ) const
inlineconstexprnoexcept

True if this instance holds an exception.

Returns
True if exception

Definition at line 66 of file result.hpp.

◆ operator!=()

template<typename ResultType , typename ExceptionType >
constexpr bool arg_router::utility::result< ResultType, ExceptionType >::operator!= ( const result< ResultType, ExceptionType > &  other) const
inlineconstexprnoexcept

Inequality operator

Parameters
otherInstance to compare against
Returns
True if not the same value, true if either carry exceptions

Definition at line 86 of file result.hpp.

◆ operator==()

template<typename ResultType , typename ExceptionType >
constexpr bool arg_router::utility::result< ResultType, ExceptionType >::operator== ( const result< ResultType, ExceptionType > &  other) const
inlineconstexprnoexcept

Equality operator

Parameters
otherInstance to compare against
Returns
True if the same value, false if either carry exceptions

Definition at line 73 of file result.hpp.

◆ throw_exception()

template<typename ResultType , typename ExceptionType >
void arg_router::utility::result< ResultType, ExceptionType >::throw_exception ( ) const
inline

Throws the exception if present, otherwise does nothing.

Exceptions
ExceptionTypeThrown if the instance holds an exception

Definition at line 198 of file result.hpp.

Friends And Related Function Documentation

◆ operator!= [1/2]

template<typename ResultType , typename ExceptionType >
constexpr friend bool operator!= ( const result< ResultType, ExceptionType > &  lhs,
const result_type rhs 
)
friend

Result type inequality operator

Parameters
lhsInstance to compare against
rhsValue instance to compare against
Returns
True if not the same value, false if either carry exceptions

Definition at line 112 of file result.hpp.

◆ operator!= [2/2]

template<typename ResultType , typename ExceptionType >
constexpr friend bool operator!= ( const result_type lhs,
const result< ResultType, ExceptionType > &  rhs 
)
friend

Result type inequality operator

Parameters
lhsInstance to compare against
rhsValue instance to compare against
Returns
True if not the same value, false if either carry exceptions

Definition at line 136 of file result.hpp.

◆ operator== [1/2]

template<typename ResultType , typename ExceptionType >
constexpr friend bool operator== ( const result< ResultType, ExceptionType > &  lhs,
const result_type rhs 
)
friend

Result type equality operator

Parameters
lhsInstance to compare against
rhsValue instance to compare against
Returns
True if the same value, false if either carry exceptions

Definition at line 97 of file result.hpp.

◆ operator== [2/2]

template<typename ResultType , typename ExceptionType >
constexpr friend bool operator== ( const result_type lhs,
const result< ResultType, ExceptionType > &  rhs 
)
friend

Result type equality operator

Parameters
lhsValue Instance to compare against
rhsInstance to compare against
Returns
True if the same value, false if either carry exceptions

Definition at line 124 of file result.hpp.


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