Result: Add try_set_value()

This helper returns true if the Result contains a value, or false if it doesn't.
Additionally, if it has a value, it sets the passed reference to it.
This commit is contained in:
apio 2022-11-19 18:38:01 +01:00
parent 883a1da0d7
commit db3e34b2ba

View File

@ -104,6 +104,13 @@ template <typename T> class Result
return other; return other;
} }
bool try_set_value(T& ref)
{
if (!has_value()) return false;
ref = m_storage.fetch_reference();
return true;
}
T release_value() T release_value()
{ {
check(has_value()); check(has_value());