1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:27:45 +00: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:
Andreas Kling 2020-02-08 11:57:13 +01:00
parent 745ea2a0ef
commit 2f82d4fb31

View file

@ -94,7 +94,7 @@ public:
KResultOr& operator=(KResultOr&& other) KResultOr& operator=(KResultOr&& other)
{ {
if (!m_is_error) if (!m_is_error)
value().~T(); value().~T();
m_is_error = other.m_is_error; m_is_error = other.m_is_error;
if (m_is_error) if (m_is_error)
m_error = other.m_error; m_error = other.m_error;
@ -119,6 +119,7 @@ public:
ASSERT(m_is_error); ASSERT(m_is_error);
return m_error; return m_error;
} }
KResult result() const { return m_is_error ? KSuccess : m_error; }
T& value() T& value()
{ {
ASSERT(!m_is_error); ASSERT(!m_is_error);
@ -139,7 +140,7 @@ public:
} }
private: private:
alignas (T) char m_storage[sizeof(T)]; alignas(T) char m_storage[sizeof(T)];
KResult m_error; KResult m_error;
bool m_is_error { false }; bool m_is_error { false };
}; };