diff --git a/deps/ox/src/ox/std/error.hpp b/deps/ox/src/ox/std/error.hpp index af36c104..4b54906f 100644 --- a/deps/ox/src/ox/std/error.hpp +++ b/deps/ox/src/ox/std/error.hpp @@ -269,7 +269,7 @@ struct [[nodiscard]] Result { * @param alt * @return value of Result or alt */ - constexpr T orVal(T &&alt) & noexcept { + constexpr T or_value(T &&alt) const& noexcept { if (error) { return std::move(alt); } @@ -281,7 +281,7 @@ struct [[nodiscard]] Result { * @param alt * @return value of Result or alt */ - constexpr T orVal(T &&alt) && noexcept { + constexpr T or_value(T &&alt) && noexcept { if (error) { return std::move(alt); } @@ -293,7 +293,7 @@ struct [[nodiscard]] Result { * @param alt * @return value of Result or alt */ - constexpr T orVal(T const&alt) & noexcept { + constexpr T or_value(T const&alt) const& noexcept { if (error) { return alt; } @@ -305,7 +305,7 @@ struct [[nodiscard]] Result { * @param alt * @return value of Result or alt */ - constexpr T orVal(T const&alt) && noexcept { + constexpr T or_value(T const&alt) && noexcept { if (error) { return alt; } diff --git a/deps/ox/src/ox/std/optional.hpp b/deps/ox/src/ox/std/optional.hpp index 1a8fb3b2..687fda4c 100644 --- a/deps/ox/src/ox/std/optional.hpp +++ b/deps/ox/src/ox/std/optional.hpp @@ -64,6 +64,54 @@ class Optional { return *m_ptr; } + /** + * Returns parameter alt if Result contains an error. + * @param alt + * @return value of Result or alt + */ + constexpr T or_value(T &&alt) const& noexcept { + if (!m_ptr) { + return std::move(alt); + } + return *m_ptr; + } + + /** + * Returns parameter alt if Result contains an error. + * @param alt + * @return value of Result or alt + */ + constexpr T or_value(T &&alt) && noexcept { + if (!m_ptr) { + return std::move(alt); + } + return std::move(*m_ptr); + } + + /** + * Returns parameter alt if Result contains an error. + * @param alt + * @return value of Result or alt + */ + constexpr T or_value(T const&alt) const& noexcept { + if (!m_ptr) { + return alt; + } + return *m_ptr; + } + + /** + * Returns parameter alt if Result contains an error. + * @param alt + * @return value of Result or alt + */ + constexpr T or_value(T const&alt) && noexcept { + if (!m_ptr) { + return alt; + } + return std::move(*m_ptr); + } + constexpr T &operator*() & noexcept { return *m_ptr; }