mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
Kernel: Add KResultOr<T>::result()
This is just a handy way to get either an error or a KSuccess, even if there is a T present.
This commit is contained in:
parent
745ea2a0ef
commit
2f82d4fb31
Notes:
sideshowbarker
2024-07-19 09:32:03 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2f82d4fb31a
@ -94,7 +94,7 @@ public:
|
||||
KResultOr& operator=(KResultOr&& other)
|
||||
{
|
||||
if (!m_is_error)
|
||||
value().~T();
|
||||
value().~T();
|
||||
m_is_error = other.m_is_error;
|
||||
if (m_is_error)
|
||||
m_error = other.m_error;
|
||||
@ -119,6 +119,7 @@ public:
|
||||
ASSERT(m_is_error);
|
||||
return m_error;
|
||||
}
|
||||
KResult result() const { return m_is_error ? KSuccess : m_error; }
|
||||
T& value()
|
||||
{
|
||||
ASSERT(!m_is_error);
|
||||
@ -139,7 +140,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
alignas (T) char m_storage[sizeof(T)];
|
||||
alignas(T) char m_storage[sizeof(T)];
|
||||
KResult m_error;
|
||||
bool m_is_error { false };
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user