#pragma once #include namespace sg { template class scope_guard_t { public: explicit scope_guard_t(Deleter&& deleter) noexcept : m_deleter(std::move(deleter)) { } scope_guard_t(scope_guard_t&&)= default; scope_guard_t(const scope_guard_t&) = delete; ~scope_guard_t() { m_deleter(); } scope_guard_t& operator=(const scope_guard_t&) = delete; scope_guard_t& operator=(scope_guard_t&&) = delete; private: Deleter m_deleter; }; template scope_guard_t scope_guard(Deleter&& deleter) noexcept { return scope_guard_t(std::move(deleter)); } }