I'm reading "C++17 - The Complete Guide" book and I came across the example on page 107 and 108 regarding fold expression in C++17:
template<typename First, typename... Args>
void print(First first, const Args&... args)
{
std::cout << first;
auto outWithSpace = [](const auto& arg)
{
std::cout << " " << arg;
};
(..., outWithSpace(args));
std::cout << "\n";
}
Is there any reason that the author couldn't do this as follows (without separating the first argument from the rest and apart from an extra printed space!):
template<typename... Types>
void print(Types const&... args)
{
([](const auto& x){ std::cout << x << " "; }(args), ...);
std::cout << "\n";
}