diff options
Diffstat (limited to 'third_party/nix/src/libutil/finally.hh')
-rw-r--r-- | third_party/nix/src/libutil/finally.hh | 13 |
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..2ead8661a6e7 --- /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: + explicit Finally(std::function<void()> fun) : fun(fun) {} + ~Finally() { fun(); } +}; |