cli20 0.1.2
A C++20 typed-schema command-line parser
Loading...
Searching...
No Matches
cli::ActionResult< T > Struct Template Reference

The result type produced and consumed at each step of an action pipeline. More...

#include <action.hh>

Public Types

enum class  State : std::uint8_t { ok , error , ignore }
using value_type = T

Public Member Functions

constexpr operator bool () const noexcept
 Returns true when the result represents success.
constexpr auto have_value () const noexcept -> bool
 Returns true when the result represents success.
constexpr auto has_value () const noexcept -> bool
 Returns true when the result represents success.
constexpr auto has_error () const noexcept -> bool
 Returns true when the result represents failure.
constexpr auto is_ignored () const noexcept -> bool
 Returns true when the result represents an ignored step.

Static Public Member Functions

template<class U>
static constexpr auto ok (U &&v) -> ActionResult
 Creates a success result holding value.
static constexpr auto fail (ParseError e) -> ActionResult
 Creates a failure result carrying error.
static constexpr auto ignore () -> ActionResult
 Creates an ignore result.

Public Attributes

State state {State::ok}
ParseError error {}
T value {}

Detailed Description

template<class T>
struct cli::ActionResult< T >

The result type produced and consumed at each step of an action pipeline.

An ActionResult<T> is a 3-state type: ok (carrying a value of type T), error (carrying a ParseError), or ignore (silent skip). The operator bool(), have_value(), has_value(), has_error(), and is_ignored() methods make it easy to check the state inline.

Factory methods:

Template Parameters
TThe value type held on success.

Definition at line 48 of file action.hh.

Member Typedef Documentation

◆ value_type

template<class T>
using cli::ActionResult< T >::value_type = T

Definition at line 49 of file action.hh.

Member Enumeration Documentation

◆ State

template<class T>
enum class cli::ActionResult::State : std::uint8_t
strong
Enumerator
ok 
error 
ignore 

Definition at line 51 of file action.hh.

Member Function Documentation

◆ fail()

template<class T>
constexpr auto cli::ActionResult< T >::fail ( ParseError e) -> ActionResult
inlinestaticnodiscardconstexpr

Creates a failure result carrying error.

Parameters
eThe error to store.
Returns
A failed ActionResult<T>.

Definition at line 100 of file action.hh.

◆ has_error()

template<class T>
auto cli::ActionResult< T >::has_error ( ) const -> bool
inlinenodiscardconstexprnoexcept

Returns true when the result represents failure.

Definition at line 73 of file action.hh.

◆ has_value()

template<class T>
auto cli::ActionResult< T >::has_value ( ) const -> bool
inlinenodiscardconstexprnoexcept

Returns true when the result represents success.

Definition at line 68 of file action.hh.

◆ have_value()

template<class T>
auto cli::ActionResult< T >::have_value ( ) const -> bool
inlinenodiscardconstexprnoexcept

Returns true when the result represents success.

Definition at line 63 of file action.hh.

◆ ignore()

template<class T>
constexpr auto cli::ActionResult< T >::ignore ( ) -> ActionResult
inlinestaticnodiscardconstexpr

Creates an ignore result.

Returns
An ignored ActionResult<T>.

Definition at line 109 of file action.hh.

◆ is_ignored()

template<class T>
auto cli::ActionResult< T >::is_ignored ( ) const -> bool
inlinenodiscardconstexprnoexcept

Returns true when the result represents an ignored step.

Definition at line 78 of file action.hh.

◆ ok()

template<class T>
template<class U>
constexpr auto cli::ActionResult< T >::ok ( U && v) -> ActionResult
inlinestaticnodiscardconstexpr

Creates a success result holding value.

Template Parameters
UType of the value (deduced).
Parameters
vThe value to store.
Returns
A successful ActionResult<T>.

Definition at line 90 of file action.hh.

◆ operator bool()

template<class T>
cli::ActionResult< T >::operator bool ( ) const
inlineexplicitnodiscardconstexprnoexcept

Returns true when the result represents success.

Definition at line 58 of file action.hh.

Member Data Documentation

◆ error

template<class T>
ParseError cli::ActionResult< T >::error {}

Definition at line 54 of file action.hh.

◆ state

template<class T>
State cli::ActionResult< T >::state {State::ok}

Definition at line 53 of file action.hh.

◆ value

template<class T>
T cli::ActionResult< T >::value {}

Definition at line 55 of file action.hh.


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