Explorar o código

common: common_funcs: Add R_UNLESS macro.

bunnei %!s(int64=5) %!d(string=hai) anos
pai
achega
92d5c63f01
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      src/common/common_funcs.h

+ 8 - 0
src/common/common_funcs.h

@@ -93,6 +93,14 @@ __declspec(dllimport) void __stdcall DebugBreak(void);
         return static_cast<T>(key) == 0;                                                           \
     }
 
+/// Evaluates a boolean expression, and returns a result unless that expression is true.
+#define R_UNLESS(expr, res)                                                                        \
+    {                                                                                              \
+        if (!(expr)) {                                                                             \
+            return res;                                                                            \
+        }                                                                                          \
+    }
+
 namespace Common {
 
 [[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) {