File: vector0.cc

package info (click to toggle)
c%2B%2B-annotations 11.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,244 kB
  • sloc: cpp: 21,698; makefile: 1,505; ansic: 165; sh: 121; perl: 90
file content (83 lines) | stat: -rw-r--r-- 1,322 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
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

//regex s_inetAddr(R"(^\s+inet addr:(\S+))");

struct VI: public vector<int>
{
    int d_v = 1;

    VI()
    {
        cout << "VI default\n";
    }
    ~VI()
    {
    }
    VI(VI const &other)
    :
        vector<int>(other),
        d_v(other.d_v)
    {
        cout << "VI copycons\n";
    }
    VI(VI &&tmp)
    :
        vector<int>(std::move(tmp)),
        d_v(tmp.d_v)
    {
        cout << "VI move cons\n";
    }

    VI &operator=(VI const &other)
    {
        VI tmp{ other };
        swap(tmp);
        return *this;
    }

    void swap(VI &other)
    {
        std::swap(d_v, other.d_v);
        static_cast<vector<int> &>(*this).swap(other);
    }

    VI &operator+=(VI const &rhs)
    {
        d_v += rhs.d_v;
        return *this;
    }
    VI &operator+=(VI &&tmp)
    {
        d_v += tmp.d_v;
        return *this;
    }
};

VI operator+(VI const &lhs, VI const &rhs)
{
    VI tmp{ lhs };

    cout << "adding, returning new object\n";

    tmp += rhs;
    return tmp;
}

VI &&operator+(VI &&tmp, VI const &rhs)
{
    cout << "adding, returning available temporary object\n";
    tmp += rhs;
    return std::move(tmp);
}

int main()
{
    VI a, b, c, d;

    d = a + b + c + d + a + b + c + d;
}