diff options
Diffstat (limited to 'Kernel/KResult.h')
-rw-r--r-- | Kernel/KResult.h | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/Kernel/KResult.h b/Kernel/KResult.h index 1cc740bc74..291e9ea2ea 100644 --- a/Kernel/KResult.h +++ b/Kernel/KResult.h @@ -3,20 +3,31 @@ #include <AK/Assertions.h> #include <LibC/errno_numbers.h> -enum KSuccessTag { KSuccess }; +enum KSuccessTag +{ + KSuccess +}; class KResult { public: - explicit KResult(int negative_e) : m_error(negative_e) { ASSERT(negative_e <= 0); } - KResult(KSuccessTag) : m_error(0) { } + explicit KResult(int negative_e) + : m_error(negative_e) + { + ASSERT(negative_e <= 0); + } + KResult(KSuccessTag) + : m_error(0) + { + } operator int() const { return m_error; } bool is_success() const { return m_error == ESUCCESS; } bool is_error() const { return !is_success(); } private: - template<typename T> friend class KResultOr; - KResult() { } + template<typename T> + friend class KResultOr; + KResult() {} int m_error { 0 }; }; @@ -27,7 +38,8 @@ public: KResultOr(KResult error) : m_error(error) , m_is_error(true) - { } + { + } KResultOr(T&& value) { @@ -54,9 +66,21 @@ public: } bool is_error() const { return m_is_error; } - KResult error() const { ASSERT(m_is_error); return m_error; } - T& value() { ASSERT(!m_is_error); return *reinterpret_cast<T*>(&m_storage); } - const T& value() const { ASSERT(!m_is_error); return *reinterpret_cast<T*>(&m_storage); } + KResult error() const + { + ASSERT(m_is_error); + return m_error; + } + T& value() + { + ASSERT(!m_is_error); + return *reinterpret_cast<T*>(&m_storage); + } + const T& value() const + { + ASSERT(!m_is_error); + return *reinterpret_cast<T*>(&m_storage); + } T release_value() { @@ -71,4 +95,3 @@ private: KResult m_error; bool m_is_error { false }; }; - |