aboutsummaryrefslogtreecommitdiff
path: root/src/util/result.h
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-05-24 08:55:47 -0400
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-05-24 08:55:47 -0400
commit5f49cb1bc8e6ba0671c21bf6292d2d3de43fd001 (patch)
tree31c8139e6151d88fea93f5d739dd2d6ee8e6ad22 /src/util/result.h
parent51c050787fd6bcd016969dd7e245818ebd110b67 (diff)
util: Add void support to util::Result
A minimal (but hacky) way to add support for void to Result originally posted https://github.com/bitcoin/bitcoin/pull/27632#discussion_r1195604095
Diffstat (limited to 'src/util/result.h')
-rw-r--r--src/util/result.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/util/result.h b/src/util/result.h
index 972b1aada0..b99995c7e5 100644
--- a/src/util/result.h
+++ b/src/util/result.h
@@ -31,16 +31,19 @@ struct Error {
//! `std::optional<T>` can be updated to return `util::Result<T>` and return
//! error strings usually just replacing `return std::nullopt;` with `return
//! util::Error{error_string};`.
-template <class T>
+template <class M>
class Result
{
private:
+ using T = std::conditional_t<std::is_same_v<M, void>, std::monostate, M>;
+
std::variant<bilingual_str, T> m_variant;
template <typename FT>
friend bilingual_str ErrorString(const Result<FT>& result);
public:
+ Result() : m_variant{std::in_place_index_t<1>{}, std::monostate{}} {} // constructor for void
Result(T obj) : m_variant{std::in_place_index_t<1>{}, std::move(obj)} {}
Result(Error error) : m_variant{std::in_place_index_t<0>{}, std::move(error.message)} {}