From 34a521e2d6471743692e60983b68b56fe35d85fc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Jun 2021 15:00:21 +0200 Subject: [PATCH] std-aux: add NM_VA_ARGS_JOIN() helper macro We have variadic macros like NM_UTILS_ENUM2STR() that create a switch statement. Their implementation relies on the way how __VA_ARGS__ gets expanded to a comma separated list. But that implementation is not great. Let's instead add (and later use) NM_VA_ARGS_JOIN() which can join variadic arguments by a configurable separator. --- src/libnm-std-aux/nm-std-aux.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 56ec7a1e4e..f14a81346a 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -618,6 +618,10 @@ nm_streq0(const char *s1, const char *s2) /*****************************************************************************/ +#define NM_VA_ARGS_JOIN(sep, ...) NM_VA_ARGS_FOREACH(, , sep, _NM_MACRO_SELECT_FIRST, __VA_ARGS__) + +/*****************************************************************************/ + #define _NM_IN_SET_EVAL_1(op, _x, y) (_x == (y)) #define _NM_IN_SET_EVAL_2(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_1(op, _x, __VA_ARGS__) #define _NM_IN_SET_EVAL_3(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_2(op, _x, __VA_ARGS__)