diff --git a/lib/utils/mu-option.hh b/lib/utils/mu-option.hh index 3ca683e0..32b1beea 100644 --- a/lib/utils/mu-option.hh +++ b/lib/utils/mu-option.hh @@ -21,6 +21,7 @@ #define MU_OPTION__ #include +#include #include namespace Mu { @@ -36,6 +37,16 @@ Some(T&& t) } constexpr auto Nothing = tl::nullopt; // 'None' is already taken. +template T +unwrap(Option&& res) +{ + if (!!res) + return std::move(res.value()); + else + throw std::runtime_error("failure is not an option"); +} + + /** * Maybe create a string from a const char pointer. * diff --git a/lib/utils/mu-result.hh b/lib/utils/mu-result.hh index c7d6aa30..46346ed5 100644 --- a/lib/utils/mu-result.hh +++ b/lib/utils/mu-result.hh @@ -106,8 +106,8 @@ Err(Error::Code code, GError **err, fmt::format_string frm, T&&... args) } -template -T unwrap(Result&& res) +template T +unwrap(Result&& res) { if (!!res) return std::move(res.value());