[ox/std] Add Result::to for passing value to functions
This commit is contained in:
parent
822090f309
commit
741026680a
12
deps/ox/src/ox/std/error.hpp
vendored
12
deps/ox/src/ox/std/error.hpp
vendored
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user