You should read that if you want to know more about this exciting future feature of C++:
C++17 Fold Expressions
by Baptiste Wicht
From the article:
C++11 introduced variadic template to the languages. This new feature allows to write template functions and classes taking an arbitrary number of template parameters. This a feature I really like and I already used it quite a lot in my different libraries. Here is a very simple example computing the sum of the parameters:
// Good with variadics auto old_sum(){ return 0; } template<typename T1, typename... T> auto old_sum(T1 s, T... ts){ return s + old_sum(ts...);; } // Better with fold expressions template<typename... T> auto fold_sum_1(T... s){ return (... + s); }x
Add a Comment
Comments are closed.