#pragma once template class ScopeGuard { public: ScopeGuard(const Callback& callback) : m_callback(callback) { } void deactivate() { m_activated = false; } ~ScopeGuard() { if (m_activated) m_callback(); } private: bool m_activated { true }; Callback m_callback; }; template [[nodiscard]] ScopeGuard make_scope_guard(const Callback& callback) { return { callback }; }