polybar-dwm/include/utils/scope.hpp
2022-03-06 18:28:26 +01:00

34 lines
569 B
C++

#pragma once
#include "common.hpp"
POLYBAR_NS
namespace scope_util {
/**
* Creates a wrapper that will trigger given callback when
* leaving the object's scope (i.e, when it gets destroyed)
*
* Example usage:
* @code cpp
* {
* on_exit handler([]{ ... });
* ...
* }
* @endcode
*/
class on_exit {
public:
on_exit(const function<void(void)>& fn) : m_callback(fn) {}
virtual ~on_exit() {
m_callback();
}
protected:
function<void()> m_callback;
};
} // namespace scope_util
POLYBAR_NS_END