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.
This commit is contained in:
Thomas Haller 2021-06-04 15:00:21 +02:00
parent dadaba9ab6
commit 34a521e2d6
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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__)