1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-18 13:55:11 -05:00
polybar/include/utils/scope.hpp
2022-03-06 18:28:26 +01:00

33 lines
573 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(void)> m_callback;
};
} // namespace scope_util
POLYBAR_NS_END