From f01efd822e25be5ffdccd01f43afb9bfbeeceb7f Mon Sep 17 00:00:00 2001 From: Dario Mirovic Date: Fri, 8 Aug 2025 08:39:31 +0200 Subject: [PATCH] utils: add result_with_exception_ptr Add `result_with_exception_ptr` result type. Successful result has user specified type. Failed result has std::exception_ptr. This approach is simpler than `result_with_exception`. It does not require user to pass exception types as variadic template through all the callstack. Specific exception type can still be accessed without costly std::rethrow_exception(eptr) by using `try_catch`, if configured so via `USE_OPTIMIZED_EXCEPTION_HANDLING`. This means no information loss, but less verbosity when writing result types. Refs: #24567 --- utils/result.hh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/utils/result.hh b/utils/result.hh index 444a23e38e..3d0426a77f 100644 --- a/utils/result.hh +++ b/utils/result.hh @@ -59,4 +59,24 @@ concept ResultRebindableTo = template using rebind_result = bo::result; +struct result_with_exception_ptr_throw_policy : bo::policy::base { + template static constexpr void wide_value_check(Impl&& self) { + if (!base::_has_value(self)) { + std::rethrow_exception(base::_error(self)); + } + } + + template static constexpr void wide_error_check(Impl&& self) { + if (!base::_has_error(self)) { + throw bo::bad_result_access("no error"); + } + } +}; + +template +using result_with_exception_ptr = bo::result; + +template +concept ExceptionPtrResult = bo::is_basic_result::value && std::same_as; + }