mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
AK/Error: Add value_or convenience method
- In the style of Optional::value_or - Only const& flavor - WARNING: no unit test (no unit tests for Error), but seems benign
This commit is contained in:
parent
6f1710121d
commit
bfe7d423c6
1 changed files with 6 additions and 0 deletions
|
@ -169,6 +169,12 @@ public:
|
|||
return m_value_or_error.template get<T>();
|
||||
}
|
||||
T const& value() const { return m_value_or_error.template get<T>(); }
|
||||
[[nodiscard]] ALWAYS_INLINE T const& value_or(T const& fallback) const
|
||||
{
|
||||
if (is_error())
|
||||
return fallback;
|
||||
return m_value_or_error.template get<T>();
|
||||
}
|
||||
|
||||
ErrorType& error() { return m_value_or_error.template get<ErrorType>(); }
|
||||
ErrorType const& error() const { return m_value_or_error.template get<ErrorType>(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue