diff --git a/AK/Error.h b/AK/Error.h index 910f917bd40..b993747ff05 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -151,6 +151,12 @@ public: T& value() { return m_value_or_error.template get(); } T const& value() const { return m_value_or_error.template get(); } + [[nodiscard]] ALWAYS_INLINE T const& value_or(T const& fallback) const + { + if (is_error()) + return fallback; + return m_value_or_error.template get(); + } ErrorType& error() { return m_value_or_error.template get(); } ErrorType const& error() const { return m_value_or_error.template get(); }