Option, Result: Introduce try_move_value(), which is the release_value() equivalent of try_set_value()

This commit is contained in:
apio 2023-01-11 17:06:17 +01:00
parent 84c82a4e75
commit 67ebb00bd3
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 14 additions and 0 deletions

View File

@ -101,6 +101,14 @@ template <typename T> class Option
return true; return true;
} }
bool try_move_value(T& ref) const
{
if (!has_value()) return false;
m_has_value = false;
ref = move(m_storage.fetch_reference());
return true;
}
~Option() ~Option()
{ {
if (has_value()) m_storage.destroy(); if (has_value()) m_storage.destroy();

View File

@ -114,6 +114,12 @@ template <typename T> class Result
return m_value.try_set_value(ref); return m_value.try_set_value(ref);
} }
bool try_move_value(T& ref) const
{
return m_value.try_move_value(ref);
}
// FIXME: Please remove this.
Result<bool> try_set_value_with_specific_error(T& ref, int error) Result<bool> try_set_value_with_specific_error(T& ref, int error)
{ {
if (has_error() && m_error != error) return release_error(); if (has_error() && m_error != error) return release_error();