Repository: bitcoin/bitcoin
File: src/util/expected.h (C/C++)

Code before:
    constexpr explicit operator bool() const noexcept { return has_value(); }

    constexpr const T& value() const LIFETIMEBOUND
    {
        if (!Assume(has_value())) {
            throw BadExpectedAccess{};
        }
        return std::get<0>(m_data);
    }
    constexpr T& value() LIFETIMEBOUND
    {
        if (!Assume(has_value())) {
            throw BadExpectedAccess{};
        }
        return std::get<0>(m_data);
    }

    template <class U>
    T value_or(U&& default_value) const&
    {
        return has_value() ? value() : std::forward<U>(default_value);
    }
    template <class U>
    T value_or(U&& default_value) &&
    {
        return has_value() ? std::move(value()) : std::forward<U>(default_value);
    }

    constexpr const E& error() const LIFETIMEBOUND
    {
        assert(!has_value());
        return std::get<1>(m_data);
    }
    constexpr E& error() LIFETIMEBOUND
    {
        assert(!has_value());
        return std::get<1>(m_data);
    }

    constexpr T& operator*() LIFETIMEBOUND { return value(); }
    constexpr const T& operator*() const LIFETIMEBOUND { return value(); }

    constexpr T* operator->() LIFETIMEBOUND { return &value(); }
    constexpr const T* operator->() const LIFETIMEBOUND { return &value(); }
};

template <class E>
class Expected<void, E>
{
private:
    std::variant<std::monostate, E> m_data;

Review comment (suggestion):
Would seem good to change `std::move(value())` to `value()` since it should already be an rvalue, and this would make the value_or implementation more consistent

Code after:

    constexpr const T& value() const& LIFETIMEBOUND
    {
        if (!has_value()) {
            throw BadExpectedAccess{};
        }
        return std::get<0>(m_data);
    }
    constexpr T& value() & LIFETIMEBOUND
    {
        if (!has_value()) {
            throw BadExpectedAccess{};
        }
        return std::get<0>(m_data);
    }
    constexpr T&& value() && LIFETIMEBOUND { return std::move(value()); }

    template <class U>
    T value_or(U&& default_value) const&
    {
        return has_value() ? value() : std::forward<U>(default_value);
    }
    template <class U>
    T value_or(U&& default_value) &&
    {
        return has_value() ? std::move(value()) : std::forward<U>(default_value);
    }

    constexpr const E& error() const& noexcept LIFETIMEBOUND { return *Assert(std::get_if<1>(&m_data)); }
    constexpr E& error() & noexcept LIFETIMEBOUND { return *Assert(std::get_if<1>(&m_data)); }
    constexpr E&& error() && noexcept LIFETIMEBOUND { return std::move(error()); }

    constexpr void swap(Expected& other) noexcept { m_data.swap(other.m_data); }

    constexpr T& operator*() & noexcept LIFETIMEBOUND { return value(); }
    constexpr const T& operator*() const& noexcept LIFETIMEBOUND { return value(); }
    constexpr T&& operator*() && noexcept LIFETIMEBOUND { return std::move(value()); }

    constexpr T* operator->() noexcept LIFETIMEBOUND { return &value(); }
    constexpr const T* operator->() const noexcept LIFETIMEBOUND { return &value(); }
};

template <class E>
class Expected<void, E>
{
private:
    std::variant<std::monostate, E> m_data;

public:
    constexpr Expected() : m_data{std::in_place_index<0>, std::monostate{}} {}
    template <class Err>