diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-12 19:28:03 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-12 19:19:49 +0200 |
commit | fa8de09edc9ec4e6d171df80f746174a0ec58afb (patch) | |
tree | c22e81dbe9a58c99c0462ee5ad94bf818287df68 | |
parent | 1d89fc695a3aeb3e3dcadf371b7667572b38c836 (diff) |
Prepare BResult for non-copyable types
-rw-r--r-- | src/util/result.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/util/result.h b/src/util/result.h index dcf5edaa5b..2f586a4c9b 100644 --- a/src/util/result.h +++ b/src/util/result.h @@ -6,6 +6,7 @@ #define BITCOIN_UTIL_RESULT_H #include <util/translation.h> + #include <variant> /* @@ -18,9 +19,9 @@ private: std::variant<bilingual_str, T> m_variant; public: - BResult() : m_variant(Untranslated("")) {} - BResult(const T& _obj) : m_variant(_obj) {} - BResult(const bilingual_str& error) : m_variant(error) {} + BResult() : m_variant{Untranslated("")} {} + BResult(T obj) : m_variant{std::move(obj)} {} + BResult(bilingual_str error) : m_variant{std::move(error)} {} /* Whether the function succeeded or not */ bool HasRes() const { return std::holds_alternative<T>(m_variant); } @@ -30,6 +31,11 @@ public: assert(HasRes()); return std::get<T>(m_variant); } + T ReleaseObj() + { + assert(HasRes()); + return std::move(std::get<T>(m_variant)); + } /* In case of failure, the error cause */ const bilingual_str& GetError() const { |