From baa2296aedcc08db6f4acd9b84d8a4f89e0e646a Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 7 Apr 2023 10:43:29 +0200 Subject: [PATCH] Result: Add try_{set,move}_value_or_error --- libluna/include/luna/Result.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libluna/include/luna/Result.h b/libluna/include/luna/Result.h index 9f833b8e..39fda591 100644 --- a/libluna/include/luna/Result.h +++ b/libluna/include/luna/Result.h @@ -110,11 +110,25 @@ template class Result return m_value.try_set_value(ref); } + bool try_set_value_or_error(T& ref, int& err) const + { + bool ok = m_value.try_set_value(ref); + if (!ok) err = m_error; + return ok; + } + bool try_move_value(T& ref) { return m_value.try_move_value(ref); } + bool try_move_value_or_error(T& ref, int& err) const + { + bool ok = m_value.try_move_value(ref); + if (!ok) err = m_error; + return ok; + } + T release_value(SourceLocation caller = SourceLocation::current()) { expect_at(has_value(), caller, "Result::release_value() called on a Result that holds an error");