Compare commits
2 Commits
9cc27f5be9
...
3a781f6704
Author | SHA1 | Date | |
---|---|---|---|
3a781f6704 | |||
30909f85a3 |
26
deps/ox/src/ox/std/error.hpp
vendored
26
deps/ox/src/ox/std/error.hpp
vendored
@ -167,28 +167,28 @@ struct [[nodiscard]] Result {
|
||||
|
||||
constexpr Error copyTo(type &val) const & noexcept {
|
||||
if (!error) [[likely]] {
|
||||
*val = value;
|
||||
val = value;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
constexpr Error copyTo(type &val) const && noexcept {
|
||||
if (!error) [[likely]] {
|
||||
*val = value;
|
||||
val = value;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
constexpr Error copyTo(type &val) & noexcept {
|
||||
if (!error) [[likely]] {
|
||||
*val = value;
|
||||
val = value;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
constexpr Error copyTo(type &val) && noexcept {
|
||||
if (!error) [[likely]] {
|
||||
*val = std::move(value);
|
||||
val = std::move(value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
@ -200,6 +200,7 @@ struct [[nodiscard]] Result {
|
||||
return error;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &unwrap() & noexcept {
|
||||
if (error) {
|
||||
oxPanic(error, "Failed unwrap");
|
||||
@ -207,6 +208,7 @@ struct [[nodiscard]] Result {
|
||||
return value;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &&unwrap() && noexcept {
|
||||
if (error) {
|
||||
oxPanic(error, "Failed unwrap");
|
||||
@ -214,6 +216,7 @@ struct [[nodiscard]] Result {
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T const&unwrap() const & noexcept {
|
||||
if (error) [[unlikely]] {
|
||||
oxPanic(error, "Failed unwrap");
|
||||
@ -221,6 +224,7 @@ struct [[nodiscard]] Result {
|
||||
return value;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &unwrapThrow() & {
|
||||
if (error) {
|
||||
throw ox::Exception(error);
|
||||
@ -228,6 +232,7 @@ struct [[nodiscard]] Result {
|
||||
return value;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &&unwrapThrow() && {
|
||||
if (error) {
|
||||
throw ox::Exception(error);
|
||||
@ -235,6 +240,7 @@ struct [[nodiscard]] Result {
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T const&unwrapThrow() const & {
|
||||
if (error) {
|
||||
throw ox::Exception(error);
|
||||
@ -243,13 +249,21 @@ struct [[nodiscard]] Result {
|
||||
}
|
||||
|
||||
template<typename U = T>
|
||||
constexpr ox::Result<U> to(const auto &f) noexcept {
|
||||
constexpr ox::Result<U> to(auto const&f) & noexcept {
|
||||
if (error) [[unlikely]] {
|
||||
return OxError(1);
|
||||
return error;
|
||||
}
|
||||
return f(value);
|
||||
}
|
||||
|
||||
template<typename U = T>
|
||||
constexpr ox::Result<U> to(auto const&f) && noexcept {
|
||||
if (error) [[unlikely]] {
|
||||
return error;
|
||||
}
|
||||
return f(std::move(value));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
Loading…
x
Reference in New Issue
Block a user