Fold Expressions

This lesson explains how variadic templates in C++ 17 are better than available in C++ 11.

C++11 introduced variadic templates which is a powerful feature, especially if you want to work with a variable number of input template parameters to a function.

Previously

Pre C++11 you had to write several different versions of a template function (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 and all. You had to specify rules for the recursion.

For example:

Get hands-on with 1200+ tech skills courses.