Result: Add try_{set,move}_value_or_error

This commit is contained in:
apio 2023-04-07 10:43:29 +02:00
parent c752b2b343
commit baa2296aed
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -110,11 +110,25 @@ template <typename T> 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");