-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtuple_cat.cpp
More file actions
43 lines (37 loc) · 754 Bytes
/
tuple_cat.cpp
File metadata and controls
43 lines (37 loc) · 754 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
38
39
40
41
42
43
#include <iostream>
#include <tuple>
#include <string>
using namespace std;
template <typename Tuple, size_t N>
struct TuplePrinter
{
static void print(Tuple const& t)
{
TuplePrinter<Tuple, N-1>::print(t);
cout << ", " << get<N-1>(t);
}
};
template <typename Tuple>
struct TuplePrinter<Tuple, 1>
{
static void print(Tuple const& t)
{
cout << get<0>(t);
}
};
template <typename... Args>
void print(const tuple<Args...>& t)
{
cout << "(";
TuplePrinter<decltype(t), sizeof...(Args)>::print(t);
cout << ")\n";
}
int main(int argc, const char *argv[])
{
tuple<int, string, float> t1(10, "Test", 3.14);
int n = 9;
auto t2 = tuple_cat(t1, make_pair("Foo", "bar"), t1, tie(n));
n = 10;
print(t2);
return 0;
}