, Boost.Preprocessor:
#include <boost/preprocessor.hpp>
#define G(args) BOOST_PP_SEQ_FOR_EACH_I(G_GENF, x, args)
#define G_GENF(r, data, i, elem) \
BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(i, 0)) f(elem)
:
G((a))
G((b)(c))
G((d)(e)(f))
:
f(a)
f(b) , f(c)
f(d) , f(e) , f(f)
G(a, b, c), , , , , , , . , . :
#define PP_NARGS(...) PP_NARGS2(__VA_ARGS__, PP_NARGS_COUNT())
#define PP_NARGS2(...) PP_NARGS_IMPL(__VA_ARGS__)
#define PP_NARGS_IMPL(x1, x2, x3, N, ...) N
#define PP_NARGS_COUNT() 3, 2, 1, 0, ERROR
#define XF(count, ...) XF_IMPL (count, __VA_ARGS__)
#define XF_IMPL(count, ...) XF_ ## count (__VA_ARGS__)
#define XF_1(x1) f(x1)
#define XF_2(x1, x2) f(x1), f(x2)
#define XF_3(x1, x2, x3) f(x1), f(x2), f(x3)
#define G(...) XF(PP_NARGS(__VA_ARGS__), __VA_ARGS__)
:
G(a)
G(b, c)
G(d, e, f)
:
f(a)
f(b), f(c)
f(d), f(e), f(f)
, , , , , . ( C99/++ 0x, .)