mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 18:22:57 +02:00
util: Add Unexpected::error()
This is not needed, but a bit closer to the std lib.
This commit is contained in:
@@ -20,8 +20,14 @@ template <class E>
|
||||
class Unexpected
|
||||
{
|
||||
public:
|
||||
constexpr explicit Unexpected(E e) : err(std::move(e)) {}
|
||||
E err;
|
||||
constexpr explicit Unexpected(E e) : m_error(std::move(e)) {}
|
||||
|
||||
constexpr const E& error() const& noexcept LIFETIMEBOUND { return m_error; }
|
||||
constexpr E& error() & noexcept LIFETIMEBOUND { return m_error; }
|
||||
constexpr E&& error() && noexcept LIFETIMEBOUND { return std::move(m_error); }
|
||||
|
||||
private:
|
||||
E m_error;
|
||||
};
|
||||
|
||||
/// The util::Expected class provides a standard way for low-level functions to
|
||||
@@ -40,7 +46,7 @@ public:
|
||||
constexpr Expected() : m_data{std::in_place_index_t<0>{}, ValueType{}} {}
|
||||
constexpr Expected(ValueType v) : m_data{std::in_place_index_t<0>{}, std::move(v)} {}
|
||||
template <class Err>
|
||||
constexpr Expected(Unexpected<Err> u) : m_data{std::in_place_index_t<1>{}, std::move(u.err)}
|
||||
constexpr Expected(Unexpected<Err> u) : m_data{std::in_place_index_t<1>{}, std::move(u).error()}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user