diff --git a/deps/ox/src/ox/std/error.hpp b/deps/ox/src/ox/std/error.hpp index a3de8952..af36c104 100644 --- a/deps/ox/src/ox/std/error.hpp +++ b/deps/ox/src/ox/std/error.hpp @@ -264,6 +264,54 @@ struct [[nodiscard]] Result { return f(std::move(value)); } + /** + * Returns parameter alt if Result contains an error. + * @param alt + * @return value of Result or alt + */ + constexpr T orVal(T &&alt) & noexcept { + if (error) { + return std::move(alt); + } + return value; + } + + /** + * Returns parameter alt if Result contains an error. + * @param alt + * @return value of Result or alt + */ + constexpr T orVal(T &&alt) && noexcept { + if (error) { + return std::move(alt); + } + return std::move(value); + } + + /** + * Returns parameter alt if Result contains an error. + * @param alt + * @return value of Result or alt + */ + constexpr T orVal(T const&alt) & noexcept { + if (error) { + return alt; + } + return value; + } + + /** + * Returns parameter alt if Result contains an error. + * @param alt + * @return value of Result or alt + */ + constexpr T orVal(T const&alt) && noexcept { + if (error) { + return alt; + } + return std::move(value); + } + }; namespace detail {