mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 10:12:28 +02:00
Prepare BResult for non-copyable types
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#define BITCOIN_UTIL_RESULT_H
|
#define BITCOIN_UTIL_RESULT_H
|
||||||
|
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -18,9 +19,9 @@ private:
|
|||||||
std::variant<bilingual_str, T> m_variant;
|
std::variant<bilingual_str, T> m_variant;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BResult() : m_variant(Untranslated("")) {}
|
BResult() : m_variant{Untranslated("")} {}
|
||||||
BResult(const T& _obj) : m_variant(_obj) {}
|
BResult(T obj) : m_variant{std::move(obj)} {}
|
||||||
BResult(const bilingual_str& error) : m_variant(error) {}
|
BResult(bilingual_str error) : m_variant{std::move(error)} {}
|
||||||
|
|
||||||
/* Whether the function succeeded or not */
|
/* Whether the function succeeded or not */
|
||||||
bool HasRes() const { return std::holds_alternative<T>(m_variant); }
|
bool HasRes() const { return std::holds_alternative<T>(m_variant); }
|
||||||
@@ -30,6 +31,11 @@ public:
|
|||||||
assert(HasRes());
|
assert(HasRes());
|
||||||
return std::get<T>(m_variant);
|
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 */
|
/* In case of failure, the error cause */
|
||||||
const bilingual_str& GetError() const {
|
const bilingual_str& GetError() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user