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

(synced from 741026680a)
This commit is contained in:
2023-06-25 17:21:56 -05:00
parent fba84f9bb5
commit 46762f3fd6
+10 -2
View File
@@ -197,6 +197,14 @@ struct [[nodiscard]] Result {
}
return value;
}
constexpr ox::Result<T> to(const auto &f) noexcept {
if (error) [[unlikely]] {
return OxError(1);
}
return f(value);
}
};
namespace detail {
@@ -206,8 +214,8 @@ constexpr Error toError(const Error &e) noexcept {
}
template<typename T>
constexpr Error toError(const Result<T> &ve) noexcept {
return ve.error;
constexpr Error toError(const Result<T> &r) noexcept {
return r.error;
}
}