aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/finally.hh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-07 09:40:36 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-07 09:40:36 -0400
commitc036de086e2f06e6dee1c31e29e05a802f6ccf80 (patch)
treea3760ae3cec9cabbab39bd95bd2eaab8e2ce2bdf /src/libutil/finally.hh
parentc863e5f338947ecff275a67725ecf50b2a47bdb5 (diff)
parent81dfc2b01231c65137017de092c8506838fadd94 (diff)
Merge remote-tracking branch 'upstream/master' into trustless-remote-builder-simple
Diffstat (limited to 'src/libutil/finally.hh')
-rw-r--r--src/libutil/finally.hh12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libutil/finally.hh b/src/libutil/finally.hh
index 7760cfe9a..db654301f 100644
--- a/src/libutil/finally.hh
+++ b/src/libutil/finally.hh
@@ -1,14 +1,16 @@
#pragma once
+///@file
-#include <functional>
-
-/* A trivial class to run a function at the end of a scope. */
+/**
+ * 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(); }
};