Variadics are even more easy to use than we tought:
Using Variadic Templates cleanly
by Florian Weber
From the article:
When one comes across examples for variadic templates, almost always recursion is used to achieve almost everything, for example like this:
// We are lucky: the author correctly used zero // arguments instead of one as the base-case, // thereby avoiding code-duplication: inline void print_to_stream(std::ostream&) {} template<typename Head, typename...Tail> void print_to_stream(std::ostream& stream, const Head& h, const Tail&... t) { stream << h; print_to_stream(stream, t...); }In this article we will see what better alternatives for this rather clumsy hack exist and see how we can write a better version with less code...
Add a Comment
Comments are closed.