From fd2e317b047b5a6233070ff097af2d96e8f616ef Mon Sep 17 00:00:00 2001 From: Twice Date: Sun, 15 Dec 2024 13:17:41 +0800 Subject: [PATCH] chore: add move assign operator for MultiLockGuard (#2693) Signed-off-by: PragmaTwice --- src/common/lock_manager.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/common/lock_manager.h b/src/common/lock_manager.h index 782d6c8254a..985d5efc8ce 100644 --- a/src/common/lock_manager.h +++ b/src/common/lock_manager.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -125,7 +126,14 @@ class MultiLockGuard { MultiLockGuard(const MultiLockGuard &) = delete; MultiLockGuard &operator=(const MultiLockGuard &) = delete; - MultiLockGuard(MultiLockGuard &&guard) : locks_(std::move(guard.locks_)) {} + MultiLockGuard(MultiLockGuard &&guard) : locks_(std::move(guard.locks_)) { guard.locks_.clear(); } + MultiLockGuard &operator=(MultiLockGuard &&other) noexcept { + if (this != &other) { + std::destroy_at(this); + new (this) MultiLockGuard(std::move(other)); + } + return *this; + } private: std::vector locks_;