Result: Remove m_has_value, rely on Option::has_value()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
67ebb00bd3
commit
6cf042e65e
@ -20,24 +20,23 @@ struct Error
|
|||||||
template <typename T> class Result
|
template <typename T> class Result
|
||||||
{
|
{
|
||||||
public:
|
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<T>& other) : m_value(other.m_value), m_has_value(other.m_has_value), m_error(other.m_error)
|
Result(const Result<T>& other) : m_value(other.m_value), m_error(other.m_error)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Result(Result<T>&& other) : m_value(move(other.m_value)), m_has_value(other.m_has_value), m_error(other.m_error)
|
Result(Result<T>&& 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 <typename T> class Result
|
|||||||
{
|
{
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
|
|
||||||
m_has_value = other.m_has_value;
|
|
||||||
m_error = other.m_error;
|
m_error = other.m_error;
|
||||||
m_value = other.m_value;
|
m_value = other.m_value;
|
||||||
|
|
||||||
@ -56,8 +54,6 @@ template <typename T> class Result
|
|||||||
{
|
{
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
|
|
||||||
m_has_value = other.m_has_value;
|
|
||||||
other.m_has_value = false;
|
|
||||||
m_error = other.m_error;
|
m_error = other.m_error;
|
||||||
m_value = move(other.m_value);
|
m_value = move(other.m_value);
|
||||||
|
|
||||||
@ -66,12 +62,12 @@ template <typename T> class Result
|
|||||||
|
|
||||||
bool has_error() const
|
bool has_error() const
|
||||||
{
|
{
|
||||||
return !m_has_value;
|
return !m_value.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_value() const
|
bool has_value() const
|
||||||
{
|
{
|
||||||
return m_has_value;
|
return m_value.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
int error() const
|
int error() const
|
||||||
@ -141,7 +137,6 @@ template <typename T> class Result
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Option<T> m_value;
|
Option<T> m_value;
|
||||||
bool m_has_value;
|
|
||||||
int m_error;
|
int m_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user