Waybar/include/util/scope_guard.hpp

22 lines
460 B
C++
Raw Normal View History

#pragma once
#include <utility>
namespace waybar::util {
template <typename Func>
class ScopeGuard {
public:
explicit ScopeGuard(Func&& exit_function) : f{std::forward<Func>(exit_function)} {}
ScopeGuard(const ScopeGuard&) = delete;
ScopeGuard(ScopeGuard&&) = default;
ScopeGuard& operator=(const ScopeGuard&) = delete;
ScopeGuard& operator=(ScopeGuard&&) = default;
~ScopeGuard() { f(); }
private:
Func f;
};
} // namespace waybar::util