mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-06 13:09:43 +01:00
util: Implement Expected::value()&& and Expected::error()&&
They are currently unused, but implementing them is closer to the std::expected.
This commit is contained in:
@@ -43,6 +43,13 @@ BOOST_AUTO_TEST_CASE(expected_value)
|
||||
BOOST_CHECK_EQUAL(read->x, 45);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(expected_value_rvalue)
|
||||
{
|
||||
Expected<std::unique_ptr<int>, int> no_copy{std::make_unique<int>(5)};
|
||||
const auto moved{std::move(no_copy).value()};
|
||||
BOOST_CHECK_EQUAL(*moved, 5);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(expected_value_or)
|
||||
{
|
||||
Expected<std::unique_ptr<int>, int> no_copy{std::make_unique<int>(1)};
|
||||
@@ -81,6 +88,20 @@ BOOST_AUTO_TEST_CASE(expected_error)
|
||||
BOOST_CHECK_EQUAL(read.error(), "fail1");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(expected_error_rvalue)
|
||||
{
|
||||
{
|
||||
Expected<int, std::unique_ptr<int>> nocopy_err{Unexpected{std::make_unique<int>(7)}};
|
||||
const auto moved{std::move(nocopy_err).error()};
|
||||
BOOST_CHECK_EQUAL(*moved, 7);
|
||||
}
|
||||
{
|
||||
Expected<void, std::unique_ptr<int>> void_nocopy_err{Unexpected{std::make_unique<int>(9)}};
|
||||
const auto moved{std::move(void_nocopy_err).error()};
|
||||
BOOST_CHECK_EQUAL(*moved, 9);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(unexpected_error_accessors)
|
||||
{
|
||||
Unexpected u{std::make_unique<int>(-1)};
|
||||
|
||||
Reference in New Issue
Block a user