2023-10-22 23:14:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace waybar::util {
|
|
|
|
|
|
|
|
template <typename Func>
|
2023-10-23 12:59:46 +00:00
|
|
|
class ScopeGuard {
|
2023-10-22 23:14:52 +00:00
|
|
|
public:
|
2023-10-23 12:59:46 +00:00
|
|
|
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(); }
|
2023-10-22 23:14:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Func f;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::util
|