Kernel: Add move assign operator to KResultOr
This commit is contained in:
parent
821484f170
commit
bae8e21a8b
Notes:
sideshowbarker
2024-07-19 10:33:26 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/bae8e21a8b5 Pull-request: https://github.com/SerenityOS/serenity/pull/953 Reviewed-by: https://github.com/awesomekling
1 changed files with 19 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue