diff --git a/luna/include/luna/Result.h b/luna/include/luna/Result.h index 66a9185a..347ed59b 100644 --- a/luna/include/luna/Result.h +++ b/luna/include/luna/Result.h @@ -20,24 +20,23 @@ struct Error template class Result { public: - Result(const T& value) : m_value(value), m_has_value(true) + Result(const T& value) : m_value(value) { } - Result(T&& value) : m_value(move(value)), m_has_value(true) + Result(T&& value) : m_value(move(value)) { } - Result(const Result& other) : m_value(other.m_value), m_has_value(other.m_has_value), m_error(other.m_error) + Result(const Result& other) : m_value(other.m_value), m_error(other.m_error) { } - Result(Result&& other) : m_value(move(other.m_value)), m_has_value(other.m_has_value), m_error(other.m_error) + Result(Result&& other) : m_value(move(other.m_value)), m_error(other.m_error) { - other.m_has_value = false; } - Result(const Error& err) : m_value(), m_has_value(false), m_error(err.error) + Result(const Error& err) : m_value(), m_error(err.error) { } @@ -45,7 +44,6 @@ template class Result { if (this == &other) return *this; - m_has_value = other.m_has_value; m_error = other.m_error; m_value = other.m_value; @@ -56,8 +54,6 @@ template class Result { 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); @@ -66,12 +62,12 @@ template class Result bool has_error() const { - return !m_has_value; + return !m_value.has_value(); } bool has_value() const { - return m_has_value; + return m_value.has_value(); } int error() const @@ -141,7 +137,6 @@ template class Result private: Option m_value; - bool m_has_value; int m_error; };