How does folding over comma work?

Viewed 2772

How does the following line unfold?

template <class... Ts>
void print_all(std::ostream& os, Ts const&... args) {
    (void(os << args), ...);
}

Applying the rule,

Unary right fold (E op ...) becomes E1 op (... op (EN-1 op EN))

provided by cppreference,

E  = void(os << args)
op = , 

Then the expansion becomes

void(os << args[0], ..., (args[N-3], (args[N-2], args[N-1])) )

?

How about

v.push_back(args), ...

Does it become

v.push_back(args[0], (args[1], ..., (args[N-2], args[N-1])))

Both the expansion and the parenthesis are confusing. Would someone explain?

1 Answers
Related