From a05824253670ec62abe26dd337a5398577d38565 Mon Sep 17 00:00:00 2001 From: wyc <1104749580@qq.com> Date: Sun, 9 Aug 2026 15:30:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/library/include/adminive/managed.hpp | 5 +++-- backend/service/tests/managed_test.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/library/include/adminive/managed.hpp b/backend/library/include/adminive/managed.hpp index 5995e21..442ecbd 100644 --- a/backend/library/include/adminive/managed.hpp +++ b/backend/library/include/adminive/managed.hpp @@ -297,11 +297,12 @@ public: std::invoke(std::forward(function), value_); }); } else { - std::optional> result; + using Value_Result = std::remove_cvref_t; + std::optional result; this->with_all_writable_locked([&](auto&) { result.emplace(std::invoke(std::forward(function), value_)); }); - return std::move(*result); + return Value_Result(std::move(*result)); } } T snapshot() const requires std::copy_constructible { diff --git a/backend/service/tests/managed_test.cpp b/backend/service/tests/managed_test.cpp index 14ea0fc..061b334 100644 --- a/backend/service/tests/managed_test.cpp +++ b/backend/service/tests/managed_test.cpp @@ -4,6 +4,7 @@ #include "adminive_test.hpp" #include #include +#include namespace managed_test { using Json = nlohmann::json; struct Section_Config { @@ -108,6 +109,12 @@ int main() { value = 12; }); ADMINIVE_CHECK(Probe_Lock::exclusive_locks.load(std::memory_order_relaxed) == 1); + const auto [written_value, write_message] = guarded.write([](Section_Config& value) { + value.backend_value = 14; + return std::tuple{value.backend_value, std::string(128, 'x')}; + }); + ADMINIVE_CHECK(written_value == 14); + ADMINIVE_CHECK(write_message == std::string(128, 'x')); Probe_Lock::reset(); unsynchronized.write([](int& value) { value = 13;