Result: Implement operator=()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2022-12-30 19:06:47 +01:00
parent 4081186b27
commit e2e21923d7
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -41,6 +41,29 @@ template <typename T> class Result
{ {
} }
Result<T>& operator=(const Result<T>& other)
{
if (this == &other) return *this;
m_has_value = other.m_has_value;
m_error = other.m_error;
m_value = other.m_value;
return *this;
}
Result<T>& operator=(Result<T>&& other)
{
if (this == &other) return *this;
m_has_value = other.m_has_value;
other.m_has_value = false;
m_error = other.m_error;
m_value = move(other.m_value);
return *this;
}
bool has_error() const bool has_error() const
{ {
return !m_has_value; return !m_has_value;
@ -135,6 +158,26 @@ template <> class Result<void>
{ {
} }
Result<void>& operator=(const Result<void>& other)
{
if (this == &other) return *this;
m_has_error = other.m_has_error;
m_error = other.m_error;
return *this;
}
Result<void>& operator=(Result<void>&& other)
{
if (this == &other) return *this;
m_has_error = other.m_has_error;
m_error = other.m_error;
return *this;
}
bool has_error() const bool has_error() const
{ {
return m_has_error; return m_has_error;