44 class [[nodiscard]] SharedScopeGuard
46 std::shared_ptr<void> Guard_;
49 SharedScopeGuard (
const F&
f)
50 : Guard_ {
nullptr, [
f] (
void*) {
f (); } }
54 SharedScopeGuard () =
delete;
56 SharedScopeGuard (
const SharedScopeGuard&) =
default;
57 SharedScopeGuard (SharedScopeGuard&&) =
default;
59 SharedScopeGuard& operator= (
const SharedScopeGuard&) =
default;
60 SharedScopeGuard& operator= (SharedScopeGuard&&) =
default;
64 class [[nodiscard]] ScopeGuard
69 ScopeGuard () noexcept
75 ScopeGuard (
const F&
f) noexcept
80 ScopeGuard (
const ScopeGuard&) =
delete;
81 ScopeGuard& operator= (
const ScopeGuard&) =
delete;
83 ScopeGuard& operator= (ScopeGuard&& other)
89 Perform_ = other.Perform_;
90 other.Perform_ =
false;
94 ScopeGuard (ScopeGuard&& other) noexcept
96 , Perform_ { other.Perform_ }
98 other.Perform_ =
false;
107 void Dismiss () noexcept
112 ScopeGuard<DefaultScopeGuardDeleter> EraseType ()
115 return ScopeGuard<DefaultScopeGuardDeleter> { F_ };
118 operator ScopeGuard<DefaultScopeGuardDeleter> ()
126 throw std::logic_error {
"this scope guard has already been converted to a shared one" };