chiark / gitweb /
macro: better make IN_SET() macro use const arrays
[elogind.git] / src / shared / macro.h
index 9f5f51cb13e2eff079c667e94785cf07dd27de06..4198095011c0750437c44041de5cc8d92ac314be 100644 (file)
@@ -285,4 +285,18 @@ do {                                                                    \
 #define SET_FLAG(v, flag, b) \
         (v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
 
+#define IN_SET(x, ...)                                                  \
+        ({                                                              \
+                const typeof(x) _x = (x);                               \
+                unsigned _i;                                            \
+                bool _found = false;                                    \
+                for (_i = 0; _i < sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
+                        if (((const typeof(_x)[]) { __VA_ARGS__ })[_i] == _x) { \
+                                _found = true;                          \
+                                break;                                  \
+                        }                                               \
+                _found;                                                 \
+        })
+
+
 #include "log.h"