mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-14 02:06:16 +02:00
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.
13 lines
220 B
C++
13 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(); }
|
|
};
|