summaryrefslogtreecommitdiff
path: root/louloulibs/utils/scopeguard.hpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-10-20 19:32:20 +0200
committerlouiz’ <louiz@louiz.org>2016-10-20 19:32:20 +0200
commitce06c25e93183282be42ab79bfed2ab7c02791ec (patch)
treeebb9d3c98d641d7a7af1191df72cb72cd801221c /louloulibs/utils/scopeguard.hpp
parent6b4d2e8e3ea6a019778624106b7a839d875152cd (diff)
downloadbiboumi-ce06c25e93183282be42ab79bfed2ab7c02791ec.tar.gz
biboumi-ce06c25e93183282be42ab79bfed2ab7c02791ec.tar.bz2
biboumi-ce06c25e93183282be42ab79bfed2ab7c02791ec.tar.xz
biboumi-ce06c25e93183282be42ab79bfed2ab7c02791ec.zip
Very little optimization by using a simpler scope_guard when possible
The version with the vector, that can be disabled etc, is “very” slow, so we use unique_ptr when we don’t need to disable it, and when it only contains one function
Diffstat (limited to 'louloulibs/utils/scopeguard.hpp')
-rw-r--r--louloulibs/utils/scopeguard.hpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/louloulibs/utils/scopeguard.hpp b/louloulibs/utils/scopeguard.hpp
index ee1e2ef..cd0e89e 100644
--- a/louloulibs/utils/scopeguard.hpp
+++ b/louloulibs/utils/scopeguard.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <functional>
+#include <memory>
#include <vector>
/**
@@ -85,5 +86,11 @@ private:
};
+template<typename F>
+auto make_scope_guard(F&& f)
+{
+ return std::unique_ptr<void, std::decay_t<F>>{(void*)1, std::forward<F>(f)};
+}
+
}