about summary refs log tree commit diff
path: root/third_party/nix/src/libutil/finally.hh
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/nix/src/libutil/finally.hh')
-rw-r--r--third_party/nix/src/libutil/finally.hh13
1 files changed, 13 insertions, 0 deletions
diff --git a/third_party/nix/src/libutil/finally.hh b/third_party/nix/src/libutil/finally.hh
new file mode 100644
index 000000000000..8d3083b6a3ac
--- /dev/null
+++ b/third_party/nix/src/libutil/finally.hh
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <functional>
+
+/* A trivial class to run a function at the end of a scope. */
+class Finally {
+ private:
+  std::function<void()> fun;
+
+ public:
+  Finally(std::function<void()> fun) : fun(fun) {}
+  ~Finally() { fun(); }
+};