Option, Result: Introduce try_move_value(), which is the release_value() equivalent of try_set_value()
This commit is contained in:
parent
84c82a4e75
commit
67ebb00bd3
@ -101,6 +101,14 @@ template <typename T> class Option
|
||||
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()
|
||||
{
|
||||
if (has_value()) m_storage.destroy();
|
||||
|
@ -114,6 +114,12 @@ template <typename T> class Result
|
||||
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)
|
||||
{
|
||||
if (has_error() && m_error != error) return release_error();
|
||||
|
Loading…
Reference in New Issue
Block a user