summaryrefslogtreecommitdiff
path: root/louloulibs/utils/scopeguard.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'louloulibs/utils/scopeguard.hpp')
-rw-r--r--louloulibs/utils/scopeguard.hpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/louloulibs/utils/scopeguard.hpp b/louloulibs/utils/scopeguard.hpp
index cd0e89e..e697fc3 100644
--- a/louloulibs/utils/scopeguard.hpp
+++ b/louloulibs/utils/scopeguard.hpp
@@ -87,9 +87,11 @@ private:
};
template<typename F>
-auto make_scope_guard(F&& f)
+auto make_scope_guard(F f)
{
- return std::unique_ptr<void, std::decay_t<F>>{(void*)1, std::forward<F>(f)};
+ static struct Empty {} empty;
+ auto deleter = [f = std::move(f)](Empty*) { f(); };
+ return std::unique_ptr<Empty, decltype(deleter)>{&empty, std::move(deleter)};
}
}