From 730d0682eea4359fa3027bca5077561c6c825ca0 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 18 Dec 2022 16:30:09 +0100 Subject: [PATCH] Result: Add try_set_value_with_specific_error() --- luna/include/luna/Result.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/luna/include/luna/Result.h b/luna/include/luna/Result.h index b012ffab..38143c7e 100644 --- a/luna/include/luna/Result.h +++ b/luna/include/luna/Result.h @@ -90,6 +90,13 @@ template class Result return m_value.try_set_value(ref); } + Result try_set_value_with_specific_error(T& ref, int error) + { + if (has_error() && m_error != error) return release_error(); + + return m_value.try_set_value(ref); + } + T release_value() { expect(has_value(), "Result::release_value() called on a Result that holds an error");