Debian Codegraph @

yo/stl/examples/tie.cc

raw
1 #include <utility>
2 #include <iostream>
3 #include <tuple>
4
5 using namespace std;
6
7 //binding
8 pair<int, int> factory()
9 {
10 return { 1, 2 };
11 }
12
13 void fun()
14 {
15 auto [one, two] = factory();
16
17 cout << one << ' ' << two << '\n';
18 }
19 //=
20
21
22 //retrieve
23 void retrieve(int &one)
24 {
25 int two;
26
27 tie(one, two) = factory();
28
29 cout << one << ' ' << two << '\n';
30 }
31 //=
32
33 //spaceship
34 struct Data
35 {
36 int d_int;
37 string d_string;
38 double d_double;
39 };
40
41
42 bool operator==(Data const &lhs, Data const &rhs)
43 {
44 return tie(lhs.d_int, lhs.d_string, lhs.d_double) ==
45 tie(rhs.d_int, rhs.d_string, rhs.d_double);
46 }
47
48 partial_ordering operator<=>(Data const &lhs, Data const &rhs)
49 {
50 return tie(lhs.d_int, lhs.d_string, lhs.d_double) <=>
51 tie(rhs.d_int, rhs.d_string, rhs.d_double);
52 }
53 //=
54
55 int main(int argc, char **argv)
56 {
57 fun();
58
59 //stmnts
60 int one = 0;
61 int two = 0;
62
63 cout << one << ' ' << two << '\n';
64
65 retrieve(one);
66
67 cout << one << ' ' << two << '\n';
68 //=
69
70 }