Compare commits

..

No commits in common. "6cf042e65e4564502a04d0c0805b295efa1b006d" and "84c82a4e7562acc643e5af0e06723ff7d93adad0" have entirely different histories.

2 changed files with 12 additions and 21 deletions

View File

@ -101,14 +101,6 @@ template <typename T> class Option
return true;
}
bool try_move_value(T& ref) const
{
if (!has_value()) return false;
m_has_value = false;
ref = move(m_storage.fetch_reference());
return true;
}
~Option()
{
if (has_value()) m_storage.destroy();

View File

@ -20,23 +20,24 @@ struct Error
template <typename T> class Result
{
public:
Result(const T& value) : m_value(value)
Result(const T& value) : m_value(value), m_has_value(true)
{
}
Result(T&& value) : m_value(move(value))
Result(T&& value) : m_value(move(value)), m_has_value(true)
{
}
Result(const Result<T>& other) : m_value(other.m_value), m_error(other.m_error)
Result(const Result<T>& other) : m_value(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)
Result(Result<T>&& other) : m_value(move(other.m_value)), m_has_value(other.m_has_value), m_error(other.m_error)
{
other.m_has_value = false;
}
Result(const Error& err) : m_value(), m_error(err.error)
Result(const Error& err) : m_value(), m_has_value(false), m_error(err.error)
{
}
@ -44,6 +45,7 @@ template <typename T> class Result
{
if (this == &other) return *this;
m_has_value = other.m_has_value;
m_error = other.m_error;
m_value = other.m_value;
@ -54,6 +56,8 @@ template <typename T> 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);
@ -62,12 +66,12 @@ template <typename T> class Result
bool has_error() const
{
return !m_value.has_value();
return !m_has_value;
}
bool has_value() const
{
return m_value.has_value();
return m_has_value;
}
int error() const
@ -110,12 +114,6 @@ template <typename T> class Result
return m_value.try_set_value(ref);
}
bool try_move_value(T& ref) const
{
return m_value.try_move_value(ref);
}
// FIXME: Please remove this.
Result<bool> try_set_value_with_specific_error(T& ref, int error)
{
if (has_error() && m_error != error) return release_error();
@ -137,6 +135,7 @@ template <typename T> class Result
private:
Option<T> m_value;
bool m_has_value;
int m_error;
};