#include <iostream> template<typename... Args> auto sum_all(Args... args) { return (args + ...); } template<typename... Args> auto any_true(Args... args) { return (args || ...); } template<typename... Args> void print_all(Args... args) { ((std::cout << args << " "), ...); std::cout << "\n"; } int main() { auto sum = sum_all(1, 2, 3, 4, 5); auto res = any_true(false, true, false); print_all("Hello", 42, 3.14, 'A'); return 0; }
Details
– The compiler expands the fold at compile time into a normal expression.
– The precalculation depends on whether the arguments are known at compile time.