mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
19 lines
285 B
C++
19 lines
285 B
C++
#pragma once
|
|
|
|
#include <functional>
|
|
|
|
template <typename FnT>
|
|
class Defer final {
|
|
public:
|
|
Defer(FnT fn)
|
|
: mFunction([&fn] { (void)fn(); }) { }
|
|
~Defer() {
|
|
if (mFunction) {
|
|
mFunction();
|
|
}
|
|
}
|
|
|
|
private:
|
|
std::function<void()> mFunction;
|
|
};
|