Другой (немного сложный) способ, который позволяет избежать рекурсии и запятой:
#include <iostream>
#include <tuple>
struct linefeed {};
template<typename...Args>
void print(Args&&... args)
{
const char* sep = "";
auto print_with_sep = [&sep](auto& os, auto& arg)
{
if constexpr (std::is_same<std::decay_t<decltype(arg)>, linefeed>())
{
sep = "";
os << '\n';
}
else
{
os << sep << arg;
sep = ",";
}
};
auto print_all = [&](auto&&...things)
{
(print_with_sep(std::cout, things), ...);
};
print_all(args..., linefeed());
}
int main()
{
print(1,2,3,4,5, "hello");
print("world", 5,4,3,2,1);
}
ожидаемый результат:
1,2,3,4,5,hello
world,5,4,3,2,1
https://coliru.stacked -crooked.com / a/ 770912eee67d04ac