diff --git a/src/ox/std/error.hpp b/src/ox/std/error.hpp index 5f4ba25a6..ca6a6e9a3 100644 --- a/src/ox/std/error.hpp +++ b/src/ox/std/error.hpp @@ -138,7 +138,7 @@ struct [[nodiscard]] Result { } template - constexpr Result(const Result &&other) noexcept: value(std::move(other.value)), error(std::move(other.error)) { + constexpr Result(Result &&other) noexcept: value(std::move(other.value)), error(std::move(other.error)) { } constexpr Result(const Error &error) noexcept: value(), error(error) { @@ -182,23 +182,44 @@ struct [[nodiscard]] Result { return error; } - constexpr auto &unwrap() noexcept { + constexpr T &unwrap() & noexcept { if (error) { oxPanic(error, "Failed unwrap"); } return value; } - constexpr auto &unwrapThrow() { + constexpr T &&unwrap() && noexcept { + if (error) { + oxPanic(error, "Failed unwrap"); + } + return std::move(value); + } + + constexpr T const&unwrap() const & noexcept { + if (error) [[unlikely]] { + oxPanic(error, "Failed unwrap"); + } + return value; + } + + constexpr T &unwrapThrow() & { if (error) { throw ox::Exception(error); } return value; } - constexpr const auto &unwrap() const noexcept { - if (error) [[unlikely]] { - oxPanic(error, "Failed unwrap"); + constexpr T &&unwrapThrow() && { + if (error) { + throw ox::Exception(error); + } + return std::move(value); + } + + constexpr T const&unwrapThrow() const & { + if (error) { + throw ox::Exception(error); } return value; }