From 741026680a4b416e6536ff8d4a999e97a2990532 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 25 Jun 2023 17:21:56 -0500 Subject: [PATCH] [ox/std] Add Result::to for passing value to functions --- deps/ox/src/ox/std/error.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/deps/ox/src/ox/std/error.hpp b/deps/ox/src/ox/std/error.hpp index e0d5fa16..d1a2cf6f 100644 --- a/deps/ox/src/ox/std/error.hpp +++ b/deps/ox/src/ox/std/error.hpp @@ -197,6 +197,14 @@ struct [[nodiscard]] Result { } return value; } + + constexpr ox::Result 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 -constexpr Error toError(const Result &ve) noexcept { - return ve.error; +constexpr Error toError(const Result &r) noexcept { + return r.error; } }