mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-22 16:17:40 +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/
|
.idea/
|
||||||
|
*.orig
|
||||||
*.toml
|
*.toml
|
||||||
boost_*
|
boost_*
|
||||||
Resources
|
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