Use Fold Expressions for Variadic Tuples

Learn to use fold expressions for variadic tuples.

The std::tuple class is essentially a more complex, and less convenient, struct. The interface for tuple is cumbersome, although class template argument deduction and structured binding have made it somewhat easier.

typically struct is used over tuple , with one significant exception: the one real advantage of tuple is that it can be used with fold expressions in a variadic context.

Fold expressions

Designed to make it easier to expand a variadic parameter pack, fold expressions are a new feature with C++17. Prior to fold expressions, expanding a parameter pack required a recursive function:

Get hands-on with 1400+ tech skills courses.