diff options
author | Erik Kundt <bitshift@posteo.org> | 2018-12-05 17:25:48 +0800 |
---|---|---|
committer | Erik Kundt <bitshift@posteo.org> | 2018-12-05 17:33:34 +0800 |
commit | c38fb534396eee62701cd08edfffbdea3bac337f (patch) | |
tree | 5404374a78a985296c9942d9039f817ca9f13757 /libdevcore/Result.h | |
parent | e3accc6aa6857c8ae7c6f075ff50d9a17989cd0d (diff) | |
download | dexon-solidity-c38fb534396eee62701cd08edfffbdea3bac337f.tar.gz dexon-solidity-c38fb534396eee62701cd08edfffbdea3bac337f.tar.zst dexon-solidity-c38fb534396eee62701cd08edfffbdea3bac337f.zip |
Cleans up Result<T> and adds additional documentation.
Diffstat (limited to 'libdevcore/Result.h')
-rw-r--r-- | libdevcore/Result.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/libdevcore/Result.h b/libdevcore/Result.h index cdff67c6..4f7a063b 100644 --- a/libdevcore/Result.h +++ b/libdevcore/Result.h @@ -23,7 +23,9 @@ namespace dev /// Simple generic result that holds a value and an optional error message. /// Results can be implicitly converted to and created from the type of -/// the value they hold. +/// the value they hold. The class is mainly designed for a result type of +/// bool or pointer type. The idea is that the default constructed value of +/// the result type is interpreted as an error value. /// /// Result<bool> check() /// { @@ -38,29 +40,27 @@ class Result { public: Result(ResultType _value): Result(_value, std::string{}) {} - Result(std::string _error): Result(ResultType{}, _error) {} + Result(std::string _message): Result(ResultType{}, std::move(_message)) {} /// @{ /// @name Wrapper functions /// Wrapper functions that provide implicit conversions to and explicit retrieval of /// the value this result holds. operator ResultType const&() const { return m_value; } - ResultType& operator*() const { return m_value; } ResultType const& get() const { return m_value; } - ResultType& get() { return m_value; } /// @} /// @returns the error message (can be empty). - std::string const& error() const { return m_error; } + std::string const& message() const { return m_message; } private: - explicit Result(ResultType _value, std::string _error): + explicit Result(ResultType _value, std::string _message): m_value(std::move(_value)), - m_error(std::move(_error)) + m_message(std::move(_message)) {} ResultType m_value; - std::string m_error; + std::string m_message; }; } |