From fabb47e4e3dba7c03f9242440cb55eb37b493a7a Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 9 Dec 2025 16:17:56 +0100 Subject: [PATCH] util: Implement Expected::operator*()&& It is currently unused, but implementing it is closer to std::expected. --- src/test/util_expected_tests.cpp | 7 +++++++ src/util/expected.h | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/util_expected_tests.cpp b/src/test/util_expected_tests.cpp index 7c9d62ad392..356735b221e 100644 --- a/src/test/util_expected_tests.cpp +++ b/src/test/util_expected_tests.cpp @@ -50,6 +50,13 @@ BOOST_AUTO_TEST_CASE(expected_value_rvalue) BOOST_CHECK_EQUAL(*moved, 5); } +BOOST_AUTO_TEST_CASE(expected_deref_rvalue) +{ + Expected, int> no_copy{std::make_unique(5)}; + const auto moved{*std::move(no_copy)}; + BOOST_CHECK_EQUAL(*moved, 5); +} + BOOST_AUTO_TEST_CASE(expected_value_or) { Expected, int> no_copy{std::make_unique(1)}; diff --git a/src/util/expected.h b/src/util/expected.h index 85d4bf9d47a..b01d866a863 100644 --- a/src/util/expected.h +++ b/src/util/expected.h @@ -88,8 +88,9 @@ public: constexpr E& error() & noexcept LIFETIMEBOUND { return *Assert(std::get_if<1>(&m_data)); } constexpr E&& error() && noexcept LIFETIMEBOUND { return std::move(error()); } - constexpr T& operator*() noexcept LIFETIMEBOUND { return value(); } - constexpr const T& operator*() const noexcept LIFETIMEBOUND { return value(); } + 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(); }