diff --git a/format.h b/format.h index bf6d466d..76fdbc93 100644 --- a/format.h +++ b/format.h @@ -2180,8 +2180,8 @@ inline void FormatDec(char *&buffer, T value) { #define FMT_EXPAND(args) args #define FMT_FOR_EACH_NARG(...) FMT_FOR_EACH_NARG_(__VA_ARGS__, FMT_FOR_EACH_RSEQ_N()) #define FMT_FOR_EACH_NARG_(...) FMT_EXPAND(FMT_FOR_EACH_ARG_N(__VA_ARGS__)) -#define FMT_FOR_EACH_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N -#define FMT_FOR_EACH_RSEQ_N() 8, 7, 6, 5, 4, 3, 2, 1, 0 +#define FMT_FOR_EACH_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N +#define FMT_FOR_EACH_RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 #define FMT_FOR_EACH_(N, func, ...) FMT_CONCATENATE(FMT_FOR_EACH, N)(func, __VA_ARGS__) #define FMT_FOR_EACH(f, ...) \ diff --git a/test/macro-test.cc b/test/macro-test.cc index 7dda30a4..57725213 100644 --- a/test/macro-test.cc +++ b/test/macro-test.cc @@ -75,3 +75,23 @@ TEST(UtilTest, VariadicVoid) { TestVariadicVoid("", 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); EXPECT_EQ(550, result); } + +template +struct S {}; + +#define GET_TYPE(n) S + +int TestVariadic(FMT_GEN(10, GET_TYPE), const fmt::ArgList &args) { \ + int result = 0; \ + for (std::size_t i = 0, n = args.size(); i < n; ++i) \ + result += args[i].int_value; \ + return result; +} +FMT_VARIADIC(int, TestVariadic, FMT_GEN(10, GET_TYPE)) + +#define MAKE_ARG(n) S() + +TEST(UtilTest, Variadic) { + EXPECT_EQ(550, TestVariadic(FMT_GEN(10, MAKE_ARG), + 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)); +}