summaryrefslogtreecommitdiff
path: root/Kernel/KResult.h
diff options
context:
space:
mode:
authorAndrew Kaster <andrewdkaster@gmail.com>2019-12-29 00:50:25 -0500
committerAndreas Kling <awesomekling@gmail.com>2019-12-29 23:01:27 +0100
commitbae8e21a8b51c1e48c51d342f8f43a012b0d5285 (patch)
treebc14d5c3f4508cc597ca3fcdc558800c143373c4 /Kernel/KResult.h
parent821484f170000e68114285b538c563be9858d119 (diff)
downloadserenity-bae8e21a8b51c1e48c51d342f8f43a012b0d5285.zip
Kernel: Add move assign operator to KResultOr
Diffstat (limited to 'Kernel/KResult.h')
-rw-r--r--Kernel/KResult.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/Kernel/KResult.h b/Kernel/KResult.h
index c631b226fc..9e6f6f6ed0 100644
--- a/Kernel/KResult.h
+++ b/Kernel/KResult.h
@@ -56,12 +56,30 @@ public:
m_is_error = other.m_is_error;
if (m_is_error)
m_error = other.m_error;
- else
+ else {
new (&m_storage) T(move(other.value()));
+ other.value().~T();
+ }
other.m_is_error = true;
other.m_error = KSuccess;
}
+ KResultOr& operator=(KResultOr&& other)
+ {
+ if (!m_is_error)
+ value().~T();
+ m_is_error = other.m_is_error;
+ if (m_is_error)
+ m_error = other.m_error;
+ else {
+ new (&m_storage) T(move(other.value()));
+ other.value().~T();
+ }
+ other.m_is_error = true;
+ other.m_error = KSuccess;
+ return *this;
+ }
+
~KResultOr()
{
if (!m_is_error)