-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariadic.cpp
57 lines (46 loc) · 1 KB
/
variadic.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <sstream>
#include <iostream>
std::string disp();
template<class T, class ... List>
std::string disp(T t, List ... list)
{
std::stringstream str;
str << t;
return str.str() + std::string(" ") + disp(list...);
}
std::string disp()
{
return std::string();
}
template<class ... List> struct Tuple {};
template<class T, class ... List> struct Tuple<T,List...> : Tuple<List...>
{
T objet;
Tuple(T t, List ... list): Tuple<List...>(list...),objet(t) {}
void display() const
{
std::cout << objet << " ";
Tuple<List...>::display();
}
};
template<> struct Tuple<>
{
Tuple(){}
void display() const
{
std::cout << std::endl;
}
};
template<class ... List>
Tuple<List...> make_tuple(List ... list)
{
return Tuple<List...>(list...);
}
int main()
{
std::cout << disp() << std::endl;
std::cout << disp(1,2.0) << std::endl;
std::cout << disp(1,2.0,'a') << std::endl;
std::cout << disp(1,2.0,'+',"Laurent") << std::endl;
make_tuple(1,2.0,'+',"Laurent").display();
}