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

The result returned by Parser::parse() and the free cli::parse() function. More...

#include <parser.hh>

Public Member Functions

constexpr operator bool () const noexcept
 Returns true when parsing succeeded.
constexpr auto has_value () const noexcept -> bool
 Returns true when parsing succeeded.
constexpr auto has_error () const noexcept -> bool
 Returns true when parsing failed.

Static Public Member Functions

template<class U>
static constexpr auto ok (U &&value) -> ParseResult< T >
 Creates a success result holding value.
static constexpr auto fail (ParseError error) -> ParseResult< T >
 Creates a failure result carrying error.

Public Attributes

T value {}
 The parsed argument struct (valid only when has_value() is true).
ParseError error {}
 The error details (valid only when has_error() is true).

Detailed Description

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

The result returned by Parser::parse() and the free cli::parse() function.

On success, value holds the fully populated argument specification struct and error is in the default (no-error) state. On failure, error describes what went wrong and value is in a partially-initialised (unusable) state.

Typical usage:

auto result = cli::parse<MyArgs>(argc, argv);
if (!result) {
std::cerr << result.error.message() << '\n';
return 1;
}
// use result.value …
Template Parameters
TThe argument specification type.

Definition at line 661 of file parser.hh.

Member Function Documentation

◆ fail()

template<class T>
constexpr auto cli::ParseResult< T >::fail ( ParseError error) -> ParseResult< T >
inlinestaticnodiscardconstexpr

Creates a failure result carrying error.

Parameters
errorThe error to store.
Returns
A failed ParseResult<T>.

Definition at line 708 of file parser.hh.

◆ has_error()

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

Returns true when parsing failed.

Definition at line 681 of file parser.hh.

◆ has_value()

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

Returns true when parsing succeeded.

Definition at line 675 of file parser.hh.

◆ ok()

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

Creates a success result holding value.

Template Parameters
UType of the value (deduced).
Parameters
valueThe parsed argument struct to store.
Returns
A successful ParseResult<T>.

Definition at line 694 of file parser.hh.

◆ operator bool()

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

Returns true when parsing succeeded.

Definition at line 669 of file parser.hh.

Member Data Documentation

◆ error

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

The error details (valid only when has_error() is true).

Definition at line 665 of file parser.hh.

◆ value

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

The parsed argument struct (valid only when has_value() is true).

Definition at line 662 of file parser.hh.


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