From e2e21923d7b37c24ae4a25bd600c3a7879dc27dd Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 30 Dec 2022 19:06:47 +0100 Subject: [PATCH] Result: Implement operator=() --- luna/include/luna/Result.h | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/luna/include/luna/Result.h b/luna/include/luna/Result.h index df34375b..f156b73c 100644 --- a/luna/include/luna/Result.h +++ b/luna/include/luna/Result.h @@ -41,6 +41,29 @@ template class Result { } + Result& operator=(const Result& 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& operator=(Result&& 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 { return !m_has_value; @@ -135,6 +158,26 @@ template <> class Result { } + Result& operator=(const Result& other) + { + if (this == &other) return *this; + + m_has_error = other.m_has_error; + m_error = other.m_error; + + return *this; + } + + Result& operator=(Result&& other) + { + if (this == &other) return *this; + + m_has_error = other.m_has_error; + m_error = other.m_error; + + return *this; + } + bool has_error() const { return m_has_error;