diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-12-06 20:06:10 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-12-07 19:52:05 +0800 |
| commit | 4a30bf58a48ed6f31f4c53473e8de70a8cd819da (patch) | |
| tree | 32aab619013cbe2d0557a212832ba24833d2cc36 /include/cru/base | |
| parent | 9a87e5cf786f3e8fddc933136d210edd4ef72c89 (diff) | |
| download | cru-4a30bf58a48ed6f31f4c53473e8de70a8cd819da.tar.gz cru-4a30bf58a48ed6f31f4c53473e8de70a8cd819da.tar.bz2 cru-4a30bf58a48ed6f31f4c53473e8de70a8cd819da.zip | |
Fix SDL popup window.
Diffstat (limited to 'include/cru/base')
| -rw-r--r-- | include/cru/base/Guard.h | 18 |
1 files changed, 6 insertions, 12 deletions
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<T> MakeAutoFree(T* ptr) { template <typename T, typename Destructor> 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<T> value_; - bool auto_destruct_; }; } // namespace cru |
