44 -> std::optional<error_info>
46 if (result.is_err()) {
47 return result.error();
69 return std::forward<Result<T>>(result);
84 -> std::optional<error_info>
100 const std::string& message,
101 const std::string& module =
"") noexcept
117 const std::string& message,
118 const std::string& module,
119 const std::string& details)
noexcept
122 return error_info{code, message, module, details};
137template<
typename... Funcs>
138[[nodiscard]]
auto chain(Funcs&&... funcs) {
139 using FirstResult = std::invoke_result_t<std::tuple_element_t<0, std::tuple<Funcs...>>>;
141 FirstResult result = std::get<0>(std::forward_as_tuple(funcs...))();
143 if constexpr (
sizeof...(funcs) > 1) {
144 ([&]<
typename Func>(Func&& func) {
145 if (result.is_ok()) {
146 result = func(result.value());
148 }(std::forward<Funcs>(funcs)), ...);
162template<
typename Func>
163[[nodiscard]]
auto safe_execute(Func&& func,
const std::string& module =
"")
166 using ReturnType = std::invoke_result_t<Func>;
169 if constexpr (std::is_void_v<ReturnType>) {
175 }
catch (
const std::exception& e) {
193template<
typename T,
typename ErrorHandler>
196 if (result.is_err()) {
197 error_handler(result.error());
200 return std::move(result).value();
218template<
typename... Results>
223 bool has_error = (... || results.is_err());
227 ((results.is_err() && (first_error = results.error(),
true)) || ...);
233 std::make_tuple(std::forward<Results>(results).value()...)
Result type for error handling with member function support.
auto make_error(int code, const std::string &message, const std::string &module="") noexcept -> error_info
Create error_info with code, message, and module (type-safe)
auto return_if_error(const Result< T > &result) -> std::optional< error_info >
Return error if Result is in error state (type-safe alternative to RETURN_IF_ERROR)
auto safe_execute(Func &&func, const std::string &module="") -> Result< std::invoke_result_t< Func > >
Execute function and convert exceptions to Result.
auto error_if(bool condition, const error_info &error) -> std::optional< error_info >
Check condition and return error if false (type-safe alternative to RETURN_ERROR_IF)
auto try_extract(Result< T > &&result) -> std::conditional_t< std::is_void_v< T >, Result< std::monostate >, Result< T > >
Safely extract value from Result or return error.
auto unwrap_or_handle(Result< T > &&result, ErrorHandler &&error_handler) -> T
Unwrap Result with custom error handler.
auto chain(Funcs &&... funcs)
Chain multiple Result-returning operations.
auto make_error_with_details(int code, const std::string &message, const std::string &module, const std::string &details) noexcept -> error_info
Create error_info with code, message, module, and details.
auto combine_results(Results &&... results) -> Result< std::tuple< typename std::decay_t< Results >::value_type... > >
Combine multiple Results into a single Result containing a tuple.
Umbrella header for Result<T> type and related utilities.
Standard error information used by Result<T>.