Search⌘ K
AI Features

Examples - Fold Expression

Explore how fold expressions in C++17 improve template programming by enabling simpler and more readable code. Understand techniques like folding over the comma operator for formatted output and discover practical applications such as custom print functions and push_back implementations. This lesson helps you master the use of fold expressions to enhance your C++17 template skills.

We'll cover the following...

Here’s a quite nice implementation of a printf using folds P0036R04

C++ 17
#include <iostream>
using namespace std;
template<typename ...Args>
void FoldPrint(Args&&... args)
{
(cout << ... << forward<Args>(args)) << '\n';
}
int main()
{
cout << "Your Arguments = ";
FoldPrint("hello", 10, 20, 30);
}

​However, the above FoldPrint ...