Suppose I have a function write(ostream& s, T& val)
I could call write multiple times on different data:
write(s, 5);
write(s, 2.5);
write(s, "abc");
Instead I would like a variadic parameter list that will generate the above with a single call:
write(s, 5, 2.5, "abc");
I can do it for a single type:
template<typename T, typename... Args>
void write(ostream& s, T first, Args... args) {
write(s, first);
write(s, args...);
}
Is there any way to achieve this for different types?
Aucun commentaire:
Enregistrer un commentaire