forked from lix-project/lix
8e2eaaaf69
no need for function<> with c++17 deduction. this saves allocations and virtual calls, but has the same semantics otherwise. not going through function has the side effect of giving compilers more insight into the cleanup code, so we need a few local warning disables.
14 lines
220 B
C++
14 lines
220 B
C++
#pragma once
|
|
|
|
/* A trivial class to run a function at the end of a scope. */
|
|
template<typename Fn>
|
|
class Finally
|
|
{
|
|
private:
|
|
Fn fun;
|
|
|
|
public:
|
|
Finally(Fn fun) : fun(std::move(fun)) { }
|
|
~Finally() { fun(); }
|
|
};
|