diff --git a/libluna/include/luna/Option.h b/libluna/include/luna/Option.h index 20c2a9cb..720dff4b 100644 --- a/libluna/include/luna/Option.h +++ b/libluna/include/luna/Option.h @@ -94,6 +94,12 @@ template class Option 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 { if (!has_value()) return false; diff --git a/libluna/include/luna/Result.h b/libluna/include/luna/Result.h index a902dd0b..823a1ddf 100644 --- a/libluna/include/luna/Result.h +++ b/libluna/include/luna/Result.h @@ -106,6 +106,11 @@ template class Result 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 { return m_value.try_set_value(ref);