example1_basic_variadic_function.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include <iostream>

template<typename... Args>
void printAll(Args... args) {
    (std::cout << ... << args) << std::endl;  // Fold expression in C++17
}

int main() {
    printAll(1, 2.5, "Hello", 'A');  // Outputs: 1 2.5 Hello A
    return 0;
}
Back to variadic_template