summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-common.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/source/core/slang-common.h b/source/core/slang-common.h
index 9e73b50a9..7d455546a 100644
--- a/source/core/slang-common.h
+++ b/source/core/slang-common.h
@@ -84,6 +84,26 @@ namespace Slang
}
}
+// SLANG_DEFER
+template<typename F>
+class SlangDeferImpl
+{
+ F f;
+public:
+ SlangDeferImpl(F&& f)
+ : f(Slang::_Move(f))
+ {}
+ ~SlangDeferImpl()
+ {
+ f();
+ }
+};
+
+#ifndef SLANG_DEFER_LAMBDA
+#define SLANG_DEFER_LAMBDA(x) auto SLANG_CONCAT(slang_defer_, __LINE__) = SlangDeferImpl(x)
+#define SLANG_DEFER(x) auto SLANG_CONCAT(slang_defer_,__LINE__) = SlangDeferImpl([&](){x;})
+#endif
+
//
// Some macros for avoiding boilerplate
// TODO: could probably deduce the size with templates, and move the whole