File: tie.cc

package info (click to toggle)
c%2B%2B-annotations 12.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,044 kB
  • sloc: cpp: 24,337; makefile: 1,517; ansic: 165; sh: 121; perl: 90
file content (70 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (4)
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
#include <utility>
#include <iostream>
#include <tuple>

using namespace std;

//binding
pair<int, int> factory()
{
    return { 1, 2 };
}

void fun()
{
    auto [one, two] = factory();

    cout << one << ' ' << two << '\n';
}
//=


//retrieve
void retrieve(int &one)
{
    int two;

    tie(one, two) = factory();

    cout << one << ' ' << two << '\n';
}
//=

//spaceship
struct Data
{
    int d_int;
    string d_string;
    double d_double;
};


bool operator==(Data const &lhs, Data const &rhs)
{
    return tie(lhs.d_int, lhs.d_string, lhs.d_double) ==
           tie(rhs.d_int, rhs.d_string, rhs.d_double);
}

partial_ordering operator<=>(Data const &lhs, Data const &rhs)
{
    return tie(lhs.d_int, lhs.d_string, lhs.d_double) <=>
           tie(rhs.d_int, rhs.d_string, rhs.d_double);
}
//=

int main(int argc, char **argv)
{
    fun();

//stmnts
    int one = 0;
    int two = 0;

    cout << one << ' ' << two << '\n';

    retrieve(one);

    cout << one << ' ' << two << '\n';
//=

}