5#ifndef BITCOIN_UTIL_RESULT_H
6#define BITCOIN_UTIL_RESULT_H
39 using T = std::conditional_t<std::is_same_v<M, void>, std::monostate,
M>;
43 template <
typename FT>
55 bool has_value() const noexcept {
return m_variant.index() == 1; }
58 return std::get<1>(m_variant);
62 return std::get<1>(m_variant);
65 return has_value() ? value() : std::forward<U>(
default_value);
68 return has_value() ? std::move(value())
71 explicit operator bool() const noexcept {
return has_value(); }
T & value() LIFETIMEBOUND
T & operator*() LIFETIMEBOUND
T value_or(U &&default_value) const &
bool has_value() const noexcept
std::optional methods, so functions returning optional<T> can change to return Result<T> with minimal...
const T & operator*() const LIFETIMEBOUND
const T & value() const LIFETIMEBOUND
const T * operator->() const LIFETIMEBOUND
T value_or(U &&default_value) &&
friend bilingual_str ErrorString(const Result< FT > &result)
std::conditional_t< std::is_same_v< M, void >, std::monostate, M > T
T * operator->() LIFETIMEBOUND
std::variant< bilingual_str, T > m_variant
bool error(const char *fmt, const Args &...args)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
bilingual_str ErrorString(const Result< T > &result)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...