Little scopeguard cleanup, and add a test

This commit is contained in:
louiz’
2017-02-15 01:07:32 +01:00
parent fa6635e548
commit 7f08cf83aa
3 changed files with 17 additions and 4 deletions
+4 -2
View File
@@ -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)};
}
}