Skip to content

Commit

Permalink
Kernel: Add KResultOr<T>::result()
Browse files Browse the repository at this point in the history
This is just a handy way to get either an error or a KSuccess, even if
there is a T present.
  • Loading branch information
awesomekling committed Feb 8, 2020
1 parent 745ea2a commit 2f82d4f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Kernel/KResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class alignas(T) KResultOr {
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;
Expand All @@ -119,6 +119,7 @@ class alignas(T) KResultOr {
ASSERT(m_is_error);
return m_error;
}
KResult result() const { return m_is_error ? KSuccess : m_error; }
T& value()
{
ASSERT(!m_is_error);
Expand All @@ -139,7 +140,7 @@ class alignas(T) KResultOr {
}

private:
alignas (T) char m_storage[sizeof(T)];
alignas(T) char m_storage[sizeof(T)];
KResult m_error;
bool m_is_error { false };
};

0 comments on commit 2f82d4f

Please sign in to comment.