libluna: Add move versions of value_or

This commit is contained in:
apio 2024-12-14 12:46:36 +01:00
parent 5d5c85a022
commit 00382421b2
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 11 additions and 0 deletions

View File

@ -94,6 +94,12 @@ template <typename T> class Option
return other; return other;
} }
T value_or(T&& other) const
{
if (has_value()) return m_storage.fetch_reference();
return move(other);
}
bool try_set_value(T& ref) const bool try_set_value(T& ref) const
{ {
if (!has_value()) return false; if (!has_value()) return false;

View File

@ -106,6 +106,11 @@ template <typename T> class Result
return m_value.value_or(other); return m_value.value_or(other);
} }
T value_or(T&& other) const
{
return m_value.value_or(move(other));
}
bool try_set_value(T& ref) const bool try_set_value(T& ref) const
{ {
return m_value.try_set_value(ref); return m_value.try_set_value(ref);