From 4a30bf58a48ed6f31f4c53473e8de70a8cd819da Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Sat, 6 Dec 2025 20:06:10 +0800 Subject: Fix SDL popup window. --- include/cru/base/Guard.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'include/cru/base/Guard.h') diff --git a/include/cru/base/Guard.h b/include/cru/base/Guard.h index ae120f5a..6097b4d3 100644 --- a/include/cru/base/Guard.h +++ b/include/cru/base/Guard.h @@ -46,26 +46,21 @@ inline AutoFreePtr MakeAutoFree(T* ptr) { template class AutoDestruct { public: - AutoDestruct() : value_(std::nullopt), auto_destruct_(false) {} + AutoDestruct() : value_(std::nullopt) {} - explicit AutoDestruct(T value, bool auto_destruct = true) - : value_(std::move(value)), auto_destruct_(auto_destruct) {} + explicit AutoDestruct(T value) : value_(std::move(value)) {} CRU_DELETE_COPY(AutoDestruct) AutoDestruct(AutoDestruct&& other) noexcept - : value_(std::move(other.value_)), auto_destruct_(other.auto_destruct_) { + : value_(std::move(other.value_)) { other.value_ = std::nullopt; - other.auto_destruct_ = false; } AutoDestruct& operator=(AutoDestruct&& other) noexcept { if (this != &other) { DoDestruct(); - value_ = other.value_; - auto_destruct_ = other.auto_destruct_; - other.value_ = std::nullopt; - other.auto_destruct_ = false; + value_.swap(other.value_); } return *this; } @@ -96,7 +91,6 @@ class AutoDestruct { CheckValid(); auto value = std::move(*value_); value_ = std::nullopt; - auto_destruct_ = false; return value; } @@ -109,13 +103,13 @@ class AutoDestruct { private: void DoDestruct() { - if (auto_destruct_ && value_) { + if (value_) { Destructor{}(*value_); + value_ = std::nullopt; } } private: std::optional value_; - bool auto_destruct_; }; } // namespace cru -- cgit v1.2.3