summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2025-10-01 13:19:35 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2025-10-01 13:19:35 +0200
commit17cd226a1531c3948ce12eca5c20fdcd96ec86cf (patch)
tree74d677f41cbf794d96c19f5813d6a9004debe8ae
parenteb11e1d94a976fafa594c25e387a130bef3c1173 (diff)
downloadforstio-forstio-17cd226a1531c3948ce12eca5c20fdcd96ec86cf.tar.gz
Small feature for basic RAII guard ensurance in C :)
-rw-r--r--modules/core/c++/raii_guard.hpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/core/c++/raii_guard.hpp b/modules/core/c++/raii_guard.hpp
new file mode 100644
index 0000000..fe17781
--- /dev/null
+++ b/modules/core/c++/raii_guard.hpp
@@ -0,0 +1,26 @@
+#pragma once
+
+namespace saw {
+template<typename Constr, typename Destr>
+class raii_guard {
+private:
+ Constr constr_;
+ Destr destr_;
+public:
+ raii_guard(Constr&& constr__, Destr&& destr__):
+ constr_{std::move(constr__)},
+ destr_{std::move(destr__)}
+ {
+ constr_();
+ }
+
+ ~raii_guard(){
+ destr()_;
+ }
+};
+
+template<typename Constr, typename Destr>
+raii_guard<Constr,Destr> make_raii_guard(Constr&& constr, Destr&& destr){
+ return {std::move(constr),std::move(destr)};
+}
+}