mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-10-20 23:46:50 +00:00
Add Defer<FnT> type to defer actions to the end of scope.
This commit is contained in:
1 parent
d054214b7f
commit
8ec90d5186
2 files changed
+19
No files matched your search
@@ -1,4 +1,5 @@
|
||||
.idea/
|
||||
*.orig
|
||||
*.toml
|
||||
boost_*
|
||||
Resources
|
||||
|
||||
@@ -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