From 16dc21cd1a820b49901df69ab3f21da1ddc69476 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Wed, 11 Feb 2026 11:13:20 +0100 Subject: interduce defer macro --- src/utils.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h index a4467d3..deba95f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,9 +1,9 @@ #pragma once -#include #include -#include +#include +#include #include #include @@ -63,3 +63,29 @@ static inline u32 wayc_min(u32 a, u32 b) { return a > b ? a : b; } } while (0) #define wayc_notnull(expr) wayc_assert(expr != NULL) + +#define WAYC_CONCAT_IMPL(a, b) a##b +#define WAYC_CONCAT(a, b) WAYC_CONCAT_IMPL(a, b) + +#define WAYC_UNIQUE(base) WAYC_CONCAT(base, WAYC_CONCAT(__LINE__, __COUNTER__)) + +template +struct is_same { + static constexpr bool value = false; +}; + +template +struct is_same { + static constexpr bool value = true; +}; + +template +struct defer_s { + Func func; + + defer_s(Func func) : func(func) {} + + ~defer_s() { func(); } +}; + +#define wayc_defer(func) auto WAYC_UNIQUE(_defer_) = defer_s([&]() { func; }) \ No newline at end of file -- cgit v1.2.3