mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
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
This commit is contained in:
parent
51c050787f
commit
5f49cb1bc8
1 changed files with 4 additions and 1 deletions
|
@ -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)} {}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue