Open Source Your Knowledge, Become a Contributor

Fold expressions

With C++11 we got variadic templates which is a great feature, especially if you want to work with a variable number of input parameters to a function. For example, previously (pre C++11) you had to write several different versions of a function (like one for one parameter, another for two parameters, another for three params... ).

Still, variadic templates required some additional code when you wanted to implement 'recursive' functions like sum, all. You had to specify rules for the recursion: