lix/src/libutil/finally.hh
pennae 8e2eaaaf69 make Finally more local
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.
2022-03-09 00:16:50 +01:00

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(); }
};