mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
Add Defer<FnT> type to defer actions to the end of scope.
This commit is contained in:
18
include/Defer.h
Normal file
18
include/Defer.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#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;
|
||||
};
|
||||
Reference in New Issue
Block a user