[ox/std] Add Result::to for passing value to functions

This commit is contained in:
Gary Talent 2023-06-25 17:21:56 -05:00
parent 822090f309
commit 741026680a

View File

@ -197,6 +197,14 @@ struct [[nodiscard]] Result {
} }
return value; return value;
} }
constexpr ox::Result<T> to(const auto &f) noexcept {
if (error) [[unlikely]] {
return OxError(1);
}
return f(value);
}
}; };
namespace detail { namespace detail {
@ -206,8 +214,8 @@ constexpr Error toError(const Error &e) noexcept {
} }
template<typename T> template<typename T>
constexpr Error toError(const Result<T> &ve) noexcept { constexpr Error toError(const Result<T> &r) noexcept {
return ve.error; return r.error;
} }
} }