5#ifndef BITCOIN_UTIL_RESULT_H
6#define BITCOIN_UTIL_RESULT_H
38 using T = std::conditional_t<std::is_same_v<M, void>, std::monostate,
M>;
52 template <
typename FT>
57 Result(
T obj) : m_variant{
std::in_place_index_t<1>{}, std::move(obj)} {}
58 Result(
Error error) : m_variant{
std::in_place_index_t<0>{}, std::move(error.message)} {}
64 bool has_value() const noexcept {
return m_variant.index() == 1; }
68 return std::get<1>(m_variant);
73 return std::get<1>(m_variant);
78 return has_value() ? value() : std::forward<U>(default_value);
83 return has_value() ? std::move(value()) : std::forward<U>(default_value);
85 explicit operator bool() const noexcept {
return has_value(); }
Result & operator=(const Result &)=delete
Disallow operator= to avoid confusion in the future when the Result class gains support for richer er...
T & value() LIFETIMEBOUND
Result & operator=(Result &&)=delete
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
Result(const Result &)=delete
Disallow copy constructor, require Result to be moved for efficiency.
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
Result(Result &&)=default
bilingual_str ErrorString(const Result< T > &result)