STX  1.0.0
Macros
try.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define STX_TRY__UTIL_JOIN_(x, y)   x##_##y
 
#define STX_WITH_UNIQUE_SUFFIX_(x, y)   STX_TRY__UTIL_JOIN_(x, y)
 
#define STX_TRY_OK_IMPL_(STX_ARG_UNIQUE_PLACEHOLDER, qualifier_identifier, result_expr)
 
#define STX_TRY_SOME_IMPL_(STX_ARG_UNIQUE_PLACEHOLDER, qualifier_identifier, option_expr)
 
#define TRY_OK(qualifier_identifier, result_expr)
 
#define TRY_SOME(qualifier_identifier, option_expr)
 

Detailed Description

Error Propagation Macros

Macro Definition Documentation

◆ STX_TRY__UTIL_JOIN_

#define STX_TRY__UTIL_JOIN_ (   x,
 
)    x##_##y

◆ STX_TRY_OK_IMPL_

#define STX_TRY_OK_IMPL_ (   STX_ARG_UNIQUE_PLACEHOLDER,
  qualifier_identifier,
  result_expr 
)
Value:
static_assert(!::std::is_const_v<decltype((result_expr))>, \
"the expression: ' " #result_expr \
" ' evaluates to a const and is not mutable"); \
static_assert( \
!::std::is_lvalue_reference_v<decltype((result_expr))>, \
"the expression: ' " #result_expr \
" ' evaluates to an l-value reference, 'TRY_OK' only accepts r-values " \
"and r-value references "); \
decltype((result_expr))&& STX_ARG_UNIQUE_PLACEHOLDER = (result_expr); \
\
if (STX_ARG_UNIQUE_PLACEHOLDER.is_err()) \
return ::stx::Err<decltype((result_expr))::error_type>( \
::stx::internal::result::unsafe_err_move(STX_ARG_UNIQUE_PLACEHOLDER)); \
\
decltype((result_expr))::value_type qualifier_identifier = \
::stx::internal::result::unsafe_value_move(STX_ARG_UNIQUE_PLACEHOLDER);
Tp && unsafe_value_move(Option< Tp > &)
Er && unsafe_err_move(Result< Tp, Er > &)
Definition: backtrace.h:45

◆ STX_TRY_SOME_IMPL_

#define STX_TRY_SOME_IMPL_ (   STX_ARG_UNIQUE_PLACEHOLDER,
  qualifier_identifier,
  option_expr 
)
Value:
static_assert(!::std::is_const_v<decltype((option_expr))>, \
"the expression: ' " #option_expr \
" ' evaluates to a const and is not mutable"); \
static_assert(!::std::is_lvalue_reference_v<decltype((option_expr))>, \
"the expression: ' " #option_expr \
" ' evaluates to an l-value reference, 'TRY_SOME' only " \
"accepts r-values " \
"and r-value references "); \
decltype((option_expr))&& STX_ARG_UNIQUE_PLACEHOLDER = (option_expr); \
\
if (STX_ARG_UNIQUE_PLACEHOLDER.is_none()) return ::stx::None; \
\
decltype((option_expr))::value_type qualifier_identifier = \
::stx::internal::option::unsafe_value_move(STX_ARG_UNIQUE_PLACEHOLDER);
constexpr NoneType const None
value-variant for Option<T> representing no-value
Definition: option_result.h:127
Tp && unsafe_value_move(Option< Tp > &)
Definition: backtrace.h:45

◆ STX_WITH_UNIQUE_SUFFIX_

#define STX_WITH_UNIQUE_SUFFIX_ (   x,
 
)    STX_TRY__UTIL_JOIN_(x, y)

◆ TRY_OK

#define TRY_OK (   qualifier_identifier,
  result_expr 
)
Value:
STX_WITH_UNIQUE_SUFFIX_(STX_TRY_OK_PLACEHOLDER, __COUNTER__), \
qualifier_identifier, result_expr)
#define STX_WITH_UNIQUE_SUFFIX_(x, y)
Definition: try.h:64
#define STX_TRY_OK_IMPL_(STX_ARG_UNIQUE_PLACEHOLDER, qualifier_identifier, result_expr)
Definition: try.h:66

if result_expr is a Result containing an error, TRY_OK returns its Err value.

result_expr must be an expression yielding an r-value (reference) of type Result

◆ TRY_SOME

#define TRY_SOME (   qualifier_identifier,
  option_expr 
)
Value:
STX_WITH_UNIQUE_SUFFIX_(STX_TRY_SOME_PLACEHOLDER, __COUNTER__), \
qualifier_identifier, option_expr)
#define STX_WITH_UNIQUE_SUFFIX_(x, y)
Definition: try.h:64
#define STX_TRY_SOME_IMPL_(STX_ARG_UNIQUE_PLACEHOLDER, qualifier_identifier, option_expr)
Definition: try.h:85

if option_expr evaluates to an Option containing a None, TRY_SOME returns its None value.

option_expr must be an expression yielding an r-value (reference) of type Option