Any trick to unpack a variadic macro? For example,
#define READ(...)
means read the arguments one by one
READ(a, b, c)
will be unpacked to read(a); read(b); read(c)
Any trick to unpack a variadic macro? For example,
#define READ(...)
means read the arguments one by one
READ(a, b, c)
will be unpacked to read(a); read(b); read(c)
You can achieve it with the "paired sliding args" macro technique as described here: https://codecraft.co/2014/11/25/variadic-macros-tricks
#define _EXPAND(args) args
#define READ1(a) read(a);
#define READ2(a,b) read(a); read(b);
#define READ3(a,b,c) read(a); read(b); read(c);
#define GETREAD(_1,_2,_3, READN,...) READN
#define READ(...) _EXPAND(GETREAD(__VA_ARGS__, READ3, READ2, READ1)(__VA_ARGS__))
The _EXPAND(args)
is only needed in MSVC.