Test FMT_VARIADIC.

This commit is contained in:
Victor Zverovich 2014-06-28 11:20:04 -07:00
parent 2f6dddd6fd
commit be7473b401
2 changed files with 22 additions and 2 deletions

View File

@ -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, ...) \

View File

@ -75,3 +75,23 @@ TEST(UtilTest, VariadicVoid) {
TestVariadicVoid("", 10, 20, 30, 40, 50, 60, 70, 80, 90, 100);
EXPECT_EQ(550, result);
}
template <int>
struct S {};
#define GET_TYPE(n) S<n>
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<n>()
TEST(UtilTest, Variadic) {
EXPECT_EQ(550, TestVariadic(FMT_GEN(10, MAKE_ARG),
10, 20, 30, 40, 50, 60, 70, 80, 90, 100));
}