mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-02 03:31:09 +00:00
util: Add Expected::swap()
This commit is contained in:
parent
fabb47e4e3
commit
faa59b3679
@ -122,4 +122,13 @@ BOOST_AUTO_TEST_CASE(unexpected_error_accessors)
|
||||
BOOST_CHECK_EQUAL(*moved, -2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(expected_swap)
|
||||
{
|
||||
Expected<const char*, std::unique_ptr<int>> a{Unexpected{std::make_unique<int>(-1)}};
|
||||
Expected<const char*, std::unique_ptr<int>> b{"good"};
|
||||
a.swap(b);
|
||||
BOOST_CHECK_EQUAL(a.value(), "good");
|
||||
BOOST_CHECK_EQUAL(*b.error(), -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@ -88,6 +88,8 @@ public:
|
||||
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()); }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user