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>
49 Result(
T obj) : m_variant{
std::in_place_index_t<1>{}, std::move(obj)} {}
51 : m_variant{
std::in_place_index_t<0>{}, std::move(
error.message)} {}
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);
64 template <
class U>
T value_or(U &&default_value)
const & {
65 return has_value() ? value() : std::forward<U>(default_value);
67 template <
class U>
T value_or(U &&default_value) && {
68 return has_value() ? std::move(value())
69 : std::forward<U>(default_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)