Compare commits
2 Commits
84c82a4e75
...
6cf042e65e
Author | SHA1 | Date | |
---|---|---|---|
6cf042e65e | |||
67ebb00bd3 |
@ -101,6 +101,14 @@ 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();
|
||||
|
@ -20,24 +20,23 @@ struct Error
|
||||
template <typename T> 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<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;
|
||||
|
||||
m_has_value = other.m_has_value;
|
||||
m_error = other.m_error;
|
||||
m_value = other.m_value;
|
||||
|
||||
@ -56,8 +54,6 @@ 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);
|
||||
|
||||
@ -66,12 +62,12 @@ template <typename T> 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
|
||||
@ -114,6 +110,12 @@ 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();
|
||||
@ -135,7 +137,6 @@ template <typename T> class Result
|
||||
|
||||
private:
|
||||
Option<T> m_value;
|
||||
bool m_has_value;
|
||||
int m_error;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user