Skip to content

Commit fa8de09

Browse files
author
MacroFake
committed
Prepare BResult for non-copyable types
1 parent 1d89fc6 commit fa8de09

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/util/result.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_UTIL_RESULT_H
77

88
#include <util/translation.h>
9+
910
#include <variant>
1011

1112
/*
@@ -18,9 +19,9 @@ class BResult {
1819
std::variant<bilingual_str, T> m_variant;
1920

2021
public:
21-
BResult() : m_variant(Untranslated("")) {}
22-
BResult(const T& _obj) : m_variant(_obj) {}
23-
BResult(const bilingual_str& error) : m_variant(error) {}
22+
BResult() : m_variant{Untranslated("")} {}
23+
BResult(T obj) : m_variant{std::move(obj)} {}
24+
BResult(bilingual_str error) : m_variant{std::move(error)} {}
2425

2526
/* Whether the function succeeded or not */
2627
bool HasRes() const { return std::holds_alternative<T>(m_variant); }
@@ -30,6 +31,11 @@ class BResult {
3031
assert(HasRes());
3132
return std::get<T>(m_variant);
3233
}
34+
T ReleaseObj()
35+
{
36+
assert(HasRes());
37+
return std::move(std::get<T>(m_variant));
38+
}
3339

3440
/* In case of failure, the error cause */
3541
const bilingual_str& GetError() const {

0 commit comments

Comments
 (0)