On Monday, November 25th, 2024 at 9:48 PM, Yongwei Wu <wuyongwei@gmail.com> wrote:On Tue, 26 Nov 2024 at 04:13, Smith, Jim via Std-Discussion <std-discussion@lists.isocpp.org> wrote:Hi All,Is there already a proposal for making the C++ for loop generic, for example able to print a function parameter pack?
As Andrey said, fold expressions can usually do. Specifically, with the comma operator.This is an example I usually use in training:template <typename T, typename... Args>
void printWithSeparator(const T& sep, const Args&... args)
{
((cout << args << sep), ...);
}
Replace with the `(cout << args << sep)` part with what you want to do with the arguments.