summaryrefslogtreecommitdiffstats
path: root/src/common/windows/util.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/windows/util.hpp')
-rw-r--r--src/common/windows/util.hpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/common/windows/util.hpp b/src/common/windows/util.hpp
new file mode 100644
index 0000000..939f6bb
--- /dev/null
+++ b/src/common/windows/util.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <utility>
+#include <type_traits>
+
+template <typename Fn>
+struct on_scope_exit {
+ static_assert(std::is_nothrow_move_constructible<Fn>::value,
+ "Fn must be nothrow move constructible");
+
+ explicit on_scope_exit(Fn&& fn) noexcept
+ : _fn(std::move(fn)) {};
+ on_scope_exit(const on_scope_exit&) = delete;
+ on_scope_exit& operator=(const on_scope_exit&) = delete;
+ ~on_scope_exit() noexcept {
+ this->_fn();
+ }
+
+ private:
+ Fn _fn;
+};