forked from wadehuber/codeexamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariadic.cpp
More file actions
37 lines (27 loc) · 681 Bytes
/
Copy pathvariadic.cpp
File metadata and controls
37 lines (27 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
using namespace std;
void print() {
cout << endl;
}
template<typename FirstType, typename... RestOfTypes>
void print(FirstType first_parameter, RestOfTypes... leftovers) {
cout << first_parameter << " ";
print(leftovers...);
}
// C++ 17
template<typename ...T>
auto sum(T ...x) {
return (x + ...);
}
int main() {
int x = 10;
string s = "Hello";
double d = 3.14;
print("Hello", "world!");
print(1, 2, 3, 4, 5);
print(x, s, d, "That's all, folks!");
cout << endl << endl;
cout << "sum ints: " << sum(1,2,3,4,5,6,x) << endl;
cout << "sum doubles: " << sum(9.99, 3.421, 1.23, d) << endl;
return 0;
}