aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/finally.hh
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2021-12-31 00:50:23 +0100
committerpennae <github@quasiparticle.net>2022-03-09 00:16:50 +0100
commit8e2eaaaf69d9e216fce3ca6f7913bd0e2048e4b2 (patch)
tree00dfe35156d96e0c16612bcf00506b1049280054 /src/libutil/finally.hh
parent47baa9d43c0339b0a738b9b75c5ddcfb07d7131d (diff)
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.
Diffstat (limited to 'src/libutil/finally.hh')
-rw-r--r--src/libutil/finally.hh7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/libutil/finally.hh b/src/libutil/finally.hh
index 7760cfe9a..dee2e8d2f 100644
--- a/src/libutil/finally.hh
+++ b/src/libutil/finally.hh
@@ -1,14 +1,13 @@
#pragma once
-#include <functional>
-
/* A trivial class to run a function at the end of a scope. */
+template<typename Fn>
class Finally
{
private:
- std::function<void()> fun;
+ Fn fun;
public:
- Finally(std::function<void()> fun) : fun(fun) { }
+ Finally(Fn fun) : fun(std::move(fun)) { }
~Finally() { fun(); }
};