42 template <
typename Tp,
typename Er>
44 Result<Tp, Er>& result) {
45 return std::move(result.value_ref_());
48 template <
typename Tp,
typename Er>
50 Result<Tp, Er>& result) {
51 return std::move(result.err_ref_());
54 template <
typename Tp>
56 return std::move(option.value_ref_());
63 #define STX_TRY__UTIL_JOIN_(x, y) x##_##y 64 #define STX_WITH_UNIQUE_SUFFIX_(x, y) STX_TRY__UTIL_JOIN_(x, y) 66 #define STX_TRY_OK_IMPL_(STX_ARG_UNIQUE_PLACEHOLDER, qualifier_identifier, \ 68 static_assert(!::std::is_const_v<decltype((result_expr))>, \ 69 "the expression: ' " #result_expr \ 70 " ' evaluates to a const and is not mutable"); \ 72 !::std::is_lvalue_reference_v<decltype((result_expr))>, \ 73 "the expression: ' " #result_expr \ 74 " ' evaluates to an l-value reference, 'TRY_OK' only accepts r-values " \ 75 "and r-value references "); \ 76 decltype((result_expr))&& STX_ARG_UNIQUE_PLACEHOLDER = (result_expr); \ 78 if (STX_ARG_UNIQUE_PLACEHOLDER.is_err()) \ 79 return ::stx::Err<decltype((result_expr))::error_type>( \ 80 ::stx::internal::result::unsafe_err_move(STX_ARG_UNIQUE_PLACEHOLDER)); \ 82 decltype((result_expr))::value_type qualifier_identifier = \ 83 ::stx::internal::result::unsafe_value_move(STX_ARG_UNIQUE_PLACEHOLDER); 85 #define STX_TRY_SOME_IMPL_(STX_ARG_UNIQUE_PLACEHOLDER, qualifier_identifier, \ 87 static_assert(!::std::is_const_v<decltype((option_expr))>, \ 88 "the expression: ' " #option_expr \ 89 " ' evaluates to a const and is not mutable"); \ 90 static_assert(!::std::is_lvalue_reference_v<decltype((option_expr))>, \ 91 "the expression: ' " #option_expr \ 92 " ' evaluates to an l-value reference, 'TRY_SOME' only " \ 94 "and r-value references "); \ 95 decltype((option_expr))&& STX_ARG_UNIQUE_PLACEHOLDER = (option_expr); \ 97 if (STX_ARG_UNIQUE_PLACEHOLDER.is_none()) return ::stx::None; \ 99 decltype((option_expr))::value_type qualifier_identifier = \ 100 ::stx::internal::option::unsafe_value_move(STX_ARG_UNIQUE_PLACEHOLDER); 107 #define TRY_OK(qualifier_identifier, result_expr) \ 109 STX_WITH_UNIQUE_SUFFIX_(STX_TRY_OK_PLACEHOLDER, __COUNTER__), \ 110 qualifier_identifier, result_expr) 117 #define TRY_SOME(qualifier_identifier, option_expr) \ 118 STX_TRY_SOME_IMPL_( \ 119 STX_WITH_UNIQUE_SUFFIX_(STX_TRY_SOME_PLACEHOLDER, __COUNTER__), \ 120 qualifier_identifier, option_expr) 124 #if defined(__cpp_coroutines) || defined(__cpp_lib_coroutine) 126 #define STX_CO_TRY_OK_IMPL_(STX_ARG_UNIQUE_PLACEHOLDER, qualifier_identifier, \ 128 static_assert(!::std::is_const_v<decltype((result_expr))>, \ 129 "the expression: ' " #result_expr \ 130 " ' evaluates to a const and is not mutable"); \ 131 static_assert(!::std::is_lvalue_reference_v<decltype((result_expr))>, \ 132 "the expression: ' " #result_expr \ 133 " ' evaluates to an l-value reference, 'CO_TRY_OK' only " \ 134 "accepts r-values " \ 135 "and r-value references "); \ 136 decltype((result_expr))&& STX_ARG_UNIQUE_PLACEHOLDER = (result_expr); \ 138 if (STX_ARG_UNIQUE_PLACEHOLDER.is_err()) \ 139 co_return ::stx::Err<decltype((result_expr))::error_type>( \ 140 ::stx::internal::result::unsafe_err_move(STX_ARG_UNIQUE_PLACEHOLDER)); \ 142 decltype((result_expr))::value_type qualifier_identifier = \ 143 ::stx::internal::result::unsafe_value_move(STX_ARG_UNIQUE_PLACEHOLDER); 145 #define STX_CO_TRY_SOME_IMPL_(STX_ARG_UNIQUE_PLACEHOLDER, \ 146 qualifier_identifier, option_expr) \ 147 static_assert(!::std::is_const_v<decltype((option_expr))>, \ 148 "the expression: ' " #option_expr \ 149 " ' evaluates to a const and is not mutable"); \ 150 static_assert(!::std::is_lvalue_reference_v<decltype((option_expr))>, \ 151 "the expression: ' " #option_expr \ 152 " ' evaluates to an l-value reference, 'CO_TRY_SOME' only " \ 153 "accepts r-values " \ 154 "and r-value references "); \ 155 decltype((option_expr))&& STX_ARG_UNIQUE_PLACEHOLDER = (option_expr); \ 157 if (STX_ARG_UNIQUE_PLACEHOLDER.is_none()) co_return ::stx::None; \ 159 decltype((option_expr))::value_type qualifier_identifier = \ 160 ::stx::internal::option::unsafe_value_move(STX_ARG_UNIQUE_PLACEHOLDER); 167 #define CO_TRY_OK(qualifier_identifier, result_expr) \ 168 STX_CO_TRY_OK_IMPL_( \ 169 STX_WITH_UNIQUE_SUFFIX_(STX_CO_TRY_OK_PLACEHOLDER, __COUNTER__), \ 170 qualifier_identifier, result_expr) 177 #define CO_TRY_SOME(qualifier_identifier, option_expr) \ 178 STX_CO_TRY_SOME_IMPL_( \ 179 STX_WITH_UNIQUE_SUFFIX_(STX_CO_TRY_SOME_PLACEHOLDER, __COUNTER__), \ 180 qualifier_identifier, option_expr) #define STX_FORCE_INLINE
Definition: config.h:254
Tp && unsafe_value_move(Option< Tp > &)
Er && unsafe_err_move(Result< Tp, Er > &)
#define STX_END_NAMESPACE
Definition: config.h:329
#define STX_BEGIN_NAMESPACE
Definition: config.h:325