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
Notes: sideshowbarker 2024-07-19 09:32:03 +09:00

View File

@ -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 };
};