-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathtest.cxx
85 lines (67 loc) · 1.96 KB
/
test.cxx
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>
#include "tuple.hxx"
int main() {
using namespace circle;
using namespace std::string_literals;
auto a = make_tuple(100, "Hello tuple", 'x');
auto b = make_tuple(21.1f, nullptr, 19i16);
auto c = make_tuple(true, 3.14l);
auto cat = tuple_cat(std::move(a), std::move(b), c);
// Print the index, the type of each element, and its value.
std::cout<< "Visit with Circle packs:\n";
std::cout<<
int...<< ": "<<
decltype(cat).tuple_elements.string << " is '"<<
cat.[:]<< "'\n" ...;
// Use apply() to visit each element.
std::cout<< "\nVisit with apply:\n";
apply([]<typename... Ts>(const Ts&... x) {
std::cout<< int...<< ": "<< Ts.string<< " is '"<< x<< "'\n" ...;
}, cat);
{
tuple<int, double, void*> tup1; // trivial
tuple<int, double, void*> tup2; { } // zeroing
tuple<int, std::string, double> tup3 { }; // default
}
{
// Construct from exact elements.
tuple<int, std::string, double> tup1(
500, "Hello world"s, 3.14
);
// Convert from elements.
tuple<int, std::string, double> tup2(
100i16, "Hello tuple", 6.28f
);
// Swap.
swap(tup1, tup2);
// Assign.
tup1 = tup2;
// Move
tup2 = std::move(tup1);
}
{
tuple<int, const char*, float> tup1(
500, "Hello world", 3.14f
);
// Converting construct from another tuple.
tuple<long, std::string, double> tup2 = tup1;
tuple<long, std::string, double> tup3 = std::move(tup1);
// Converting copy assign.
tup2 = tup1;
// Converting move assign.
tup3 = std::move(tup1);
}
{
auto pair = std::make_pair(500, "Hello pair");
// Converting construct from a pair.
tuple<long, std::string> tup1 = pair;
tuple<long, std::string> tup2 = std::move(pair);
}
{
// Construct with deduction guides.
tuple tup1 = 100;
tuple<const char*> tup2 = "Hello World";
tuple tup3(100, "Hello world", &tup1);
}
}