Fold Expressions

Get to know the types of fold expressions added in C++17 and their benefits in this lesson.

Implementing fold expressions

A fold expression is an expression involving a parameter pack that folds (or reduces) the elements of the parameter pack over a binary operator. To understand how this works, we’ll look at several examples. Earlier in this section, we implemented a variable function template called sum that returned the sum of all its supplied arguments.

For convenience, we’ll show it again here:

Get hands-on with 1400+ tech skills courses.