mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02: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:
committed by
Andreas Kling
parent
47e1aa054b
commit
666c323577
Notes:
github-actions[bot]
2025-05-26 16:49:26 +00:00
Author: https://github.com/manuel-za Commit: https://github.com/LadybirdBrowser/ladybird/commit/666c323577b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3619 Reviewed-by: https://github.com/R-Goc
@@ -151,6 +151,12 @@ public:
|
||||
|
||||
T& value() { 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>(); }
|
||||
|
||||
Reference in New Issue
Block a user