From 46762f3fd673ff7ba670b6adb06427a69bf54583 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 (synced from 741026680a4b416e6536ff8d4a999e97a2990532) --- src/ox/std/error.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ox/std/error.hpp b/src/ox/std/error.hpp index e0d5fa167..d1a2cf6f0 100644 --- a/src/ox/std/error.hpp +++ b/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; } }